A type. All types must inherit from this class
Inheritance: Generated.Type, IDefaultValueElement, IGraphicalDisplay
Ejemplo n.º 1
0
        /// <summary>
        ///     Converts the value provided as an EFS value
        /// </summary>
        /// <returns></returns>
        public override IValue ConvertBack(Type type)
        {
            IValue retVal = type.getValue(Value.ToString());

            CheckReturnValue(retVal, type);
            return retVal;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the reference of the designator if it covers the position given
        /// </summary>
        /// <param name="designator"></param>
        protected override void VisitDesignator(Designator designator)
        {
            if (ShouldCheck(designator))
            {
                Type type = designator.Ref as Type;
                if (Context == null && type != null)
                {
                    Context = type;
                }

                ITypedElement element = designator.Ref as ITypedElement;
                if (Context == null && element != null)
                {
                    Context = element;
                }

                ICallable callable = designator.Ref as ICallable;
                if (Context == null && callable != null)
                {
                    Context = callable;
                }

                NameSpace nameSpace = designator.Ref as NameSpace;
                if (Context == null && nameSpace != null)
                {
                    Context = nameSpace;
                }
            }
        }
Ejemplo 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);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Provides the callable that is called by this expression
        /// </summary>
        /// <param name="context"></param>
        /// <param name="explain"></param>
        /// <returns></returns>
        public override ICallable GetCalled(InterpretationContext context, ExplanationPart explain)
        {
            ICallable retVal;

            Call calledFunction = Called as Call;

            if (calledFunction != null)
            {
                retVal = Called.GetValue(context, explain) as ICallable;
            }
            else
            {
                retVal = Called.GetCalled(context, explain);
                if (retVal == null)
                {
                    Type type = Called.GetExpressionType();
                    if (type != null)
                    {
                        retVal = type.CastFunction;
                    }

                    if (retVal == null)
                    {
                        retVal = Called.GetValue(context, explain) as ICallable;
                    }
                }
            }

            return(retVal);
        }
        /// <summary>
        /// Checks an expression associated to a model element
        /// </summary>
        /// <param name="model">The model element on which the expression is defined</param>
        /// <param name="expression">The expression to check</param>
        /// <returns>the expression parse tree</returns>
        private Interpreter.Expression checkExpression(ModelElement model, string expression)
        {
            Interpreter.Expression retVal = null;

            Interpreter.Parser parser = model.EFSSystem.Parser;
            try
            {
                retVal = parser.Expression(model, expression);

                if (retVal != null)
                {
                    retVal.checkExpression();
                    Types.Type type = retVal.GetExpressionType();
                    if (type == null)
                    {
                        model.AddError("Cannot determine expression type (5) for " + retVal.ToString());
                    }
                }
                else
                {
                    model.AddError("Cannot parse expression");
                }
            }
            catch (Exception exception)
            {
                model.AddException(exception);
            }
            return(retVal);
        }
        /// <summary>
        /// Applied to all nodes of the tree
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="visitSubNodes"></param>
        public override void visit(Generated.Namable obj, bool visitSubNodes)
        {
            Namable namable = (Namable)obj;

            if (obj is Types.ITypedElement)
            {
                Types.ITypedElement typedElement = obj as Types.ITypedElement;

                Types.Type type = typedElement.Type;
                if (type == null)
                {
                    namable.AddError("Cannot find type " + typedElement.TypeName);
                }
                else if (!(typedElement is Parameter) && !(type is Types.StateMachine))
                {
                    Types.ITypedElement enclosingTypedElement = Utils.EnclosingFinder <Types.ITypedElement> .find(typedElement);

                    while (enclosingTypedElement != null)
                    {
                        if (enclosingTypedElement.Type == type)
                        {
                            namable.AddError("Recursive types are not allowed for " + type.Name);
                            enclosingTypedElement = null;
                        }
                        else
                        {
                            enclosingTypedElement = Utils.EnclosingFinder <Types.ITypedElement> .find(enclosingTypedElement);
                        }
                    }
                }
            }

            base.visit(obj, visitSubNodes);
        }
        public override void visit(Generated.Case obj, bool visitSubNodes)
        {
            Functions.Case cas = obj as Functions.Case;

            try
            {
                Interpreter.Expression expression = cas.Expression;
                if (expression != null)
                {
                    expression.checkExpression();
                    Types.Type expressionType = cas.Expression.GetExpressionType();
                    if (expressionType != null)
                    {
                        if (!cas.EnclosingFunction.ReturnType.Match(expressionType))
                        {
                            cas.AddError("Expression type (" + expressionType.FullName + ") does not match function return type (" + cas.EnclosingFunction.ReturnType.Name + ")");
                        }
                    }
                    else
                    {
                        cas.AddError("Cannot determine expression type (6) for " + cas.Expression.ToString());
                    }
                }
                else
                {
                    cas.AddError("Cannot evaluate expression " + cas.ExpressionText);
                }
            }
            catch (Exception e)
            {
                cas.AddException(e);
            }

            base.visit(obj, visitSubNodes);
        }
