Class FunctionNode
java.lang.Object
com.oracle.js.parser.ir.Node
com.oracle.js.parser.ir.Expression
com.oracle.js.parser.ir.FunctionNode
- All Implemented Interfaces:
Flags<FunctionNode>, LexicalContextNode, Cloneable
IR representation for function (or script.)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intAll 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 final intFlag this function as one that defines the identifier "arguments" as a function parameter or nested function name.static final intDoes this function contain afn.apply(_, arguments)call?static final intFlag indicating that this function has an eval nested in an arrow function.static final intDoes this function have closures?static final intDoes this function contain a super call? (cf.static final intDoes 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 final intDoes this function have nested declarations?static final intDoes a nested function contain eval? If it does, then all variables in this function might be get/set by it.static final intFlag indicating that this function has a non-simple parameter list.static final intDoes 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 final intIs anonymous function flag.static final intAn arrow functionstatic final intIs it an async function?static final intIs this the constructor method?static final intIs this function a class field/static initializer?static final intIs the function created in a function declaration (as opposed to a function expression)static final intIs this the constructor of a subclass (i.e., a class with an extends declaration)?static final intA generator functionstatic final intA getter functionstatic final intIs this function a (class or object) method?static final intA module functionstatic final intIs this function the top-level program?static final intA script functionstatic final intA setter functionstatic final intIs it a statement?static final intis this a strict mode function?static final intDoes 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 final intIf one of these flags are set, this function does not have a function self binding.static final intDoes this function or any of its descendants use variables from an ancestor function's scope (incl.static final intDoes the function use the "arguments" identifier ?static final intDoes this function use new.target?static final intDoes this function use the super binding?static final intDoes this function use the "this" keyword? -
Constructor Summary
ConstructorsConstructorDescriptionFunctionNode(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 -
Method Summary
Modifier and TypeMethodDescriptionaccept(LexicalContext lc, NodeVisitor<? extends LexicalContext> visitor) Accept function for the node given a lexical context.<R> Raccept(LexicalContext lc, TranslatorNodeVisitor<? extends LexicalContext, R> visitor) final Nodeaccept(NodeVisitor<? extends LexicalContext> visitor) Provides a means to navigate the IR.final <R> Raccept(TranslatorNodeVisitor<? extends LexicalContext, R> visitor) Provides a means to navigate the IR.getBody()Get the function body, i.e., the top-most block of the function.Returns the end parser state for this function.longGet the first token for this functionbooleangetFlag(int flag) Check if a flag is set in a lexical context nodeintgetFlags()Get all flags of a LexicalContextNodeintgetId()Get the unique ID for this function within the script file.getIdent()Get the identifier for this function, this is its symbol.com.oracle.truffle.api.strings.TruffleStringlongReturn the last token for this function's codeintThe value of the function's length property, i.e., the typical number of arguments expected by the function.intReturns the line number.getName()Get the name of this functioncom.oracle.truffle.api.strings.TruffleStringintReturn the number of parameters to this functionGet the parameters to this functionGet the source for this functionget source name - sourceURL or name derived from Source.static StringgetSourceName(Source source) Static source name getterGet thevardeclaration block, i.e., the actual function body, which is eithergetBody()or the next block after skipping the parameter initialization block.booleanbooleanbooleanbooleanbooleanhasEval()Check if this function has a call expression for the identifier "eval" (that is,eval(...)).booleanbooleanCheck if this function is anonymousbooleanisArrow()booleanisAsync()booleanbooleanbooleanCheck if this function is created as a function declaration (as opposed to function expression)booleanbooleanbooleanisGetter()booleanisMethod()booleanisModule()booleanReturns 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).booleanisNormal()booleanReturns true if the function is the top-level program.booleanisScript()booleanisSetter()booleanbooleanisStrict()Check if the function is generated in strict modebooleanReturns true if this function needs to have an Arguments object defined as a local variable named "arguments".booleanCheck whether a function would need dynamic scope, which is does if it has evals and isn't strict.booleanbooleanbooleansetBody(LexicalContext lc, Block body) Reset the function bodysetFlag(LexicalContext lc, int flag) Set a flag of a LexicalContextNodesetFlags(LexicalContext lc, int flags) Set all flags of a LexicalContextNode, overwriting previous flagssetName(LexicalContext lc, com.oracle.truffle.api.strings.TruffleString name) Set the name of this function.voidsetUsesAncestorScope(boolean usesAncestorScope) voidtoString(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 valuebooleanbooleanbooleanbooleanusesThis()Returntrueif this function makes use of thethisobject.Methods inherited from class Expression
getFinish, getFinishWithoutParens, getStart, getStartWithoutParens, isAlwaysFalse, isAlwaysTrue, isParenthesized, isSelfModifying, makeParenthesizedMethods inherited from class Node
clone, equals, getSourceOrder, getToken, hashCode, isAssignment, isLoop, isTokenType, tokenType, toString, toString
-
Field Details
-
IS_ANONYMOUS
public static final int IS_ANONYMOUSIs anonymous function flag.- See Also:
-
IS_DECLARED
public static final int IS_DECLAREDIs the function created in a function declaration (as opposed to a function expression)- See Also:
-
IS_STRICT
public static final int IS_STRICTis this a strict mode function?- See Also:
-
USES_ARGUMENTS
public static final int USES_ARGUMENTSDoes the function use the "arguments" identifier ?- See Also:
-
IS_STATEMENT
public static final int IS_STATEMENTIs it a statement?- See Also:
-
HAS_EVAL
public static final int HAS_EVALDoes 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.- See Also:
-
HAS_NESTED_EVAL
public static final int HAS_NESTED_EVALDoes a nested function contain eval? If it does, then all variables in this function might be get/set by it.- See Also:
-
HAS_SCOPE_BLOCK
public static final int HAS_SCOPE_BLOCKDoes 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.- See Also:
-
DEFINES_ARGUMENTS
public static final int DEFINES_ARGUMENTSFlag this function as one that defines the identifier "arguments" as a function parameter or nested function name. This precludes it from needing to have an Arguments object defined as "arguments" local variable. Note that defining a local variable named "arguments" still requires construction of the Arguments object (see ECMAScript 5.1 Chapter 10.5).- See Also:
-
USES_ANCESTOR_SCOPE
public static final int USES_ANCESTOR_SCOPEDoes this function or any of its descendants use variables from an ancestor function's scope (incl. globals)?- See Also:
-
IS_SCRIPT
public static final int IS_SCRIPTA script function- See Also:
-
IS_GETTER
public static final int IS_GETTERA getter function- See Also:
-
IS_SETTER
public static final int IS_SETTERA setter function- See Also:
-
IS_PROGRAM
public static final int IS_PROGRAMIs this function the top-level program?- See Also:
-
HAS_CLOSURES
public static final int HAS_CLOSURESDoes this function have closures?- See Also:
-
USES_THIS
public static final int USES_THISDoes this function use the "this" keyword?- See Also:
-
NEEDS_PARENT_SCOPE
public static final int NEEDS_PARENT_SCOPEDoes 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.- See Also:
-
IS_ARROW
public static final int IS_ARROWAn arrow function- See Also:
-
IS_MODULE
public static final int IS_MODULEA module function- See Also:
-
HAS_DIRECT_SUPER
public static final int HAS_DIRECT_SUPERDoes this function contain a super call? (cf. ES6 14.3.5 Static Semantics: HasDirectSuper)- See Also:
-
USES_SUPER
public static final int USES_SUPERDoes this function use the super binding?- See Also:
-
IS_METHOD
public static final int IS_METHODIs this function a (class or object) method?- See Also:
-
NO_FUNCTION_SELF
public static final int NO_FUNCTION_SELFIf one of these flags are set, this function does not have a function self binding.- See Also:
-
IS_CLASS_CONSTRUCTOR
public static final int IS_CLASS_CONSTRUCTORIs this the constructor method?- See Also:
-
IS_DERIVED_CONSTRUCTOR
public static final int IS_DERIVED_CONSTRUCTORIs this the constructor of a subclass (i.e., a class with an extends declaration)?- See Also:
-
USES_NEW_TARGET
public static final int USES_NEW_TARGETDoes this function use new.target?- See Also:
-
IS_GENERATOR
public static final int IS_GENERATORA generator function- See Also:
-
IS_ASYNC
public static final int IS_ASYNCIs it an async function?- See Also:
-
HAS_NON_SIMPLE_PARAMETER_LIST
public static final int HAS_NON_SIMPLE_PARAMETER_LISTFlag indicating that this function has a non-simple parameter list.- See Also:
-
HAS_ARROW_EVAL
public static final int HAS_ARROW_EVALFlag indicating that this function has an eval nested in an arrow function.- See Also:
-
HAS_FUNCTION_DECLARATIONS
public static final int HAS_FUNCTION_DECLARATIONSDoes this function have nested declarations?- See Also:
-
HAS_APPLY_ARGUMENTS_CALL
public static final int HAS_APPLY_ARGUMENTS_CALLDoes this function contain afn.apply(_, arguments)call?- See Also:
-
IS_CLASS_FIELD_INITIALIZER
public static final int IS_CLASS_FIELD_INITIALIZERIs this function a class field/static initializer?- See Also:
-
ARROW_HEAD_FLAGS
public static final int ARROW_HEAD_FLAGSAll 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.- See Also:
-
-
Constructor Details
-
FunctionNode
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) Constructor- Parameters:
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.
-
-
Method Details
-
accept
Description copied from interface:LexicalContextNodeAccept function for the node given a lexical context. It must be prepared to replace itself if present in the lexical context- Specified by:
acceptin interfaceLexicalContextNode- Parameters:
lc- lexical contextvisitor- node visitor- Returns:
- new node or same node depending on state change
-
accept
- Specified by:
acceptin interfaceLexicalContextNode
-
getSource
-
getId
public int getId()Get the unique ID for this function within the script file.- Returns:
- the id
-
getSourceName
get source name - sourceURL or name derived from Source.- Returns:
- name for the script source
-
getSourceName
-
getLineNumber
public int getLineNumber()Returns the line number.- Returns:
- the line number.
-
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 -
getFlags
public int getFlags()Description copied from interface:FlagsGet all flags of a LexicalContextNode- Specified by:
getFlagsin interfaceFlags<FunctionNode>- Returns:
- flags
-
getFlag
public boolean getFlag(int flag) Description copied from interface:FlagsCheck if a flag is set in a lexical context node- Specified by:
getFlagin interfaceFlags<FunctionNode>- Parameters:
flag- flag to check- Returns:
- flags
-
setFlags
Description copied from interface:FlagsSet all flags of a LexicalContextNode, overwriting previous flags- Specified by:
setFlagsin interfaceFlags<FunctionNode>- Parameters:
lc- lexical contextflags- new flags value- Returns:
- the new LexicalContext node if flags were changed, same otherwise
-
setFlag
Description copied from interface:FlagsSet a flag of a LexicalContextNode- Specified by:
setFlagin interfaceFlags<FunctionNode>- Parameters:
lc- lexical contextflag- flag to set- Returns:
- the new LexicalContext node if flags were changed, same otherwise
-
isProgram
public boolean isProgram()Returns true if the function is the top-level program.- Returns:
- True if this function node represents the top-level program.
-
hasEval
public boolean hasEval()Check if this function has a call expression for the identifier "eval" (that is,eval(...)).- Returns:
- true if
evalis called.
-
getFirstToken
public long getFirstToken()Get the first token for this function- Returns:
- the first token
-
usesThis
public boolean usesThis()Returntrueif this function makes use of thethisobject.- Returns:
- true if function uses
thisobject
-
getIdent
Get the identifier for this function, this is its symbol.- Returns:
- the identifier as an IdentityNode
-
getBody
Get the function body, i.e., the top-most block of the function.- Returns:
- the function body
-
getVarDeclarationBlock
-
setBody
Reset the function body- Parameters:
lc- lexical contextbody- new body- Returns:
- new function node if body changed, same if not
-
needsDynamicScope
public boolean needsDynamicScope()Check whether a function would need dynamic scope, which is does if it has evals and isn't strict.- Returns:
- true if dynamic scope is needed
-
needsArguments
public boolean needsArguments()Returns true if this function needs to have an Arguments object defined as a local variable named "arguments". Functions that use "arguments" as identifier and don't define it as a name of a parameter or a nested function (see ECMAScript 5.1 Chapter 10.5), as well as any function that uses eval or with, or has a nested function that does the same, will have an "arguments" object. Also, if this function is a script, it will not have an "arguments" object, because it does not have local variables; rather the Global object will have an explicit "arguments" property that provides command-line arguments for the script.- Returns:
- true if this function needs an arguments object.
-
getLastToken
public long getLastToken()Return the last token for this function's code- Returns:
- last token
-
getEndParserState
Returns the end parser state for this function.- Returns:
- the end parser state for this function.
-
getName
-
getNameTS
public com.oracle.truffle.api.strings.TruffleString getNameTS() -
setName
Set the name of this function.- Parameters:
lc- lexical contextname- new name- Returns:
- new function node if changed, otherwise the same
-
getInternalName
-
getInternalNameTS
public com.oracle.truffle.api.strings.TruffleString getInternalNameTS() -
getParameters
-
getNumOfParams
public int getNumOfParams()Return the number of parameters to this function- Returns:
- the number of parameters
-
getLength
public int getLength()The value of the function's length property, i.e., the typical number of arguments expected by the function. -
isDeclared
public boolean isDeclared()Check if this function is created as a function declaration (as opposed to function expression)- Returns:
- true if function is declared.
-
isAnonymous
public boolean isAnonymous()Check if this function is anonymous- Returns:
- true if function is anonymous
-
isNamedFunctionExpression
public 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).- Returns:
- true if this is a named function expression
-
isStrict
public boolean isStrict()Check if the function is generated in strict mode- Returns:
- true if strict mode enabled for function
-
isMethod
public boolean isMethod() -
usesSuper
public boolean usesSuper() -
hasDirectSuper
public boolean hasDirectSuper() -
isClassConstructor
public boolean isClassConstructor() -
isDerivedConstructor
public boolean isDerivedConstructor() -
usesNewTarget
public boolean usesNewTarget() -
isScript
public boolean isScript() -
isGetter
public boolean isGetter() -
isSetter
public boolean isSetter() -
isArrow
public boolean isArrow() -
isGenerator
public boolean isGenerator() -
isModule
public boolean isModule() -
getModule
-
isStatement
public boolean isStatement() -
isAsync
public boolean isAsync() -
hasSimpleParameterList
public boolean hasSimpleParameterList() -
usesAncestorScope
public boolean usesAncestorScope() -
setUsesAncestorScope
public void setUsesAncestorScope(boolean usesAncestorScope) -
isNormal
public boolean isNormal() -
hasApplyArgumentsCall
public boolean hasApplyArgumentsCall() -
hasArrowEval
public boolean hasArrowEval() -
needsThis
public boolean needsThis() -
needsNewTarget
public boolean needsNewTarget() -
needsSuper
public boolean needsSuper() -
isClassFieldInitializer
public boolean isClassFieldInitializer() -
hasClosures
public boolean hasClosures() -
accept
Description copied from class:NodeProvides a means to navigate the IR.- Specified by:
acceptin interfaceLexicalContextNode- Specified by:
acceptin classNode- Parameters:
visitor- Node visitor.- Returns:
- node the node or its replacement after visitation, null if no further visitations are required
-
accept
Description copied from class:NodeProvides a means to navigate the IR.- Specified by:
acceptin interfaceLexicalContextNode- Specified by:
acceptin classNode- Parameters:
visitor- Node visitor.- Returns:
- node the node or its replacement after visitation, null if no further visitations are required
-