Class VarNode
java.lang.Object
com.oracle.js.parser.ir.Node
com.oracle.js.parser.ir.Statement
com.oracle.js.parser.ir.VarNode
- All Implemented Interfaces:
Assignment<IdentNode>,Terminal,Cloneable
Node represents a var/let declaration.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intBlock-scope function declarations are hoisted into the front of the block and later (when the corresponding function declaration is evaluated at its original position) transferred into the function scope.static final intFlag for ES6 CONST declarationstatic final intFlag synthetic destructuring var nodestatic final intFlag synthetic export var nodestatic final intFlag that determines if this is the last function declaration in a function This is used to micro optimize the placement of return value assignments for a program nodestatic final intFlag for ES6 LET declaration -
Constructor Summary
ConstructorsConstructorDescriptionVarNode(int lineNumber, long token, int sourceOrder, int start, int finish, IdentNode name, Expression init, int flags) ConstructorVarNode(int lineNumber, long token, int sourceOrder, int finish, IdentNode name, Expression init, int flags) ConstructorVarNode(int lineNumber, long token, int finish, IdentNode name, Expression init) ConstructorVarNode(int lineNumber, long token, int finish, IdentNode name, Expression init, int flags) Constructor -
Method Summary
Modifier and TypeMethodDescriptionaccept(NodeVisitor<? extends LexicalContext> visitor) Assist in IR navigation.<R> Raccept(TranslatorNodeVisitor<? extends LexicalContext, R> visitor) Provides a means to navigate the IR.Get assignment destination.Get the assignment source.booleangetFlag(int flag) Check if a flag is set for this var nodegetInit()If this is an assignment of the formvar x = init;, get the init part.getName()Get the identifier for the variableintInteger to sort nodes in source order.intReturn the flags to use for symbols for this declaration.booleanhasInit()Does this variable declaration have an init valuebooleanIs this an assignment node - for example a var node with an init or a binary node that writes to a destinationbooleanIs this a VAR node block scoped? This returns true for ECMAScript 6 LET and CONST nodes.booleanReturns true if this is a Class declaration.booleanisConst()Is this an ECMAScript 6 CONST node?booleanbooleanisExport()booleanReturns true if this is a FunctionDeclaration.booleanReturns true if this is a HoistableDeclaration (i.e., FunctionDeclaration, GeneratorDeclaration, AsyncFunctionDeclaration, or AsyncGeneratorDeclaration).booleanisLet()Is this an ECMAScript 6 LET node?setFlag(int flag) Set a flag for this var nodevoidtoString(StringBuilder sb, boolean printType) 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 valueMethods inherited from class com.oracle.js.parser.ir.Statement
getLineNumber, hasGoto, hasTerminalFlags, isCompletionValueNeverEmpty, isTerminal
-
Field Details
-
IS_LET
public static final int IS_LETFlag for ES6 LET declaration- See Also:
-
IS_CONST
public static final int IS_CONSTFlag for ES6 CONST declaration- See Also:
-
IS_LAST_FUNCTION_DECLARATION
public static final int IS_LAST_FUNCTION_DECLARATIONFlag that determines if this is the last function declaration in a function This is used to micro optimize the placement of return value assignments for a program node- See Also:
-
IS_EXPORT
public static final int IS_EXPORTFlag synthetic export var node- See Also:
-
IS_DESTRUCTURING
public static final int IS_DESTRUCTURINGFlag synthetic destructuring var node- See Also:
-
IS_ANNEXB_BLOCK_TO_FUNCTION_TRANSFER
public static final int IS_ANNEXB_BLOCK_TO_FUNCTION_TRANSFERBlock-scope function declarations are hoisted into the front of the block and later (when the corresponding function declaration is evaluated at its original position) transferred into the function scope. This flag corresponds to this transfer.- See Also:
-
-
Constructor Details
-
VarNode
Constructor- Parameters:
lineNumber- line numbertoken- tokenfinish- finishname- name of variableinit- init node or null if just a declaration
-
VarNode
Constructor- Parameters:
lineNumber- line numbertoken- tokenfinish- finishname- name of variableinit- init node or null if just a declarationflags- flags
-
VarNode
public VarNode(int lineNumber, long token, int sourceOrder, int finish, IdentNode name, Expression init, int flags) Constructor- Parameters:
lineNumber- line numbertoken- tokensourceOrder- source orderfinish- finishname- name of variableinit- init node or null if just a declarationflags- flags
-
VarNode
public VarNode(int lineNumber, long token, int sourceOrder, int start, int finish, IdentNode name, Expression init, int flags) Constructor- Parameters:
lineNumber- line numbertoken- tokensourceOrder- source orderstart- startfinish- finishname- name of variableinit- init node or null if just a declarationflags- flags
-
-
Method Details
-
getSourceOrder
public int getSourceOrder()Description copied from class:NodeInteger to sort nodes in source order. This order is used by parser API to sort statements in correct order. By default, this is the start position of this node.- Overrides:
getSourceOrderin classNode- Returns:
- int code to sort this node.
-
isAssignment
public boolean isAssignment()Description copied from class:NodeIs this an assignment node - for example a var node with an init or a binary node that writes to a destination- Overrides:
isAssignmentin classNode- Returns:
- true if assignment
-
getAssignmentDest
Description copied from interface:AssignmentGet assignment destination.- Specified by:
getAssignmentDestin interfaceAssignment<IdentNode>- Returns:
- the assignment destination node
-
getAssignmentSource
Description copied from interface:AssignmentGet the assignment source.- Specified by:
getAssignmentSourcein interfaceAssignment<IdentNode>- Returns:
- the assignment source node
-
isBlockScoped
public boolean isBlockScoped()Is this a VAR node block scoped? This returns true for ECMAScript 6 LET and CONST nodes.- Returns:
- true if an ES6 LET or CONST node
-
isLet
public boolean isLet()Is this an ECMAScript 6 LET node?- Returns:
- true if LET node
-
isConst
public boolean isConst()Is this an ECMAScript 6 CONST node?- Returns:
- true if CONST node
-
getSymbolFlags
public int getSymbolFlags()Return the flags to use for symbols for this declaration.- Returns:
- the symbol flags
-
hasInit
public boolean hasInit()Does this variable declaration have an init value- Returns:
- true if an init exists, false otherwise
-
accept
Assist in IR navigation. -
accept
Description copied from class:NodeProvides a means to navigate the IR. -
toString
Description copied from class:NodePrint 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 -
getInit
If this is an assignment of the formvar x = init;, get the init part.- Returns:
- the expression to initialize the variable to, null if just a declaration
-
getName
Get the identifier for the variable- Returns:
- IdentNode representing the variable being set or declared
-
getFlag
public boolean getFlag(int flag) Check if a flag is set for this var node- Parameters:
flag- flag- Returns:
- true if flag is set
-
setFlag
Set a flag for this var node- Parameters:
flag- flag- Returns:
- new node if flags changed, same otherwise
-
isHoistableDeclaration
public boolean isHoistableDeclaration()Returns true if this is a HoistableDeclaration (i.e., FunctionDeclaration, GeneratorDeclaration, AsyncFunctionDeclaration, or AsyncGeneratorDeclaration).- Returns:
- true if this is a HoistableDeclaration
-
isFunctionDeclaration
public boolean isFunctionDeclaration()Returns true if this is a FunctionDeclaration.- Returns:
- true if this is a FunctionDeclaration
-
isExport
public boolean isExport() -
isDestructuring
public boolean isDestructuring() -
isClassDeclaration
public boolean isClassDeclaration()Returns true if this is a Class declaration.- Returns:
- true if this is a Class declaration.
-