private void EmitFunctionCallNode(Func node, out AssociativeNode outnode) { Validity.Assert(node != null); FunctionCallNode fNode = new FunctionCallNode(); List<ProtoCore.AST.AssociativeAST.AssociativeNode> args = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>(); if (node.Name.Contains(".")) { string funcName = (node.Name.Split('.'))[1]; fNode.Function = new IdentifierNode(funcName); } //else if (node.GetChildrenWithIndices().Count != 0) //{ //} else fNode.Function = new IdentifierNode(node.Name); for (int i = 0; i < node.numParameters; i++) args.Add(new NullNode()); if (args.Count > 0) { Dictionary<int, Node> nodes = node.GetChildrenWithIndices(); for (int i = 0; i < nodes.Count; ++i) { AssociativeNode argNode = null; DFSTraverse(nodes[i], out argNode); args.RemoveAt(i); args.Insert(i, argNode); } } fNode.FormalArguments = args; outnode = fNode; }
private void EmitRangeExpNode(Func node, out AssociativeNode outnode) { Validity.Assert(node != null); Validity.Assert(node.isRange); RangeExprNode rangeNode = new RangeExprNode(); // Set FromNode, ToNode, stepOperator and StepNode for rangeNode Dictionary<int, Node> nodes = node.GetChildrenWithIndices(); //int numParams = node.numParameters; AssociativeNode startNode = null; AssociativeNode endNode = null; AssociativeNode stepNode = null; if (nodes.Count >= 1) { DFSTraverse(nodes[0], out startNode); } if (nodes.Count >= 2) { DFSTraverse(nodes[1], out endNode); } if (nodes.Count >= 3) { DFSTraverse(nodes[2], out stepNode); } rangeNode.FromNode = startNode; rangeNode.ToNode = endNode; rangeNode.StepNode = stepNode; if (node.Name == "Range.ByIncrementValue") { rangeNode.stepoperator = ProtoCore.DSASM.RangeStepOperator.stepsize; } else if (node.Name == "Range.ByIntervals") { rangeNode.stepoperator = ProtoCore.DSASM.RangeStepOperator.num; } else { rangeNode.stepoperator = ProtoCore.DSASM.RangeStepOperator.approxsize; } outnode = rangeNode; //outnode = CreateBinaryExpNode(node, rangeNode); }
private void EmitFunctionNode(Func node, out AssociativeNode outnode) { Validity.Assert(node != null); AssociativeNode fNode = new NullNode(); string funcQualifier = node.Name; if (node.isRange) { EmitRangeExpNode(node, out fNode); } else if (!funcQualifier.Contains(".")) { if (node.isProperty) { Dictionary<int, Node> nodes = node.GetChildrenWithIndices(); Validity.Assert(nodes.Count == 1); for (int i = 0; i < nodes.Count; ++i) { AssociativeNode instanceNode = null; DFSTraverse(nodes[i], out instanceNode); EmitFunctionCallNode(node, out fNode); ((fNode as FunctionCallNode).Function as IdentifierNode).Value = ProtoCore.DSASM.Constants.kGetterPrefix + ((fNode as FunctionCallNode).Function as IdentifierNode).Value; //string className = (node.Name.Split('.'))[0]; //IdentifierNode inode = new IdentifierNode(className); fNode = ProtoCore.Utils.CoreUtils.GenerateCallDotNode(instanceNode, fNode as FunctionCallNode); } } else if (node.isMemberFunction) { Dictionary<int, Node> nodes = node.GetChildrenWithIndices(); AssociativeNode instanceNode = null; DFSTraverse(nodes[0], out instanceNode); EmitFunctionCallNode(node, out fNode); //string className = (node.Name.Split('.'))[0]; //IdentifierNode inode = new IdentifierNode(className); fNode = ProtoCore.Utils.CoreUtils.GenerateCallDotNode(instanceNode, fNode as FunctionCallNode); } else { // Create AssociativeAST.FunctionCallNode for global and built-in functions EmitFunctionCallNode(node, out fNode); } } else { // Create FunctionDotCallNode for ctors, static and instance methods EmitFunctionDotCallNode(node, out fNode); } BinaryExpressionNode assignmentNode = new BinaryExpressionNode(); assignmentNode.LeftNode = new IdentifierNode(node.tempName); assignmentNode.Optr = ProtoCore.DSASM.Operator.assign; assignmentNode.RightNode = fNode; assignmentNode.Guid = node.Guid; Validity.Assert(gc != null); gc.HandleNewNode(assignmentNode); outnode = assignmentNode; }
private void EmitFunctionDotCallNode(Func node, out AssociativeNode outnode) { Validity.Assert(node != null); AssociativeNode fNode = null; EmitFunctionCallNode(node, out fNode); string className = (node.Name.Split('.'))[0]; IdentifierNode inode = new IdentifierNode(className); outnode = ProtoCore.Utils.CoreUtils.GenerateCallDotNode(inode, fNode as FunctionCallNode); }
internal FunctionCall(Func f) : base(f.Name, f.Guid) { func = f; if (f.numParameters != 0) { int k = f.numParameters; while (k > 0) { parameters.Add(k - 1, null); k--; } } }
public bool CreatePropertyNode(uint guid,string propertyName,string tempName) { if (guid < 0) { throw new ArgumentException("Invalid argument value!", "guid"); } if (String.IsNullOrEmpty(propertyName)) { throw new ArgumentException("Invalid argument value!", "propertyName"); } // Handle static calls // TODO Jun: Determine if this check needs to be done at the UI level Validity.Assert(null != core); if (IsStaticCall(propertyName)) { CreateCodeblockNode(guid, tempName + "=" + propertyName); } else { Func op = new Func(propertyName, guid); op.isStatic = false; op.isProperty = true; op.tempName = tempName; graph.AddNode(op); } return true; }
public bool CreateMethodNode(uint guid, string functionName, int args, string tempName, string replicationGuides, bool isMemberFunction = false) { if (guid < 0) throw new ArgumentException("Invalid argument value!", "guid"); if (String.IsNullOrEmpty(functionName)) throw new ArgumentException("Invalid argument value!", "methodName"); Func op = new Func(functionName, guid, args, replicationGuides); op.isStatic = false; op.isMemberFunction = isMemberFunction; op.tempName = tempName; graph.AddNode(op); return true; }
public bool CreateFunctionNode(uint guid, string functionName, int args, string tempName) { if (guid < 0) throw new ArgumentException("Invalid argument value!", "guid"); if (String.IsNullOrEmpty(functionName)) throw new ArgumentException("Invalid argument value!", "functionName"); Func op = new Func(functionName, guid, args); op.tempName = tempName; op.isStatic = true; graph.AddNode(op); return true; }
public bool CreateRangeNode(uint guid, string range, int args, int argType, string tempName,string replicationGuides) { if (guid < 0) throw new ArgumentException("Invalid argument value!", "guid"); if (String.IsNullOrEmpty(range)) throw new ArgumentException("Invalid argument value!", "opSymbol"); Func op = new Func(range, guid, args,replicationGuides); op.isRange = true; op.isStatic = true; op.argTypeRange = argType; op.tempName = tempName; graph.AddNode(op); return true; }