Ejemplo n.º 8
0
        /// <summary>
        ///     Converts the value provided as an EFS value
        /// </summary>
        /// <returns></returns>
        public override IValue ConvertBack(Type type)
        {
            IValue retVal = type.getValue(Name);

            CheckReturnValue(retVal, type);
            return retVal;
        }
        public override void visit(Generated.Type obj, bool visitSubNodes)
        {
            Types.Type type = obj as Types.Type;

            if (type != null)
            {
                if (type is Types.StateMachine)
                {
                    // Ignore state machines
                }
                else
                {
                    if (!(type is Types.Structure) && !(type is Functions.Function))
                    {
                        if (Utils.Utils.isEmpty(type.getDefault()))
                        {
                            type.AddError("Types should define their default value");
                        }
                        else
                        {
                            if (type.DefaultValue == null)
                            {
                                type.AddError("Invalid default value");
                            }
                        }
                        if (type is Types.Range)
                        {
                            Types.Range range = type as Types.Range;
                            if (range.getPrecision() == Generated.acceptor.PrecisionEnum.aIntegerPrecision && range.Default.IndexOf('.') > 0 ||
                                range.getPrecision() == Generated.acceptor.PrecisionEnum.aDoublePrecision && range.Default.IndexOf('.') <= 0)
                            {
                                type.AddError("Default value's precision does not correspond to the type's precision");
                            }
                            foreach (Constants.EnumValue specValue in range.SpecialValues)
                            {
                                String value = specValue.getValue();
                                if (range.getPrecision() == Generated.acceptor.PrecisionEnum.aDoublePrecision && value.IndexOf('.') <= 0 ||
                                    range.getPrecision() == Generated.acceptor.PrecisionEnum.aIntegerPrecision && value.IndexOf('.') > 0)
                                {
                                    type.AddError("Precision of the special value + " + specValue.Name + " does not correspond to the type's precision");
                                }
                            }
                        }
                    }

                    if (declaredTypes.ContainsKey(type.FullName))
                    {
                        declaredTypes[type.Name].AddError(TYPE_DECLARED_SEVERAL_TIMES);
                        type.AddError(TYPE_DECLARED_SEVERAL_TIMES);
                    }
                    else
                    {
                        declaredTypes[type.Name] = type;
                    }
                }
            }

            base.visit(obj, visitSubNodes);
        }
Ejemplo n.º 10
0
 /// <summary>
 ///     Checks the return value for a conversion to EFS type
 /// </summary>
 /// <param name="value"></param>
 /// <param name="type"></param>
 public void CheckReturnValue(IValue value, Type type)
 {
     if (value == null)
     {
         throw new FaultException<EFSServiceFault>(
             new EFSServiceFault("Cannot convert to EFS value " + DisplayValue() + " for type " + type.FullName));
     }
 }
