示例#1
0
        /// <summary>
        ///     Creates the association between parameter (from the called ICallable) and its associated expression
        /// </summary>
        /// <param name="callable"></param>
        /// <returns></returns>
        private Dictionary <Parameter, Expression> CreateParameterAssociation(ICallable callable)
        {
            Dictionary <Parameter, Expression> retVal = null;

            if (callable != null)
            {
                if (callable.FormalParameters.Count == NamedActualParameters.Count + ActualParameters.Count)
                {
                    retVal = new Dictionary <Parameter, Expression>();

                    int i = 0;
                    foreach (Expression expression in ActualParameters)
                    {
                        Parameter parameter = (Parameter)callable.FormalParameters[i];
                        retVal.Add(parameter, expression);
                        i = i + 1;
                    }

                    foreach (KeyValuePair <Designator, Expression> pair in NamedActualParameters)
                    {
                        Parameter parameter = callable.GetFormalParameter(pair.Key.Image);
                        if (parameter != null)
                        {
                            retVal.Add(parameter, pair.Value);
                        }
                    }
                }
            }

            return(retVal);
        }
示例#2
0
        /// <summary>
        ///     Creates the parameter value associationg according to actual parameters
        /// </summary>
        /// <param name="context">The interpretation context</param>
        /// <param name="callable">The callable</param>
        /// <param name="log">Indicates whether errors should be logged</param>
        /// <param name="explain"></param>
        /// <returns></returns>
        public Dictionary <Actual, IValue> AssignParameterValues(InterpretationContext context, ICallable callable,
                                                                 bool log, ExplanationPart explain)
        {
            // Compute the unnamed actual parameter values
            Dictionary <Actual, IValue> retVal = new Dictionary <Actual, IValue>();

            if (callable.FormalParameters.Count == NamedActualParameters.Count + ActualParameters.Count)
            {
                int i = 0;
                foreach (Expression expression in ActualParameters)
                {
                    Parameter       parameter      = (Parameter)callable.FormalParameters[i];
                    ExplanationPart subExplanation = ExplanationPart.CreateSubExplanation(explain, parameter);
                    IValue          val            = expression.GetValue(context, subExplanation);
                    if (val != null)
                    {
                        Actual actual = parameter.CreateActual();
                        val = val.RightSide(actual, false, false);
                        retVal.Add(actual, val);
                    }
                    else
                    {
                        AddError("Cannot evaluate value for parameter " + i + " (" + expression +
                                 ") of function " + callable.Name, RuleChecksEnum.ExecutionFailed);
                        throw new Exception("Evaluation of parameters failed: Cannot evaluate value for parameter " + i +
                                            " (" + expression + ") of function " + callable.Name);
                    }
                    ExplanationPart.SetNamable(subExplanation, val);

                    i = i + 1;
                }

                foreach (KeyValuePair <Designator, Expression> pair in NamedActualParameters)
                {
                    Parameter       parameter      = callable.GetFormalParameter(pair.Key.Image);
                    ExplanationPart subExplanation = ExplanationPart.CreateSubExplanation(explain, parameter);
                    IValue          val            = pair.Value.GetValue(context, subExplanation);
                    if (val != null)
                    {
                        Actual actual = parameter.CreateActual();
                        val          = val.RightSide(actual, false, false);
                        actual.Value = val;
                        retVal.Add(actual, val);
                    }
                    else
                    {
                        AddError("Cannot evaluate value for parameter " + pair.Key + " of function " + callable.Name, RuleChecksEnum.ExecutionFailed);
                        throw new Exception("Evaluation of parameters failed: cannot evaluate value for parameter " + pair.Key + " of function " + callable.Name);
                    }
                    ExplanationPart.SetNamable(subExplanation, val);
                }
            }

            return(retVal);
        }
示例#3
0
        /// <summary>
        ///     Performs the semantic analysis of the expression
        /// </summary>
        /// <param name="instance">the reference instance on which this element should analysed</param>
        /// <param name="expectation">Indicates the kind of element we are looking for</param>
        /// <returns>True if semantic analysis should be continued</returns>
        public override bool SemanticAnalysis(INamable instance, BaseFilter expectation)
        {
            bool retVal = base.SemanticAnalysis(instance, expectation);

            if (retVal)
            {
                // Called
                if (Called != null)
                {
                    Called.SemanticAnalysis(instance, IsCallable.INSTANCE);
                    StaticUsage.AddUsages(Called.StaticUsage, Usage.ModeEnum.Call);

                    // Actual parameters
                    foreach (Expression actual in ActualParameters)
                    {
                        actual.SemanticAnalysis(instance, IsActualParameter.INSTANCE);
                        StaticUsage.AddUsages(actual.StaticUsage, Usage.ModeEnum.Read);
                    }

                    foreach (KeyValuePair <Designator, Expression> pair in NamedActualParameters)
                    {
                        ICallable called = Called.Ref as ICallable;
                        if (called != null)
                        {
                            pair.Key.Ref = called.GetFormalParameter(pair.Key.Image);
                            StaticUsage.AddUsage(pair.Key.Ref, Root, Usage.ModeEnum.Parameter);
                        }
                        pair.Value.SemanticAnalysis(instance, IsActualParameter.INSTANCE);
                        StaticUsage.AddUsages(pair.Value.StaticUsage, Usage.ModeEnum.Read);
                    }

                    ParameterAssociation = CreateParameterAssociation(Called.Ref as ICallable);
                }
                else
                {
                    AddError("Called function not provided", RuleChecksEnum.SemanticAnalysisError);
                }
            }

            return(retVal);
        }
