Class PrintVisitor

java.lang.Object
com.oracle.js.parser.ir.visitor.NodeVisitor<LexicalContext>
com.oracle.truffle.js.parser.internal.ir.debug.PrintVisitor

public final class PrintVisitor extends NodeVisitor<LexicalContext>
Print out the AST as human readable source code. This works both on lowered and unlowered ASTs see the flags --print-parse and --print-lower-parse
  • Constructor Details

    • PrintVisitor

      public PrintVisitor()
      Constructor.
    • PrintVisitor

      public PrintVisitor(boolean printLineNumbers, boolean printTypes)
      Constructor.
      Parameters:
      printLineNumbers - should line number nodes be included in the output?
      printTypes - should we print optimistic and inferred types?
    • PrintVisitor

      public PrintVisitor(Node root)
      Constructor.
      Parameters:
      root - a node from which to start printing code
    • PrintVisitor

      public PrintVisitor(Node root, boolean printLineNumbers, boolean printTypes)
      Constructor.
      Parameters:
      root - a node from which to start printing code
      printLineNumbers - should line numbers nodes be included in the output?
      printTypes - should we print optimistic and inferred types?
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • enterDefault

      public boolean enterDefault(Node node)
      Description copied from class: NodeVisitor
      Override this method to do a double inheritance pattern, e.g. avoid using
       if (x instanceof NodeTypeA) {
          ...
       } else if (x instanceof NodeTypeB) {
          ...
       } else {
          ...
       }
       
      Use a NodeVisitor instead, and this method contents forms the else case.
      Overrides:
      enterDefault in class NodeVisitor<LexicalContext>
      Parameters:
      node - the node to visit
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
      See Also:
    • enterContinueNode

      public boolean enterContinueNode(ContinueNode node)
      Description copied from class: NodeVisitor
      Callback for entering a ContinueNode
      Overrides:
      enterContinueNode in class NodeVisitor<LexicalContext>
      Parameters:
      node - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterBreakNode

      public boolean enterBreakNode(BreakNode node)
      Description copied from class: NodeVisitor
      Callback for entering a BreakNode
      Overrides:
      enterBreakNode in class NodeVisitor<LexicalContext>
      Parameters:
      node - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterThrowNode

      public boolean enterThrowNode(ThrowNode node)
      Description copied from class: NodeVisitor
      Callback for entering a ThrowNode
      Overrides:
      enterThrowNode in class NodeVisitor<LexicalContext>
      Parameters:
      node - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterBlock

      public boolean enterBlock(Block block)
      Description copied from class: NodeVisitor
      Callback for entering a Block
      Overrides:
      enterBlock in class NodeVisitor<LexicalContext>
      Parameters:
      block - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterBlockStatement

      public boolean enterBlockStatement(BlockStatement statement)
      Description copied from class: NodeVisitor
      Callback for entering a BlockStatement
      Overrides:
      enterBlockStatement in class NodeVisitor<LexicalContext>
      Parameters:
      statement - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterBinaryNode

      public boolean enterBinaryNode(BinaryNode binaryNode)
      Description copied from class: NodeVisitor
      Callback for entering a BinaryNode
      Overrides:
      enterBinaryNode in class NodeVisitor<LexicalContext>
      Parameters:
      binaryNode - the node
      Returns:
      processed node
    • enterJoinPredecessorExpression

      public boolean enterJoinPredecessorExpression(JoinPredecessorExpression expr)
      Description copied from class: NodeVisitor
      Callback for entering a JoinPredecessorExpression.
      Overrides:
      enterJoinPredecessorExpression in class NodeVisitor<LexicalContext>
      Parameters:
      expr - the join predecessor expression
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterIdentNode

      public boolean enterIdentNode(IdentNode identNode)
      Description copied from class: NodeVisitor
      Callback for entering an IdentNode
      Overrides:
      enterIdentNode in class NodeVisitor<LexicalContext>
      Parameters:
      identNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterUnaryNode

      public boolean enterUnaryNode(UnaryNode unaryNode)
      Description copied from class: NodeVisitor
      Callback for entering a UnaryNode
      Overrides:
      enterUnaryNode in class NodeVisitor<LexicalContext>
      Parameters:
      unaryNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterExpressionStatement

      public boolean enterExpressionStatement(ExpressionStatement expressionStatement)
      Description copied from class: NodeVisitor
      Callback for entering an ExpressionStatement
      Overrides:
      enterExpressionStatement in class NodeVisitor<LexicalContext>
      Parameters:
      expressionStatement - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterForNode

      public boolean enterForNode(ForNode forNode)
      Description copied from class: NodeVisitor
      Callback for entering a ForNode
      Overrides:
      enterForNode in class NodeVisitor<LexicalContext>
      Parameters:
      forNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterFunctionNode

      public boolean enterFunctionNode(FunctionNode functionNode)
      Description copied from class: NodeVisitor
      Callback for entering a FunctionNode
      Overrides:
      enterFunctionNode in class NodeVisitor<LexicalContext>
      Parameters:
      functionNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterIfNode

      public boolean enterIfNode(IfNode ifNode)
      Description copied from class: NodeVisitor
      Callback for entering an IfNode
      Overrides:
      enterIfNode in class NodeVisitor<LexicalContext>
      Parameters:
      ifNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterLabelNode

      public boolean enterLabelNode(LabelNode labeledNode)
      Description copied from class: NodeVisitor
      Callback for entering a LabelNode
      Overrides:
      enterLabelNode in class NodeVisitor<LexicalContext>
      Parameters:
      labeledNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterSwitchNode

      public boolean enterSwitchNode(SwitchNode switchNode)
      Description copied from class: NodeVisitor
      Callback for entering a SwitchNode
      Overrides:
      enterSwitchNode in class NodeVisitor<LexicalContext>
      Parameters:
      switchNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterTryNode

      public boolean enterTryNode(TryNode tryNode)
      Description copied from class: NodeVisitor
      Callback for entering a TryNode
      Overrides:
      enterTryNode in class NodeVisitor<LexicalContext>
      Parameters:
      tryNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterVarNode

      public boolean enterVarNode(VarNode varNode)
      Description copied from class: NodeVisitor
      Callback for entering a VarNode
      Overrides:
      enterVarNode in class NodeVisitor<LexicalContext>
      Parameters:
      varNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterWhileNode

      public boolean enterWhileNode(WhileNode whileNode)
      Description copied from class: NodeVisitor
      Callback for entering a WhileNode
      Overrides:
      enterWhileNode in class NodeVisitor<LexicalContext>
      Parameters:
      whileNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise
    • enterWithNode

      public boolean enterWithNode(WithNode withNode)
      Description copied from class: NodeVisitor
      Callback for entering a WithNode
      Overrides:
      enterWithNode in class NodeVisitor<LexicalContext>
      Parameters:
      withNode - the node
      Returns:
      true if traversal should continue and node children be traversed, false otherwise