Ejemplo n.º 11
0
            GetStandardValues(ITypeDescriptorContext context)
            {
                ItemEditor editor = (ItemEditor)context.Instance;

                DataDictionary.Types.NameSpace nameSpace = editor.Item.NameSpace;
                DataDictionary.Types.Type      type      = editor.Item.Type;

                return(GetValues(nameSpace, type));
            }
Ejemplo n.º 12
0
        /// <summary>
        ///     Converts the value provided as an EFS value
        /// </summary>
        /// <returns></returns>
        public override IValue ConvertBack(Type type)
        {
            IValue retVal = null;

            StringType stringType = type as StringType;
            if (stringType != null)
            {
                retVal = new DataDictionary.Values.StringValue(stringType, Value);
            }

            CheckReturnValue(retVal, type);
            return retVal;
        }
Ejemplo n.º 13
0
        /// <summary>
        ///     Checks the statement for semantical errors
        /// </summary>
        public override void CheckStatement()
        {
            if (ListExpression != null)
            {
                if (ListExpression.Ref is Parameter)
                {
                    Root.AddError("Cannot change the list value which is a parameter (" + ListExpression + ")");
                }

                Collection targetListType = ListExpression.GetExpressionType() as Collection;
                if (targetListType != null)
                {
                    Type elementType = Value.GetExpressionType();
                    if (elementType != targetListType.Type)
                    {
                        Root.AddError("Inserted element type does not corresponds to list type");
                    }

                    if (Condition != null)
                    {
                        Condition.CheckExpression();
                        BoolType conditionType = Condition.GetExpressionType() as BoolType;
                        if (conditionType == null)
                        {
                            Root.AddError("Condition does not evaluates to boolean");
                        }
                    }
                    else
                    {
                        Root.AddError("Condition should be provided");
                    }
                }
                else
                {
                    Root.AddError("Cannot determine collection type of " + ListExpression);
                }
            }
            else
            {
                Root.AddError("List should be specified");
            }

            if (Value != null)
            {
                Value.CheckExpression();
            }
            else
            {
                Root.AddError("Value should be specified");
            }
        }
Ejemplo n.º 14
0
        public override void visit(BaseModelElement obj, bool visitSubNodes)
        {
            IExpressionable expressionable = obj as IExpressionable;

            if (expressionable != null)
            {
                // In case of rebuild, cleans the previously constructed tree
                if (Options.Rebuild)
                {
                    expressionable.CleanCompilation();
                }
                // Ensures that the expressionable is compiled
                expressionable.Compile();

                Structure structure = expressionable as Structure;
                if (structure != null)
                {
                    if (structure != structure.UnifiedStructure)
                    {
                        visit(structure.UnifiedStructure, visitSubNodes);
                    }
                }

                StateMachine stateMachine = expressionable as StateMachine;
                if (stateMachine != null)
                {
                    if (stateMachine != stateMachine.UnifiedStateMachine)
                    {
                        visit(stateMachine.UnifiedStateMachine, visitSubNodes);
                    }
                }
            }

            ITypedElement typedElement = obj as ITypedElement;

            if (typedElement != null)
            {
                // Ensures that the type of the corresponding element is cached
                Type type = typedElement.Type;
            }

            Function function = obj as Function;

            if (function != null)
            {
                Type returnType = function.ReturnType;
            }

            base.visit(obj, visitSubNodes);
        }
Ejemplo n.º 15
0
        /// <summary>
        ///     Provides the type of this expression
        /// </summary>
        /// <returns></returns>
        public override Type GetExpressionType()
        {
            Type retVal = Ref as Type;

            if (retVal == null)
            {
                ITypedElement typedElement = Ref as ITypedElement;
                if (typedElement != null)
                {
                    retVal = typedElement.Type;
                }
            }

            return(retVal);
        }
