AstRoot

class AstRoot(pos: Int = -1) : ScriptNode

Root of a parse tree. Holds the statements and functions in the script plus the Comment nodes attached to the script as a whole. Node type is Token.SCRIPT.

The tree itself does not store errors. To collect parse errors and warnings, hand an ErrorReporter to the Parser through CompilerEnvirons.

KMP: upstream keeps the comments in a TreeSet ordered by AstNode.PositionComparator. Common Kotlin has no sorted set, so the port keeps an insertion-sorted list with the same ordering and the same drop-on-equal-position behavior a TreeSet has (D-8).

Constructors

Link copied to clipboard
constructor(pos: Int = -1)

Properties

Link copied to clipboard

The absolute document position, computed by adding this node's relative position to the relative positions of all its parents.

Link copied to clipboard

The AstRoot at the top of this node's parent chain, or null if there is none.

Link copied to clipboard

Base (starting) line number for this script or function. Setting it is a one-time operation and fails if the line number is already set.

Link copied to clipboard
open var bigInt: KBigInt?

Only valid when type == Token.BIGINT.

Link copied to clipboard

The scopes whose parent is this scope, or null if there are none.

Link copied to clipboard
open val column: Int

The column where this node is defined in source, one-based. -1 means it was never initialized. May be overridden by subclasses.

Link copied to clipboard

Comments sorted by start position, or null if the script has none.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open val defaultParams: List<Any?>?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Only valid when type == Token.NUMBER.

Link copied to clipboard

The innermost enclosing function, or null. The search begins with the parent.

Link copied to clipboard

The innermost enclosing Scope, or null. The search begins with the parent. This is not the same as the defining scope for a Name.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Comments on the same line as the statement, for example the trailing comment in if (x == 2) // note.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The JsDoc comment string attached to this node, or null.

Link copied to clipboard

The JsDoc Comment attached to this node, or null.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
var length: Int

Number of characters spanned by this node in the source text.

Link copied to clipboard
open override val lineno: Int

The line number recorded for this node. If none was recorded, searches the parent chain and returns -1 when nothing is found.

Link copied to clipboard
var loop: Jump?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Number of parameters, counted as Token.LP symbols arrive.

Link copied to clipboard

The node parent, or null. Setting it adjusts this node's start position to be relative to the new parent.

Link copied to clipboard
Link copied to clipboard

Relative position in the parent.

Link copied to clipboard

The raw source, or null if it was not recorded. Used by the code generator.

Link copied to clipboard

End offset of the raw source. Only valid when rawSource is non-null.

Link copied to clipboard

Start offset of the raw source. Only valid when rawSource is non-null.

Link copied to clipboard
Link copied to clipboard
open var scope: Scope?

Only valid when the node has String context.

Link copied to clipboard

The URI, path or descriptive text naming the origin of this script's source.

Link copied to clipboard

A copy of the child list, with each child cast to an AstNode. Throws once the code generator has begun the tree transformation and non-AstNode children appear.

Link copied to clipboard

Only valid when the node has String context.

Link copied to clipboard

Every symbol in this script or function, in declaration order.

Link copied to clipboard

Insertion-ordered so that iteration follows declaration order.

Link copied to clipboard
var target: Node?
Link copied to clipboard
Link copied to clipboard

The current script or function scope.

Link copied to clipboard
open var type: Int

The node type, e.g. Token.NAME.

Functions

Link copied to clipboard
fun addChild(kid: AstNode)

Adds a child to the end of the block. Sets the child's parent to this node, rewrites the child position to be relative, and grows this node to include the child.

Link copied to clipboard
fun addChildAfter(newChild: Node, node: Node)

Add newChild after node.

Link copied to clipboard
fun addChildBefore(newChild: Node, node: Node)

Add newChild before node.

Link copied to clipboard
fun addChildrenToBack(children: Node)
Link copied to clipboard
fun addChildrenToFront(children: Node)
Link copied to clipboard
fun addChildScope(child: Scope)

Adds a scope to the child list and sets the child's parent scope to this scope.

Link copied to clipboard
fun addChildToBack(child: Node)
Link copied to clipboard
fun addChildToFront(child: Node)
Link copied to clipboard
fun addComment(comment: Comment)

Adds a comment to the comment set.

Link copied to clipboard
open fun addFunction(fnNode: FunctionNode): Int

Adds a FunctionNode to the functions table for codegen. Does not set the parent of the node.

