AstRoot
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).
Properties
The absolute document position, computed by adding this node's relative position to the relative positions of all its parents.
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.
The scopes whose parent is this scope, or null if there are none.
The innermost enclosing function, or null. The search begins with the parent.
Comments on the same line as the statement, for example the trailing comment in if (x == 2) // note.
Number of parameters, counted as Token.LP symbols arrive.
End offset of the raw source. Only valid when rawSource is non-null.
Start offset of the raw source. Only valid when rawSource is non-null.
The URI, path or descriptive text naming the origin of this script's source.
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.
Every symbol in this script or function, in declaration order.
Insertion-ordered so that iteration follows declaration order.
The current script or function scope.
The node type, e.g. Token.NAME.
Functions
Adds a scope to the child list and sets the child's parent scope to this scope.
Adds a comment to the comment set.
Adds a FunctionNode to the functions table for codegen. Does not set the parent of the node.
Called by IRFactory to add a RegExp to the regexp table.
Called by IRFactory to add a template literal to the table.
Checks that the parser set the parent link for every node in the tree.
Used only for code generation.
A debug printer that includes the comments, at the end.
Assigns every symbol a unique integer index and builds the name and constness arrays that can be indexed by it.
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.
Checks that every return usage in a function body is consistent with strict mode. See the END_* flags for what the analysis reports.
Constructs an indentation string of indent steps.
Used by the parser. Repoints this scope's child scopes at newScope and copies this scope's symbols into it.
Recursively unlabel every TARGET or YIELD node in the tree. Used only for inlining finally blocks where jsr instructions used to be.
Replaces the comment list and reparents every entry to this node.
Used by the code generator.
Makes this node's position relative to a parent. The current position is assumed to be absolute and is decremented by parentPosition.
Jumps are only used during code generation and do not support the visitor interface.
Visits the AST nodes, then the comment nodes.
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.