Exemplo n.º 1
0
        private void PassProblem(Expression problemSource, ProblemMetadata problemMetadata)
        {
            string   variableName;
            Fragment expectedFragment = problemMetadata.ExpectedFragment;

            if (ExpressionIsVariableFromPrecedingBlock(problemSource, out variableName))
            {
                _preConditions.Add(new AssignabilityPreCondition(variableName, expectedFragment, problemMetadata));
            }
            else if (problemSource is MethodCall)
            {
                MethodCall methodCall   = (MethodCall)problemSource;
                Method     calleeMethod = IntrospectionUtility.ExtractMethod(methodCall);

                if (_customInferenceController.Analyzes(calleeMethod))
                {
                    _customInferenceController.PassProblem(methodCall, _preConditions, problemMetadata, _symbolTable, _problemPipe);
                }
                else
                {
                    _problemPipe.AddProblem(problemMetadata);
                }
            }
            else
            {
                _problemPipe.AddProblem(problemMetadata);
            }
        }
        public void Analyze(MethodCall methodCall, ISymbolTable context, List <IPreCondition> preConditions)
        {
            Method           calleeMethod = IntrospectionUtility.ExtractMethod(methodCall);
            ICustomInference matchingRule = MatchingAnalyzeRule(calleeMethod);

            if (matchingRule != null)
            {
                matchingRule.Analyze(methodCall, context, preConditions);
            }
        }
        public Fragment InferFragmentType(MethodCall methodCall, ISymbolTable context)
        {
            Fragment returnFragment = Fragment.CreateEmpty();
            Method   calleeMethod   = IntrospectionUtility.ExtractMethod(methodCall);

            if (_coveredMethods.Contains(calleeMethod.FullName))
            {
                returnFragment = ParameterFragmentUtility.ParameterFragmentIntersection(methodCall, context);
            }
            return(returnFragment);
        }
        public void PassProblem(
            MethodCall methodCall, List <IPreCondition> preConditions, ProblemMetadata problemMetadata, ISymbolTable symbolTable, IProblemPipe problemPipe)
        {
            Method           calleeMethod = IntrospectionUtility.ExtractMethod(methodCall);
            ICustomInference matchingRule = MatchingAnalyzeRule(calleeMethod);

            if (matchingRule != null)
            {
                matchingRule.PassProblem(methodCall, preConditions, problemMetadata, symbolTable, problemPipe);
            }
        }
        public Fragment InferFragmentType(MethodCall methodCall, ISymbolTable context)
        {
            Fragment         fragmentType = Fragment.CreateEmpty();
            Method           calleeMethod = IntrospectionUtility.ExtractMethod(methodCall);
            ICustomInference matchingRule = MatchingInferRule(calleeMethod);

            if (matchingRule != null)
            {
                fragmentType = matchingRule.InferFragmentType(methodCall, context);
            }
            return(fragmentType);
        }
Exemplo n.º 6
0
        private void CheckParameters(MethodCall methodCall)
        {
            ArgumentUtility.CheckNotNull("methodCall", methodCall);
            Method calleeMethod = IntrospectionUtility.ExtractMethod(methodCall);

            _parameterFragmentTypes = _symbolTable.InferParameterFragmentTypes(calleeMethod);

            for (int i = 0; i < _parameterFragmentTypes.Length; i++)
            {
                Expression operand          = methodCall.Operands[i];
                Fragment   expectedFragment = _parameterFragmentTypes[i];
                CheckParameter(operand, expectedFragment);
            }
        }
Exemplo n.º 7
0
        private void UpdateOutAndRefSymbols(MethodCall methodCall)
        {
            Method method = IntrospectionUtility.ExtractMethod(methodCall);

            for (int i = 0; i < methodCall.Operands.Count; i++)
            {
                bool isReturnParameter = IntrospectionUtility.IsVariable(methodCall.Operands[i]) &&
                                         (method.Parameters[i].IsOut || method.Parameters[i].Type is Reference);

                if (isReturnParameter)
                {
                    PassReturnFragmentTypeToContext(methodCall.Operands[i], method.Parameters[i]);
                }
            }
        }
