public void IsField_NonFieldAssignment_ReturnsFalse()
        {
            Method sample          = TestHelper.GetSample <IntrospectionUtility_ClassSample> ("NonFieldAssignment");
            Block  assignmentBlock = (Block)sample.Body.Statements[0];
            AssignmentStatement assignmentStatement = (AssignmentStatement)assignmentBlock.Statements[1];
            Expression          sampleExpression    = assignmentStatement.Target;
            bool fieldRecognized = IntrospectionUtility.IsField(sampleExpression);

            Assert.That(fieldRecognized, Is.False);
        }
示例#2
0
        protected override void HandleStatement(HandleContext context)
        {
            AssignmentStatement assignmentStatement = (AssignmentStatement)context.Statement;

            string targetSymbol = IntrospectionUtility.GetVariableName(assignmentStatement.Target);

            context.AssignmentTargetVariables.Add(targetSymbol);
            string sourceSymbol = IntrospectionUtility.GetVariableName(assignmentStatement.Source);
            bool   localSourceVariableNotAssignedInsideCurrentBlock =
                sourceSymbol != null &&
                !context.AssignmentTargetVariables.Contains(sourceSymbol) &&
                !IntrospectionUtility.IsField(assignmentStatement.Source);
            bool targetIsField = IntrospectionUtility.IsField(assignmentStatement.Target);

            if (localSourceVariableNotAssignedInsideCurrentBlock)
            {
                if (targetIsField)
                {
                    AddAssignmentPreCondition(assignmentStatement, context);
                }
                else
                {
                    AddBlockAssignment(assignmentStatement, context);
                }
            }
            else
            {
                if (targetIsField)
                {
                    ValidateAssignmentOnField(assignmentStatement, context);
                }
                else
                {
                    context.SymbolTable.InferSafeness(targetSymbol, assignmentStatement.Source);
                }
            }
            _blockParserContext.Inspect(assignmentStatement.Source);
        }