Esempio n. 1
0
        public override void ConsolidateNames(ref Dictionary <string, List <Node> > names)
        {
            TerminalNode rightTerminalNode = RightNode as TerminalNode;

            if (rightTerminalNode != null)
            {
                if (Operator != Operator.Dot)
                {
                    //replace RHS
                    Consolidate(ref (names), ref (rightTerminalNode));
                    RightNode = rightTerminalNode;
                }
            }
            else
            {
                RightNode.ConsolidateNames(ref (names));
            }

            //left has to be done 2nd, because in case of modifiers, we dont want to
            //replace the node on RHS by a node on LHS. So a modifier stack name is not unique.
            TerminalNode leftTerminalNode = LeftNode as TerminalNode;

            if (leftTerminalNode != null)
            {
                if (Operator != Operator.Assign)
                {
                    //replace LHS
                    Consolidate(ref (names), ref (leftTerminalNode));
                    LeftNode = leftTerminalNode;
                }
                else
                {
                    if (leftTerminalNode.Name != null)
                    {
                        if (names.ContainsKey(leftTerminalNode.Name))
                        {
                            List <Node> candidates = names[leftTerminalNode.Name];
                            candidates.Add(leftTerminalNode);
                        }
                        else
                        {
                            //append LHS
                            List <Node> candidates = new List <Node>();
                            candidates.Add(leftTerminalNode);
                            names.Add(leftTerminalNode.Name, candidates);
                        }
                    }
                }
            }
            else
            {
                LeftNode.ConsolidateNames(ref (names));
            }
        }
Esempio n. 2
0
        public override void ConsolidateNames(ref Dictionary <string, List <Node> > names)
        {
            List <Node> newFormalArguments = new List <Node>();

            //replace the names in arguments by current names in calling context
            foreach (Node argument in FormalArguments)
            {
                Node         newArgument  = argument;
                TerminalNode terminalNode = newArgument as TerminalNode;
                if (terminalNode != null)
                {
                    Consolidate(ref (names), ref (terminalNode));
                    newArgument = terminalNode;
                }
                else
                {
                    argument.ConsolidateNames(ref (names));
                }
                newFormalArguments.Add(newArgument);
            }
            FormalArguments = newFormalArguments;
        }
Esempio n. 3
0
        /*
        public DependencyPass.DependencyTracker generateAST(ProtoCore.CodeBlock codeblock)
        {
            DependencyTracker tempTracker = new DependencyTracker();

            foreach (Object obj in codeblock.Body)
            {
                Debug.Assert(obj is ProtoAssociative.DependencyPass.Node);
                Node node = obj as ProtoAssociative.DependencyPass.Node;
                tempTracker.AllNodes.Add(node);
            }
            return tempTracker;
        }
         * */

		public DependencyPass.DependencyTracker GetDemoTracker()
		{
			TerminalNode a = new TerminalNode();
			a.Value = "1..1000..+1";
			
			FunctionCallNode b = new FunctionCallNode();
            b.Function = new TerminalNode() { Value = "SQRT" };
			b.FormalArguments.Add(a);
			
			BinaryExpressionNode c = new BinaryExpressionNode();
			c.LeftNode = a;
			c.Operator = Operator.Mult;
			TerminalNode _2Node = new TerminalNode() { Value = "2" };
			c.RightNode = _2Node;
			
			BinaryExpressionNode d = new BinaryExpressionNode();
			d.LeftNode = c;
			d.RightNode = c;
			d.Operator = Operator.Mult;
			
			FunctionCallNode e = new FunctionCallNode();
            e.Function = new TerminalNode() { Value = "LineFromPoint" };
			e.FormalArguments.Add(a);
			e.FormalArguments.Add(b);
			e.FormalArguments.Add(d);

            Node f = new FunctionCallNode() { Function = new TerminalNode() { Value = "Trim" } };
			Node g = new FunctionCallNode() { Function = new TerminalNode() { Value = "Rotate" } };

			DependencyPass.DependencyTracker tracker = new DependencyPass.DependencyTracker();
			tracker.AllNodes.Add(a);
			tracker.AllNodes.Add(b);
			tracker.AllNodes.Add(c);
			tracker.AllNodes.Add(_2Node);
			tracker.AllNodes.Add(d);
			tracker.AllNodes.Add(e);
			tracker.AllNodes.Add(f);
			tracker.AllNodes.Add(g);
			
			tracker.DirectContingents.Add(a, new List<Node>() { });
			tracker.DirectContingents.Add(_2Node, new List<Node>() { });
			
			tracker.DirectContingents.Add(b, new List<Node>() { a });
			tracker.DirectContingents.Add(c, new List<Node>() { a, _2Node });
			tracker.DirectContingents.Add(d, new List<Node>() { c });
			tracker.DirectContingents.Add(e, new List<Node>() { a, b, d });
			tracker.DirectContingents.Add(f, new List<Node>() { e });
			tracker.DirectContingents.Add(g, new List<Node>() { f });
	
			tracker.DirectDependents.Add(a, new List<Node>() {b, c, e});
			tracker.DirectDependents.Add(b, new List<Node>() {e});
			tracker.DirectDependents.Add(c, new List<Node>() {d});
			tracker.DirectDependents.Add(d, new List<Node>() {e});
			tracker.DirectDependents.Add(e, new List<Node>() {f});
			tracker.DirectDependents.Add(f, new List<Node>() {g});
			tracker.DirectDependents.Add(g, new List<Node>() {});
			
			tracker.DirectDependents.Add(_2Node, new List<Node>() {c});
			
			return tracker;
		}
