public final class FunctionNode extends Expression implements Flags<FunctionNode>
| Modifier and Type | Field and Description |
|---|---|
static int |
ARROW_HEAD_FLAGS
All flags that may be set during parsing of an arrow head cover grammar and that have to be
propagated to the enclosing function if the expression ends up not being an arrow function.
|
static int |
DEFINES_ARGUMENTS
Flag this function as one that defines the identifier "arguments" as a function parameter or
nested function name.
|
static int |
HAS_APPLY_ARGUMENTS_CALL
Does this function contain a
fn.apply(_, arguments) call? |
static int |
HAS_ARROW_EVAL
Flag indicating that this function has an eval nested in an arrow function.
|
static int |
HAS_CLOSURES
Does this function have closures?
|
static int |
HAS_DIRECT_SUPER
Does this function contain a super call? (cf.
|
static int |
HAS_EVAL
Does the function call eval? If it does, then all variables in this function might be get/set
by it and it can introduce new variables into this function's scope too.
|
static int |
HAS_FUNCTION_DECLARATIONS
Does this function have nested declarations?
|
static int |
HAS_NESTED_EVAL
Does a nested function contain eval? If it does, then all variables in this function might be
get/set by it.
|
static int |
HAS_NON_SIMPLE_PARAMETER_LIST
Flag indicating that this function has a non-simple parameter list.
|
static int |
HAS_SCOPE_BLOCK
Does this function have any blocks that create a scope? This is used to determine if the
function needs to have a local variable slot for the scope symbol.
|
static int |
IS_ANONYMOUS
Is anonymous function flag.
|
static int |
IS_ARROW
An arrow function
|
static int |
IS_ASYNC
Is it an async function?
|
static int |
IS_CLASS_CONSTRUCTOR
Is this the constructor method?
|
static int |
IS_CLASS_FIELD_INITIALIZER
Is this function a class field/static initializer?
|
static int |
IS_DECLARED
Is the function created in a function declaration (as opposed to a function expression)
|
static int |
IS_DERIVED_CONSTRUCTOR
Is this the constructor of a subclass (i.e., a class with an extends declaration)?
|
static int |
IS_GENERATOR
A generator function
|
static int |
IS_GETTER
A getter function
|
static int |
IS_METHOD
Is this function a (class or object) method?
|
static int |
IS_MODULE
A module function
|
static int |
IS_PROGRAM
Is this function the top-level program?
|
static int |
IS_SCRIPT
A script function
|
static int |
IS_SETTER
A setter function
|
static int |
IS_STATEMENT
Is it a statement?
|
static int |
IS_STRICT
is this a strict mode function?
|
static int |
NEEDS_PARENT_SCOPE
Does this function need the parent scope? It needs it if either it or its descendants use
variables from it, or have a deep eval, or it's the program.
|
static int |
NO_FUNCTION_SELF
If one of these flags are set, this function does not have a function self binding.
|
static int |
USES_ANCESTOR_SCOPE
Does this function or any of its descendants use variables from an ancestor function's scope
(incl.
|
static int |
USES_ARGUMENTS
Does the function use the "arguments" identifier ?
|
static int |
USES_NEW_TARGET
Does this function use new.target?
|
static int |
USES_SUPER
Does this function use the super binding?
|
static int |
USES_THIS
Does this function use the "this" keyword?
|
| Constructor and Description |
|---|
FunctionNode(Source source,
int lineNumber,
long token,
int finish,
long firstToken,
long lastToken,
IdentNode ident,
com.oracle.truffle.api.strings.TruffleString name,
int length,
int numOfParams,
List<IdentNode> parameters,
int flags,
Block body,
Object endParserState,
Module module,
com.oracle.truffle.api.strings.TruffleString internalName)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
Node |
accept(LexicalContext lc,
NodeVisitor<? extends LexicalContext> visitor)
Accept function for the node given a lexical context.
|
<R> R |
accept(LexicalContext lc,
TranslatorNodeVisitor<? extends LexicalContext,R> visitor) |
Node |
accept(NodeVisitor<? extends LexicalContext> visitor)
Provides a means to navigate the IR.
|
<R> R |
accept(TranslatorNodeVisitor<? extends LexicalContext,R> visitor)
Provides a means to navigate the IR.
|
Block |
getBody()
Get the function body, i.e., the top-most block of the function.
|
Object |
getEndParserState()
Returns the end parser state for this function.
|
long |
getFirstToken()
Get the first token for this function
|
boolean |
getFlag(int flag)
Check if a flag is set in a lexical context node
|
int |
getFlags()
Get all flags of a LexicalContextNode
|
int |
getId()
Get the unique ID for this function within the script file.
|
IdentNode |
getIdent()
Get the identifier for this function, this is its symbol.
|
String |
getInternalName() |
com.oracle.truffle.api.strings.TruffleString |
getInternalNameTS() |
long |
getLastToken()
Return the last token for this function's code
|
int |
getLength()
The value of the function's length property, i.e., the typical number of arguments expected
by the function.
|
int |
getLineNumber()
Returns the line number.
|
Module |
getModule() |
String |
getName()
Get the name of this function
|
com.oracle.truffle.api.strings.TruffleString |
getNameTS() |
int |
getNumOfParams()
Return the number of parameters to this function
|
List<IdentNode> |
getParameters()
Get the parameters to this function
|
Source |
getSource()
Get the source for this function
|
String |
getSourceName()
get source name - sourceURL or name derived from Source.
|
static String |
getSourceName(Source source)
Static source name getter
|
Block |
getVarDeclarationBlock()
Get the
var declaration block, i.e., the actual function body, which is either
FunctionNode.getBody() or the next block after skipping the parameter initialization block. |
boolean |
hasApplyArgumentsCall() |
boolean |
hasArrowEval() |
boolean |
hasClosures() |
boolean |
hasDirectSuper() |
boolean |
hasEval()
Check if this function has a call expression for the identifier "eval" (that is,
eval(...)). |
boolean |
hasSimpleParameterList() |
boolean |
isAnonymous()
Check if this function is anonymous
|
boolean |
isArrow() |
boolean |
isAsync() |
boolean |
isClassConstructor() |
boolean |
isClassFieldInitializer() |
boolean |
isDeclared()
Check if this function is created as a function declaration (as opposed to function
expression)
|
boolean |
isDerivedConstructor() |
boolean |
isGenerator() |
boolean |
isGetter() |
boolean |
isMethod() |
boolean |
isModule() |
boolean |
isNamedFunctionExpression()
Returns true if this is a named function expression (that is, it isn't a declared function,
it isn't an anonymous function expression, it isn't a method, and it isn't a program).
|
boolean |
isNormal() |
boolean |
isProgram()
Returns true if the function is the top-level program.
|
boolean |
isScript() |
boolean |
isSetter() |
boolean |
isStatement() |
boolean |
isStrict()
Check if the function is generated in strict mode
|
boolean |
needsArguments()
Returns true if this function needs to have an Arguments object defined as a local variable
named "arguments".
|
boolean |
needsDynamicScope()
Check whether a function would need dynamic scope, which is does if it has evals and isn't
strict.
|
boolean |
needsNewTarget() |
boolean |
needsSuper() |
boolean |
needsThis() |
FunctionNode |
setBody(LexicalContext lc,
Block body)
Reset the function body
|
FunctionNode |
setFlag(LexicalContext lc,
int flag)
Set a flag of a LexicalContextNode
|
FunctionNode |
setFlags(LexicalContext lc,
int flags)
Set all flags of a LexicalContextNode, overwriting previous flags
|
FunctionNode |
setName(LexicalContext lc,
com.oracle.truffle.api.strings.TruffleString name)
Set the name of this function.
|
void |
setUsesAncestorScope(boolean usesAncestorScope) |
void |
toString(StringBuilder sb,
boolean printTypes)
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
|
boolean |
usesAncestorScope() |
boolean |
usesNewTarget() |
boolean |
usesSuper() |
boolean |
usesThis()
Return
true if this function makes use of the this object. |
getFinish, getFinishWithoutParens, getStart, getStartWithoutParens, isAlwaysFalse, isAlwaysTrue, isParenthesized, isSelfModifying, makeParenthesizedclone, equals, getSourceOrder, getToken, hashCode, isAssignment, isLoop, isTokenType, tokenType, toString, toStringpublic static final int IS_ANONYMOUS
public static final int IS_DECLARED
public static final int IS_STRICT
public static final int USES_ARGUMENTS
public static final int IS_STATEMENT
public static final int HAS_EVAL
public static final int HAS_NESTED_EVAL
public static final int HAS_SCOPE_BLOCK
public static final int DEFINES_ARGUMENTS
public static final int USES_ANCESTOR_SCOPE
public static final int IS_SCRIPT
public static final int IS_GETTER
public static final int IS_SETTER
public static final int IS_PROGRAM
public static final int HAS_CLOSURES
public static final int USES_THIS
public static final int NEEDS_PARENT_SCOPE
public static final int IS_ARROW
public static final int IS_MODULE
public static final int HAS_DIRECT_SUPER
public static final int USES_SUPER
public static final int IS_METHOD
public static final int NO_FUNCTION_SELF
public static final int IS_CLASS_CONSTRUCTOR
public static final int IS_DERIVED_CONSTRUCTOR
public static final int USES_NEW_TARGET
public static final int IS_GENERATOR
public static final int IS_ASYNC
public static final int HAS_NON_SIMPLE_PARAMETER_LIST
public static final int HAS_ARROW_EVAL
public static final int HAS_FUNCTION_DECLARATIONS
public static final int HAS_APPLY_ARGUMENTS_CALL
fn.apply(_, arguments) call?public static final int IS_CLASS_FIELD_INITIALIZER
public static final int ARROW_HEAD_FLAGS
public FunctionNode(Source source, int lineNumber, long token, int finish, long firstToken, long lastToken, IdentNode ident, com.oracle.truffle.api.strings.TruffleString name, int length, int numOfParams, List<IdentNode> parameters, int flags, Block body, Object endParserState, Module module, com.oracle.truffle.api.strings.TruffleString internalName)
source - the sourcelineNumber - line numbertoken - tokenfinish - finishfirstToken - first token of the function node (including the function declaration)lastToken - lastTokenident - the identifiername - the name of the functionparameters - parameter listflags - initial flagsbody - body of the functionendParserState - The parser state at the end of the parsing.public Node accept(LexicalContext lc, NodeVisitor<? extends LexicalContext> visitor)
LexicalContextNodeaccept in interface LexicalContextNodelc - lexical contextvisitor - node visitorpublic <R> R accept(LexicalContext lc, TranslatorNodeVisitor<? extends LexicalContext,R> visitor)
accept in interface LexicalContextNodepublic Source getSource()
public int getId()
public String getSourceName()
public static String getSourceName(Source source)
source - the sourcepublic int getLineNumber()
public void toString(StringBuilder sb, boolean printTypes)
Nodepublic int getFlags()
FlagsgetFlags in interface Flags<FunctionNode>public boolean getFlag(int flag)
FlagsgetFlag in interface Flags<FunctionNode>flag - flag to checkpublic FunctionNode setFlags(LexicalContext lc, int flags)
FlagssetFlags in interface Flags<FunctionNode>lc - lexical contextflags - new flags valuepublic FunctionNode setFlag(LexicalContext lc, int flag)
FlagssetFlag in interface Flags<FunctionNode>lc - lexical contextflag - flag to setpublic boolean isProgram()
public boolean hasEval()
eval(...)).eval is called.public long getFirstToken()
public boolean usesThis()
true if this function makes use of the this object.this objectpublic IdentNode getIdent()
public Block getBody()
public Block getVarDeclarationBlock()
var declaration block, i.e., the actual function body, which is either
FunctionNode.getBody() or the next block after skipping the parameter initialization block.public FunctionNode setBody(LexicalContext lc, Block body)
lc - lexical contextbody - new bodypublic boolean needsDynamicScope()
public boolean needsArguments()
public long getLastToken()
public Object getEndParserState()
public String getName()
public com.oracle.truffle.api.strings.TruffleString getNameTS()
public FunctionNode setName(LexicalContext lc, com.oracle.truffle.api.strings.TruffleString name)
lc - lexical contextname - new namepublic String getInternalName()
public com.oracle.truffle.api.strings.TruffleString getInternalNameTS()
public List<IdentNode> getParameters()
public int getNumOfParams()
public int getLength()
public boolean isDeclared()
public boolean isAnonymous()
public boolean isNamedFunctionExpression()
public boolean isStrict()
public boolean isMethod()
public boolean usesSuper()
public boolean hasDirectSuper()
public boolean isClassConstructor()
public boolean isDerivedConstructor()
public boolean usesNewTarget()
public boolean isScript()
public boolean isGetter()
public boolean isSetter()
public boolean isArrow()
public boolean isGenerator()
public boolean isModule()
public Module getModule()
public boolean isStatement()
public boolean isAsync()
public boolean hasSimpleParameterList()
public boolean usesAncestorScope()
public void setUsesAncestorScope(boolean usesAncestorScope)
public boolean isNormal()
public boolean hasApplyArgumentsCall()
public boolean hasArrowEval()
public boolean needsThis()
public boolean needsNewTarget()
public boolean needsSuper()
public boolean isClassFieldInitializer()
public boolean hasClosures()
public final Node accept(NodeVisitor<? extends LexicalContext> visitor)
Nodeaccept in interface LexicalContextNodeaccept in class Nodevisitor - Node visitor.public final <R> R accept(TranslatorNodeVisitor<? extends LexicalContext,R> visitor)
Nodeaccept in interface LexicalContextNodeaccept in class Nodevisitor - Node visitor.