public override void VisitFieldInitializer(IFieldInitializer operation)
        {
            LogString(nameof(IFieldInitializer));

            if (operation.InitializedFields.Length <= 1)
            {
                if (operation.InitializedFields.Length == 1)
                {
                    LogSymbol(operation.InitializedFields[0], header: " (Field");
                    LogString(")");
                }

                LogCommonPropertiesAndNewLine(operation);
            }
            else
            {
                LogString($" ({operation.InitializedFields.Length} initialized fields)");
                LogCommonPropertiesAndNewLine(operation);

                Indent();

                int index = 1;
                foreach (var local in operation.InitializedFields)
                {
                    LogSymbol(local, header: $"Field_{index++}");
                    LogNewLine();
                }

                Unindent();
            }

            base.VisitFieldInitializer(operation);
        }
Esempio n. 2
0
 public override void VisitFieldInitializer(IFieldInitializer operation)
 {
     foreach (var field in operation.InitializedFields)
     {
         // empty loop body, just want to make sure it won't crash.
     }
     base.VisitFieldInitializer(operation);
 }
Esempio n. 3
0
        internal Field(int width, int height, IFieldInitializer initializer)
        {
            _width       = width > 0 ? width : throw new ArgumentOutOfRangeException(nameof(width));
            _height      = height > 0 ? height : throw new ArgumentOutOfRangeException(nameof(height));
            _initializer = initializer ?? throw new ArgumentNullException(nameof(initializer));

            _cells    = new byte[width, height];
            _rotation = new byte[width, height];
        }
Esempio n. 4
0
        private void LoadInitializer(XmlElement fieldElement)
        {
            XmlElement initializerElement = fieldElement.SelectSingleNode("*") as XmlElement;

            if (null == initializerElement)
            {
                _initializer = DefaultFieldInitializer;
            }
            else
            {
                _initializer = LoadRegisteredInitializer(initializerElement);
            }
        }
