/// <summary>
        ///     Performs the semantic analysis of the statement
        /// </summary>
        /// <param name="instance">the reference instance on which this element should analysed</param>
        /// <returns>True if semantic analysis should be continued</returns>
        public override bool SemanticAnalysis(INamable instance = null)
        {
            bool retVal = base.SemanticAnalysis(instance);

            if (retVal)
            {
                // ListExpression
                if (ListExpression != null)
                {
                    ListExpression.SemanticAnalysis(instance);
                    StaticUsage.AddUsages(ListExpression.StaticUsage, Usage.ModeEnum.ReadAndWrite);

                    Collection collectionType = ListExpression.GetExpressionType() as Collection;
                    if (collectionType != null)
                    {
                        IteratorVariable.Type = collectionType.Type;
                    }
                }
                else
                {
                    AddError("List expression not provided", RuleChecksEnum.SemanticAnalysisError);
                }

                // Condition
                if (Condition != null)
                {
                    Condition.SemanticAnalysis(instance);
                    StaticUsage.AddUsages(Condition.StaticUsage, Usage.ModeEnum.Read);
                }
            }

            return(retVal);
        }
        /// <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)
            {
                // ListExpression
                if (ListExpression != null)
                {
                    ListExpression.SemanticAnalysis(instance, IsRightSide.INSTANCE);
                    StaticUsage.AddUsages(ListExpression.StaticUsage, Usage.ModeEnum.Read);

                    Collection collectionType = ListExpression.GetExpressionType() as Collection;
                    if (collectionType != null)
                    {
                        StaticUsage.AddUsage(collectionType, Root, Usage.ModeEnum.Type);
                        IteratorVariable.Type         = collectionType.Type;
                        PreviousIteratorVariable.Type = collectionType.Type;
                    }
                    else
                    {
                        AddError("Cannot determine collection type on list expression " + ToString(), RuleChecksEnum.SemanticAnalysisError);
                    }
                }
                else
                {
                    AddError("List expression not provided", RuleChecksEnum.SemanticAnalysisError);
                }
            }

            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)
            {
                Type elementType = null;

                if (ListElements != null)
                {
                    foreach (Expression expr in ListElements)
                    {
                        expr.SemanticAnalysis(instance, expectation);
                        StaticUsage.AddUsages(expr.StaticUsage, null);

                        Type current = expr.GetExpressionType();
                        if (elementType == null)
                        {
                            elementType = current;
                        }
                        else
                        {
                            if (!current.Match(elementType))
                            {
                                AddError("Cannot mix types " + current + " and " + elementType + "in collection", RuleChecksEnum.SemanticAnalysisError);
                            }
                        }
                    }
                }

                if (elementType != null)
                {
                    ExpressionType           = (Collection)acceptor.getFactory().createCollection();
                    ExpressionType.Type      = elementType;
                    ExpressionType.Name      = "ListOf_" + elementType.FullName;
                    ExpressionType.Enclosing = Root.EFSSystem;
                    ExpressionType.setMaxSize(ListElements.Count);

                    StaticUsage.AddUsage(elementType, Root, Usage.ModeEnum.Type);
                }
                else
                {
                    ExpressionType = new GenericCollection(EfsSystem.Instance);
                }
            }

            return(retVal);
        }
