コード例 #1
0
        /// <summary>
        /// Performs the semantic analysis of the expression
        /// </summary>
        /// <param name="instance">the reference instance on which this element should analysed</param>
        /// <paraparam name="expectation">Indicates the kind of element we are looking for</paraparam>
        /// <returns>True if semantic analysis should be continued</returns>
        public override bool SemanticAnalysis(Utils.INamable instance, Filter.AcceptableChoice expectation)
        {
            bool retVal = base.SemanticAnalysis(instance, expectation);

            if (retVal)
            {
                Expression.SemanticAnalysis(instance, Filter.AllMatches);
            }

            return(retVal);
        }
コード例 #2
0
        /// <summary>
        /// Provides the enclosing sub declarator
        /// </summary>
        /// <param name="instance"></param>
        /// <returns></returns>
        private Utils.INamable enclosingSubDeclarator(Utils.INamable instance)
        {
            Utils.INamable retVal = instance;

            do
            {
                retVal = enclosing(retVal);
            } while (retVal != null && !(retVal is Utils.ISubDeclarator));

            return(retVal);
        }
コード例 #3
0
        /// <summary>
        /// Performs the semantic analysis of the term
        /// </summary>
        /// <param name="instance">the reference instance on which this element should analysed</param>
        /// <para name="expectation">Indicates the kind of element we are looking for</paraparam>
        /// <param name="lastElement">Indicates that this element is the last one in a dereference chain</param>
        /// <returns>True if semantic analysis should be continued</returns>
        public void SemanticAnalysis(Utils.INamable instance, Filter.AcceptableChoice expectation, bool lastElement)
        {
            ReturnValue tmp = getReferences(instance, expectation, lastElement);

            if (Image.CompareTo("THIS") != 0)
            {
                tmp.filter(expectation);
            }
            if (tmp.IsUnique)
            {
                Ref = tmp.Values[0].Value;
            }
        }
コード例 #4
0
        /// <summary>
        /// Performs the semantic analysis of the expression
        /// </summary>
        /// <param name="instance">the reference instance on which this element should analysed</param>
        /// <paraparam name="expectation">Indicates the kind of element we are looking for</paraparam>
        /// <returns>True if semantic analysis should be continued</returns>
        public override bool SemanticAnalysis(Utils.INamable instance, Filter.AcceptableChoice expectation)
        {
            bool retVal = base.SemanticAnalysis(instance, expectation);

            if (retVal)
            {
                InitialValue.SemanticAnalysis(instance, Filter.AllMatches);

                AccumulatorVariable.Type = InitialValue.GetExpressionType();
            }

            return(retVal);
        }
コード例 #5
0
        /// <summary>
        /// Provides the enclosing element
        /// </summary>
        /// <param name="retVal"></param>
        /// <returns></returns>
        private Utils.INamable enclosing(Utils.INamable retVal)
        {
            Utils.IEnclosed enclosed = retVal as Utils.IEnclosed;

            if (enclosed != null)
            {
                retVal = enclosed.Enclosing as Utils.INamable;
            }
            else
            {
                retVal = null;
            }

            return(retVal);
        }
コード例 #6
0
        /// <summary>
        /// Performs the semantic analysis of the expression
        /// </summary>
        /// <param name="instance">the reference instance on which this element should analysed</param>
        /// <paraparam name="expectation">Indicates the kind of element we are looking for</paraparam>
        /// <returns>True if semantic analysis should be continued</returns>
        public override bool SemanticAnalysis(Utils.INamable instance, Filter.AcceptableChoice expectation)
        {
            bool retVal = base.SemanticAnalysis(instance, expectation);

            if (retVal)
            {
                ListExpression.SemanticAnalysis(instance, Filter.IsRightSide);

                Types.Collection collectionType = ListExpression.GetExpressionType() as Types.Collection;
                if (collectionType != null)
                {
                    IteratorVariable.Type         = collectionType.Type;
                    PreviousIteratorVariable.Type = collectionType.Type;
                }
                else
                {
                    AddError("Cannot determine collection type on list expression " + ToString());
                }
            }

            return(retVal);
        }
コード例 #7
0
        /// <summary>
        /// Performs the semantic analysis of the expression
        /// </summary>
        /// <param name="instance">the reference instance on which this element should analysed</param>
        /// <paraparam name="expectation">Indicates the kind of element we are looking for</paraparam>
        /// <returns>True if semantic analysis should be continued</returns>
        public override bool SemanticAnalysis(Utils.INamable instance, Filter.AcceptableChoice expectation)
        {
            bool retVal = base.SemanticAnalysis(instance, expectation);

            if (retVal)
            {
                Ref = null;

                ReturnValue tmp = Arguments[0].getReferences(instance, Filter.AllMatches, false);
                if (tmp.IsEmpty)
                {
                    tmp = Arguments[0].getReferenceTypes(instance, Filter.AllMatches, false);
                }

                if (!tmp.IsEmpty)
                {
                    for (int i = 1; i < Arguments.Count; i++)
                    {
                        ReturnValue tmp2 = tmp;
                        tmp = new ReturnValue(Arguments[i]);

                        foreach (ReturnValueElement elem in tmp2.Values)
                        {
                            tmp.Merge(elem, Arguments[i].getReferences(elem.Value, Filter.AllMatches, i == (Arguments.Count - 1)));
                        }

                        if (tmp.IsEmpty)
                        {
                            AddError("Cannot find " + Arguments[i].ToString() + " in " + Arguments[i - 1].ToString());
                        }
                    }
                }
                else
                {
                    AddError("Cannot evaluate " + Arguments[0].ToString());
                }

                tmp.filter(expectation);
                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;

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

            return(retVal);
        }
コード例 #8
0
        /// <summary>
        /// Provides the element referenced by this designator, given the enclosing element
        /// </summary>
        /// <param name="enclosing"></param>
        /// <returns></returns>
        public INamable getReference(InterpretationContext context)
        {
            INamable retVal = null;

            switch (Location)
            {
            case LocationEnum.Stack:
                retVal = context.LocalScope.getVariable(Image);

                if (retVal == null)
                {
                    AddError(Image + " not found on the stack");
                }
                break;

            case LocationEnum.Instance:
                Utils.INamable instance = context.Instance;

                while (instance != null)
                {
                    ISubDeclarator subDeclarator = instance as ISubDeclarator;
                    if (subDeclarator != null)
                    {
                        INamable tmp = getReferenceBySubDeclarator(subDeclarator);
                        if (tmp != null)
                        {
                            if (retVal == null)
                            {
                                retVal   = tmp;
                                instance = null;
                            }
                        }
                    }

                    instance = enclosingSubDeclarator(instance);
                }

                if (retVal == null)
                {
                    AddError(Image + " not found in the current instance " + context.Instance.Name);
                }
                break;

            case LocationEnum.This:
                retVal = context.Instance;
                break;

            case LocationEnum.Model:
                retVal = Ref;

                if (retVal == null)
                {
                    AddError(Image + " not found in the enclosing model");
                }
                break;

            case LocationEnum.NotDefined:
                AddError("Semantic analysis not performed on " + ToString());
                break;
            }

            return(retVal);
        }