Esempio n. 5
0
            private void AnalyzeFieldDeclaration(OperationAnalysisContext context)
            {
                IFieldInitializer fieldInit = context.Operation as IFieldInitializer;

                if (fieldInit == null)
                {
                    return;
                }

                foreach (IFieldSymbol field in fieldInit.InitializedFields)
                {
                    IOperation valueOperation = fieldInit.Value;
                    AnalyzeObjectCreationInternal(context, field, valueOperation);
                }
            }
        public virtual void InitializeObject(MigrationContext context)
        {
            Type        type    = context.CurrentObject.GetType();
            TypeMapping mapping = context.GetTypeMapping(type);

            if (null == mapping)
            {
                mapping = TypeMapping.Default;
            }

            FieldInfo[] fields = context.GetSerializableFields(type);
            foreach (FieldInfo field in fields)
            {
                context.EnterField(field);

                IFieldInitializer initializer = mapping.GetFieldInitializer(field.Name);
                initializer.InitializeField(context);

                context.LeaveField();
            }
        }
        public sealed override void Initialize(AnalysisContext context)
        {
            context.RegisterCompilationStartAction(
                (compilationContext) =>
            {
                Dictionary <IFieldSymbol, HashSet <INamedTypeSymbol> > fieldsSourceTypes = new Dictionary <IFieldSymbol, HashSet <INamedTypeSymbol> >();

                compilationContext.RegisterOperationBlockStartAction(
                    (operationBlockContext) =>
                {
                    if (operationBlockContext.OwningSymbol is IMethodSymbol containingMethod)
                    {
                        Dictionary <ILocalSymbol, HashSet <INamedTypeSymbol> > localsSourceTypes = new Dictionary <ILocalSymbol, HashSet <INamedTypeSymbol> >();

                        // Track explicit assignments.
                        operationBlockContext.RegisterOperationAction(
                            (operationContext) =>
                        {
                            if (operationContext.Operation is IAssignmentExpression assignment)
                            {
                                AssignTo(assignment.Target, localsSourceTypes, fieldsSourceTypes, assignment.Value);
                            }
                            else if (operationContext.Operation is IIncrementOrDecrementExpression increment)
                            {
                                SyntaxNode syntax = increment.Syntax;
                                ITypeSymbol type  = increment.Type;
                                Optional <object> constantValue = new Optional <object>(1);
                                bool isImplicit = increment.IsImplicit;
                                var value       = new LiteralExpression(operationContext.Compilation.GetSemanticModel(syntax.SyntaxTree), syntax, type, constantValue, isImplicit);

                                AssignTo(increment.Target, localsSourceTypes, fieldsSourceTypes, value);
                            }
                            else
                            {
                                throw TestExceptionUtilities.UnexpectedValue(operationContext.Operation);
                            }
                        },
                            OperationKind.SimpleAssignmentExpression,
                            OperationKind.CompoundAssignmentExpression,
                            OperationKind.IncrementExpression);

                        // Track arguments that match out or ref parameters.
                        operationBlockContext.RegisterOperationAction(
                            (operationContext) =>
                        {
                            IInvocationExpression invocation = (IInvocationExpression)operationContext.Operation;
                            foreach (IArgument argument in invocation.ArgumentsInEvaluationOrder)
                            {
                                if (argument.Parameter.RefKind == RefKind.Out || argument.Parameter.RefKind == RefKind.Ref)
                                {
                                    AssignTo(argument.Value, localsSourceTypes, fieldsSourceTypes, argument.Parameter.Type);
                                }
                            }
                        },
                            OperationKind.InvocationExpression);

                        // Track local variable initializations.
                        operationBlockContext.RegisterOperationAction(
                            (operationContext) =>
                        {
                            IVariableDeclarationStatement declaration = (IVariableDeclarationStatement)operationContext.Operation;
                            foreach (IVariableDeclaration variable in declaration.Declarations)
                            {
                                foreach (ILocalSymbol local in variable.Variables)
                                {
                                    if (variable.Initializer != null)
                                    {
                                        AssignTo(local, local.Type, localsSourceTypes, variable.Initializer);
                                    }
                                }
                            }
                        },
                            OperationKind.VariableDeclarationStatement);

                        // Report locals that could have more specific types.
                        operationBlockContext.RegisterOperationBlockEndAction(
                            (operationBlockEndContext) =>
                        {
                            foreach (ILocalSymbol local in localsSourceTypes.Keys)
                            {
                                if (HasMoreSpecificSourceType(local, local.Type, localsSourceTypes, out var mostSpecificSourceType))
                                {
                                    Report(operationBlockEndContext, local, mostSpecificSourceType, LocalCouldHaveMoreSpecificTypeDescriptor);
                                }
                            }
                        });
                    }
                });

                // Track field initializations.
                compilationContext.RegisterOperationAction(
                    (operationContext) =>
                {
                    IFieldInitializer initializer = (IFieldInitializer)operationContext.Operation;
                    foreach (IFieldSymbol initializedField in initializer.InitializedFields)
                    {
                        AssignTo(initializedField, initializedField.Type, fieldsSourceTypes, initializer.Value);
                    }
                },
                    OperationKind.FieldInitializer);

                // Report fields that could have more specific types.
                compilationContext.RegisterCompilationEndAction(
                    (compilationEndContext) =>
                {
                    foreach (IFieldSymbol field in fieldsSourceTypes.Keys)
                    {
                        if (HasMoreSpecificSourceType(field, field.Type, fieldsSourceTypes, out var mostSpecificSourceType))
                        {
                            Report(compilationEndContext, field, mostSpecificSourceType, FieldCouldHaveMoreSpecificTypeDescriptor);
                        }
                    }
                });
            });
        }
Esempio n. 8
0
 public override void VisitFieldInitializer(IFieldInitializer operation)
 {
     Visit(operation.Value);
 }