Exemplo n.º 8
0
        public void Analyze(MethodCall methodCall, ISymbolTable symbolTable, List <IPreCondition> preConditions)
        {
            _symbolTable   = symbolTable;
            _preConditions = preConditions;
            Method calleeMethod = IntrospectionUtility.ExtractMethod(methodCall);

            if (_customInferenceController.Analyzes(calleeMethod))
            {
                //_customInferenceController.InferFragmentType(methodCall, symbolTable);
                _customInferenceController.Analyze(methodCall, symbolTable, preConditions);
            }
            else
            {
                AnalyzeOrdinaryMethodCall(methodCall);
            }
        }
Exemplo n.º 9
0
        private Fragment InferMethodCallReturnFragmentType(MethodCall methodCall)
        {
            Fragment returnFragment;
            Method   calleeMethod = IntrospectionUtility.ExtractMethod(methodCall);

            if (_customInferenceController.Infers(calleeMethod))
            {
                returnFragment = _customInferenceController.InferFragmentType(methodCall, this);
            }
            else
            {
                returnFragment = FragmentUtility.InferReturnFragmentType(calleeMethod);
            }

            return(returnFragment);
        }
        public Fragment InferFragmentType(MethodCall methodCall, ISymbolTable context)
        {
            Fragment returnFragment = Fragment.CreateEmpty();
            Method   method         = IntrospectionUtility.ExtractMethod(methodCall);

            if (Infers(method) && methodCall.Callee is MemberBinding)
            {
                MemberBinding memberBinding = (MemberBinding)methodCall.Callee;
                string        variableName;
                if (IntrospectionUtility.IsVariable(memberBinding.TargetObject, out variableName))
                {
                    returnFragment = context.GetFragmentType(variableName);
                }
            }
            return(returnFragment);
        }
        public void Analyze(MethodCall methodCall, ISymbolTable context, List <IPreCondition> preConditions)
        {
            Method method = IntrospectionUtility.ExtractMethod(methodCall);

            if (Analyzes(method) && methodCall.Callee is MemberBinding)
            {
                MemberBinding memberBinding = (MemberBinding)methodCall.Callee;

                if (IsFragmentParameterInferenceMethod(method))
                {
                    string variableName;
                    if (IntrospectionUtility.IsVariable(memberBinding.TargetObject, out variableName))
                    {
                        Fragment parameterFragment    = ParameterFragmentUtility.ParameterFragmentIntersection(methodCall, context);
                        Fragment targetObjectFragment = context.GetFragmentType(variableName);
                        if (targetObjectFragment == Fragment.CreateLiteral() || targetObjectFragment.Undefined)
                        {
                            context.MakeSafe(variableName, parameterFragment);
                        }
                        else
                        {
                            if (targetObjectFragment == Fragment.CreateEmpty() && parameterFragment != Fragment.CreateLiteral()) // && parameterFragment != Fragment.CreateEmpty()
                            {
                                ProblemMetadata problemMetadata = new ProblemMetadata(methodCall.UniqueKey, methodCall.SourceContext, parameterFragment, targetObjectFragment);
                                IPreCondition   precondition    = new CustomInferencePreCondition(variableName, parameterFragment, problemMetadata);
                                preConditions.Add(precondition);
                            }
                            else if (!FragmentUtility.FragmentTypesAssignable(parameterFragment, targetObjectFragment))
                            {
                                context.MakeUnsafe(variableName);
                            }
                        }
                    }
                }
                else if (!IsSafeMethod(method))
                {
                    string variableName;
                    if (IntrospectionUtility.IsVariable(memberBinding.TargetObject, out variableName))
                    {
                        context.MakeUnsafe(variableName);
                    }
                }
            }
        }
        public void PassProblem(
            MethodCall methodCall, List <IPreCondition> preConditions, ProblemMetadata problemMetadata, ISymbolTable symbolTable, IProblemPipe problemPipe)
        {
            Method calleeMethod = IntrospectionUtility.ExtractMethod(methodCall);

            if (_coveredMethods.Contains(calleeMethod.FullName))
            {
                foreach (var operand in methodCall.Operands)
                {
                    string nestedVariableName;
                    if (OperandIsVariableFromPrecedingBlock(operand, symbolTable, out nestedVariableName))
                    {
                        preConditions.Add(new AssignabilityPreCondition(nestedVariableName, problemMetadata.ExpectedFragment, problemMetadata));
                    }
                    else
                    {
                        problemPipe.AddProblem(problemMetadata);
                    }
                }
            }
        }