Ejemplo n.º 16
0
        /// <summary>
        ///     Provides the ICallable that is statically defined
        /// </summary>
        public virtual ICallable GetStaticCallable()
        {
            ICallable retVal = Ref as ICallable;

            if (retVal == null)
            {
                Type type = Ref as Type;
                if (type != null)
                {
                    retVal = type.CastFunction;
                }
            }

            return(retVal);
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
0
        /// <summary>
        ///     Refactors an element which has a type
        /// </summary>
        /// <param name="element">The element that has been modified</param>
        /// <param name="user">The user which references this type</param>
        private static void RefactorTypedElement(ModelElement element, ITypedElement user)
        {
            if (user != null)
            {
                try
                {
                    ModelElement enclosing = EnclosingFinder <NameSpace> .find(user, true);

                    Function function = user as Function;
                    if (function != null)
                    {
                        bool refactor = false;
                        Type current  = function.ReturnType;
                        while (current != null && !refactor)
                        {
                            refactor = current == element;
                            current  = EnclosingFinder <Type> .find(current);
                        }

                        if (refactor)
                        {
                            function.TypeName = function.ReturnType.ReferenceName(enclosing);
                        }
                    }
                    else
                    {
                        bool refactor = false;
                        Type current  = user.Type;
                        while (current != null && !refactor)
                        {
                            refactor = current == element;
                            current  = EnclosingFinder <Type> .find(current);
                        }

                        if (refactor)
                        {
                            user.TypeName = user.Type.ReferenceName(enclosing);
                        }
                    }
                }
                catch (Exception e)
                {
                    ((ModelElement)user).AddError("Cannot refactor this element, reason = " + e.Message);
                }
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        ///     Provides the type of this expression
        /// </summary>
        /// <returns></returns>
        public override Type GetExpressionType()
        {
            Type retVal = null;

            Function function = Called.GetStaticCallable() as Function;

            if (function != null)
            {
                retVal = function.ReturnType;
            }
            else
            {
                AddError("Cannot get type of function call " + ToString(), RuleChecksEnum.SemanticAnalysisError);
            }

            return(retVal);
        }
Ejemplo n.º 20
0
        /// <summary>
        ///     Provides the type of this expression
        /// </summary>
        /// <returns></returns>
        public override Type GetExpressionType()
        {
            Type retVal = null;

            if (Term != null)
            {
                retVal = Term.GetExpressionType();
            }
            else if (Expression != null)
            {
                if (Not.Equals(UnaryOp))
                {
                    Type type = Expression.GetExpressionType();
                    if (type is BoolType)
                    {
                        retVal = type;
                    }
                    else
                    {
                        AddError("Cannot apply NOT on non boolean types", RuleChecksEnum.SemanticAnalysisError);
                    }
                }
                else if (Minus.Equals(UnaryOp))
                {
                    Type type = Expression.GetExpressionType();
                    if (type == EfsSystem.Instance.IntegerType || type == EfsSystem.Instance.DoubleType || type is Range)
                    {
                        retVal = type;
                    }
                    else
                    {
                        AddError("Cannot apply - on non integral types", RuleChecksEnum.SemanticAnalysisError);
                    }
                }
                else
                {
                    retVal = Expression.GetExpressionType();
                }
            }

            return(retVal);
        }
Ejemplo n.º 21
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);
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        ///     Converts the value provided as an EFS value
        /// </summary>
        /// <returns></returns>
        public override IValue ConvertBack(Type type)
        {
            IValue retVal = null;

            Collection collectionType = type as Collection;
            if (collectionType != null)
            {
                List<IValue> values = new List<IValue>();

                foreach (Value item in Value)
                {
                    values.Add(item.ConvertBack(collectionType.Type));
                }

                retVal = new DataDictionary.Values.ListValue(collectionType, values);
            }

            CheckReturnValue(retVal, type);
            return retVal;
        }
Ejemplo n.º 23
0
        public override void visit(Generated.Frame obj, bool visitSubNodes)
        {
            Tests.Frame frame = (Tests.Frame)obj;

            if (frame != null)
            {
                checkExpression(frame, frame.getCycleDuration());

                Types.Type type = frame.CycleDuration.GetExpressionType();
                if (type != null)
                {
                    if (!frame.EFSSystem.DoubleType.Match(type))
                    {
                        frame.AddError("Cycle duration should be compatible with the Time type");
                    }
                }
            }

            base.visit(obj, visitSubNodes);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Provides the type associated to the name
        /// </summary>
        /// <param name="nameSpace"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public Types.Type findType(Types.NameSpace nameSpace, string name)
        {
            Types.Type retVal = null;

            if (name != null)
            {
                foreach (Dictionary dictionary in Dictionaries)
                {
                    retVal = dictionary.findType(nameSpace, name);
                    if (retVal != null)
                    {
                        break;
                    }
                }

                if (retVal == null)
                {
                    PredefinedTypes.TryGetValue(name, out retVal);
                }
            }

            return(retVal);
        }
        /// <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");
                }
            }
        }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="source"></param>
 /// <param name="target"></param>
 /// <param name="model"></param>
 public ElementReferenceArrow(Structure source, Type target, StructureElement model)
     : base(source, target, model.Name, model)
 {
 }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="source"></param>
 /// <param name="target"></param>
 /// <param name="model"></param>
 public CollectionTypeArrow(Collection source, Type target, Collection model)
     : base(source, target, "of " + source.getMaxSize(), model)
 {
 }
