src/jdk/nashorn/internal/ir/FunctionNode.java

Print this page




 180     public static final int DEFINES_ARGUMENTS           = 1 << 8;
 181 
 182     /** Does this function or any of its descendants use variables from an ancestor function's scope (incl. globals)? */
 183     public static final int USES_ANCESTOR_SCOPE         = 1 << 9;
 184 
 185     /** Is this function lazily compiled? */
 186     public static final int IS_LAZY                     = 1 << 10;
 187 
 188     /** Does this function have lazy, yet uncompiled children */
 189     public static final int HAS_LAZY_CHILDREN           = 1 << 11;
 190 
 191     /** Does this function have lazy, yet uncompiled children */
 192     public static final int IS_PROGRAM                  = 1 << 12;
 193 
 194     /** Does this function have nested declarations? */
 195     public static final int HAS_FUNCTION_DECLARATIONS   = 1 << 13;
 196 
 197     /** Can this function be specialized? */
 198     public static final int CAN_SPECIALIZE              = 1 << 14;
 199 



 200     /** Does this function or any nested functions contain an eval? */
 201     private static final int HAS_DEEP_EVAL = HAS_EVAL | HAS_NESTED_EVAL;
 202 
 203     /** Does this function need to store all its variables in scope? */
 204     private static final int HAS_ALL_VARS_IN_SCOPE = HAS_DEEP_EVAL | IS_SPLIT | HAS_LAZY_CHILDREN;
 205 
 206     /** Does this function potentially need "arguments"? Note that this is not a full test, as further negative check of REDEFINES_ARGS is needed. */
 207     private static final int MAYBE_NEEDS_ARGUMENTS = USES_ARGUMENTS | HAS_EVAL;
 208 
 209     /** 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.
 210      *  We also pessimistically need a parent scope if we have lazy children that have not yet been compiled */
 211     private static final int NEEDS_PARENT_SCOPE = USES_ANCESTOR_SCOPE | HAS_DEEP_EVAL | HAS_LAZY_CHILDREN;
 212 
 213     /** What is the return type of this function? */
 214     private Type returnType = Type.UNKNOWN;
 215 
 216     /**
 217      * Constructor
 218      *
 219      * @param source     the source


 571     }
 572 
 573     /**
 574      * Check whether this function has nested function declarations
 575      * @return true if nested function declarations exist
 576      */
 577     public boolean hasDeclaredFunctions() {
 578         return getFlag(HAS_FUNCTION_DECLARATIONS);
 579     }
 580 
 581     /**
 582      * Check if this function's generated Java method needs a {@code callee} parameter. Functions that need access to
 583      * their parent scope, functions that reference themselves, and non-strict functions that need an Arguments object
 584      * (since it exposes {@code arguments.callee} property) will need to have a callee parameter. We also return true
 585      * for split functions to make sure symbols slots are the same in the main and split methods.
 586      *
 587      * @return true if the function's generated Java method needs a {@code callee} parameter.
 588      */
 589     public boolean needsCallee() {
 590         return needsParentScope() || needsSelfSymbol() || isSplit() || (needsArguments() && !isStrict());









 591     }
 592 
 593     /**
 594      * Get the identifier for this function, this is its symbol.
 595      * @return the identifier as an IdentityNode
 596      */
 597     public IdentNode getIdent() {
 598         return ident;
 599     }
 600 
 601     /**
 602      * Return a set of symbols declared in this function node. This
 603      * is only relevant after Attr, otherwise it will be an empty
 604      * set as no symbols have been introduced
 605      * @return set of declared symbols in function
 606      */
 607     public Set<Symbol> getDeclaredSymbols() {
 608         return Collections.unmodifiableSet(declaredSymbols);
 609     }
 610 




 180     public static final int DEFINES_ARGUMENTS           = 1 << 8;
 181 
 182     /** Does this function or any of its descendants use variables from an ancestor function's scope (incl. globals)? */
 183     public static final int USES_ANCESTOR_SCOPE         = 1 << 9;
 184 
 185     /** Is this function lazily compiled? */
 186     public static final int IS_LAZY                     = 1 << 10;
 187 
 188     /** Does this function have lazy, yet uncompiled children */
 189     public static final int HAS_LAZY_CHILDREN           = 1 << 11;
 190 
 191     /** Does this function have lazy, yet uncompiled children */
 192     public static final int IS_PROGRAM                  = 1 << 12;
 193 
 194     /** Does this function have nested declarations? */
 195     public static final int HAS_FUNCTION_DECLARATIONS   = 1 << 13;
 196 
 197     /** Can this function be specialized? */
 198     public static final int CAN_SPECIALIZE              = 1 << 14;
 199 
 200     /** Does this function use the "this" keyword? */
 201     public static final int USES_THIS                   = 1 << 15;
 202 
 203     /** Does this function or any nested functions contain an eval? */
 204     private static final int HAS_DEEP_EVAL = HAS_EVAL | HAS_NESTED_EVAL;
 205 
 206     /** Does this function need to store all its variables in scope? */
 207     private static final int HAS_ALL_VARS_IN_SCOPE = HAS_DEEP_EVAL | IS_SPLIT | HAS_LAZY_CHILDREN;
 208 
 209     /** Does this function potentially need "arguments"? Note that this is not a full test, as further negative check of REDEFINES_ARGS is needed. */
 210     private static final int MAYBE_NEEDS_ARGUMENTS = USES_ARGUMENTS | HAS_EVAL;
 211 
 212     /** 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.
 213      *  We also pessimistically need a parent scope if we have lazy children that have not yet been compiled */
 214     private static final int NEEDS_PARENT_SCOPE = USES_ANCESTOR_SCOPE | HAS_DEEP_EVAL | HAS_LAZY_CHILDREN;
 215 
 216     /** What is the return type of this function? */
 217     private Type returnType = Type.UNKNOWN;
 218 
 219     /**
 220      * Constructor
 221      *
 222      * @param source     the source


 574     }
 575 
 576     /**
 577      * Check whether this function has nested function declarations
 578      * @return true if nested function declarations exist
 579      */
 580     public boolean hasDeclaredFunctions() {
 581         return getFlag(HAS_FUNCTION_DECLARATIONS);
 582     }
 583 
 584     /**
 585      * Check if this function's generated Java method needs a {@code callee} parameter. Functions that need access to
 586      * their parent scope, functions that reference themselves, and non-strict functions that need an Arguments object
 587      * (since it exposes {@code arguments.callee} property) will need to have a callee parameter. We also return true
 588      * for split functions to make sure symbols slots are the same in the main and split methods.
 589      *
 590      * @return true if the function's generated Java method needs a {@code callee} parameter.
 591      */
 592     public boolean needsCallee() {
 593         return needsParentScope() || needsSelfSymbol() || isSplit() || (needsArguments() && !isStrict());
 594     }
 595 
 596     /**
 597      * Return {@code true} if this function makes use of the {@code this} object.
 598      *
 599      * @return true if function uses {@code this} object
 600      */
 601     public boolean usesThis() {
 602         return getFlag(USES_THIS);
 603     }
 604 
 605     /**
 606      * Get the identifier for this function, this is its symbol.
 607      * @return the identifier as an IdentityNode
 608      */
 609     public IdentNode getIdent() {
 610         return ident;
 611     }
 612 
 613     /**
 614      * Return a set of symbols declared in this function node. This
 615      * is only relevant after Attr, otherwise it will be an empty
 616      * set as no symbols have been introduced
 617      * @return set of declared symbols in function
 618      */
 619     public Set<Symbol> getDeclaredSymbols() {
 620         return Collections.unmodifiableSet(declaredSymbols);
 621     }
 622