예제 #1
0
        protected override void Context()
        {
            _buildingBlockIconRetriever = A.Fake <IBuildingBlockIconRetriever>();
            _view = A.Fake <ISimulationExplorerView>();
            A.CallTo(() => _view.TreeView).Returns(A.Fake <IUxTreeView>());
            _treeNodeFactory    = A.Fake <ITreeNodeFactory>();
            _contextMenuFactory = A.Fake <ITreeNodeContextMenuFactory>();
            _regionResolver     = A.Fake <IRegionResolver>();
            _buildingBlockInSimulationManager = A.Fake <IBuildingBlockInSimulationManager>();
            _buildingBlockTask  = A.Fake <IBuildingBlockTask>();
            _toolTipNodeCreator = A.Fake <IToolTipPartCreator>();
            _projectRetriever   = A.Fake <IProjectRetriever>();
            _multipleTreeNodeContextMenuFactory      = A.Fake <IMultipleTreeNodeContextMenuFactory>();
            _parameterAnalysablesInExplorerPresenter = A.Fake <IParameterAnalysablesInExplorerPresenter>();

            _simulationFolderNode = new RootNode(RootNodeTypes.SimulationFolder);
            _comparisonFolderNode = new RootNode(RootNodeTypes.ComparisonFolder);
            _project          = new PKSimProject();
            _usedObservedData = new UsedObservedData {
                Id = "UsedData"
            };
            _simulation           = new IndividualSimulation().WithName("individualSimulation").WithId("individualSimulation");
            _populationSimulation = new PopulationSimulation().WithName("populationSimulation").WithId("populationSimulation");
            _importedSimulaton    = A.Fake <Simulation>().WithName("ImportedSimulation").WithId("ImportedSimulation");
            A.CallTo(() => _importedSimulaton.IsImported).Returns(true);
            _simulation.Properties                   = new SimulationProperties();
            _simulation.ModelProperties              = new ModelProperties();
            _simulation.ModelConfiguration           = A.Fake <ModelConfiguration>();
            _populationSimulation.Properties         = new SimulationProperties();
            _populationSimulation.ModelProperties    = new ModelProperties();
            _populationSimulation.ModelConfiguration = A.Fake <ModelConfiguration>();
            _classificationPresenter                 = A.Fake <IClassificationPresenter>();
            _project.AddBuildingBlock(_simulation);
            _project.AddBuildingBlock(_populationSimulation);
            var classifiableIndividualSimulation = new ClassifiableSimulation {
                Subject = _simulation
            };
            var classfiablePopulationSimulation = new ClassifiableSimulation {
                Subject = _populationSimulation
            };
            var classifiableImportSimulation = new ClassifiableSimulation {
                Subject = _importedSimulaton
            };

            _project.AddClassifiable(classifiableIndividualSimulation);
            _project.AddClassifiable(classfiablePopulationSimulation);
            _individualSimulationNode = new SimulationNode(classifiableIndividualSimulation);
            _populationSimulationNode = new SimulationNode(classfiablePopulationSimulation);
            _importedSimulationNode   = new SimulationNode(classifiableImportSimulation);
            _usedObservedDataNode     = A.Fake <ITreeNode>();
            A.CallTo(() => _treeNodeFactory.CreateFor(classifiableIndividualSimulation)).Returns(_individualSimulationNode);
            A.CallTo(() => _treeNodeFactory.CreateFor(classfiablePopulationSimulation)).Returns(_populationSimulationNode);
            A.CallTo(() => _treeNodeFactory.CreateFor(classifiableImportSimulation)).Returns(_importedSimulationNode);
            A.CallTo(() => _treeNodeFactory.CreateFor(_usedObservedData)).Returns(_usedObservedDataNode);
            _project.AddBuildingBlock(_importedSimulaton);

            var simulationComparison   = A.Fake <ISimulationComparison>().WithId("SimComp_Id");
            var classifiableComparison = new ClassifiableComparison {
                Subject = simulationComparison
            };

            _comparisonNode = new ComparisonNode(classifiableComparison);
            _project.AddSimulationComparison(simulationComparison);
            A.CallTo(() => _treeNodeFactory.CreateFor(classifiableComparison)).Returns(_comparisonNode);


            _usedCompoundBuildingBlock = new UsedBuildingBlock("toto", PKSimBuildingBlockType.Compound)
            {
                Id = "usedBB"
            };
            _simulation.AddUsedBuildingBlock(_usedCompoundBuildingBlock);
            _simulation.AddUsedObservedData(_usedObservedData);

            _project.AddClassifiable(classifiableComparison);

            _templageCompoundBuildingBlock = A.Fake <IPKSimBuildingBlock>();
            _usedBuildingBlockNode         = new UsedBuildingBlockInSimulationNode(_simulation, _usedCompoundBuildingBlock, _templageCompoundBuildingBlock);
            A.CallTo(() => _treeNodeFactory.CreateFor(_simulation, _usedCompoundBuildingBlock)).Returns(_usedBuildingBlockNode);
            A.CallTo(() => _buildingBlockIconRetriever.IconFor(_simulation)).Returns(ApplicationIcons.SimulationGreen);
            A.CallTo(() => _buildingBlockIconRetriever.IconFor(_populationSimulation)).Returns(ApplicationIcons.SimulationGreen);
            A.CallTo(() => _buildingBlockIconRetriever.IconFor(_usedCompoundBuildingBlock)).Returns(ApplicationIcons.CompoundRed);
            A.CallTo(() => _view.TreeView.NodeById(_simulation.Id)).Returns(_individualSimulationNode);
            A.CallTo(() => _view.TreeView.NodeById(_usedCompoundBuildingBlock.Id)).Returns(_usedBuildingBlockNode);
            A.CallTo(() => _view.TreeView.NodeById(RootNodeTypes.SimulationFolder.Id)).Returns(_simulationFolderNode);
            A.CallTo(() => _view.TreeView.NodeById(RootNodeTypes.ComparisonFolder.Id)).Returns(_comparisonFolderNode);

            _observedDataInSimulationManager = A.Fake <IObservedDataInSimulationManager>();
            sut = new SimulationExplorerPresenter(_view, _treeNodeFactory, _contextMenuFactory, _multipleTreeNodeContextMenuFactory, _buildingBlockIconRetriever,
                                                  _regionResolver, _buildingBlockTask, _buildingBlockInSimulationManager, _toolTipNodeCreator, _projectRetriever, _classificationPresenter, _parameterAnalysablesInExplorerPresenter, _observedDataInSimulationManager);

            A.CallTo(() => _projectRetriever.CurrentProject).Returns(_project);
        }