Ejemplo n.º 28
0
        /// <summary>
        ///     Combines two types to create a new one
        /// </summary>
        /// <param name="right"></param>
        /// <param name="Operator"></param>
        /// <returns></returns>
        public override Type CombineType(Type right, BinaryExpression.Operator Operator)
        {
            Type retVal = null;

            Function function = right as Function;
            if (function != null)
            {
                if (ReturnType == function.ReturnType)
                {
                    if (FormalParameters.Count >= function.FormalParameters.Count)
                    {
                        retVal = this;
                    }
                    else
                    {
                        retVal = function;
                    }
                }
                else
                {
                    AddError("Cannot combine types " + ReturnType.Name + " and " + function.ReturnType.Name);
                }
            }
            else if (right.IsDouble())
            {
                retVal = this;
            }
            else
            {
                AddError("Cannot combine types " + ReturnType.Name + " and " + right.Name);
            }

            return retVal;
        }
Ejemplo n.º 29
0
        /// <summary>
        ///     Indicates that binary operation is valid for this type and the other type
        /// </summary>
        /// <param name="operation"></param>
        /// <param name="otherType"></param>
        /// <returns></returns>
        public override bool ValidBinaryOperation(BinaryExpression.Operator operation, Type otherType)
        {
            bool retVal = false;

            if (ReturnType != null)
            {
                Function otherFunction = otherType as Function;
                if (otherFunction != null)
                {
                    if (otherFunction.ReturnType != null)
                    {
                        retVal = ReturnType.ValidBinaryOperation(operation, otherFunction.ReturnType);
                    }
                }
                else if (ReturnType != this)
                {
                    retVal = ReturnType.ValidBinaryOperation(operation, otherType);
                }
                else
                {
                    retVal = true;
                }
            }

            return retVal;
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Provides the type associated to the name
        /// </summary>
        /// <param name="nameSpace">the namespace in which the name should be found</param>
        /// <param name="name"></param>
        /// <returns></returns>
        public Types.Type findType(Types.NameSpace nameSpace, string name)
        {
            Types.Type retVal = null;

            if (name != null)
            {
                if (nameSpace != null)
                {
                    if (!cache.ContainsKey(nameSpace))
                    {
                        cache[nameSpace] = new Dictionary <string, Types.Type>();
                    }
                    Dictionary <string, Types.Type> subCache = cache[nameSpace];

                    if (!subCache.ContainsKey(name))
                    {
                        Types.Type tmp = null;

                        if (!Utils.Utils.isEmpty(name))
                        {
                            tmp = nameSpace.findTypeByName(name);

                            if (tmp == null)
                            {
                                if (DefinedTypes.ContainsKey(name))
                                {
                                    tmp = DefinedTypes[name];
                                }
                            }

                            if (tmp == null && DefinedTypes.ContainsKey("Default." + name))
                            {
                                tmp = DefinedTypes["Default." + name];
                            }
                        }

                        if (tmp == null)
                        {
                            Log.Error("Cannot find type named " + name);
                        }

                        subCache[name] = tmp;
                    }

                    retVal = subCache[name];
                }
                else
                {
                    if (DefinedTypes.ContainsKey(name))
                    {
                        retVal = DefinedTypes[name];
                    }
                    else if (DefinedTypes.ContainsKey("Default." + name))
                    {
                        retVal = DefinedTypes["Default." + name];
                    }
                }
            }

            return(retVal);
        }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="panel"></param>
 /// <param name="model"></param>
 protected TypeModelControl(ModelDiagramPanel panel, Type model)
     : base(panel, model)
 {
     NormalColor = Color.LightSteelBlue;
 }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="source"></param>
 /// <param name="target"></param>
 /// <param name="model"></param>
 public VariableTypeArrow(Variable source, Type target, Variable model)
     : base(source, target, "type", model)
 {
 }
Ejemplo n.º 33
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);
        }
        /// <summary>
        /// Indicates that the other type can be placed in variables of this type
        /// </summary>
        /// <param name="otherType"></param>
        /// <returns></returns>
        public override bool Match(Type otherType)
        {
            bool retVal = base.Match(otherType);

            StateMachine current = otherType as StateMachine;
            while (current != null && !retVal)
            {
                retVal = this == current;
                current = current.EnclosingStateMachine;
            }

            return retVal;
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Indicates that the other type may be placed in this
        /// </summary>
        /// <param name="otherType"></param>
        /// <returns></returns>
        public override bool Match(Type otherType)
        {
            bool retVal = base.Match(otherType);

            if (!retVal && otherType is Enum)
            {
                Enum current = (Enum)otherType;

                while (current != null && !retVal)
                {
                    retVal = current == this;
                    current = current.EnclosingEnum;
                }
            }

            return retVal;
        }
Ejemplo n.º 36
0
        public override void ClearCache()
        {
            base.ClearCache();

            // Remove the cached type
            _type = null;
        }
Ejemplo n.º 37
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="type"></param>
 protected Value(Type type)
 {
     Type = type;
 }
Ejemplo n.º 38
0
        public StandardValuesCollection GetValues(NameSpace nameSpace, Type type)
        {
            FinderRepository.INSTANCE.ClearCache();

            List<string> retVal = new List<string>();
            if (type != null)
            {
                string prefix = type.FullName;
                if (nameSpace == type.NameSpace && nameSpace != null)
                {
                    prefix = prefix.Substring(nameSpace.FullName.Length + 1);
                }
                OverallValueFinder.INSTANCE.findAllValueNames(prefix, type, false, retVal);
                retVal.Sort();
            }

            return new StandardValuesCollection(retVal);
        }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="root"></param>
 /// <param name="log"></param>
 /// <param name="value"></param>
 /// <param name="type"></param>
 /// <param name="start">The start character for this expression in the original string</param>
 /// <param name="end">The end character for this expression in the original string</param>
 public NumberExpression(ModelElement root, ModelElement log, string value, Type type, int start, int end)
     : base(root, log, start, end)
 {
     Image = value;
     Type = type;
 }
Ejemplo n.º 40
0
 /// <summary>
 ///     Converts the value provided as an EFS value
 /// </summary>
 /// <param name="type">the value expected type</param>
 /// <returns></returns>
 public abstract IValue ConvertBack(Type type);
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="root"></param>
 /// <param name="log"></param>
 /// <param name="value"></param>
 /// <param name="type"></param>
 /// <param name="parsingData">Additional information about the parsing process</param>
 public NumberExpression(ModelElement root, ModelElement log, string value, Type type, ParsingData parsingData)
     : base(root, log, parsingData)
 {
     Image = value;
     Type = type;
 }