示例#4
0
        /// <summary>
        ///     Creates the association between parameter (from the called ICallable) and its associated expression
        /// </summary>
        /// <param name="callable"></param>
        /// <returns></returns>
        private Dictionary<Parameter, Expression> CreateParameterAssociation(ICallable callable)
        {
            Dictionary<Parameter, Expression> retVal = null;

            if (callable != null)
            {
                if (callable.FormalParameters.Count == NamedActualParameters.Count + ActualParameters.Count)
                {
                    retVal = new Dictionary<Parameter, Expression>();

                    int i = 0;
                    foreach (Expression expression in ActualParameters)
                    {
                        Parameter parameter = (Parameter) callable.FormalParameters[i];
                        retVal.Add(parameter, expression);
                        i = i + 1;
                    }

                    foreach (KeyValuePair<Designator, Expression> pair in NamedActualParameters)
                    {
                        Parameter parameter = callable.GetFormalParameter(pair.Key.Image);
                        if (parameter != null)
                        {
                            retVal.Add(parameter, pair.Value);
                        }
                    }
                }
            }

            return retVal;
        }
示例#5
0
        /// <summary>
        ///     Creates the parameter value associationg according to actual parameters
        /// </summary>
        /// <param name="context">The interpretation context</param>
        /// <param name="callable">The callable</param>
        /// <param name="log">Indicates whether errors should be logged</param>
        /// <param name="explain"></param>
        /// <returns></returns>
        public Dictionary<Actual, IValue> AssignParameterValues(InterpretationContext context, ICallable callable,
            bool log, ExplanationPart explain)
        {
            // Compute the unnamed actual parameter values
            Dictionary<Actual, IValue> retVal = new Dictionary<Actual, IValue>();

            if (callable.FormalParameters.Count == NamedActualParameters.Count + ActualParameters.Count)
            {
                int i = 0;
                foreach (Expression expression in ActualParameters)
                {
                    Parameter parameter = (Parameter) callable.FormalParameters[i];
                    ExplanationPart subExplanation = ExplanationPart.CreateSubExplanation(explain, parameter);
                    IValue val = expression.GetValue(context, subExplanation);
                    if (val != null)
                    {
                        Actual actual = parameter.CreateActual();
                        val = val.RightSide(actual, false, false);
                        retVal.Add(actual, val);
                    }
                    else
                    {
                        AddError("Cannot evaluate value for parameter " + i + " (" + expression +
                                 ") of function " + callable.Name);
                        throw new Exception("Evaluation of parameters failed");
                    }
                    ExplanationPart.SetNamable(subExplanation, val);

                    i = i + 1;
                }

                foreach (KeyValuePair<Designator, Expression> pair in NamedActualParameters)
                {
                    Parameter parameter = callable.GetFormalParameter(pair.Key.Image);
                    ExplanationPart subExplanation = ExplanationPart.CreateSubExplanation(explain, parameter);
                    IValue val = pair.Value.GetValue(context, subExplanation);
                    if (val != null)
                    {
                        Actual actual = parameter.CreateActual();
                        val = val.RightSide(actual, false, false);
                        actual.Value = val;
                        retVal.Add(actual, val);
                    }
                    else
                    {
                        AddError("Cannot evaluate value for parameter " + pair.Key + " of function " + callable.Name);
                        throw new Exception("Evaluation of parameters failed");
                    }
                    ExplanationPart.SetNamable(subExplanation, val);
                }
            }

            return retVal;
        }
示例#6
0
        /// <summary>
        ///     Checks the expression and appends errors to the root tree node when inconsistencies are found
        /// </summary>
        public override void CheckExpression()
        {
            base.CheckExpression();

            Called.CheckExpression();
            ICallable called = Called.GetStaticCallable();

            if (called != null)
            {
                if (called.FormalParameters.Count != AllParameters.Count)
                {
                    AddError("Invalid number of arguments provided for function call " + ToString() + " expected " +
                             called.FormalParameters.Count + " actual " + AllParameters.Count, RuleChecksEnum.SemanticAnalysisError);
                }
                else
                {
                    Dictionary <string, Expression> actuals = new Dictionary <string, Expression>();

                    int i = 0;
                    foreach (Expression expression in ActualParameters)
                    {
                        Parameter parameter = called.FormalParameters[i] as Parameter;
                        if (parameter != null)
                        {
                            CheckActualAgainstFormal(actuals, expression, parameter);
                            i = i + 1;
                        }
                    }

                    foreach (KeyValuePair <Designator, Expression> pair in NamedActualParameters)
                    {
                        string     name       = pair.Key.Image;
                        Expression expression = pair.Value;
                        Parameter  parameter  = called.GetFormalParameter(name);
                        if (parameter == null)
                        {
                            AddError("Parameter " + name + " is not defined as formal parameter of function " +
                                     called.FullName, RuleChecksEnum.SemanticAnalysisError);
                        }
                        else
                        {
                            if (actuals.ContainsKey(name))
                            {
                                AddError("Parameter " + name + " is assigned twice in " + ToString(), RuleChecksEnum.SemanticAnalysisError);
                            }
                            else
                            {
                                CheckActualAgainstFormal(actuals, expression, parameter);
                            }
                        }
                    }

                    if (called.FormalParameters.Count > 2)
                    {
                        if (ActualParameters.Count > 0)
                        {
                            AddWarning(
                                "Calls where more than two parameters are provided must be performed using named association");
                        }
                    }

                    called.AdditionalChecks(Root, actuals);
                }
            }
            else
            {
                AddError("Cannot determine callable referenced by " + ToString(), RuleChecksEnum.SemanticAnalysisError);
            }
        }