示例#1
0
 protected static void Consolidate(ref Dictionary<string, List<Node>> names, ref IdentifierNode node)
 {
     if (null != node.Name)
     {
         if (names.ContainsKey(node.Name))
         {
             List<Node> candidates = names[node.Name];
             node = candidates[candidates.Count - 1] as IdentifierNode;
         }
         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);
         }
     }
 }
示例#2
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()
		{
            IdentifierNode a = new IdentifierNode();
			a.Value = "1..1000..+1";
			
			FunctionCallNode b = new FunctionCallNode();
            b.Function = new IdentifierNode() { Value = "SQRT" };
			b.FormalArguments.Add(a);
			
			BinaryExpressionNode c = new BinaryExpressionNode();
			c.LeftNode = a;
            c.Optr = ProtoCore.DSASM.Operator.mul;
            IdentifierNode _2Node = new IdentifierNode() { Value = "2" };
			c.RightNode = _2Node;
			
			BinaryExpressionNode d = new BinaryExpressionNode();
			d.LeftNode = c;
			d.RightNode = c;
			d.Optr = ProtoCore.DSASM.Operator.mul;
			
			FunctionCallNode e = new FunctionCallNode();
            e.Function = new IdentifierNode() { Value = "LineFromPoint" };
			e.FormalArguments.Add(a);
			e.FormalArguments.Add(b);
			e.FormalArguments.Add(d);

            Node f = new FunctionCallNode() { Function = new IdentifierNode() { Value = "Trim" } };
            Node g = new FunctionCallNode() { Function = new IdentifierNode() { 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;
		}
示例#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()
        {
            IdentifierNode a = new IdentifierNode();

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

            FunctionCallNode b = new FunctionCallNode();

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

            BinaryExpressionNode c = new BinaryExpressionNode();

            c.LeftNode = a;
            c.Optr     = ProtoCore.DSASM.Operator.mul;
            IdentifierNode _2Node = new IdentifierNode()
            {
                Value = "2"
            };

            c.RightNode = _2Node;

            BinaryExpressionNode d = new BinaryExpressionNode();

            d.LeftNode  = c;
            d.RightNode = c;
            d.Optr      = ProtoCore.DSASM.Operator.mul;

            FunctionCallNode e = new FunctionCallNode();

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

            Node f = new FunctionCallNode()
            {
                Function = new IdentifierNode()
                {
                    Value = "Trim"
                }
            };
            Node g = new FunctionCallNode()
            {
                Function = new IdentifierNode()
                {
                    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);
        }
示例#4
0
        // a = 25
        // b = 4 + 20 / 5
        // c = a - 20 * 5
        public DependencyPass.DependencyTracker GetDemoTrackerJun()
        {
            DependencyPass.DependencyTracker tracker = new DependencyPass.DependencyTracker();

            
            string varIdent = null;

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

            varIdent = "a";
            IdentifierNode fAssignLeft = new IdentifierNode() { 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.Optr = ProtoCore.DSASM.Operator.assign;
            IdentifierNode fAssignRight = new IdentifierNode() { Value = "25", type = (int)ProtoCore.PrimitiveType.kTypeInt };
            i1.RightNode = fAssignRight;

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


            // b = 4 + 20 / 5

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


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


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

            varIdent = "b";
            IdentifierNode sAssignLeft = new IdentifierNode() { 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.Optr = ProtoCore.DSASM.Operator.assign;
            BinaryExpressionNode sAssignRight = new BinaryExpressionNode();
            sAssignRight = sAdd;
            i2.RightNode = sAssignRight;



            // c = a - 20 * 5

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


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


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

            varIdent = "c";
            IdentifierNode si3Left = new IdentifierNode() { 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.Optr = ProtoCore.DSASM.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;
        }
示例#5
0
 protected static void Consolidate(ref Dictionary <string, List <Node> > names, ref IdentifierNode node)
 {
     if (null != node.Name)
     {
         if (names.ContainsKey(node.Name))
         {
             List <Node> candidates = names[node.Name];
             node = candidates[candidates.Count - 1] as IdentifierNode;
         }
         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);
         }
     }
 }
示例#6
0
        // a = 25
        // b = 4 + 20 / 5
        // c = a - 20 * 5
        public DependencyPass.DependencyTracker GetDemoTrackerJun()
        {
            DependencyPass.DependencyTracker tracker = new DependencyPass.DependencyTracker();


            string varIdent = null;

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

            varIdent = "a";
            IdentifierNode fAssignLeft = new IdentifierNode()
            {
                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.Optr     = ProtoCore.DSASM.Operator.assign;
            IdentifierNode fAssignRight = new IdentifierNode()
            {
                Value = "25", type = (int)ProtoCore.PrimitiveType.kTypeInt
            };

            i1.RightNode = fAssignRight;

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


            // b = 4 + 20 / 5

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

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

            sDiv.RightNode = sDivRight;


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

            sAdd.LeftNode = sAddLeft;
            sAdd.Optr     = ProtoCore.DSASM.Operator.add;
            BinaryExpressionNode sAddRight = new BinaryExpressionNode();

            sAddRight      = sDiv;
            sAdd.RightNode = sAddRight;


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

            varIdent = "b";
            IdentifierNode sAssignLeft = new IdentifierNode()
            {
                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.Optr     = ProtoCore.DSASM.Operator.assign;
            BinaryExpressionNode sAssignRight = new BinaryExpressionNode();

            sAssignRight = sAdd;
            i2.RightNode = sAssignRight;



            // c = a - 20 * 5

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

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

            sMul.RightNode = sMulRight;


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

            sSub.LeftNode = sSubLeft;
            sSub.Optr     = ProtoCore.DSASM.Operator.sub;
            BinaryExpressionNode sSubRight = new BinaryExpressionNode();

            sSubRight      = sMul;
            sSub.RightNode = sSubRight;


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

            varIdent = "c";
            IdentifierNode si3Left = new IdentifierNode()
            {
                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.Optr     = ProtoCore.DSASM.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);
        }
示例#7
0
	void ArgDecl(out Node node, ProtoCore.DSASM.AccessModifier access = ProtoCore.DSASM.AccessModifier.kPublic) {
		IdentifierNode tNode = null; 
		VarDeclNode varDeclNode = new VarDeclNode(); 
		varDeclNode.memregion = ProtoCore.DSASM.MemoryRegion.kMemStack;
		varDeclNode.access = access;
		
		if (IsArrayAccess()) {
			arrayIdent(out node);
			tNode = node as IdentifierNode; 
			varDeclNode.NameNode = tNode;
			
		} else if (la.kind == 1) {
			Get();
			tNode = new IdentifierNode() 
			{ 
			   Value = t.val, 
			   Name = t.val, 
			   type = (int)ProtoCore.PrimitiveType.kTypeVar, 
			   datatype = ProtoCore.PrimitiveType.kTypeVar 
			}; 
			varDeclNode.NameNode = tNode;
			
		} else SynErr(71);
		ProtoCore.Type argtype = new ProtoCore.Type(); argtype.Name = "var"; argtype.rank = 0; argtype.UID = 0; 
		if (la.kind == 36) {
			Get();
			Expect(1);
			argtype.Name = t.val; 
			if (la.kind == 11) {
				argtype.IsIndexable = true; 
				Get();
				Expect(12);
				argtype.rank = 1; 
				if (la.kind == 11 || la.kind == 21 || la.kind == 35) {
					if (la.kind == 21) {
						Get();
						Expect(11);
						Expect(12);
						argtype.rank = ProtoCore.DSASM.Constants.nDimensionArrayRank; 
					} else {
						while (la.kind == 11) {
							Get();
							Expect(12);
							argtype.rank++; 
						}
					}
				}
			}
		}
		varDeclNode.ArgumentType = argtype; 
		if (la.kind == 35) {
			Get();
			Node rhsNode; 
			Expression(out rhsNode);
			BinaryExpressionNode bNode = new BinaryExpressionNode();
			bNode.LeftNode = tNode;
			bNode.RightNode = rhsNode;
			bNode.Optr = Operator.assign;
			varDeclNode.NameNode = bNode;		
			
		}
		node = varDeclNode; 
	}
示例#8
0
	void Ident(out Node node) {
		Expect(1);
		int ltype = (0 == String.Compare(t.val, "return")) ? (int)ProtoCore.PrimitiveType.kTypeReturn : (int)ProtoCore.PrimitiveType.kTypeVar;
		IdentifierNode var = new IdentifierNode() 
		{
		// TODO Jun: Move the primitive types into a class table 
		Value = t.val, 
		Name = t.val, 
		type = ltype,
		datatype = (ProtoCore.PrimitiveType)ltype 
		}; 
		node = var;
		
	}
示例#9
0
	void ReplicationGuideIdent(out Node node) {
		Ident(out node);
		IdentifierNode identNode = node as IdentifierNode; 
		NodeList guides = new NodeList();
		Expect(16);
		Expect(2);
		Node numNode = new IdentifierNode() { Value = t.val }; 
		Expect(17);
		guides.Add(numNode); 
		while (la.kind == 16) {
			Get();
			Expect(2);
			numNode = new IdentifierNode() { Value = t.val }; 
			Expect(17);
			guides.Add(numNode); 
		}
		identNode.ReplicationGuides = guides; 
		node = identNode; 
	}