Beispiel #1
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);
            }
        }