예제 #2
0
    void ContextCallback(object obj)
    {
        string clb = obj.ToString();

        if (clb.Equals("inputNode"))
        {
            InputNode inputNode = new InputNode()
            {
                windowRect = new Rect(mousePos.x, mousePos.y, 200, 150)
            };
            windows.Add(inputNode);
        }
        else if (clb.Equals("outputNode"))
        {
            OutputNode outputNode = new OutputNode()
            {
                windowRect = new Rect(mousePos.x, mousePos.y, 200, 100)
            };
            windows.Add(outputNode);
        }
        else if (clb.Equals("calcNode"))
        {
            CalcNode calcNode = new CalcNode()
            {
                windowRect = new Rect(mousePos.x, mousePos.y, 200, 100)
            };
            windows.Add(calcNode);
        }
        else if (clb.Equals("compNode"))
        {
            ComparisonNode compNode = new ComparisonNode()
            {
                windowRect = new Rect(mousePos.x, mousePos.y, 200, 100)
            };
            windows.Add(compNode);
        }
        else if (clb.Equals("makeTransition"))
        {
            bool clickedOnWindow = false;
            int  selectIndex     = -1;

            for (int i = 0; i < windows.Count; i++)
            {
                if (windows[i].windowRect.Contains(mousePos))
                {
                    selectIndex     = i;
                    clickedOnWindow = true;
                    break;
                }
            }

            if (clickedOnWindow)
            {
                selectedNode       = windows[selectIndex];
                makeTransitionMode = true;
            }
        }
        else if (clb.Equals("deleteNode"))
        {
            bool clickedOnWindow = false;
            int  selectIndex     = -1;

            for (int i = 0; i < windows.Count; i++)
            {
                if (windows[i].windowRect.Contains(mousePos))
                {
                    selectIndex     = i;
                    clickedOnWindow = true;
                    break;
                }
            }

            if (clickedOnWindow)
            {
                BaseNodeOld selNode = windows[selectIndex];
                windows.RemoveAt(selectIndex);

                foreach (BaseNodeOld n in windows)
                {
                    n.NodeDeleted(selNode);
                }
            }
        }
    }
 private ComparisonNode NumberComparison()
 {
     ComparisonNode comparisonNode = new ComparisonNode
     {
         FilterOperator = FilterOperator.IsEqualTo,
         First = new PropertyNode
         {
             Name = "Age"
         },
         Second = new NumberNode
         {
             Value = 10
         }
     };
     return comparisonNode;
 }
        static void FilterRoot(ComparisonNode node)
        {
            Filters filters = GetDataAccess().GetFilters();

            FilterNode(filters, node);
        }
