コード例 #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();

            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);
            }
        }