Esempio n. 9
0
 void IPoolFieldsInitializable.OnPrePoolFieldsInitialize(IFieldInitializer initializer)
 {
     InitializeHierarchyIfNeeded();
     InitializeComponentsIfNeeded();
 }
        public sealed override void Initialize(AnalysisContext context)
        {
            context.RegisterCompilationStartAction(
                (compilationContext) =>
            {
                Dictionary <IFieldSymbol, HashSet <INamedTypeSymbol> > fieldsSourceTypes = new Dictionary <IFieldSymbol, HashSet <INamedTypeSymbol> >();

                compilationContext.RegisterOperationBlockStartAction(
                    (operationBlockContext) =>
                {
                    if (operationBlockContext.OwningSymbol is IMethodSymbol containingMethod)
                    {
                        Dictionary <ILocalSymbol, HashSet <INamedTypeSymbol> > localsSourceTypes = new Dictionary <ILocalSymbol, HashSet <INamedTypeSymbol> >();

                        // Track explicit assignments.
                        operationBlockContext.RegisterOperationAction(
                            (operationContext) =>
                        {
                            IAssignmentExpression assignment = (IAssignmentExpression)operationContext.Operation;
                            AssignTo(assignment.Target, localsSourceTypes, fieldsSourceTypes, assignment.Value);
                        },
                            OperationKind.AssignmentExpression,
                            OperationKind.CompoundAssignmentExpression,
                            OperationKind.IncrementExpression);

                        // Track arguments that match out or ref parameters.
                        operationBlockContext.RegisterOperationAction(
                            (operationContext) =>
                        {
                            IInvocationExpression invocation = (IInvocationExpression)operationContext.Operation;
                            foreach (IArgument argument in invocation.ArgumentsInEvaluationOrder)
                            {
                                if (argument.Parameter.RefKind == RefKind.Out || argument.Parameter.RefKind == RefKind.Ref)
                                {
                                    AssignTo(argument.Value, localsSourceTypes, fieldsSourceTypes, argument.Parameter.Type);
                                }
                            }
                        },
                            OperationKind.InvocationExpression);

                        // Track local variable initializations.
                        operationBlockContext.RegisterOperationAction(
                            (operationContext) =>
                        {
                            IVariableDeclarationStatement declaration = (IVariableDeclarationStatement)operationContext.Operation;
                            foreach (IVariableDeclaration variable in declaration.Declarations)
                            {
                                foreach (ILocalSymbol local in variable.Variables)
                                {
                                    if (variable.Initializer != null)
                                    {
                                        AssignTo(local, local.Type, localsSourceTypes, variable.Initializer);
                                    }
                                }
                            }
                        },
                            OperationKind.VariableDeclarationStatement);

                        // Report locals that could have more specific types.
                        operationBlockContext.RegisterOperationBlockEndAction(
                            (operationBlockEndContext) =>
                        {
                            foreach (ILocalSymbol local in localsSourceTypes.Keys)
                            {
                                if (HasMoreSpecificSourceType(local, local.Type, localsSourceTypes, out var mostSpecificSourceType))
                                {
                                    Report(operationBlockEndContext, local, mostSpecificSourceType, LocalCouldHaveMoreSpecificTypeDescriptor);
                                }
                            }
                        });
                    }
                });

                // Track field initializations.
                compilationContext.RegisterOperationAction(
                    (operationContext) =>
                {
                    IFieldInitializer initializer = (IFieldInitializer)operationContext.Operation;
                    foreach (IFieldSymbol initializedField in initializer.InitializedFields)
                    {
                        AssignTo(initializedField, initializedField.Type, fieldsSourceTypes, initializer.Value);
                    }
                },
                    OperationKind.FieldInitializerAtDeclaration);

                // Report fields that could have more specific types.
                compilationContext.RegisterCompilationEndAction(
                    (compilationEndContext) =>
                {
                    foreach (IFieldSymbol field in fieldsSourceTypes.Keys)
                    {
                        if (HasMoreSpecificSourceType(field, field.Type, fieldsSourceTypes, out var mostSpecificSourceType))
                        {
                            Report(compilationEndContext, field, mostSpecificSourceType, FieldCouldHaveMoreSpecificTypeDescriptor);
                        }
                    }
                });
            });
        }
 void IPoolFieldsInitializable.OnPostPoolFieldsInitialize(IFieldInitializer initializer)
 {
 }
		public CustomInitializer(XmlElement element)
		{
			_custom = (IFieldInitializer)InitializerHelper.LoadInitializer(element);
		}
