Exemplo n.º 1
0
        /// <summary>
        /// Creates a function which gets the field named "fieldName" from one of the subfield of the structure provided as parameter
        /// </summary>
        /// <param name="nameSpace">The namespace in which the function should be created</param>
        /// <param name="structure">The structure which should be looked for</param>
        /// <param name="subField">The name of the subfield to look for</param>
        /// <param name="returnType">The function return type</param>
        private void AppendGetFunction(DataDictionary.Types.NameSpace nameSpace, DataDictionary.Types.Structure structure, string subField, string returnType)
        {
            DataDictionary.Functions.Function getFunction = (DataDictionary.Functions.Function)DataDictionary.Generated.acceptor.getFactory().createFunction();
            getFunction.Name = subField;
            getFunction.setTypeName(returnType);

            DataDictionary.Parameter param = (DataDictionary.Parameter)DataDictionary.Generated.acceptor.getFactory().createParameter();
            param.Name     = "msg";
            param.TypeName = structure.Name;
            getFunction.appendParameters(param);

            foreach (DataDictionary.Types.StructureElement element in structure.Elements)
            {
                DataDictionary.Functions.Case     cas       = (DataDictionary.Functions.Case)DataDictionary.Generated.acceptor.getFactory().createCase();
                DataDictionary.Rules.PreCondition condition = (DataDictionary.Rules.PreCondition)DataDictionary.Generated.acceptor.getFactory().createPreCondition();
                condition.Expression = "msg." + element.Name + " != EMPTY";

                cas.appendPreConditions(condition);
                cas.ExpressionText = "msg." + element.Name + "." + subField;

                getFunction.appendCases(cas);
            }

            nameSpace.appendFunctions(getFunction);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Provides the states used in an expression
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public static List <State> GetStates(Expression expression)
        {
            List <State> retval = new List <State>();

            if (expression != null)
            {
                foreach (IValue value in expression.GetLiterals())
                {
                    State state = value as State;
                    if (state != null)
                    {
                        retval.Add(state);
                    }
                }

                Call call = expression as Call;
                if (call != null)
                {
                    Function function = call.Called.GetStaticCallable() as Function;
                    if (function != null)
                    {
                        foreach (IValue value in function.GetLiterals())
                        {
                            State state = value as State;
                            if (state != null)
                            {
                                retval.Add(state);
                            }
                        }
                    }
                }
            }

            return(retval);
        }
Exemplo n.º 3
0
 /// <summary>
 ///     Adds a model element in this model element
 /// </summary>
 /// <param name="element"></param>
 public override void AddModelElement(IModelElement element)
 {
     {
         Range item = element as Range;
         if (item != null)
         {
             appendRanges(item);
         }
     }
     {
         Enum item = element as Enum;
         if (item != null)
         {
             appendEnumerations(item);
         }
     }
     {
         Structure item = element as Structure;
         if (item != null)
         {
             appendStructures(item);
         }
     }
     {
         Collection item = element as Collection;
         if (item != null)
         {
             appendCollections(item);
         }
     }
     {
         Function item = element as Function;
         if (item != null)
         {
             appendFunctions(item);
         }
     }
     {
         Procedure item = element as Procedure;
         if (item != null)
         {
             appendProcedures(item);
         }
     }
     {
         Rule item = element as Rule;
         if (item != null)
         {
             appendRules(item);
         }
     }
     {
         Variable item = element as Variable;
         if (item != null)
         {
             appendVariables(item);
         }
     }
 }
 /// <summary>
 /// Constructor (for function)
 /// </summary>
 /// <param name="item"></param>
 public ParametersTreeNode(DataDictionary.Functions.Function item)
     : base(item, "Parameters", true, false)
 {
     foreach (DataDictionary.Parameter parameter in item.FormalParameters)
     {
         Nodes.Add(new ParameterTreeNode(parameter));
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="item"></param>
 /// <param name="name"></param>
 public CasesTreeNode(DataDictionary.Functions.Function item)
     : base(item, "Cases", true, false)
 {
     foreach (DataDictionary.Functions.Case aCase in item.Cases)
     {
         Nodes.Add(new CaseTreeNode(aCase));
     }
 }
Exemplo n.º 6
0
            public override void visit(DataDictionary.Generated.Function obj, bool visitSubNodes)
            {
                DataDictionary.Functions.Function function = obj as DataDictionary.Functions.Function;

                function.ExecutionTimeInMilli = 0;
                function.ExecutionCount       = 0;

                base.visit(obj);
            }
Exemplo n.º 7
0
        /// <summary>
        ///     Creates a function in the enclosing namespace
        /// </summary>
        /// <param name="enclosing"></param>
        /// <param name="name"></param>
        /// <param name="typeName"></param>
        /// <returns></returns>
        protected Function CreateFunction(NameSpace enclosing, string name, string typeName)
        {
            Function retVal = (Function)Factory.createFunction();

            enclosing.appendFunctions(retVal);
            retVal.Name     = name;
            retVal.TypeName = typeName;

            return(retVal);
        }
Exemplo n.º 8
0
        /// <summary>
        ///     Creates a parameter in the enclosing function
        /// </summary>
        /// <param name="function"></param>
        /// <param name="name"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        protected Parameter CreateParameter(Function function, string name, string type)
        {
            Parameter retVal = (Parameter)Factory.createParameter();

            function.appendParameters(retVal);
            retVal.Name     = name;
            retVal.TypeName = type;

            return(retVal);
        }
Exemplo n.º 9
0
 public void DisplayHandler(object sender, EventArgs args)
 {
     DataDictionary.Functions.Function function = Item.Value as DataDictionary.Functions.Function;
     if (function != null)
     {
         GraphView.GraphView view = new GraphView.GraphView();
         MainWindow.AddChildWindow(view);
         view.Functions.Add(function);
         view.Refresh();
     }
 }
Exemplo n.º 10
0
        public void AddHandler(object sender, EventArgs args)
        {
            DataDictionaryTreeView treeView = BaseTreeView as DataDictionaryTreeView;

            if (treeView != null)
            {
                DataDictionary.Functions.Function function = (DataDictionary.Functions.Function)DataDictionary.Generated.acceptor.getFactory().createFunction();
                function.Name = "<Function" + (GetNodeCount(false) + 1) + ">";
                AddFunction(function);
            }
        }
Exemplo n.º 11
0
            private int Comparer(DataDictionary.Functions.Function f1, DataDictionary.Functions.Function f2)
            {
                if (f1.ExecutionTimeInMilli < f2.ExecutionTimeInMilli)
                {
                    return(1);
                }
                else if (f1.ExecutionTimeInMilli > f2.ExecutionTimeInMilli)
                {
                    return(-1);
                }

                return(0);
            }
Exemplo n.º 12
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);
        }
            /// <summary>
            /// Compares two functions according to their execution time
            /// </summary>
            /// <param name="f1"></param>
            /// <param name="f2"></param>
            /// <returns></returns>
            private static int Comparer(Function f1, Function f2)
            {
                int retVal = 0;

                if (f1.ExecutionTimeInMilli < f2.ExecutionTimeInMilli)
                {
                    retVal = 1;
                }
                else if (f1.ExecutionTimeInMilli > f2.ExecutionTimeInMilli)
                {
                    retVal = -1;
                }

                return(retVal);
            }
Exemplo n.º 14
0
        /// <summary>
        /// The menu items for this tree node
        /// </summary>
        /// <returns></returns>
        protected override List <MenuItem> GetMenuItems()
        {
            List <MenuItem> retVal;

            if (!IsASubVariable)
            {
                retVal = base.GetMenuItems();
                retVal.Add(new MenuItem("Delete", new EventHandler(DeleteHandler)));
            }
            else
            {
                retVal = new List <MenuItem>();
                retVal.Add(new MenuItem("Refresh", new EventHandler(RefreshNodeHandler)));
            }

            DataDictionary.Functions.Function function = Item.Value as DataDictionary.Functions.Function;
            if (function != null)
            {
                DataDictionary.Interpreter.InterpretationContext context = new DataDictionary.Interpreter.InterpretationContext(Item);
                if (function.FormalParameters.Count == 1)
                {
                    Parameter parameter = (Parameter)function.FormalParameters[0];
                    DataDictionary.Functions.Graph graph = function.createGraph(context, parameter);
                    if (graph != null && graph.Segments.Count != 0)
                    {
                        retVal.Add(new MenuItem("-"));
                        retVal.Add(new MenuItem("Display", new EventHandler(DisplayHandler)));
                    }
                }
                else if (function.FormalParameters.Count == 2)
                {
                    DataDictionary.Functions.Surface surface = function.createSurface(context);
                    if (surface != null && surface.Segments.Count != 0)
                    {
                        retVal.Add(new MenuItem("-"));
                        retVal.Add(new MenuItem("Display", new EventHandler(DisplayHandler)));
                    }
                }
            }

            if (Item.Type is StateMachine)
            {
                retVal.Add(new MenuItem("-"));
                retVal.Add(new MenuItem("View state diagram", new EventHandler(ViewStateDiagramHandler)));
            }

            return(retVal);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Adds a new function
        /// </summary>
        /// <param name="function"></param>
        public FunctionTreeNode AddFunction(DataDictionary.Functions.Function function)
        {
            // Ensure that functions always have a type
            if (function.ReturnType == null)
            {
                function.ReturnType = function.EFSSystem.BoolType;
            }

            Item.appendFunctions(function);
            FunctionTreeNode retVal = new FunctionTreeNode(function);

            Nodes.Add(retVal);
            SortSubNodes();

            return(retVal);
        }
Exemplo n.º 16
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);
                }
            }
        }