Esempio n. 4
0
 protected static void Consolidate(ref Dictionary<string, List<Node>> names, ref TerminalNode node)
 {
     if (null != node.Name)
     {
         if (names.ContainsKey(node.Name))
         {
             List<Node> candidates = names[node.Name];
             node = candidates[candidates.Count - 1] as TerminalNode;
         }
         else
         {
             //symbol not defined.
             //should we ignore this until somebody else defines a symbol? 
             //or add the symbol?
             //throw new KeyNotFoundException();
             List<Node> candidates = new List<Node>();
             candidates.Add(node);
             names.Add(node.Name, candidates);
         }
     }
 }
Esempio n. 5
0
        // a = 25
        // b = 4 + 20 / 5
        // c = a - 20 * 5
        public DependencyPass.DependencyTracker GetDemoTrackerJun()
        {
            DependencyPass.DependencyTracker tracker = new DependencyPass.DependencyTracker();

            
            string varIdent = null;
            const int functionIndex = (int)ProtoCore.DSASM.Constants.kGlobalScope;

            //========================================================
            // a = 25
            BinaryExpressionNode i1 = new BinaryExpressionNode();

            varIdent = "a";
            TerminalNode fAssignLeft = new TerminalNode() { Value = varIdent, type = /*SDD*/(int)ProtoCore.PrimitiveType.kTypeVar };
                // SDD - automatic allocation
                //tracker.Allocate(varIdent, (int)FusionCore.DSASM.Constants.kGlobalScope, (int)FusionCore.DSASM.Constants.kPrimitiveSize);

            i1.LeftNode = fAssignLeft;
            i1.Operator = Operator.Assign;
            TerminalNode fAssignRight = new TerminalNode() { Value = "25", type = (int)ProtoCore.PrimitiveType.kTypeInt };
            i1.RightNode = fAssignRight;

            //========================================================


            // b = 4 + 20 / 5

            // 20 / 5
            BinaryExpressionNode sDiv = new BinaryExpressionNode();
            TerminalNode sDivLeft = new TerminalNode() { Value = "20", /*SDD*/type = (int)ProtoCore.PrimitiveType.kTypeInt };
            sDiv.LeftNode = sDivLeft;
            sDiv.Operator = Operator.Divide;
            TerminalNode sDivRight = new TerminalNode() { Value = "5", /*SDD*/type = (int)ProtoCore.PrimitiveType.kTypeInt };
            sDiv.RightNode = sDivRight;


            // 4 + ( 20 / 5 )
            BinaryExpressionNode sAdd = new BinaryExpressionNode();
            TerminalNode sAddLeft = new TerminalNode() { Value = "4", /*SDD*/type = (int)ProtoCore.PrimitiveType.kTypeInt };
            sAdd.LeftNode = sAddLeft;
            sAdd.Operator = Operator.Add;
            BinaryExpressionNode sAddRight = new BinaryExpressionNode();
            sAddRight = sDiv;
            sAdd.RightNode = sAddRight;


            // b = 4 + 20 / 5
            BinaryExpressionNode i2 = new BinaryExpressionNode();

            varIdent = "b";
            TerminalNode sAssignLeft = new TerminalNode() { Value = varIdent, /*SDD*/type = (int)ProtoCore.PrimitiveType.kTypeVar };
                // SDD - automatic allocation
                //tracker.Allocate(varIdent, (int)FusionCore.DSASM.Constants.kGlobalScope, (int)FusionCore.DSASM.Constants.kPrimitiveSize);

            i2.LeftNode = sAssignLeft;
            i2.Operator = Operator.Assign;
            BinaryExpressionNode sAssignRight = new BinaryExpressionNode();
            sAssignRight = sAdd;
            i2.RightNode = sAssignRight;



            // c = a - 20 * 5

            // 20 * 5
            BinaryExpressionNode sMul = new BinaryExpressionNode();
            TerminalNode sMulLeft = new TerminalNode() { Value = "20", /*SDD*/type = (int)ProtoCore.PrimitiveType.kTypeInt };
            sMul.LeftNode = sMulLeft;
            sMul.Operator = Operator.Mult;
            TerminalNode sMulRight = new TerminalNode() { Value = "5", /*SDD*/type = (int)ProtoCore.PrimitiveType.kTypeInt };
            sMul.RightNode = sMulRight;


            // a - ( 20 * 5 )
            BinaryExpressionNode sSub = new BinaryExpressionNode();
            TerminalNode sSubLeft = new TerminalNode() { Value = "a", /*SDD*/type = (int)ProtoCore.PrimitiveType.kTypeVar };
            sSub.LeftNode = sSubLeft;
            sSub.Operator = Operator.Subtract;
            BinaryExpressionNode sSubRight = new BinaryExpressionNode();
            sSubRight = sMul;
            sSub.RightNode = sSubRight;


            // c = a - 20 * 5
            BinaryExpressionNode i3 = new BinaryExpressionNode();

            varIdent = "c";
            TerminalNode si3Left = new TerminalNode() { Value = varIdent, /*SDD*/type = (int)ProtoCore.PrimitiveType.kTypeVar };
                // SDD - automatic allocation
                //tracker.Allocate(varIdent, (int)FusionCore.DSASM.Constants.kGlobalScope, (int)FusionCore.DSASM.Constants.kPrimitiveSize);

            i3.LeftNode = si3Left;
            i3.Operator = Operator.Assign;
            BinaryExpressionNode si3Right = new BinaryExpressionNode();
            si3Right = sSub;
            i3.RightNode = si3Right;


            tracker.AllNodes.Add(i1);
            tracker.AllNodes.Add(i2);
            tracker.AllNodes.Add(i3);

            return tracker;
        }
