Beispiel #1
0
        /// <summary>
        /// Checks the statement for semantical errors
        /// </summary>
        public override void CheckStatement()
        {
            Types.Type targetType = VariableIdentification.GetExpressionType();
            if (targetType == null)
            {
                Root.AddError("Cannot determine type of target " + VariableIdentification.ToString());
            }
            else if (Expression != null)
            {
                Expression.checkExpression();

                Types.Type type = Expression.GetExpressionType();
                if (type != null)
                {
                    if (targetType != null)
                    {
                        if (!targetType.Match(type))
                        {
                            UnaryExpression unaryExpression = Expression as UnaryExpression;
                            if (unaryExpression != null && unaryExpression.Term.LiteralValue != null)
                            {
                                if (targetType.getValue(unaryExpression.ToString()) == null)
                                {
                                    Root.AddError("Expression " + Expression.ToString() + " does not fit in variable " + VariableIdentification.ToString());
                                }
                            }
                            else
                            {
                                Root.AddError("Expression [" + Expression.ToString() + "] type (" + type.FullName + ") does not match variable [" + VariableIdentification.ToString() + "] type (" + targetType.FullName + ")");
                            }
                        }
                    }
                    else
                    {
                        Root.AddError("Cannot determine variable type");
                    }
                }
                else
                {
                    Root.AddError("Cannot determine expression type (3) for " + Expression.ToString());
                }
            }
            else
            {
                Root.AddError("Invalid expression in assignment");
            }
        }
        /// <summary>
        ///     Checks the statement for semantical errors
        /// </summary>
        public override void CheckStatement()
        {
            VariableIdentification.CheckExpression();
            if (VariableIdentification.Ref is Parameter)
            {
                Root.AddError("Cannot assign a value to a parameter (" + VariableIdentification + ")");
            }

            if (VariableIdentification.Ref == null)
            {
                Root.AddError("Cannot assign a value to " + VariableIdentification);
            }

            Type targetType = VariableIdentification.GetExpressionType();

            if (targetType == null)
            {
                Root.AddError("Cannot determine type of target " + VariableIdentification);
            }
            else if (Expression != null)
            {
                Expression.CheckExpression();

                Type type = Expression.GetExpressionType();
                if (type != null)
                {
                    if (!targetType.Match(type))
                    {
                        UnaryExpression unaryExpression = Expression as UnaryExpression;
                        if (unaryExpression != null && unaryExpression.Term.LiteralValue != null)
                        {
                            Root.AddError("Expression " + Expression + " does not fit in variable " +
                                          VariableIdentification);
                        }
                        else
                        {
                            Root.AddError("Expression [" + Expression + "] type (" + type.FullName +
                                          ") does not match variable [" + VariableIdentification +
                                          "] type (" + targetType.FullName + ")");
                        }
                    }
                    else
                    {
                        Range rangeType = targetType as Range;
                        if (rangeType != null)
                        {
                            IValue value = Expression.Ref as IValue;
                            if (value != null)
                            {
                                if (rangeType.convert(value) == null)
                                {
                                    Root.AddError("Cannot set " + value.LiteralName + " in variable of type " +
                                                  rangeType.Name);
                                }
                            }
                        }
                    }

                    if (Expression.Ref == EfsSystem.Instance.EmptyValue)
                    {
                        if (targetType is Collection)
                        {
                            Root.AddError("Assignation of " + Expression.Ref.Name +
                                          " cannot be performed on variables of type collection. Use [] instead.");
                        }
                    }
                }
                else
                {
                    Root.AddError("Cannot determine expression type (3) for " + Expression);
                }
            }
            else
            {
                Root.AddError("Invalid expression in assignment");
            }
            // Check that the incoming variables are not modified
            if (EnclosingFinder <DataDictionary.Types.NameSpace> .find(Root, true) != null)
            {
                IVariable variable = VariableIdentification.Ref as IVariable;
                if (variable != null && variable.Mode == acceptor.VariableModeEnumType.aIncoming)
                {
                    Root.AddError("An incoming variable cannot be written");
                }
            }
        }