protected virtual void EmitBinaryNode(ref ProtoCore.AST.AssociativeAST.BinaryExpressionNode binaryExprNode) { Validity.Assert(null != binaryExprNode); AST.AssociativeAST.AssociativeNode leftNode = binaryExprNode.LeftNode; DFSTraverse(ref leftNode); //EmitCode(ProtoCore.Utils.CoreUtils.GetOperatorString(binaryExprNode.Optr)); AST.AssociativeAST.AssociativeNode rightNode = binaryExprNode.RightNode; DFSTraverse(ref rightNode); }
private void EmitExprListNode(ref AST.AssociativeAST.ExprListNode exprListNode) { for (int i = 0; i < exprListNode.list.Count; i++) { AST.AssociativeAST.AssociativeNode node = exprListNode.list[i]; DFSTraverse(ref node); exprListNode.list[i] = node; } }
//======================= /// <summary> /// Depth first traversal of an AST node /// </summary> /// <param name="node"></param> /// <summary> /// These functions emit the DesignScript code on the destination stream /// </summary> /// <param name="identNode"></param> #region ASTNODE_CODE_EMITTERS private void EmitArrayIndexerNode(ref AST.AssociativeAST.ArrayIndexerNode arrIdxNode) { if (arrIdxNode.Array is AST.AssociativeAST.IdentifierNode) { EmitIdentifierNode(ref arrIdxNode.Array); } else if (arrIdxNode.Array is AST.AssociativeAST.BinaryExpressionNode) { AST.AssociativeAST.AssociativeNode ben = (arrIdxNode.Array as AST.AssociativeAST.BinaryExpressionNode).LeftNode; EmitIdentifierNode(ref ben); AST.AssociativeAST.AssociativeNode rightNode = (arrIdxNode.Array as AST.AssociativeAST.BinaryExpressionNode).RightNode; DFSTraverse(ref rightNode); } }
/*protected override void EmitFunctionDotCallNode(ProtoCore.AST.AssociativeAST.FunctionDotCallNode dotCall) * { * Validity.Assert(null != dotCall); * * EmitFunctionCallNode(dotCall.FunctionCall); * } * * protected override void EmitFunctionCallNode(AST.AssociativeAST.FunctionCallNode funcCallNode) * { * Validity.Assert(null != funcCallNode); * * Validity.Assert(funcCallNode.Function is ProtoCore.AST.AssociativeAST.IdentifierNode); * string functionName = (funcCallNode.Function as ProtoCore.AST.AssociativeAST.IdentifierNode).Value; * * Validity.Assert(!string.IsNullOrEmpty(functionName)); * EmitCode(functionName); * } * * public void EmitFunctionCallNode(ref AST.AssociativeAST.AssociativeNode node) * { * if (node is AST.AssociativeAST.FunctionCallNode) * { * AST.AssociativeAST.FunctionCallNode functionCallNode = node as AST.AssociativeAST.FunctionCallNode; * for (int i = 0; i < functionCallNode.FormalArguments.Count; i++) * { * AST.AssociativeAST.IdentifierNode ident = functionCallNode.FormalArguments[i] as AST.AssociativeAST.IdentifierNode; * } * } * else * return; * }*/ //protected override void EmitCode(string src) //{ // if (src.Contains(ProtoCore.DSASM.Constants.kSetterPrefix)) // src = src.Remove(0, ProtoCore.DSASM.Constants.kSetterPrefix.Length); // base.EmitCode(src); //} protected void EmitIdentifierNode(ref AST.AssociativeAST.AssociativeNode identNode) { ProtoCore.AST.AssociativeAST.IdentifierNode iNode = ChildTree.LeftNode as ProtoCore.AST.AssociativeAST.IdentifierNode; Validity.Assert(iNode != null); if ((identNode as ProtoCore.AST.AssociativeAST.IdentifierNode).Value == iNode.Value) { //ProtoCore.AST.AssociativeAST.ArrayNode temp = (identNode as ProtoCore.AST.AssociativeAST.IdentifierNode).ArrayDimensions; identNode = ChildTree; //if ((identNode as ProtoCore.AST.AssociativeAST.BinaryExpressionNode).LeftNode is ProtoCore.AST.AssociativeAST.IdentifierNode) // ((identNode as ProtoCore.AST.AssociativeAST.BinaryExpressionNode).LeftNode // as AST.AssociativeAST.IdentifierNode).ArrayDimensions = temp; } //else // base.EmitIdentifierNode(identNode as AST.AssociativeAST.IdentifierNode); }
public void DFSTraverse(ref AST.AssociativeAST.AssociativeNode node) { if (node is AST.AssociativeAST.IdentifierNode) { EmitIdentifierNode(ref node); } else if (node is ProtoCore.AST.AssociativeAST.IdentifierListNode) { AST.AssociativeAST.IdentifierListNode identList = node as ProtoCore.AST.AssociativeAST.IdentifierListNode; EmitIdentifierListNode(ref identList); } else if (node is ProtoCore.AST.AssociativeAST.IntNode) { AST.AssociativeAST.IntNode intNode = node as ProtoCore.AST.AssociativeAST.IntNode; EmitIntNode(ref intNode); } else if (node is ProtoCore.AST.AssociativeAST.DoubleNode) { AST.AssociativeAST.DoubleNode doubleNode = node as ProtoCore.AST.AssociativeAST.DoubleNode; EmitDoubleNode(ref doubleNode); } else if (node is ProtoCore.AST.AssociativeAST.FunctionCallNode) { AST.AssociativeAST.FunctionCallNode funcCallNode = node as ProtoCore.AST.AssociativeAST.FunctionCallNode; EmitFunctionCallNode(ref funcCallNode); } else if (node is ProtoCore.AST.AssociativeAST.FunctionDotCallNode) { AST.AssociativeAST.FunctionDotCallNode funcDotCall = node as ProtoCore.AST.AssociativeAST.FunctionDotCallNode; EmitFunctionDotCallNode(ref funcDotCall); } else if (node is ProtoCore.AST.AssociativeAST.BinaryExpressionNode) { ProtoCore.AST.AssociativeAST.BinaryExpressionNode binaryExpr = node as ProtoCore.AST.AssociativeAST.BinaryExpressionNode; if (binaryExpr.Optr != DSASM.Operator.assign) { ; } //EmitCode("("); EmitBinaryNode(ref binaryExpr); if (binaryExpr.Optr == DSASM.Operator.assign) { //EmitCode(ProtoCore.DSASM.Constants.termline); } if (binaryExpr.Optr != DSASM.Operator.assign) { ; } //EmitCode(")"); } else if (node is ProtoCore.AST.AssociativeAST.FunctionDefinitionNode) { AST.AssociativeAST.FunctionDefinitionNode funcDefNode = node as ProtoCore.AST.AssociativeAST.FunctionDefinitionNode; EmitFunctionDefNode(ref funcDefNode); } else if (node is ProtoCore.AST.AssociativeAST.ClassDeclNode) { AST.AssociativeAST.ClassDeclNode classDeclNode = node as ProtoCore.AST.AssociativeAST.ClassDeclNode; EmitClassDeclNode(ref classDeclNode); } else if (node is ProtoCore.AST.AssociativeAST.NullNode) { AST.AssociativeAST.NullNode nullNode = node as ProtoCore.AST.AssociativeAST.NullNode; EmitNullNode(ref nullNode); } else if (node is ProtoCore.AST.AssociativeAST.ArrayIndexerNode) { AST.AssociativeAST.ArrayIndexerNode arrIdxNode = node as ProtoCore.AST.AssociativeAST.ArrayIndexerNode; EmitArrayIndexerNode(ref arrIdxNode); } else if (node is ProtoCore.AST.AssociativeAST.ExprListNode) { AST.AssociativeAST.ExprListNode exprListNode = node as ProtoCore.AST.AssociativeAST.ExprListNode; EmitExprListNode(ref exprListNode); } }