예제 #5
0
    //Is called when a selection from the context menu is made
    void ContextCallback(object obj)
    {
        //make the passed object to a string
        string clb = obj.ToString();

        //add the node we want
        if (clb.Equals("inputNode"))
        {
            InputNode inputNode = ScriptableObject.CreateInstance <InputNode>();
            inputNode.WindowRect = new Rect(mousePos.x, mousePos.y, 200, 80);

            windows.Add(inputNode);
        }
        else if (clb.Equals("outputNode"))
        {
            OutputNode outputNode = ScriptableObject.CreateInstance <OutputNode>();
            outputNode.WindowRect = new Rect(mousePos.x, mousePos.y, 200, 80);

            windows.Add(outputNode);
        }
        else if (clb.Equals("calcNode"))
        {
            CalcNode calcNode = ScriptableObject.CreateInstance <CalcNode>();
            calcNode.WindowRect = new Rect(mousePos.x, mousePos.y, 200, 95);

            windows.Add(calcNode);
        }
        else if (clb.Equals("compNode"))
        {
            ComparisonNode compNode = ScriptableObject.CreateInstance <ComparisonNode>();
            compNode.WindowRect = new Rect(mousePos.x, mousePos.y, 200, 95);

            windows.Add(compNode);
        }
        else if (clb.Equals("numNode"))
        {
            NumberNode numNode = ScriptableObject.CreateInstance <NumberNode>();
            numNode.WindowRect = new Rect(mousePos.x, mousePos.y, 200, 95);

            windows.Add(numNode);
        }
        else if (clb.Equals("goObj"))
        {
            GameObjectNode goObj = ScriptableObject.CreateInstance <GameObjectNode>();
            goObj.WindowRect = new Rect(mousePos.x, mousePos.y, 200, 100);

            windows.Add(goObj);
        }
        else if (clb.Equals("goActive"))
        {
            GameObjectActive goNode = ScriptableObject.CreateInstance <GameObjectActive>();
            goNode.WindowRect = new Rect(mousePos.x, mousePos.y, 200, 80);

            windows.Add(goNode);
        }
        else if (clb.Equals("goDistance"))
        {
            GameObjectDistance goDistance = ScriptableObject.CreateInstance <GameObjectDistance>();
            goDistance.WindowRect = new Rect(mousePos.x, mousePos.y, 200, 80);

            windows.Add(goDistance);
        }
        else if (clb.Equals("timerNode"))
        {
            TimerNode tNode = ScriptableObject.CreateInstance <TimerNode>();
            tNode.WindowRect = new Rect(mousePos.x, mousePos.y, 200, 95);

            windows.Add(tNode);
        }
        else if (clb.Equals("boolNode"))
        {
            BoolNode bNode = ScriptableObject.CreateInstance <BoolNode>();
            bNode.WindowRect = new Rect(mousePos.x, mousePos.y, 120, 75);

            windows.Add(bNode);
        }
        else if (clb.Equals("clearAll"))
        {
            windows.Clear();
        }
        else if (clb.Equals("reset"))
        {
            PanX = PanY = 0;
        }
        else if (clb.Equals("makeTransition"))    //if it's a transition
        {
            bool clickedOnWindow = false;
            int  selectedIndex   = -1;
            //find the window that it was clicked
            for (int i = 0; i < windows.Count; i++)
            {
                if (windows[i].WindowRect.Contains(mousePos))
                {
                    selectedIndex   = i;
                    clickedOnWindow = true;
                    break;
                }
            }

            //and make it the selected node of the transition
            if (clickedOnWindow)
            {
                selectedNode       = windows[selectedIndex];
                makeTransitionMode = true;
            }
        }
        else if (clb.Equals("deleteNode"))    //if it's a delete node
        {
            bool clickedOnWindow = false;
            int  selectedIndex   = -1;

            //find the selected node
            for (int i = 0; i < windows.Count; i++)
            {
                if (windows[i].WindowRect.Contains(mousePos))
                {
                    selectedIndex   = i;
                    clickedOnWindow = true;
                    break;
                }
            }

            if (clickedOnWindow)
            {
                //delete it from our list
                BaseNode selNode = windows[selectedIndex];
                windows.RemoveAt(selectedIndex);

                //then pass it to all our nodes that is deleted
                foreach (BaseNode n in windows)
                {
                    n.NodeDeleted(selNode);
                }
            }
        }

        //we use else if instead of a switch because:

        /*Selecting from a set of multiple cases is faster with if statements than with switch
         */
    }