Esempio n. 6
0
        /*
         * public DependencyPass.DependencyTracker generateAST(ProtoCore.CodeBlock codeblock)
         * {
         *  DependencyTracker tempTracker = new DependencyTracker();
         *
         *  foreach (Object obj in codeblock.Body)
         *  {
         *      Debug.Assert(obj is ProtoAssociative.DependencyPass.Node);
         *      Node node = obj as ProtoAssociative.DependencyPass.Node;
         *      tempTracker.AllNodes.Add(node);
         *  }
         *  return tempTracker;
         * }
         * */

        public DependencyPass.DependencyTracker GetDemoTracker()
        {
            TerminalNode a = new TerminalNode();

            a.Value = "1..1000..+1";

            FunctionCallNode b = new FunctionCallNode();

            b.Function = new TerminalNode()
            {
                Value = "SQRT"
            };
            b.FormalArguments.Add(a);

            BinaryExpressionNode c = new BinaryExpressionNode();

            c.LeftNode = a;
            c.Operator = Operator.Mult;
            TerminalNode _2Node = new TerminalNode()
            {
                Value = "2"
            };

            c.RightNode = _2Node;

            BinaryExpressionNode d = new BinaryExpressionNode();

            d.LeftNode  = c;
            d.RightNode = c;
            d.Operator  = Operator.Mult;

            FunctionCallNode e = new FunctionCallNode();

            e.Function = new TerminalNode()
            {
                Value = "LineFromPoint"
            };
            e.FormalArguments.Add(a);
            e.FormalArguments.Add(b);
            e.FormalArguments.Add(d);

            Node f = new FunctionCallNode()
            {
                Function = new TerminalNode()
                {
                    Value = "Trim"
                }
            };
            Node g = new FunctionCallNode()
            {
                Function = new TerminalNode()
                {
                    Value = "Rotate"
                }
            };

            DependencyPass.DependencyTracker tracker = new DependencyPass.DependencyTracker();
            tracker.AllNodes.Add(a);
            tracker.AllNodes.Add(b);
            tracker.AllNodes.Add(c);
            tracker.AllNodes.Add(_2Node);
            tracker.AllNodes.Add(d);
            tracker.AllNodes.Add(e);
            tracker.AllNodes.Add(f);
            tracker.AllNodes.Add(g);

            tracker.DirectContingents.Add(a, new List <Node>()
            {
            });
            tracker.DirectContingents.Add(_2Node, new List <Node>()
            {
            });

            tracker.DirectContingents.Add(b, new List <Node>()
            {
                a
            });
            tracker.DirectContingents.Add(c, new List <Node>()
            {
                a, _2Node
            });
            tracker.DirectContingents.Add(d, new List <Node>()
            {
                c
            });
            tracker.DirectContingents.Add(e, new List <Node>()
            {
                a, b, d
            });
            tracker.DirectContingents.Add(f, new List <Node>()
            {
                e
            });
            tracker.DirectContingents.Add(g, new List <Node>()
            {
                f
            });

            tracker.DirectDependents.Add(a, new List <Node>()
            {
                b, c, e
            });
            tracker.DirectDependents.Add(b, new List <Node>()
            {
                e
            });
            tracker.DirectDependents.Add(c, new List <Node>()
            {
                d
            });
            tracker.DirectDependents.Add(d, new List <Node>()
            {
                e
            });
            tracker.DirectDependents.Add(e, new List <Node>()
            {
                f
            });
            tracker.DirectDependents.Add(f, new List <Node>()
            {
                g
            });
            tracker.DirectDependents.Add(g, new List <Node>()
            {
            });

            tracker.DirectDependents.Add(_2Node, new List <Node>()
            {
                c
            });

            return(tracker);
        }
