Exemplo n.º 1
0
        protected override void HandleStatement(HandleContext context)
        {
            AssignmentStatement assignment = (AssignmentStatement)context.Statement;

            if (!CoversAssignment(assignment))
            {
                return;
            }

            Method sourceConstructor             = ExtractConstructor(assignment.Source);
            string variableName                  = IntrospectionUtility.GetVariableName(assignment.Target);
            bool   fragmentTypeInferenceRequired = FirstParameterIsString(sourceConstructor);

            if (fragmentTypeInferenceRequired)
            {
                Fragment fragmentType = FirstOperandsFragmentType(assignment, context);
                context.StringBuilderFragmentTypeDefined[variableName] = true;
                context.SymbolTable.MakeSafe(variableName, fragmentType);
            }
            else
            {
                //context.StringBuilderFragmentTypeDefined[variableName] = false;
                context.SymbolTable.MakeSafe(variableName, Fragment.CreateUndefined());
            }
        }
        public void GetVariableName_Indexer_ReturnsNameOfDeclaringObject()
        {
            Method sampleMethod = TestHelper.GetSample <IntrospectionUtility_ClassSample> ("ArrayVariableAndIndexer");
            Block  sampleBlock  = (Block)sampleMethod.Body.Statements[0];
            AssignmentStatement sampleAssignment = (AssignmentStatement)sampleBlock.Statements[2];
            Expression          sample           = sampleAssignment.Target;

            Assert.That(IntrospectionUtility.GetVariableName(sample), Is.EqualTo("local$0"));
        }
        public void GetVariableName_Method_IsNull()
        {
            Method sample          = TestHelper.GetSample <IntrospectionUtility_ClassSample>("UsingField");
            Block  expressionBlock = (Block)sample.Body.Statements[0];
            ExpressionStatement expressionStatement   = (ExpressionStatement)expressionBlock.Statements[1];
            UnaryExpression     sampleUnaryExpression = (UnaryExpression)expressionStatement.Expression;
            MethodCall          sampleMethodCall      = (MethodCall)sampleUnaryExpression.Operand;
            string variableName = IntrospectionUtility.GetVariableName(sampleMethodCall);

            Assert.That(variableName, Is.Null);
        }
Exemplo n.º 4
0
        private void AddBlockAssignment(AssignmentStatement assignmentStatement, HandleContext context)
        {
            string targetSymbol = IntrospectionUtility.GetVariableName(assignmentStatement.Target);
            string sourceSymbol = IntrospectionUtility.GetVariableName(assignmentStatement.Source);

            if (targetSymbol != null && sourceSymbol != null)
            {
                BlockAssignment blockAssignment = new BlockAssignment(sourceSymbol, targetSymbol);
                context.BlockAssignments.Add(blockAssignment);
            }
        }
        public void GetVariableName_FieldInMemberbinding_ReturnsName()
        {
            Method sample          = TestHelper.GetSample <IntrospectionUtility_ClassSample>("UsingField");
            Block  expressionBlock = (Block)sample.Body.Statements[0];
            ExpressionStatement expressionStatement   = (ExpressionStatement)expressionBlock.Statements[1];
            UnaryExpression     sampleUnaryExpression = (UnaryExpression)expressionStatement.Expression;
            MethodCall          sampleMethodCall      = (MethodCall)sampleUnaryExpression.Operand;
            Expression          sampleExpression      = sampleMethodCall.Operands[0];
            string variableName = IntrospectionUtility.GetVariableName(sampleExpression);

            Assert.That(variableName, Is.EqualTo("_field"));
        }
Exemplo n.º 6
0
        private void PassReturnFragmentTypeToContext(Expression operand, Parameter parameter)
        {
            string   symbol       = IntrospectionUtility.GetVariableName(operand);
            Fragment fragmentType = FragmentUtility.GetFragmentType(parameter.Attributes);

            if (FragmentUtility.ContainsFragment(parameter.Attributes))
            {
                _symbolTable.MakeSafe(symbol, fragmentType);
            }
            else
            {
                _symbolTable.MakeUnsafe(symbol);
            }
        }
        private void HandleReturnType(ReturnNode returnNode, HandleContext context)
        {
            _blockParserContext.Inspect(returnNode.Expression);
            string returnSymbol = IntrospectionUtility.GetVariableName(returnNode.Expression);

            if (returnSymbol != null)
            {
                ProblemMetadata problemMetadata = new ProblemMetadata(
                    returnNode.UniqueKey, returnNode.SourceContext, _blockParserContext.ReturnFragmentType, context.SymbolTable.GetFragmentType(returnSymbol));
                AssignabilityPreCondition returnBlockCondition = new AssignabilityPreCondition(
                    returnSymbol, _blockParserContext.ReturnFragmentType, problemMetadata);
                context.PreConditions.Add(returnBlockCondition);
                context.PreConditions.AddRange(_blockParserContext.ReturnConditions);
            }
        }
Exemplo n.º 8
0
        private List <ReturnCondition> ReferenceAndOutConditions(Method method)
        {
            List <ReturnCondition> referenceAndOutConditions = new List <ReturnCondition>();

            foreach (var parameter in method.Parameters)
            {
                if (parameter.Type is Reference && parameter.Attributes != null)
                {
                    Fragment parameterFragmentType = FragmentUtility.GetFragmentType(parameter.Attributes);
                    if (parameterFragmentType != null)
                    {
                        string          parameterName   = IntrospectionUtility.GetVariableName(parameter);
                        ReturnCondition returnCondition = new ReturnCondition(parameterName, parameterFragmentType);
                        referenceAndOutConditions.Add(returnCondition);
                    }
                }
            }
            return(referenceAndOutConditions);
        }
Exemplo n.º 9
0
        private void AddAssignmentPreCondition(AssignmentStatement assignmentStatement, HandleContext context)
        {
            Field    targetField        = IntrospectionUtility.GetField(assignmentStatement.Target);
            Fragment targetFragmentType = FragmentUtility.GetFragmentType(targetField.Attributes);

            if (targetFragmentType != Fragment.CreateEmpty())
            {
                ProblemMetadata problemMetadata = new ProblemMetadata(
                    assignmentStatement.UniqueKey,
                    assignmentStatement.SourceContext,
                    targetFragmentType,
                    Fragment.CreateNamed("??"));
                string sourceSymbol = IntrospectionUtility.GetVariableName(assignmentStatement.Source);
                if (sourceSymbol != null)
                {
                    AssignabilityPreCondition preCondition = new AssignabilityPreCondition(sourceSymbol, targetFragmentType, problemMetadata);
                    context.PreConditions.Add(preCondition);
                }
            }
        }
Exemplo n.º 10
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);
        }
        protected override void HandleStatement(HandleContext context)
        {
            AssignmentStatement assignmentStatement = (AssignmentStatement)context.Statement;

            if (!CoversAssignment(assignmentStatement))
            {
                return;
            }

            Indexer targetIndexer = (Indexer)assignmentStatement.Target;
            string  targetName    = IntrospectionUtility.GetVariableName(targetIndexer.Object);

            if (context.ArrayFragmentTypeDefined.ContainsKey(targetName))
            {
                InferArrayFragment(assignmentStatement, targetName, context);
            }
            else
            {
                CheckAssignment(assignmentStatement, targetName, context);
            }

            _blockParserContext.Inspect(assignmentStatement.Source);
        }