Class LiteralNode<T>

Type Parameters:
T - the literal type
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
LiteralNode.ArrayLiteralNode, LiteralNode.PrimitiveLiteralNode

public abstract class LiteralNode<T> extends Expression
Literal nodes represent JavaScript values.
  • Field Details

    • value

      protected final T value
      Literal value
  • Constructor Details

    • LiteralNode

      protected LiteralNode(long token, int finish, T value)
      Constructor
      Parameters:
      token - token
      finish - finish
      value - the value of the literal
    • LiteralNode

      protected LiteralNode(LiteralNode<T> literalNode)
      Copy constructor
      Parameters:
      literalNode - source node
    • LiteralNode

      protected LiteralNode(LiteralNode<T> literalNode, T newValue)
      A copy constructor with value change.
      Parameters:
      literalNode - the original literal node
      newValue - new value for this node
  • Method Details

    • getString

      public String getString()
      Fetch String value of node.
      Returns:
      String value of node.
    • getObject

      public Object getObject()
      Fetch Object value of node.
      Returns:
      Object value of node.
    • isArray

      public boolean isArray()
      Test if the value is an array
      Returns:
      True if value is an array
    • getElementExpressions

      public List<Expression> getElementExpressions()
    • isString

      public boolean isString()
      Test if the value is a string.
      Returns:
      True if value is a string.
    • accept

      public Node accept(NodeVisitor<? extends LexicalContext> visitor)
      Assist in IR navigation.
      Specified by:
      accept in class Node
      Parameters:
      visitor - IR navigating visitor.
      Returns:
      node the node or its replacement after visitation, null if no further visitations are required
    • accept

      public <R> R accept(TranslatorNodeVisitor<? extends LexicalContext,R> visitor)
      Description copied from class: Node
      Provides a means to navigate the IR.
      Specified by:
      accept in class Node
      Parameters:
      visitor - Node visitor.
      Returns:
      node the node or its replacement after visitation, null if no further visitations are required
    • toString

      public void toString(StringBuilder sb, boolean printType)
      Description copied from class: Node
      Print logic that decides whether to show the optimistic type or not - for example it should not be printed after just parse, when it hasn't been computed, or has been set to a trivially provable value
      Specified by:
      toString in class Node
      Parameters:
      sb - string builder
      printType - print type?
    • getValue

      public final T getValue()
      Get the literal node value
      Returns:
      the value
    • newInstance

      public static LiteralNode<Object> newInstance(long token, int finish)
      Create a new null literal
      Parameters:
      token - token
      finish - finish
      Returns:
      the new literal node
    • newInstance

      public static LiteralNode<Boolean> newInstance(long token, int finish, boolean value)
      Create a new boolean literal
      Parameters:
      token - token
      finish - finish
      value - true or false
      Returns:
      the new literal node
    • newInstance

      public static LiteralNode<Number> newInstance(long token, int finish, Number value)
      Create a new number literal
      Parameters:
      token - token
      finish - finish
      value - literal value
      Returns:
      the new literal node
    • newInstance

      public static LiteralNode<Number> newInstance(long token, int finish, Number value, Function<Number,com.oracle.truffle.api.strings.TruffleString> toStringConverter)
      Create a new number literal
      Parameters:
      token - token
      finish - finish
      value - literal value
      Returns:
      the new literal node
    • newInstance

      public static LiteralNode.PrimitiveLiteralNode<com.oracle.truffle.api.strings.TruffleString> newInstance(long token, com.oracle.truffle.api.strings.TruffleString value)
      Create a new string literal
      Parameters:
      token - token
      value - string value
      Returns:
      the new literal node
    • newInstance

      public static LiteralNode<Lexer.LexerToken> newInstance(long token, int finish, Lexer.LexerToken value)
      Create a new literal node for a lexer token
      Parameters:
      token - token
      finish - finish
      value - lexer token value
      Returns:
      the new literal node
    • newInstance

      public static LiteralNode<Expression[]> newInstance(long token, int finish, List<Expression> value)
      Create a new array literal of Nodes from a list of Node values
      Parameters:
      token - token
      finish - finish
      value - literal value list
      Returns:
      the new literal node
    • newInstance

      public static LiteralNode<Expression[]> newInstance(long token, int finish, List<Expression> value, boolean hasSpread, boolean hasTrailingComma)
      Create a new array literal of Nodes from a list of Node values
      Parameters:
      token - token
      finish - finish
      value - literal value list
      hasSpread - true if the array has a spread element
      hasTrailingComma - true if the array literal has a comma after the last element
      Returns:
      the new literal node
    • newInstance

      public static LiteralNode<Expression[]> newInstance(long token, int finish, Expression[] value)
      Create a new array literal of Nodes
      Parameters:
      token - token
      finish - finish
      value - literal value array
      Returns:
      the new literal node