internal override IEnumerable <AssociativeNode> BuildAst(List <AssociativeNode> inputAstNodes) { //Do not build if the node is in error. if (State == ElementState.Error) { return(null); } var resultNodes = new List <AssociativeNode>(); // Define unbound variables if necessary if (inputIdentifiers != null && inputAstNodes != null && inputIdentifiers.Count == inputAstNodes.Count) { var initStatments = inputIdentifiers.Zip(inputAstNodes, (ident, rhs) => { var identNode = AstFactory.BuildIdentifier(ident); MapIdentifiers(identNode); return(AstFactory.BuildAssignment(identNode, rhs)); }); resultNodes.AddRange(initStatments); } foreach (var astNode in codeStatements.Select(stmnt => NodeUtils.Clone(stmnt.AstNode))) { MapIdentifiers(astNode); resultNodes.Add(astNode as AssociativeNode); } return(resultNodes); }
/// <summary> /// For code block nodes, each output identifier of an output port is mapped. /// For an example, "p = 1" would have its internal identifier renamed to /// "pXXXX", where "XXXX" is the GUID of the code block node. This mapping is /// done to ensure the uniqueness of the output variable name. /// </summary> /// <param name="portIndex">Output port index</param> /// <param name="forRawName">Set this parameter to true to retrieve the /// original identifier name "p". If this parameter is false, the mapped /// identifer name "pXXXX" is returned instead.</param> /// <returns></returns> private IdentifierNode GetAstIdentifierForOutputIndexInternal(int portIndex, bool forRawName) { var statement = GetStatementForOutput(portIndex); if (statement == null) { return(null); } var binExprNode = statement.AstNode as BinaryExpressionNode; if (binExprNode == null || (binExprNode.LeftNode == null)) { return(null); } var identNode = binExprNode.LeftNode as IdentifierNode; var mappedIdent = NodeUtils.Clone(identNode); if (!forRawName) { MapIdentifiers(mappedIdent); } return(mappedIdent as IdentifierNode); }
public CodeBlockNode(CodeBlockNode rhs) : base(rhs) { Body = new List <ImperativeNode>(); foreach (ImperativeNode aNode in rhs.Body) { ImperativeNode newNode = NodeUtils.Clone(aNode); Body.Add(newNode); } }
public ExprListNode(ExprListNode rhs) : base(rhs) { Exprs = new List <ImperativeNode>(); foreach (ImperativeNode argNode in rhs.Exprs) { ImperativeNode tempNode = NodeUtils.Clone(argNode); Exprs.Add(tempNode); } }
public WhileStmtNode(WhileStmtNode rhs) : base(rhs) { Expr = NodeUtils.Clone(rhs.Expr); Body = new List <ImperativeNode>(); foreach (ImperativeNode iNode in rhs.Body) { ImperativeNode newNode = NodeUtils.Clone(iNode); Body.Add(newNode); } }
public FunctionCallNode(FunctionCallNode rhs) : base(rhs) { Function = NodeUtils.Clone(rhs.Function); FormalArguments = new List <ImperativeNode>(); foreach (ImperativeNode argNode in rhs.FormalArguments) { ImperativeNode tempNode = NodeUtils.Clone(argNode); FormalArguments.Add(tempNode); } }
public RangeExprNode(RangeExprNode rhs) : base(rhs) { From = NodeUtils.Clone(rhs.From); To = NodeUtils.Clone(rhs.To); if (null != rhs.Step) { Step = NodeUtils.Clone(rhs.Step); } StepOperator = rhs.StepOperator; HasRangeAmountOperator = rhs.HasRangeAmountOperator; }
public LanguageBlockNode(LanguageBlockNode rhs) : base(rhs) { CodeBlockNode = ProtoCore.Utils.NodeUtils.Clone(rhs.CodeBlockNode); codeblock = new ProtoCore.LanguageCodeBlock(rhs.codeblock); Attributes = new List <ImperativeNode>(); foreach (ImperativeNode aNode in rhs.Attributes) { ImperativeNode newNode = ProtoCore.Utils.NodeUtils.Clone(aNode); Attributes.Add(newNode); } CodeBlockNode = NodeUtils.Clone(rhs.CodeBlockNode); }
/// <summary> /// For code block nodes, each output identifier of an output port is mapped. /// For an example, "p = 1" would have its internal identifier renamed to /// "pXXXX", where "XXXX" is the GUID of the code block node. This mapping is /// done to ensure the uniqueness of the output variable name. /// </summary> /// <param name="portIndex">Output port index</param> /// <param name="forRawName">Set this parameter to true to retrieve the /// original identifier name "p". If this parameter is false, the mapped /// identifer name "pXXXX" is returned instead.</param> /// <returns></returns> private IdentifierNode GetAstIdentifierForOutputIndexInternal(int portIndex, bool forRawName) { if (State == ElementState.Error) { return(null); } // Here the "portIndex" is back mapped to the corresponding "Statement" // object. However, not all "Statement" objects produce an output port, // so "portIndex" cannot be used directly to index into "codeStatements" // list. This loop goes through "codeStatements", decrementing "portIndex" // along the way to determine the right "Statement" object matching the // port index. // Statement statement = null; var svs = CodeBlockUtils.GetStatementVariables(codeStatements, true); for (int stmt = 0, port = 0; stmt < codeStatements.Count; stmt++) { if (CodeBlockUtils.DoesStatementRequireOutputPort(svs, stmt)) { if (port == portIndex) { statement = codeStatements[stmt]; break; } port = port + 1; } } if (statement == null) { return(null); } var binExprNode = statement.AstNode as BinaryExpressionNode; if (binExprNode == null || (binExprNode.LeftNode == null)) { return(null); } var identNode = binExprNode.LeftNode as IdentifierNode; var mappedIdent = NodeUtils.Clone(identNode); if (!forRawName) { MapIdentifiers(mappedIdent); } return(mappedIdent as IdentifierNode); }
/// <summary> /// Apppend replication guide to the input parameter based on lacing /// strategy. /// </summary> /// <param name="inputs"></param> /// <returns></returns> private void AppendReplicationGuides(List <AssociativeNode> inputs) { if (inputs == null || !inputs.Any()) { return; } switch (ArgumentLacing) { case LacingStrategy.Longest: for (int i = 0; i < inputs.Count(); ++i) { if (inputs[i] is ArrayNameNode) { var astNode = NodeUtils.Clone(inputs[i]) as ArrayNameNode; astNode.ReplicationGuides = new List <AssociativeNode>(); var guideNode = new ReplicationGuideNode { RepGuide = AstFactory.BuildIdentifier("1"), IsLongest = true }; astNode.ReplicationGuides.Add(guideNode); inputs[i] = astNode; } } break; case LacingStrategy.CrossProduct: int guide = 1; for (int i = 0; i < inputs.Count(); ++i) { if (inputs[i] is ArrayNameNode) { var astNode = NodeUtils.Clone(inputs[i]) as ArrayNameNode; astNode.ReplicationGuides = new List <AssociativeNode>(); var guideNode = new ReplicationGuideNode { RepGuide = AstFactory.BuildIdentifier(guide.ToString()) }; astNode.ReplicationGuides.Add(guideNode); inputs[i] = astNode; guide++; } } break; } }
public ElseIfBlock(ElseIfBlock rhs) : base(rhs) { Expr = NodeUtils.Clone(rhs.Expr); ElseIfBodyPosition = NodeUtils.Clone(rhs.ElseIfBodyPosition); Body = new List <ImperativeNode>(); foreach (ImperativeNode iNode in rhs.Body) { ImperativeNode newNode = NodeUtils.Clone(iNode); Body.Add(newNode); } }
public ForLoopNode(ForLoopNode rhs) : base(rhs) { Body = new List <ImperativeNode>(); foreach (ImperativeNode iNode in rhs.Body) { ImperativeNode newNode = NodeUtils.Clone(iNode); Body.Add(newNode); } LoopVariable = NodeUtils.Clone(rhs.LoopVariable); Expression = NodeUtils.Clone(rhs.Expression); KwForLine = rhs.KwForLine; KwForCol = rhs.KwForCol; KwInLine = rhs.KwInLine; KwInCol = rhs.KwInCol; }
public ArrayNode(ArrayNode rhs) : base(rhs) { Expr = null; Type = null; if (null != rhs) { if (null != rhs.Expr) { Expr = NodeUtils.Clone(rhs.Expr); } if (null != rhs.Type) { Type = NodeUtils.Clone(rhs.Type); } } }
private IdentifierNode GetAstIdentifierForOutputIndexInternal(int portIndex, bool forRawName) { var ass = outnodes[portIndex] as AssociativeNode; var identNode = ass as IdentifierNode; if (identNode == null) { return(null); } var mappedIdent = NodeUtils.Clone(identNode); if (!forRawName) { var identMapper = new IdentifierInPlaceMapper(libraryServices.LibraryManagementCore, ShouldBeRenamed, LocalizeIdentifier); mappedIdent.Accept(identMapper); } return(mappedIdent as IdentifierNode); }
public IfStmtNode(IfStmtNode rhs) : base(rhs) { // IfExprNode = NodeUtils.Clone(rhs.IfExprNode); // IfBody = new List <ImperativeNode>(); foreach (ImperativeNode stmt in rhs.IfBody) { ImperativeNode body = NodeUtils.Clone(stmt); IfBody.Add(body); } // IfBodyPosition = NodeUtils.Clone(rhs.IfBodyPosition); // ElseIfList = new List <ElseIfBlock>(); foreach (ElseIfBlock elseBlock in rhs.ElseIfList) { ImperativeNode elseNode = NodeUtils.Clone(elseBlock); ElseIfList.Add(elseNode as ElseIfBlock); } // ElseBody = new List <ImperativeNode>(); foreach (ImperativeNode stmt in rhs.ElseBody) { ImperativeNode tmpNode = NodeUtils.Clone(stmt); ElseBody.Add(tmpNode); } // ElseBodyPosition = NodeUtils.Clone(rhs.ElseBodyPosition); }
public UnaryExpressionNode(UnaryExpressionNode rhs) : base(rhs) { Operator = rhs.Operator; Expression = NodeUtils.Clone(rhs.Expression); }
public BinaryExpressionNode(BinaryExpressionNode rhs) : base(rhs) { Optr = rhs.Optr; LeftNode = rhs.LeftNode == null ? null : NodeUtils.Clone(rhs.LeftNode); RightNode = rhs.RightNode == null ? null : NodeUtils.Clone(rhs.RightNode); }
public IdentifierListNode(IdentifierListNode rhs) : base(rhs) { Optr = rhs.Optr; LeftNode = NodeUtils.Clone(rhs.LeftNode); RightNode = NodeUtils.Clone(rhs.RightNode); }