Esempio n. 13
0
 void IPoolFieldsInitializable.OnPostPoolFieldsInitialize(IFieldInitializer initializer)
 {
 }
Esempio n. 14
0
 public override IOperation VisitFieldInitializer(IFieldInitializer operation, object argument)
 {
     return(new FieldInitializer(operation.InitializedFields, Visit(operation.Value), operation.Kind, ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit));
 }
Esempio n. 15
0
 public Game(int width, int height, IFieldInitializer initializer, IFieldVisualizer visualizer)
 {
     _field      = new Field(width, height, initializer);
     _visualizer = visualizer ?? throw new ArgumentNullException(nameof(visualizer));
 }
Esempio n. 16
0
 public override void VisitFieldInitializer(IFieldInitializer operation)
 {
     foreach (var field in operation.InitializedFields)
     {
         // empty loop body, just want to make sure it won't crash.
     }
     base.VisitFieldInitializer(operation);
 }
Esempio n. 17
0
		private void LoadInitializer(XmlElement fieldElement)
		{
			XmlElement initializerElement = fieldElement.SelectSingleNode("*") as XmlElement;
			if (null == initializerElement)
			{
				_initializer = DefaultFieldInitializer;
			}
			else
			{
				_initializer = LoadRegisteredInitializer(initializerElement);
			}
		}
 void IPoolFieldsInitializable.OnPrePoolFieldsInitialize(IFieldInitializer initializer)
 {
     Initialize();
 }
Esempio n. 19
0
 public virtual void VisitFieldInitializer(IFieldInitializer operation)
 {
     DefaultVisit(operation);
 }
Esempio n. 20
0
 void IPoolFieldsInitializable.OnPrePoolFieldsInitialize(IFieldInitializer initializer)
 {
     Initialize();
 }
Esempio n. 21
0
 public CustomInitializer(XmlElement element)
 {
     _custom = (IFieldInitializer)InitializerHelper.LoadInitializer(element);
 }
Esempio n. 22
0
 public virtual void VisitFieldInitializer(IFieldInitializer operation)
 {
     DefaultVisit(operation);
 }
Esempio n. 23
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            field = new Field(400, 400);
            fieldInitializer = new RandomFieldInitializer();
            rule = new RegularCellRule();
            InitializeStartPopulation();

            int fieldWidth = graphics.PreferredBackBufferWidth / field.Columns;
            int fieldHeight = graphics.PreferredBackBufferHeight / field.Rows;

            InitializeRectangles(fieldWidth, fieldHeight);

            base.Initialize();
        }
Esempio n. 24
0
 /// <inheritdoc />
 public override Expression VisitFieldInitializer(IFieldInitializer operation, LocalBinder argument)
 {
     return(base.VisitFieldInitializer(operation, argument));
 }
Esempio n. 25
0
 void IPoolFieldsInitializable.OnPrePoolFieldsInitialize(IFieldInitializer initializer)
 {
     InitializeHierarchyIfNeeded();
     InitializeComponentsIfNeeded();
 }
Esempio n. 26
0
 public void OnPostPoolFieldsInitialize(IFieldInitializer initializer)
 {
 }
 /// <inheritdoc />
 public override IOperation VisitFieldInitializer(IFieldInitializer operation, object argument)
 {
     return(base.VisitFieldInitializer(operation, argument));
 }