Esempio n. 7
0
 protected static void Consolidate(ref Dictionary <string, List <Node> > names, ref TerminalNode node)
 {
     if (null != node.Name)
     {
         if (names.ContainsKey(node.Name))
         {
             List <Node> candidates = names[node.Name];
             node = candidates[candidates.Count - 1] as TerminalNode;
         }
         else
         {
             //symbol not defined.
             //should we ignore this until somebody else defines a symbol?
             //or add the symbol?
             //throw new KeyNotFoundException();
             List <Node> candidates = new List <Node>();
             candidates.Add(node);
             names.Add(node.Name, candidates);
         }
     }
 }
Esempio n. 8
0
        // a = 25
        // b = 4 + 20 / 5
        // c = a - 20 * 5
        public DependencyPass.DependencyTracker GetDemoTrackerJun()
        {
            DependencyPass.DependencyTracker tracker = new DependencyPass.DependencyTracker();


            string    varIdent      = null;
            const int functionIndex = (int)ProtoCore.DSASM.Constants.kGlobalScope;

            //========================================================
            // a = 25
            BinaryExpressionNode i1 = new BinaryExpressionNode();

            varIdent = "a";
            TerminalNode fAssignLeft = new TerminalNode()
            {
                Value = varIdent, type = /*SDD*/ (int)ProtoCore.PrimitiveType.kTypeVar
            };

            // SDD - automatic allocation
            //tracker.Allocate(varIdent, (int)FusionCore.DSASM.Constants.kGlobalScope, (int)FusionCore.DSASM.Constants.kPrimitiveSize);

            i1.LeftNode = fAssignLeft;
            i1.Operator = Operator.Assign;
            TerminalNode fAssignRight = new TerminalNode()
            {
                Value = "25", type = (int)ProtoCore.PrimitiveType.kTypeInt
            };

            i1.RightNode = fAssignRight;

            //========================================================


            // b = 4 + 20 / 5

            // 20 / 5
            BinaryExpressionNode sDiv     = new BinaryExpressionNode();
            TerminalNode         sDivLeft = new TerminalNode()
            {
                Value = "20", /*SDD*/ type = (int)ProtoCore.PrimitiveType.kTypeInt
            };

            sDiv.LeftNode = sDivLeft;
            sDiv.Operator = Operator.Divide;
            TerminalNode sDivRight = new TerminalNode()
            {
                Value = "5", /*SDD*/ type = (int)ProtoCore.PrimitiveType.kTypeInt
            };

            sDiv.RightNode = sDivRight;


            // 4 + ( 20 / 5 )
            BinaryExpressionNode sAdd     = new BinaryExpressionNode();
            TerminalNode         sAddLeft = new TerminalNode()
            {
                Value = "4", /*SDD*/ type = (int)ProtoCore.PrimitiveType.kTypeInt
            };

            sAdd.LeftNode = sAddLeft;
            sAdd.Operator = Operator.Add;
            BinaryExpressionNode sAddRight = new BinaryExpressionNode();

            sAddRight      = sDiv;
            sAdd.RightNode = sAddRight;


            // b = 4 + 20 / 5
            BinaryExpressionNode i2 = new BinaryExpressionNode();

            varIdent = "b";
            TerminalNode sAssignLeft = new TerminalNode()
            {
                Value = varIdent, /*SDD*/ type = (int)ProtoCore.PrimitiveType.kTypeVar
            };

            // SDD - automatic allocation
            //tracker.Allocate(varIdent, (int)FusionCore.DSASM.Constants.kGlobalScope, (int)FusionCore.DSASM.Constants.kPrimitiveSize);

            i2.LeftNode = sAssignLeft;
            i2.Operator = Operator.Assign;
            BinaryExpressionNode sAssignRight = new BinaryExpressionNode();

            sAssignRight = sAdd;
            i2.RightNode = sAssignRight;



            // c = a - 20 * 5

            // 20 * 5
            BinaryExpressionNode sMul     = new BinaryExpressionNode();
            TerminalNode         sMulLeft = new TerminalNode()
            {
                Value = "20", /*SDD*/ type = (int)ProtoCore.PrimitiveType.kTypeInt
            };

            sMul.LeftNode = sMulLeft;
            sMul.Operator = Operator.Mult;
            TerminalNode sMulRight = new TerminalNode()
            {
                Value = "5", /*SDD*/ type = (int)ProtoCore.PrimitiveType.kTypeInt
            };

            sMul.RightNode = sMulRight;


            // a - ( 20 * 5 )
            BinaryExpressionNode sSub     = new BinaryExpressionNode();
            TerminalNode         sSubLeft = new TerminalNode()
            {
                Value = "a", /*SDD*/ type = (int)ProtoCore.PrimitiveType.kTypeVar
            };

            sSub.LeftNode = sSubLeft;
            sSub.Operator = Operator.Subtract;
            BinaryExpressionNode sSubRight = new BinaryExpressionNode();

            sSubRight      = sMul;
            sSub.RightNode = sSubRight;


            // c = a - 20 * 5
            BinaryExpressionNode i3 = new BinaryExpressionNode();

            varIdent = "c";
            TerminalNode si3Left = new TerminalNode()
            {
                Value = varIdent, /*SDD*/ type = (int)ProtoCore.PrimitiveType.kTypeVar
            };

            // SDD - automatic allocation
            //tracker.Allocate(varIdent, (int)FusionCore.DSASM.Constants.kGlobalScope, (int)FusionCore.DSASM.Constants.kPrimitiveSize);

            i3.LeftNode = si3Left;
            i3.Operator = Operator.Assign;
            BinaryExpressionNode si3Right = new BinaryExpressionNode();

            si3Right     = sSub;
            i3.RightNode = si3Right;


            tracker.AllNodes.Add(i1);
            tracker.AllNodes.Add(i2);
            tracker.AllNodes.Add(i3);

            return(tracker);
        }