示例#4
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)
            {
                // Condition
                if (Condition != null)
                {
                    Condition.SemanticAnalysis(instance, expectation);
                    StaticUsage.AddUsages(Condition.StaticUsage, Usage.ModeEnum.Read);
                }
            }

            return(retVal);
        }
        /// <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)
            {
                Ref = null;

                ReturnValue tmp = GetReferences(instance, expectation, false);

                if (tmp.IsUnique)
                {
                    // Unique element has been found. Reference it and perform the semantic analysis
                    // on all dereferenced expression, now that the context is known for each expression
                    Ref = tmp.Values[0].Value;
                    StaticUsage.AddUsage(Ref, Root, null);

                    References         referenceFilter;
                    ReturnValueElement current = tmp.Values[0];
                    for (int i = Arguments.Count - 1; i > 0; i--)
                    {
                        referenceFilter = new References(current.Value);
                        current         = current.PreviousElement;
                        Arguments[i].SemanticAnalysis(current.Value, referenceFilter);
                        StaticUsage.AddUsages(Arguments[i].StaticUsage, null);
                        StaticUsage.AddUsage(Arguments[i].Ref, Root, null);
                    }
                    referenceFilter = new References(current.Value);
                    Arguments[0].SemanticAnalysis(null, referenceFilter);
                    StaticUsage.AddUsages(Arguments[0].StaticUsage, null);
                    StaticUsage.AddUsage(Arguments[0].Ref, Root, null);
                }
                else if (tmp.IsAmbiguous)
                {
                    // Several possible interpretations for this deref expression, not allowed
                    AddError("Expression " + ToString() + " may have several interpretations " + tmp +
                             ", please disambiguate", RuleChecksEnum.SemanticAnalysisError);
                }
                else
                {
                    // No possible interpretation for this deref expression, not allowed
                    AddError("Expression " + ToString() + " has no interpretation", RuleChecksEnum.SemanticAnalysisError);
                }
            }

            return(retVal);
        }
        /// <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)
            {
                // InitialValue
                if (InitialValue != null)
                {
                    InitialValue.SemanticAnalysis(instance, IsRightSide.INSTANCE);
                    StaticUsage.AddUsages(InitialValue.StaticUsage, Usage.ModeEnum.Read);

                    LastIteration.Type    = InitialValue.GetExpressionType();
                    CurrentIteration.Type = InitialValue.GetExpressionType();
                    StaticUsage.AddUsage(InitialValue.GetExpressionType(), Root, Usage.ModeEnum.Type);
                }
                else
                {
                    AddError("Initial value not provided", RuleChecksEnum.SemanticAnalysisError);
                }

                // Expression
                if (Expression != null)
                {
                    Expression.SemanticAnalysis(instance, AllMatches.INSTANCE);
                    StaticUsage.AddUsages(Expression.StaticUsage, Usage.ModeEnum.Read);
                }
                else
                {
                    Root.AddError("Accumulator expression value not provided");
                }

                // Condition
                if (Condition != null)
                {
                    Condition.SemanticAnalysis(instance, AllMatches.INSTANCE);
                    StaticUsage.AddUsages(Condition.StaticUsage, Usage.ModeEnum.Read);
                }
                else
                {
                    Root.AddError("Stop condition not provided");
                }
            }

            return(retVal);
        }
示例#7
0
        /// <summary>
        ///     Performs the semantic analysis of the statement
        /// </summary>
        /// <param name="instance">the reference instance on which this element should analysed</param>
        /// <returns>True if semantic analysis should be continued</returns>
        public override bool SemanticAnalysis(INamable instance = null)
        {
            bool retVal = base.SemanticAnalysis(instance);

            if (retVal)
            {
                if (Call != null)
                {
                    Call.SemanticAnalysis(instance);
                    StaticUsage.AddUsages(Call.StaticUsage, Usage.ModeEnum.Call);
                }
                else
                {
                    AddError("Called procedure not provided", RuleChecksEnum.SemanticAnalysisError);
                }
            }

            return(retVal);
        }
示例#8
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)
            {
                // Binding expression
                if (BindingExpression != null)
                {
                    BindingExpression.SemanticAnalysis(instance, IsRightSide.INSTANCE);
                    StaticUsage.AddUsages(BindingExpression.StaticUsage, Usage.ModeEnum.Read);

                    Type bindingExpressionType = BindingExpression.GetExpressionType();
                    if (bindingExpressionType != null)
                    {
                        StaticUsage.AddUsage(bindingExpressionType, Root, Usage.ModeEnum.Type);
                        BoundVariable.Type = bindingExpressionType;
                    }
                    else
                    {
                        AddError("Cannot determine binding expression type for " + ToString(), RuleChecksEnum.SemanticAnalysisError);
                    }
                }
                else
                {
                    AddError("Binding expression not provided", RuleChecksEnum.SemanticAnalysisError);
                }


                // The evaluated expression
                if (Expression != null)
                {
                    Expression.SemanticAnalysis(instance, expectation);
                    StaticUsage.AddUsages(Expression.StaticUsage, Usage.ModeEnum.Read);
                }
                else
                {
                    AddError("Value expression not provided", RuleChecksEnum.SemanticAnalysisError);
                }
            }

            return(retVal);
        }