Link copied to clipboard

Called by IRFactory to add a RegExp to the regexp table.

Link copied to clipboard
fun addTemplateLiteral(templateLiteral: TemplateLiteral)

Called by IRFactory to add a template literal to the table.

Link copied to clipboard

Checks that the parser set the parent link for every node in the tree.

Link copied to clipboard

Used only for code generation.

Link copied to clipboard
open operator override fun compareTo(other: AstNode): Int

Sorts by start position, then by length, then arbitrarily by hash code. Lets Comment and error nodes be mixed into a sorted collection of other AST nodes.

Link copied to clipboard
open override fun debugPrint(): String

A debug printer that includes the comments, at the end.

Link copied to clipboard
fun depth(): Int

The depth of this node. The root is depth 0, its children depth 1, and so on.

Link copied to clipboard
fun flattenSymbolTable(flattenAllTables: Boolean)

Assigns every symbol a unique integer index and builds the name and constness arrays that can be indexed by it.

Link copied to clipboard
fun getChildBefore(child: Node): Node?
Link copied to clipboard

The scope in which name is defined: this scope, one of its parents, or null when the name is not defined anywhere in this scope chain.

Link copied to clipboard
fun getExistingIntProp(propType: Int): Int
Link copied to clipboard
Link copied to clipboard
fun getIndexForNameNode(nameNode: Node): Int
Link copied to clipboard
fun getIntProp(propType: Int, defaultValue: Int): Int
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun getProp(propType: Int): Any?
Link copied to clipboard
fun getRegexpFlags(index: Int): String?
Link copied to clipboard
fun getRegexpString(index: Int): String?
Link copied to clipboard
fun getSymbol(name: String): Symbol?

Looks up a symbol in this scope, or null if it is not there.

Link copied to clipboard
Link copied to clipboard

Checks that every return usage in a function body is consistent with strict mode. See the END_* flags for what the analysis reports.

Link copied to clipboard
open override fun hasSideEffects(): Boolean
Link copied to clipboard
open operator override fun iterator(): MutableIterator<Node>
Link copied to clipboard
fun labelId(): Int
fun labelId(labelId: Int)
Link copied to clipboard
fun makeIndent(indent: Int): String

Constructs an indentation string of indent steps.

Link copied to clipboard
open fun putDestructuringRvalues(left: Node, right: Node)
Link copied to clipboard
fun putIntProp(propType: Int, prop: Int)
Link copied to clipboard
fun putProp(propType: Int, prop: Any?)
Link copied to clipboard
fun putSymbol(symbol: Symbol)

Enters a symbol into this scope.

Link copied to clipboard
fun removeChild(child: Node)
Link copied to clipboard
Link copied to clipboard
fun removeProp(propType: Int)
Link copied to clipboard
fun replaceChild(child: Node, newChild: Node)
Link copied to clipboard
fun replaceChildAfter(prevChild: Node, newChild: Node)
Link copied to clipboard
fun replaceWith(newScope: Scope)

Used by the parser. Repoints this scope's child scopes at newScope and copies this scope's symbols into it.

Link copied to clipboard

Recursively unlabel every TARGET or YIELD node in the tree. Used only for inlining finally blocks where jsr instructions used to be.

Link copied to clipboard
fun setBounds(position: Int, end: Int)

Sets the start and end positions; the length becomes end - position.

Link copied to clipboard
fun setComments(comments: Collection<Comment>?)

Replaces the comment list and reparents every entry to this node.

Link copied to clipboard
fun setLineColumnNumber(lineno: Int, column: Int)
Link copied to clipboard
fun setRawSourceBounds(start: Int, end: Int)

Used by the code generator.

Link copied to clipboard
fun setRelative(parentPosition: Int)

Makes this node's position relative to a parent. The current position is assumed to be absolute and is decremented by parentPosition.

Link copied to clipboard

A short, descriptive name for the node, such as "ArrayComprehension".

Link copied to clipboard
open override fun toSource(depth: Int = 0): String

Jumps are only used during code generation and cannot render source.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
Link copied to clipboard
open override fun visit(visitor: NodeVisitor)

Jumps are only used during code generation and do not support the visitor interface.

Link copied to clipboard
fun visitAll(visitor: NodeVisitor)

Visits the AST nodes, then the comment nodes.

Link copied to clipboard

Visits the comment nodes in source order. The comments are not visited by visit, so this is the only way to reach them. Return values are ignored.