public bool IsAssignableTo(string symbolName, Fragment fragmentType)
        {
            ArgumentUtility.CheckNotNull("symbolName", symbolName);
            ArgumentUtility.CheckNotNull("fragmentType", fragmentType);

            return(FragmentUtility.FragmentTypesAssignable(GetFragmentType(symbolName), fragmentType));
        }
Exemple #2
0
        private void CheckParameter(Expression operand, Fragment expectedFragment)
        {
            Fragment operandFragmentType = _symbolTable.InferFragmentType(operand);

            if (!FragmentUtility.FragmentTypesAssignable(operandFragmentType, expectedFragment))
            {
                ProblemMetadata problemMetadata = new ProblemMetadata(operand.UniqueKey, operand.SourceContext, expectedFragment, operandFragmentType);
                PassProblem(operand, problemMetadata);
            }
        }
        private void HandleVoidReturn(ReturnNode returnNode, HandleContext context)
        {
            foreach (var returnCondition in _blockParserContext.ReturnConditions)
            {
                Fragment blockInternalFragmentType = context.SymbolTable.GetFragmentType(returnCondition.Symbol);

                if (!FragmentUtility.FragmentTypesAssignable(blockInternalFragmentType, returnCondition.Fragment))
                {
                    ProcessBlockInternalPreConditionViolation(
                        returnNode, returnCondition, blockInternalFragmentType, context);
                }
            }
        }
Exemple #4
0
        private void ValidateAssignmentOnField(AssignmentStatement assignmentStatement, HandleContext context)
        {
            Field    targetField        = IntrospectionUtility.GetField(assignmentStatement.Target);
            Fragment targetFragmentType = FragmentUtility.GetFragmentType(targetField.Attributes);
            Fragment givenFragmentType  = context.SymbolTable.InferFragmentType(assignmentStatement.Source);

            if (!FragmentUtility.FragmentTypesAssignable(givenFragmentType, targetFragmentType))
            {
                ProblemMetadata problemMetadata = new ProblemMetadata(
                    targetField.UniqueKey,
                    targetField.SourceContext,
                    targetFragmentType,
                    givenFragmentType);
                _blockParserContext.ProblemPipe.AddProblem(problemMetadata);
            }
        }
        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 NamedFragmentAssignableToUndefinedFragment()
 {
     FragmentUtility.FragmentTypesAssignable(Fragment.CreateNamed("dummy"), Fragment.CreateUndefined());
 }
        protected override bool ViolationCheckStrategy(ISymbolTable context)
        {
            Fragment givenFragment = context.GetFragmentType(_symbol);

            return(!FragmentUtility.FragmentTypesAssignable(givenFragment, _fragment));
        }