示例#9
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)
            {
                if (Expression != null)
                {
                    Expression.SemanticAnalysis(instance, AllMatches.INSTANCE);
                    StaticUsage.AddUsages(Expression.StaticUsage, null);
                }
                else
                {
                    AddError("Function body not provided", RuleChecksEnum.SemanticAnalysisError);
                }
            }

            return(retVal);
        }
        /// <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)
            {
                // Iterator expression
                if (IteratorExpression != null)
                {
                    IteratorExpression.SemanticAnalysis(instance, AllMatches.INSTANCE);
                    StaticUsage.AddUsages(IteratorExpression.StaticUsage, Usage.ModeEnum.Read);
                }
                else
                {
                    AddError("Iterator expression not provided", RuleChecksEnum.SemanticAnalysisError);
                }
            }

            return(retVal);
        }
示例#11
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);
        }
示例#12
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)
            {
                if (InitialValue != null)
                {
                    InitialValue.SemanticAnalysis(instance, AllMatches.INSTANCE);
                    StaticUsage.AddUsages(InitialValue.StaticUsage, Usage.ModeEnum.Read);

                    AccumulatorVariable.Type = InitialValue.GetExpressionType();
                }
                else
                {
                    AddError("Initial value not provided", RuleChecksEnum.SemanticAnalysisError);
                }
            }

            return(retVal);
        }
示例#13
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)
            {
                // Value
                if (Type != null)
                {
                    Value = Type.getValue(Image);
                    StaticUsage.AddUsage(Type, Root, Usage.ModeEnum.Type);
                }

                if (Value == null)
                {
                    AddError("Cannot evaluate " + ToString() + " as a number", RuleChecksEnum.SemanticAnalysisError);
                }
            }

            return(retVal);
        }
示例#14
0
        /// <summary>
        ///     Performs the semantic analysis of the statement
        /// </summary>
        /// <param name="instance">the reference instance on which this element should analysed</param>
        /// <returns>True if semantic analysis should be continued</returns>
        public override bool SemanticAnalysis(INamable instance = null)
        {
            bool retVal = base.SemanticAnalysis(instance);

            if (retVal)
            {
                // Value
                if (Value != null)
                {
                    Value.SemanticAnalysis(instance);
                    StaticUsage.AddUsages(Value.StaticUsage, Usage.ModeEnum.Read);
                }
                else
                {
                    AddError("Value to insert not provided", RuleChecksEnum.SemanticAnalysisError);
                }

                // ListExpression
                if (ListExpression != null)
                {
                    ListExpression.SemanticAnalysis(instance, IsLeftSide.INSTANCE);
                    StaticUsage.AddUsages(ListExpression.StaticUsage, Usage.ModeEnum.ReadAndWrite);
                }
                else
                {
                    AddError("List expression not provided", RuleChecksEnum.SemanticAnalysisError);
                }

                // ReplaceElement
                if (ReplaceElement != null)
                {
                    ReplaceElement.SemanticAnalysis(instance);
                    StaticUsage.AddUsages(ReplaceElement.StaticUsage, Usage.ModeEnum.Read);
                }
            }

            return(retVal);
        }