예제 #6
0
        protected override void DoAction(int action)
        {
#pragma warning disable 162, 1522
            switch (action)
            {
            case 2: // start -> Program, block, EOF
#line 22 "D:\MINICompiler\kompilator.y"
            {
                if (syntaxErrorLines.Count != 0)
                {
                    YYAbort();
                }
                ProgramTree.block = ValueStack[ValueStack.Depth - 2] as BlockNode;
                ProgramTree.Line  = ValueStack[ValueStack.Depth - 3].Line;
            }
#line default
                break;

            case 3: // block -> OpenBracket, lines, CloseBracket
#line 34 "D:\MINICompiler\kompilator.y"
            {
                BlockNode node;
                if (ValueStack[ValueStack.Depth - 2] is null)
                {
                    node = new BlockNode();
                }
                else
                {
                    node = new BlockNode(ValueStack[ValueStack.Depth - 2] as BlockNode);
                }
                node.Line            = ValueStack[ValueStack.Depth - 3].Line;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 5: // lines -> lines, instruction
#line 44 "D:\MINICompiler\kompilator.y"
            {
                BlockNode node;
                if (ValueStack[ValueStack.Depth - 2] is null)
                {
                    node = new BlockNode();
                }
                else
                {
                    node = new BlockNode(ValueStack[ValueStack.Depth - 2] as BlockNode);
                }
                node.instructions.Add(ValueStack[ValueStack.Depth - 1]);
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 6: // lines -> EOF
#line 52 "D:\MINICompiler\kompilator.y"
            {
                syntaxErrorLines.Add(ProgramTree.LineCount);
                YYAbort();
            }
#line default
                break;

            case 11: // instruction -> exp, Semicolon
#line 62 "D:\MINICompiler\kompilator.y"
            {
                ExpressionNode node = ValueStack[ValueStack.Depth - 2] as ExpressionNode;
                node.ShouldReturnValue = false;
            }
#line default
                break;

            case 15: // instruction -> Semicolon
#line 70 "D:\MINICompiler\kompilator.y"
            {
                syntaxErrorLines.Add(ValueStack[ValueStack.Depth - 1].Line);
            }
#line default
                break;

            case 16: // instruction -> error
#line 74 "D:\MINICompiler\kompilator.y"
            {
                syntaxErrorLines.Add(ValueStack[ValueStack.Depth - 1].Line);
            }
#line default
                break;

            case 17: // write -> Write, String
#line 80 "D:\MINICompiler\kompilator.y"
            {
                WriteNode node = new WriteNode(ValueStack[ValueStack.Depth - 2].Line);
                node.content         = ValueStack[ValueStack.Depth - 1];
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 18: // write -> Write, exp
#line 86 "D:\MINICompiler\kompilator.y"
            {
                WriteNode node = new WriteNode(ValueStack[ValueStack.Depth - 2].Line);
                node.content         = ValueStack[ValueStack.Depth - 1] as ExpressionNode;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 19: // read -> Read, Variable
#line 93 "D:\MINICompiler\kompilator.y"
            {
                ReadNode node = new ReadNode(ValueStack[ValueStack.Depth - 2].Line);
                node.target          = ValueStack[ValueStack.Depth - 1] as VariableNode;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 20: // init -> Int, Variable
#line 100 "D:\MINICompiler\kompilator.y"
            {
                InitNode node = new InitNode(ValueStack[ValueStack.Depth - 2].Line);
                node.variable         = ValueStack[ValueStack.Depth - 1] as VariableNode;
                node.variable.ValType = ValType.Int;
                CurrentSemanticValue  = node;
            }
#line default
                break;

            case 21: // init -> Double, Variable
#line 108 "D:\MINICompiler\kompilator.y"
            {
                InitNode node = new InitNode(ValueStack[ValueStack.Depth - 2].Line);
                node.variable         = ValueStack[ValueStack.Depth - 1] as VariableNode;
                node.variable.ValType = ValType.Double;
                CurrentSemanticValue  = node;
            }
#line default
                break;

            case 22: // init -> Bool, Variable
#line 115 "D:\MINICompiler\kompilator.y"
            {
                InitNode node = new InitNode(ValueStack[ValueStack.Depth - 2].Line);
                node.variable         = ValueStack[ValueStack.Depth - 1] as VariableNode;
                node.variable.ValType = ValType.Bool;
                CurrentSemanticValue  = node;
            }
#line default
                break;

            case 23: // assign -> Variable, Assign, exp
#line 123 "D:\MINICompiler\kompilator.y"
            {
                AssignNode node = new AssignNode(ValueStack[ValueStack.Depth - 3].Line);
                node.left              = ValueStack[ValueStack.Depth - 3] as VariableNode;
                node.right             = ValueStack[ValueStack.Depth - 1];
                node.ShouldReturnValue = true;
                CurrentSemanticValue   = node;
            }
#line default
                break;

            case 24: // exp -> OpenPar, exp, ClosePar
#line 133 "D:\MINICompiler\kompilator.y"
            {
                ParenthesisNode node = new ParenthesisNode(ValueStack[ValueStack.Depth - 3].Line);
                node.content         = ValueStack[ValueStack.Depth - 2] as ExpressionNode;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 25: // exp -> exp, Add, exp
#line 139 "D:\MINICompiler\kompilator.y"
            {
                BinaryOpNode node = ValueStack[ValueStack.Depth - 2] as BinaryOpNode;
                CurrentSemanticValue = AssignToBinaryOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode);
            }
#line default
                break;

            case 26: // exp -> exp, Sub, exp
#line 144 "D:\MINICompiler\kompilator.y"
            {
                BinaryOpNode node = ValueStack[ValueStack.Depth - 2] as BinaryOpNode;
                CurrentSemanticValue = AssignToBinaryOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode);
            }
#line default
                break;

            case 27: // exp -> exp, Mult, exp
#line 149 "D:\MINICompiler\kompilator.y"
            {
                BinaryOpNode node = ValueStack[ValueStack.Depth - 2] as BinaryOpNode;
                CurrentSemanticValue = AssignToBinaryOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode);
            }
#line default
                break;

            case 28: // exp -> exp, Div, exp
#line 154 "D:\MINICompiler\kompilator.y"
            {
                BinaryOpNode node = ValueStack[ValueStack.Depth - 2] as BinaryOpNode;
                CurrentSemanticValue = AssignToBinaryOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode);
            }
#line default
                break;

            case 29: // exp -> exp, BitAnd, exp
#line 159 "D:\MINICompiler\kompilator.y"
            {
                BinaryOpNode node = ValueStack[ValueStack.Depth - 2] as BinaryOpNode;
                CurrentSemanticValue = AssignToBinaryOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode);
            }
#line default
                break;

            case 30: // exp -> exp, BitOr, exp
#line 164 "D:\MINICompiler\kompilator.y"
            {
                BinaryOpNode node = ValueStack[ValueStack.Depth - 2] as BinaryOpNode;
                CurrentSemanticValue = AssignToBinaryOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode);
            }
#line default
                break;

            case 32: // exp -> IntCast, exp
#line 170 "D:\MINICompiler\kompilator.y"
            {
                IntCastNode node = new IntCastNode(ValueStack[ValueStack.Depth - 2].Line);
                node.content         = ValueStack[ValueStack.Depth - 1] as ExpressionNode;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 33: // exp -> DoubleCast, exp
#line 176 "D:\MINICompiler\kompilator.y"
            {
                DoubleCastNode node = new DoubleCastNode(ValueStack[ValueStack.Depth - 2].Line);
                node.content         = ValueStack[ValueStack.Depth - 1] as ExpressionNode;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 37: // exp -> Not, exp
#line 185 "D:\MINICompiler\kompilator.y"
            {
                NotNode node = new NotNode(ValueStack[ValueStack.Depth - 2].Line);
                node.content         = ValueStack[ValueStack.Depth - 1] as ExpressionNode;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 38: // exp -> Tilde, exp
#line 191 "D:\MINICompiler\kompilator.y"
            {
                NegNode node = new NegNode(ValueStack[ValueStack.Depth - 2].Line);
                node.content         = ValueStack[ValueStack.Depth - 1] as ExpressionNode;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 39: // exp -> Sub, exp
#line 197 "D:\MINICompiler\kompilator.y"
            {
                MinusNode node = new MinusNode(ValueStack[ValueStack.Depth - 2].Line);
                node.content         = ValueStack[ValueStack.Depth - 1] as ExpressionNode;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 40: // exp -> exp, And, exp
#line 203 "D:\MINICompiler\kompilator.y"
            {
                LogicOpNode node = ValueStack[ValueStack.Depth - 2] as LogicOpNode;
                node.left            = ValueStack[ValueStack.Depth - 3] as ExpressionNode;
                node.right           = ValueStack[ValueStack.Depth - 1] as ExpressionNode;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 41: // exp -> exp, Or, exp
#line 210 "D:\MINICompiler\kompilator.y"
            {
                LogicOpNode node = ValueStack[ValueStack.Depth - 2] as LogicOpNode;
                node.left            = ValueStack[ValueStack.Depth - 3] as ExpressionNode;
                node.right           = ValueStack[ValueStack.Depth - 1] as ExpressionNode;
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 42: // exp -> exp, Comparison, exp
#line 217 "D:\MINICompiler\kompilator.y"
            {
                ComparisonNode node = ValueStack[ValueStack.Depth - 2] as ComparisonNode;
                CurrentSemanticValue = AssignToComparisonOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode);
            }
#line default
                break;

            case 44: // if -> If, OpenPar, exp, ClosePar, instruction
#line 225 "D:\MINICompiler\kompilator.y"
            {
                IfNode node = new IfNode(ValueStack[ValueStack.Depth - 5].Line);
                node.check           = ValueStack[ValueStack.Depth - 3] as ExpressionNode;
                node.ifBlock         = ValueStack[ValueStack.Depth - 1];
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 45: // if -> If, OpenPar, exp, ClosePar, instruction, Else, instruction
#line 232 "D:\MINICompiler\kompilator.y"
            {
                IfNode node = new IfNode(ValueStack[ValueStack.Depth - 7].Line);
                node.check           = ValueStack[ValueStack.Depth - 5] as ExpressionNode;
                node.elseBlock       = ValueStack[ValueStack.Depth - 1];
                node.ifBlock         = ValueStack[ValueStack.Depth - 3];
                CurrentSemanticValue = node;
            }
#line default
                break;

            case 46: // while -> While, OpenPar, exp, ClosePar, instruction
#line 241 "D:\MINICompiler\kompilator.y"
            {
                WhileNode node = new WhileNode(ValueStack[ValueStack.Depth - 5].Line);
                node.check           = ValueStack[ValueStack.Depth - 3] as ExpressionNode;
                node.block           = ValueStack[ValueStack.Depth - 1];
                CurrentSemanticValue = node;
            }
#line default
                break;
            }
#pragma warning restore 162, 1522
        }
예제 #7
0
 public ComparisonNode AssignToComparisonOp(ComparisonNode node, ExpressionNode left, ExpressionNode right)
 {
     node.left  = left;
     node.right = right;
     return(node);
 }
예제 #8
0
        public static BlockNode ProcessTokens(List <ScriptToken> tokens)
        {
            List <AstTreeNode> blockNodes = new List <AstTreeNode>();
            AstTreeNode        node       = new BlockNode(null);
            int count = 0;

            StripWhiteSpace(tokens);

            while (tokens.Count > 0)
            {
                count++;
                if (count > 1000)
                {
                    break;               // Limit to 1000 iterations while in development
                }
                if (tokens[0].Type == EScriptTokenType.RETURN)
                {
                    tokens.RemoveAt(0); // Last value in block is returned by default
                }
                ScriptToken scriptToken = tokens[0];

                if (scriptToken.Type == EScriptTokenType.NAME)
                {
                    node = new RootScopeMemberNode(
                        new LiteralNode <string>(scriptToken.Value)
                        );
                    tokens.RemoveAt(0);
                }
                else if (scriptToken.Type == EScriptTokenType.ASSIGN)
                {
                    node = AssignmentNode.Parse(node, scriptToken, tokens);
                }
                else if (scriptToken.Type == EScriptTokenType.IF)
                {
                    node = IfStatementNode.Parse(node, scriptToken, tokens);
                    blockNodes.Add(node);
                    node = null;
                }
                else if (scriptToken.Type == EScriptTokenType.FOR)
                {
                    node = ForStatementNode.Parse(node, scriptToken, tokens);
                    blockNodes.Add(node);
                    node = null;
                }
                else if (scriptToken.Type == EScriptTokenType.STRING_LITERAL)
                {
                    node = new LiteralNode <string>(scriptToken.Value);
                    tokens.RemoveAt(0);
                }
                else if (scriptToken.Type == EScriptTokenType.NUMBER_LITERAL)
                {
                    AstTreeNode _node;
                    if (scriptToken.Value.Contains("."))
                    {
                        _node = new FloatLiteralNode(scriptToken.Value);
                    }
                    else
                    {
                        _node = new IntegerLiteralNode(scriptToken.Value);
                    }

                    node = _node;
                    tokens.RemoveAt(0);
                }
                else if (scriptToken.Type == EScriptTokenType.PERIOD)
                {
                    if (tokens[1].Type == EScriptTokenType.NAME)
                    {
                        node = new ScopeMemberNode(
                            node,
                            new LiteralNode <string>(tokens[1].Value)
                            );
                        tokens.RemoveAt(0);
                        tokens.RemoveAt(0);
                    }
                }
                else if (scriptToken.Type == EScriptTokenType.L_BRACKET)
                {
                    if (node.GetType() == typeof(RootScopeMemberNode))
                    {
                        // indice
                    }
                    else
                    {
                        node = ArrayNode.Parse(node, scriptToken, tokens);
                    }
                }
                else if (scriptToken.Type == EScriptTokenType.L_PAREN)
                {
                    List <List <ScriptToken> > funcArgs = GetBlockTokens(tokens);
                    List <AstTreeNode>         nodes    = new List <AstTreeNode>();
                    ;
                    foreach (List <ScriptToken> arg in funcArgs)
                    {
                        nodes.Add(ProcessTokens(arg));
                    }
                    node = new FunctionCallNode(
                        node, // Previous node should be a NAME
                        new FunctionArgumentNode(nodes)
                        );
                }
                else if (scriptToken.Type == EScriptTokenType.SEMI_COLON)
                {
                    if (node != null)
                    {
                        blockNodes.Add(node);
                    }

                    node = null;
                    tokens.RemoveAt(0);
                }
                else if (ComparisonNode.Matches(tokens))
                {
                    node = ComparisonNode.Parse(node, scriptToken, tokens);
                }
                else if (ArithmeticNode.Matches(tokens))
                {
                    AstTreeNode _node = ArithmeticNode.Parse(node, scriptToken, tokens);
                    node = _node;
                }
                else if (ArithmeticAssignmentNode.Matches(tokens))
                {
                    node = ArithmeticAssignmentNode.Parse(node, scriptToken, tokens);
                }
                else if (scriptToken.Type == EScriptTokenType.WHITESPACE)
                {
                    tokens.RemoveAt(0);
                }
                else if (scriptToken.Type == EScriptTokenType.BOOLEAN_LITERAL)
                {
                    node = new BooleanLiteralNode(tokens[0].Value);
                    tokens.RemoveAt(0);
                }
                else if (scriptToken.Type == EScriptTokenType.NULL_LITERAL)
                {
                    node = new LiteralNode <object>(null);
                    tokens.RemoveAt(0);
                }
                else
                {
                    string code = ScriptTree.ToCode(tokens, 10);
                    Console.WriteLine($"Syntax Error.Near {code}");
                }
            }

            if (node != null)
            {
                blockNodes.Add(node);
            }

            return(new BlockNode(blockNodes));
        }
예제 #9
0
 public abstract object Visit(ComparisonNode node);
예제 #10
0
    void ContextCallback(object obj)
    {
        string clb = obj.ToString();

        bool clickedOnWindow = false;
        int  selectIndex     = -1;

        for (int i = 0; i < _windows.Count; i++)
        {
            if (_windows[i].WindowRect.Contains(_mousePos))
            {
                selectIndex     = i;
                clickedOnWindow = true;
                break;
            }
        }

        switch (clb)
        {
        case "inputNode":
            InputNode inputNode = new InputNode();
            inputNode.WindowRect = new Rect(_mousePos.x, _mousePos.y, 200, 150);

            _windows.Add(inputNode);
            break;

        case "outputNode":
            OutputNode outputNode = new OutputNode();
            outputNode.WindowRect = new Rect(_mousePos.x, _mousePos.y, 200, 100);

            _windows.Add(outputNode);
            break;

        case "calcNode":
            CalcNode calcNode = new CalcNode();
            calcNode.WindowRect = new Rect(_mousePos.x, _mousePos.y, 200, 150);

            _windows.Add(calcNode);
            break;

        case "compNode":
            ComparisonNode compNode = new ComparisonNode();
            compNode.WindowRect = new Rect(_mousePos.x, _mousePos.y, 200, 150);

            _windows.Add(compNode);
            break;

        case "makeTransition":
            if (clickedOnWindow)
            {
                _selectedNode       = _windows[selectIndex];
                _makeTransitionMode = true;
            }

            break;

        case "deleteNode":
            if (clickedOnWindow)
            {
                BaseNode selectedNode = _windows[selectIndex];
                _windows.RemoveAt(selectIndex);

                foreach (BaseNode baseNode in _windows)
                {
                    baseNode.NodeDeleted(selectedNode);
                }
            }

            break;
        }
    }
        /// <summary>
        /// Helper method to transform comparison object to structure understood by Angular control
        /// </summary>
        /// <param name="comparisonObject">Individual node in the tree</param>
        /// <param name="level">Level in the heirarchy to which the object belongs</param>
        /// <param name="parentNode">Reference to the parent node of the current object</param>
        private void PopulateComparisonData(ComparisonObject comparisonObject, int level, ComparisonNode parentNode)
        {
            if (comparisonObject != null)
            {
                ComparisonNode currentNode = new ComparisonNode
                {
                    NodeType = Equals(ComparisonObjectType.DataSource, comparisonObject.ComparisonObjectType) ? "Data Source" : comparisonObject.ComparisonObjectType.ToString(),

                    SourceName             = comparisonObject.SourceObjectName,
                    TargetName             = comparisonObject.TargetObjectName,
                    SourceInternalName     = comparisonObject.SourceObjectInternalName,
                    TargetInternalName     = comparisonObject.TargetObjectInternalName,
                    SourceObjectDefinition = comparisonObject.SourceObjectDefinition,
                    TargetObjectDefinition = comparisonObject.TargetObjectDefinition,
                    ShowNode         = true,
                    Level            = level,
                    MergeAction      = comparisonObject.MergeAction.ToString(),
                    DisableMessage   = "",
                    DropdownDisabled = false
                };

                if (parentNode != null)
                {
                    currentNode.ParentId = parentNode.Id;
                    parentNode.ChildNodes.Add(currentNode.Id);
                }

                switch (comparisonObject.Status)
                {
                case ComparisonObjectStatus.MissingInTarget:
                    currentNode.Status = "Missing in Target";
                    break;

                case ComparisonObjectStatus.MissingInSource:
                    currentNode.Status = "Missing in Source";
                    break;

                case ComparisonObjectStatus.SameDefinition:
                    currentNode.Status = "Same Definition";
                    break;

                case ComparisonObjectStatus.DifferentDefinitions:
                    currentNode.Status = "Different Definitions";
                    break;

                default:
                    break;
                }

                comparisonList.Add(currentNode);

                // Populate helper objects
                AngularComposite angularComposite = new AngularComposite(currentNode, comparisonObject);
                _directAccessList.Add(currentNode.Id, angularComposite);


                // set drop-down to have limited members based on what is available
                switch (comparisonObject.MergeAction)
                {
                case MergeAction.Create:
                    currentNode.AvailableActions = new List <string> {
                        "Create", "Skip"
                    };

                    if (parentNode != null && string.Equals(parentNode.Status, "Missing in Target") && string.Equals(parentNode.MergeAction, "Skip"))
                    {
                        comparisonObject.MergeAction = MergeAction.Skip;
                        currentNode.MergeAction      = MergeAction.Skip.ToString();
                        currentNode.DropdownDisabled = true;
                        SetNodeTooltip(angularComposite, true);
                    }
                    break;

                case MergeAction.Update:
                    currentNode.AvailableActions = new List <string> {
                        "Update", "Skip"
                    };
                    break;

                case MergeAction.Delete:
                    currentNode.AvailableActions = new List <string> {
                        "Delete", "Skip"
                    };

                    //check if parent is also set to delete, in which case make this cell readonly
                    if (parentNode != null && string.Equals(parentNode.MergeAction, "Delete"))
                    {
                        currentNode.DropdownDisabled = true;
                        SetNodeTooltip(angularComposite, true);
                    }
                    break;

                case MergeAction.Skip:

                    switch (comparisonObject.Status)
                    {
                    case ComparisonObjectStatus.MissingInTarget:
                        currentNode.AvailableActions = new List <string> {
                            "Create", "Skip"
                        };

                        //check if parent is also MissingInTarget and Skip, make this cell readonly
                        if (parentNode != null && string.Equals(parentNode.Status, "Missing in Target") && string.Equals(parentNode.MergeAction, "Skip"))
                        {
                            currentNode.DropdownDisabled = true;
                            SetNodeTooltip(angularComposite, true);
                        }

                        break;

                    case ComparisonObjectStatus.MissingInSource:
                        currentNode.AvailableActions = new List <string> {
                            "Delete", "Skip"
                        };
                        break;

                    case ComparisonObjectStatus.DifferentDefinitions:
                        currentNode.AvailableActions = new List <string> {
                            "Update", "Skip"
                        };
                        break;

                    default:
                        //default covers ComparisonObjectStatus.SameDefinition: which is most common case (above cases are for saved skip selections from file)
                        currentNode.AvailableActions = new List <string> {
                            "Skip"
                        };
                        currentNode.DropdownDisabled = true;
                        SetNodeTooltip(angularComposite, true);
                        break;
                    }

                    break;

                default:
                    break;
                }
                ;

                // Add child objects if it exists
                if (comparisonObject.ChildComparisonObjects != null && comparisonObject.ChildComparisonObjects.Count > 0)
                {
                    foreach (ComparisonObject childComparisonObject in comparisonObject.ChildComparisonObjects)
                    {
                        PopulateComparisonData(childComparisonObject, level + 1, currentNode);
                    }
                }
            }
        }
예제 #12
0
        protected void TreeNodePopulate(object sender, TreeNodeEventArgs e)
        {
            string         val = e.Node.Value;
            ComparisonNode cn  = DB.GetNodeByName(val);

            if (cn == null)
            {
                Console.WriteLine("ERROR: Did not find the node " + e.Node.Value);
                e.Node.ChildNodes.Add(new TreeNode("ERROR: Did not find the node", "Error"));
                return;
            }

            ComparisonNode chain = cn;
            int            last  = val.LastIndexOf('-');

            while (last > 0)
            {
                string         parent = val.Substring(0, last);
                ComparisonNode node   = DB.GetNodeByName(parent, false, false);
                if (node == null)
                {
                    break;
                }
                chain.Parent = node;
                chain        = node;
                last         = parent.LastIndexOf('-');
            }

            foreach (var child in cn.Children)
            {
                TreeNode tn;

                switch (child.Type)
                {
                case CompType.Namespace:
                case CompType.Class:
                case CompType.Struct:
                case CompType.Interface:
                case CompType.Enum:
                    tn = new TreeNode(GetHtmlForNode(child, true), child.InternalID.ToString());
                    tn.SelectAction = TreeNodeSelectAction.None;
                    break;

                case CompType.Method:
                    tn = new TreeNode(GetHtmlForNode(child, false));
                    AttachComments(tn, child);
                    switch (cn.Type)
                    {
                    case CompType.Property:
                        tn.NavigateUrl = MakeURL(GetFQN(cn));
                        break;

                    default:
                        tn.NavigateUrl = MakeURL(GetMethodFQN(child));
                        break;
                    }
                    tn.Target = "_blank";
                    break;

                case CompType.Property:
                case CompType.Field:
                case CompType.Delegate:
                case CompType.Event:
                    bool prop_or_evt = (child.Type == CompType.Property || child.Type == CompType.Event);
                    tn = new TreeNode(GetHtmlForNode(child, prop_or_evt));
                    AttachComments(tn, child);

                    // Fields whose parents are an enum are enum definitions, make the link useful
                    if (child.Type == CompType.Field && cn.Type == CompType.Enum)
                    {
                        tn.NavigateUrl = MakeURL(GetFQN(cn));
                    }
                    else
                    {
                        tn.NavigateUrl = MakeURL(GetFQN(child));
                    }
                    tn.Target = "_blank";
                    break;

                case CompType.Attribute:
                    tn = new TreeNode(GetHtmlForNode(child, false));
                    tn.SelectAction = TreeNodeSelectAction.None;
                    break;

                case CompType.Assembly:
                    /* Should not happen */
                    throw new Exception("Should not happen");

                default:
                    tn = new TreeNode("Unknown type: " + child.Type.ToString());
                    break;
                }

                tn.Value = child.InternalID.ToString();
                if (tn.ChildNodes.Count == 0)
                {
                    tn.PopulateOnDemand = child.HasChildren;
                }

                e.Node.ChildNodes.Add(tn);
            }
        }