CheckExpression() public method

Checks the expression and appends errors to the root tree node when inconsistencies are found
public CheckExpression ( ) : void
return void
Exemplo n.º 1
0
        /// <summary>
        ///     Checks the expression and appends errors to the root tree node when inconsistencies are found
        /// </summary>
        public override void CheckExpression()
        {
            Structure structureType = Structure.GetExpressionType() as Structure;

            if (structureType != null)
            {
                if (structureType.IsAbstract)
                {
                    AddError("Instantiation of abstract types is forbidden", RuleChecksEnum.SyntaxError);
                }
                foreach (KeyValuePair <Designator, Expression> pair in Associations)
                {
                    Designator name       = pair.Key;
                    Expression expression = pair.Value;

                    List <INamable> targets = new List <INamable>();
                    structureType.Find(name.Image, targets);
                    if (targets.Count > 0)
                    {
                        expression.CheckExpression();
                        Type type = expression.GetExpressionType();
                        if (type != null)
                        {
                            if (type.IsAbstract)
                            {
                                AddError("Instantiation of abstract types is forbidden", RuleChecksEnum.SyntaxError);
                            }
                            else
                            {
                                foreach (INamable namable in targets)
                                {
                                    ITypedElement element = namable as ITypedElement;
                                    if (element != null && element.Type != null)
                                    {
                                        if (!element.Type.Match(type))
                                        {
                                            AddError("Expression " + expression + " type (" + type.FullName +
                                                     ") does not match the target element " + element.Name + " type (" +
                                                     element.Type.FullName + ")", RuleChecksEnum.SyntaxError);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            AddError("Expression " + expression + " type cannot be found", RuleChecksEnum.SyntaxError);
                        }
                    }
                    else
                    {
                        Root.AddError("Cannot find " + name + " in structure " + Structure);
                    }
                }
            }
            else
            {
                AddError("Cannot find structure type " + Structure, RuleChecksEnum.SyntaxError);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Checks the expression and appends errors to the root tree node when inconsistencies are found
        /// </summary>
        public override void CheckExpression()
        {
            base.CheckExpression();

            BindingExpression.CheckExpression();
            Expression.CheckExpression();
        }
Exemplo n.º 3
0
        private void CheckActualAgainstFormal(Dictionary <string, Expression> actuals, Expression expression,
                                              Parameter parameter)
        {
            actuals[parameter.Name] = expression;

            expression.CheckExpression();
            Type argumentType = expression.GetExpressionType();

            if (argumentType == null)
            {
                AddError("Cannot evaluate argument type for argument " + expression, RuleChecksEnum.SemanticAnalysisError);
            }
            else
            {
                if (parameter.Type == null)
                {
                    AddError("Cannot evaluate formal parameter type for " + parameter.Name, RuleChecksEnum.SemanticAnalysisError);
                }
                else
                {
                    if (!parameter.Type.Match(argumentType))
                    {
                        AddError("Invalid argument " + expression + " type, expected " +
                                 parameter.Type.FullName + ", actual " + argumentType.FullName, RuleChecksEnum.SemanticAnalysisError);
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Checks the expression and appends errors to the root tree node when inconsistencies are found
        /// </summary>
        public override void CheckExpression()
        {
            base.CheckExpression();

            if (Term != null)
            {
                Term.CheckExpression();
            }
            if (Expression != null)
            {
                Expression.CheckExpression();
            }
        }
        /// <summary>
        ///     Checks the expression and appends errors to the root tree node when inconsistencies are found
        /// </summary>
        public override void CheckExpression()
        {
            base.CheckExpression();

            InitialValue.CheckExpression();
            Type initialValueType = InitialValue.GetExpressionType();

            if (initialValueType != null)
            {
                Expression.CheckExpression();
                Type expressionType = Expression.GetExpressionType();
                if (expressionType != null)
                {
                    if (expressionType != initialValueType)
                    {
                        AddError("Expression " + Expression + " has not the same type (" + expressionType.FullName +
                                 " than initial value " + InitialValue + " type " + initialValueType.FullName, RuleChecksEnum.SemanticAnalysisError);
                    }
                }
                else
                {
                    AddError("Cannot determine type of expression " + Expression, RuleChecksEnum.SemanticAnalysisError);
                }

                Type conditionType = Condition.GetExpressionType();
                if (conditionType != null)
                {
                    if (!(conditionType is BoolType))
                    {
                        AddError("Condition " + Condition + " does not evaluate to a boolean", RuleChecksEnum.SemanticAnalysisError);
                    }
                }
                else
                {
                    AddError("Cannot determine type of condition " + Condition, RuleChecksEnum.SyntaxError);
                }
            }
            else
            {
                AddError("Cannot determine type of the initial value " + InitialValue, RuleChecksEnum.SemanticAnalysisError);
            }
        }
Exemplo n.º 6
0
        private void CheckActualAgainstFormal(Dictionary<string, Expression> actuals, Expression expression,
            Parameter parameter)
        {
            actuals[parameter.Name] = expression;

            expression.CheckExpression();
            Type argumentType = expression.GetExpressionType();
            if (argumentType == null)
            {
                AddError("Cannot evaluate argument type for argument " + expression);
            }
            else
            {
                if (parameter.Type == null)
                {
                    AddError("Cannot evaluate formal parameter type for " + parameter.Name);
                }
                else
                {
                    if (!parameter.Type.Match(argumentType))
                    {
                        AddError("Invalid argument " + expression + " type, expected " +
                                 parameter.Type.FullName + ", actual " + argumentType.FullName);
                    }
                }
            }
        }