示例#15
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)
            {
                // Structure
                if (Structure != null)
                {
                    Structure.SemanticAnalysis(instance, IsStructure.INSTANCE);
                    StaticUsage.AddUsages(Structure.StaticUsage, Usage.ModeEnum.Type);

                    // Structure field Association
                    if (Associations != null)
                    {
                        Structure structureType = Structure.Ref as Structure;
                        foreach (KeyValuePair <Designator, Expression> pair in Associations)
                        {
                            if (structureType != null)
                            {
                                pair.Key.Ref = structureType.FindStructureElement(pair.Key.Image);
                                StaticUsage.AddUsage(pair.Key.Ref, Root, Usage.ModeEnum.Parameter);
                            }

                            pair.Value.SemanticAnalysis(instance, IsRightSide.INSTANCE);
                            StaticUsage.AddUsages(pair.Value.StaticUsage, Usage.ModeEnum.Read);
                        }
                    }
                }
                else
                {
                    AddError("Structure type not specified", RuleChecksEnum.SemanticAnalysisError);
                }
            }

            return(retVal);
        }
        /// <summary>
        ///     Performs the semantic analysis of the statement
        /// </summary>
        /// <param name="instance">the reference instance on which this element should analysed</param>
        /// <returns>True if semantic analysis should be continued</returns>
        public override bool SemanticAnalysis(INamable instance = null)
        {
            bool retVal = base.SemanticAnalysis(instance);

            if (retVal)
            {
                // VariableIdentification
                if (VariableIdentification != null)
                {
                    VariableIdentification.SemanticAnalysis(instance, IsLeftSide.INSTANCE);
                    StaticUsage.AddUsages(VariableIdentification.StaticUsage, Usage.ModeEnum.Write);
                }
                else
                {
                    AddError("Altered variable not specified", RuleChecksEnum.SemanticAnalysisError);
                }

                // Expression
                Expression.SemanticAnalysis(instance, IsRightSide.INSTANCE);
                StaticUsage.AddUsages(Expression.StaticUsage, Usage.ModeEnum.Read);
            }

            return(retVal);
        }
示例#17
0
        /// <summary>
        ///     Performs the semantic analysis of the statement
        /// </summary>
        /// <param name="instance">the reference instance on which this element should analysed</param>
        /// <returns>True if semantic analysis should be continued</returns>
        public override bool SemanticAnalysis(INamable instance = null)
        {
            bool retVal = base.SemanticAnalysis(instance);

            if (retVal)
            {
                // ListExpression
                Collection collectionType = null;
                if (ListExpression != null)
                {
                    ListExpression.SemanticAnalysis(instance);
                    StaticUsage.AddUsages(ListExpression.StaticUsage, Usage.ModeEnum.ReadAndWrite);

                    collectionType = ListExpression.GetExpressionType() as Collection;
                    if (collectionType != null)
                    {
                        IteratorVariable.Type = collectionType.Type;
                    }
                    else
                    {
                        AddError("Cannot determine collection type", RuleChecksEnum.SemanticAnalysisError);
                    }
                }
                else
                {
                    AddError("List expression not provided", RuleChecksEnum.SemanticAnalysisError);
                }

                // Value
                if (Value != null)
                {
                    Value.SemanticAnalysis(instance);
                    StaticUsage.AddUsages(Value.StaticUsage, Usage.ModeEnum.Read);
                    Type valueType = Value.GetExpressionType();
                    if (valueType != null)
                    {
                        if (collectionType != null && !valueType.Match(collectionType.Type))
                        {
                            AddError("Type of " + Value + " does not match collection type " + collectionType, RuleChecksEnum.SemanticAnalysisError);
                        }
                    }
                    else
                    {
                        AddError("Cannot determine type of " + Value, RuleChecksEnum.SemanticAnalysisError);
                    }
                }
                else
                {
                    AddError("Replacement value not provided", RuleChecksEnum.SemanticAnalysisError);
                }

                // Condition
                if (Condition != null)
                {
                    Condition.SemanticAnalysis(instance);
                    StaticUsage.AddUsages(Condition.StaticUsage, Usage.ModeEnum.Read);
                }
            }

            return(retVal);
        }