Exemplo n.º 17
0
            public override void visit(BaseModelElement obj, bool visitSubNodes)
            {
                IExpressionable expressionnable = obj as IExpressionable;

                if (expressionnable != null)
                {
                    Function enclosingFunction = EnclosingFinder <Function> .find(obj, true);

                    if (enclosingFunction != null)
                    {
                        // The value of the function depends on this.
                        TheReferenceVisitor.UpdateReferences(enclosingFunction, expressionnable.Tree);
                    }
                }

                base.visit(obj, visitSubNodes);
            }
Exemplo n.º 18
0
        /// <summary>
        ///     Creates a case in the enclosing function
        /// </summary>
        /// <param name="function"></param>
        /// <param name="name"></param>
        /// <param name="expression"></param>
        /// <param name="preConditionExpression"></param>
        /// <returns></returns>
        protected Case CreateCase(Function function, string name, string expression, string preConditionExpression = "")
        {
            Case retVal = (Case)Factory.createCase();

            function.appendCases(retVal);
            retVal.Name           = name;
            retVal.ExpressionText = expression;

            if (preConditionExpression != "")
            {
                PreCondition preCondition = (PreCondition)Factory.createPreCondition();
                preCondition.ExpressionText = preConditionExpression;
                retVal.appendPreConditions(preCondition);
            }

            return(retVal);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Accepts drop of a tree node, in a drag & drop operation
        /// </summary>
        /// <param name="SourceNode"></param>
        public override void AcceptDrop(BaseTreeNode SourceNode)
        {
            base.AcceptDrop(SourceNode);

            if (SourceNode is FunctionTreeNode)
            {
                FunctionTreeNode node = SourceNode as FunctionTreeNode;
                DataDictionary.Functions.Function function     = node.Item;
                DataDictionary.Functions.Function duplFunction = DataDictionary.OverallFunctionFinder.INSTANCE.findByName(function.Dictionary, function.Name);
                if (duplFunction != null) // If there is a function with the same name, we must delete it
                {
                    if (MessageBox.Show("Are you sure you want to move the corresponding function?", "Move action", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        for (int i = 0; i < Nodes.Count; i++)
                        {
                            FunctionTreeNode temp = Nodes[i] as FunctionTreeNode;
                            if (temp.Item.Name == function.Name)
                            {
                                temp.Delete();
                            }
                        }
                        node.Delete();
                        AddFunction(function);
                    }
                }
                else
                {
                    node.Delete();
                    AddFunction(function);
                }
            }
            else if (SourceNode is SpecificationView.ParagraphTreeNode)
            {
                SpecificationView.ParagraphTreeNode    node     = SourceNode as SpecificationView.ParagraphTreeNode;
                DataDictionary.Specification.Paragraph paragaph = node.Item;

                DataDictionary.Functions.Function function = (DataDictionary.Functions.Function)DataDictionary.Generated.acceptor.getFactory().createFunction();
                function.Name = paragaph.Name;

                DataDictionary.ReqRef reqRef = (DataDictionary.ReqRef)DataDictionary.Generated.acceptor.getFactory().createReqRef();
                reqRef.Name = paragaph.FullId;
                function.appendRequirements(reqRef);
                AddFunction(function);
            }
        }
Exemplo n.º 20
0
                protected override void VisitDesignator(Designator designator)
                {
                    base.VisitDesignator(designator);

                    Utils.ModelElement current = designator.Ref as Utils.ModelElement;
                    while (current != null && !(current is NameSpace) && !(current is Parameter))
                    {
                        bool change;

                        Variable variable = current as Variable;
                        if (variable != null)
                        {
                            change           = variable.AddDependancy(DependantFunction);
                            DependancyChange = DependancyChange || change;
                        }
                        else
                        {
                            StructureElement structureElement = current as StructureElement;
                            if (structureElement != null)
                            {
                                change           = structureElement.AddDependancy(DependantFunction);
                                DependancyChange = DependancyChange || change;

                                change           = structureElement.Structure.AddDependancy(DependantFunction);
                                DependancyChange = DependancyChange || change;
                            }
                            else
                            {
                                Function function = current as Function;
                                if (function != null)
                                {
                                    change           = function.AddDependancy(DependantFunction);
                                    DependancyChange = DependancyChange || change;
                                }
                            }
                        }

                        current = current.Enclosing as Utils.ModelElement;
                    }
                }
            /// <summary>
            /// Compares two functions according to their execution time
            /// </summary>
            /// <param name="f1"></param>
            /// <param name="f2"></param>
            /// <returns></returns>
            private static int Comparer(Function f1, Function f2)
            {
                int retVal = 0;

                if (f1.ExecutionTimeInMilli < f2.ExecutionTimeInMilli)
                {
                    retVal = 1;
                }
                else if (f1.ExecutionTimeInMilli > f2.ExecutionTimeInMilli)
                {
                    retVal = -1;
                }

                return retVal;
            }
Exemplo n.º 22
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="item"></param>
 /// <param name="buildSubNodes"></param>
 public CasesTreeNode(Function item, bool buildSubNodes)
     : base(item, buildSubNodes, "Cases", true, false)
 {
 }
Exemplo n.º 23
0
 /// <summary>
 /// Adds a new function
 /// </summary>
 /// <param name="structure"></param>
 /// <returns>the corresponding node</returns>
 public FunctionTreeNode AddFunction(DataDictionary.Functions.Function function)
 {
     return(functions.AddFunction(function));
 }
Exemplo n.º 24
0
            public override void visit(DataDictionary.Generated.Function obj, bool visitSubNodes)
            {
                DataDictionary.Functions.Function function = obj as DataDictionary.Functions.Function;

                Functions.Add(function);
            }
Exemplo n.º 25
0
                /// <summary>
                ///     Updates the dependancy graph according to this expression tree
                /// </summary>
                /// <param name="dependantFunction" />
                /// <param name="tree"></param>
                public void UpdateReferences(Function dependantFunction, InterpreterTreeNode tree)
                {
                    DependantFunction = dependantFunction;

                    visitInterpreterTreeNode(tree);
                }
 /// <summary>
 ///     Constructor (for function)
 /// </summary>
 /// <param name="item"></param>
 /// <param name="buildSubNodes"></param>
 public ParametersTreeNode(Function item, bool buildSubNodes)
     : base(item, buildSubNodes, "Parameters", true, false)
 {
 }
        /// <summary>
        ///     Creates a parameter in the enclosing function
        /// </summary>
        /// <param name="function"></param>
        /// <param name="name"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        protected Parameter CreateParameter(Function function, string name, string type)
        {
            Parameter retVal = (Parameter) Factory.createParameter();
            function.appendParameters(retVal);
            retVal.Name = name;
            retVal.TypeName = type;

            return retVal;
        }
 public DisplayObject(Function function)
 {
     Function = function;
 }
Exemplo n.º 29
0
 public DisplayObject(DataDictionary.Functions.Function function)
 {
     Function = function;
 }
        /// <summary>
        ///     Creates a case in the enclosing function
        /// </summary>
        /// <param name="function"></param>
        /// <param name="name"></param>
        /// <param name="expression"></param>
        /// <param name="preConditionExpression"></param>
        /// <returns></returns>
        protected Case CreateCase(Function function, string name, string expression, string preConditionExpression = "")
        {
            Case retVal = (Case) Factory.createCase();
            function.appendCases(retVal);
            retVal.Name = name;
            retVal.ExpressionText = expression;

            if (preConditionExpression != "")
            {
                PreCondition preCondition = (PreCondition) Factory.createPreCondition();
                preCondition.ExpressionText = preConditionExpression;
                retVal.appendPreConditions(preCondition);
            }

            return retVal;
        }
Exemplo n.º 31
0
                /// <summary>
                ///     Updates the dependancy graph according to this expression tree
                /// </summary>
                /// <param name="dependantFunction" />
                /// <param name="tree"></param>
                public void UpdateReferences(Function dependantFunction, InterpreterTreeNode tree)
                {
                    DependantFunction = dependantFunction;

                    visitInterpreterTreeNode(tree);
                }
            private int Comparer(Function f1, Function f2)
            {
                if (f1.ExecutionTimeInMilli < f2.ExecutionTimeInMilli)
                {
                    return 1;
                }
                else if (f1.ExecutionTimeInMilli > f2.ExecutionTimeInMilli)
                {
                    return -1;
                }

                return 0;
            }
 /// <summary>
 /// Constuctor
 /// </summary>
 /// <param name="function"></param>
 public DisplayObject(Function function)
 {
     Function = function;
 }