StaticScope represents lexical scoping of variables and module/class constants. At a very high level every scopes enclosing scope contains variables in the next outer lexical layer. The enclosing scopes variables may or may not be reachable depending on the scoping rules for variables (governed by BlockStaticScope and LocalStaticScope). StaticScope also keeps track of current module/class that is in scope. previousCRefScope will point to the previous scope of the enclosing module/class (cref).
| constant | type | note |
|---|---|---|
| MAX_SPECIALIZED_SIZE | int | |
| IMPLICIT | int |
addAssign(int line, org.jruby.RubySymbol symbolID, org.jruby.ast.Node value)addImplicitVariableThisScope(String name)Add an implicit variable ("it", "_1") to this (current) scope unless it is already defined in the current scope. The variable will be marked as implicit to omit it from local variable lists and functions.
| name | type | description |
|---|---|---|
| name | String | of new variable |
Returns: index of variable
addVariable(String name)Add a new variable to this (current) scope unless it is already defined in any reachable scope.
| name | type | description |
|---|---|---|
| name | String | of new variable |
Returns: index+depth merged location of scope
addVariableName(String name)addVariableThisScope(String name)Add a new variable to this (current) scope unless it is already defined in the current scope.
| name | type | description |
|---|---|---|
| name | String | of new variable |
Returns: index of variable
getAllNamesInScope() · also: get_all_names_in_scopeGet all visible variables that we can see from this scope that have been assigned (e.g. seen so far)
Returns: a list of all names (sans $~ and $_ which are special names)
isArgumentScope() · also: is_argument_scopeArgument scopes represent scopes which contain arguments for zsuper. All LocalStaticScopes are argument scopes and BlockStaticScopes can be when they are used by define_method.
assign(int line, org.jruby.RubySymbol name, org.jruby.ast.Node value)Make a DASgn or LocalAsgn node based on scope logic Note: This is private code made public only for parser.
assign(int line, org.jruby.RubySymbol symbolID, org.jruby.ast.Node value, org.jruby.parser.StaticScope topScope, int depth)assignKeyword(int line, org.jruby.RubySymbol symbolID, org.jruby.ast.Node value)Register a keyword argument with this staticScope. It additionally will track where the first keyword argument started so we can test and tell whether we have a kwarg or an ordinary variable during live execution (See keywordExists).
isBlockScope() · also: is_block_scopecaptureParentRefinements(org.jruby.runtime.ThreadContext context)Duplicate the parent scope's refinements overlay to get a moment-in-time snapshot. Caller must decide whether this scope is using (or maybe) using refinements.
collectAllVariables(org.jruby.runtime.ThreadContext context, java.util.function.BiFunction<org.jruby.runtime.ThreadContext,Integer,T> collectionFactory, java.util.function.BiConsumer<T,String> collectionPopulator)Populate a deduplicated collection of variable names in scope using the given functions. This may include variables that are not strictly Ruby local variable names, so the consumer should validate names as appropriate.
| name | type | description |
|---|---|---|
| collection_factory | java.util.function.BiFunction<org.jruby.runtime.ThreadContext,Integer,T> | used to construct the collection |
| collection_populator | java.util.function.BiConsumer<T,String> | used to pass values into the collection |
Returns: populated collection
collectImplicitVariables(org.jruby.runtime.ThreadContext context, java.util.function.BiFunction<org.jruby.runtime.ThreadContext,Integer,T> collectionFactory, java.util.function.BiConsumer<T,String> collectionPopulator)Populate a deduplicated collection of implicit variable names("it", "_1", etc) in scope using the given functions. This may include variables that are not strictly Ruby local variable names, so the consumer should validate names as appropriate.
| name | type | description |
|---|---|---|
| collection_factory | java.util.function.BiFunction<org.jruby.runtime.ThreadContext,Integer,T> | used to construct the collection |
| collection_populator | java.util.function.BiConsumer<T,String> | used to pass values into the collection |
Returns: populated collection
collectVariables(java.util.function.IntFunction<T> collectionFactory, java.util.function.BiConsumer<T,String> collectionPopulator)collectVariables(org.jruby.runtime.ThreadContext context, java.util.function.BiFunction<org.jruby.runtime.ThreadContext,Integer,T> collectionFactory, java.util.function.BiConsumer<T,String> collectionPopulator)Populate a deduplicated collection of variable names in scope using the given functions. This may include variables that are not strictly Ruby local variable names, so the consumer should validate names as appropriate.
| name | type | description |
|---|---|---|
| collection_factory | java.util.function.BiFunction<org.jruby.runtime.ThreadContext,Integer,T> | used to construct the collection |
| collection_populator | java.util.function.BiConsumer<T,String> | used to pass values into the collection |
Returns: populated collection
collectVariables(org.jruby.runtime.ThreadContext context, java.util.function.BiFunction<org.jruby.runtime.ThreadContext,Integer,T> collectionFactory, java.util.function.BiConsumer<T,String> collectionPopulator, Boolean implicit)construct(org.jruby.runtime.DynamicScope parent)declare(int line, org.jruby.RubySymbol symbolID, int depth)declare(int line, org.jruby.RubySymbol symbolID)Make a DVar or LocalVar node based on scoping logic
| name | type | description |
|---|---|---|
| line | int | the location that in the source that the new node will come from |
| symbol_id | org.jruby.RubySymbol | of the variable to be created is named |
Returns: a DVarNode or LocalVarNode Note: This is private code made public only for parser.
Update current scoping structure to populate with proper cref scoping values. This should be called at any point when you reference a scope for the first time. For the interpreter this is done in a small number of places (defnNode, defsNode, and getBlock). The compiler does this in the same places.
Returns: the current cref, though this is largely an implementation detail
Next outer most scope in list of scopes. An enclosing scope may have no direct scoping relationship to its child. If I am in a localScope and then I enter something which creates another localScope the enclosing scope will be the first scope, but there are no valid scoping relationships between the two. Methods which walk the enclosing scopes are responsible for enforcing appropriate scoping relationships.
Returns: the parent scope
setEnclosingScope(org.jruby.parser.StaticScope parent) · also: set_enclosing_scopeexists(String name)Does the variable exist?
| name | type | description |
|---|---|---|
| name | String | of the variable to find |
Returns: index of variable or -1 if it does not exist
existsAndNotImplicit(String name)Does the variable exist and not implicit?
| name | type | description |
|---|---|---|
| name | String | of the variable to find |
Returns: index of variable; -1 if it does not exist; -2 if is implicit.
getFile() · also: get_filesetFile(String file) · also: set_filegetFirstKeywordIndex() · also: get_first_keyword_indexgetConstant(org.jruby.runtime.ThreadContext context, String internedName)getConstantDefined(String internedName)getConstantDefined(org.jruby.runtime.ThreadContext context, String internedName)Gets a constant back from lexical search from the cref in this scope. As it is for defined? we will not forced resolution of autoloads nor call const_defined
getConstantDefinedNoObject(String internedName)getLocalVariables(org.jruby.runtime.ThreadContext context)Get a Ruby Array of all local variables.
| name | type | description |
|---|---|---|
| context | org.jruby.runtime.ThreadContext | the current context |
Returns: populated RubyArray
getOverlayModuleForWrite(org.jruby.runtime.ThreadContext context)getScopedConstant(org.jruby.runtime.ThreadContext context, String internedName)getInstanceVariableNames() · also: get_instance_variable_namessetInstanceVariableNames(Collection<String> ivarWrites) · also: set_instance_variable_namesisDefined(String name)Is this name in the visible to the current scope
| name | type | description |
|---|---|---|
| name | String | to be looked for |
Returns: a location where the left-most 16 bits of number of scopes down it is and the right-most 16 bits represents its index in that scope
isDefined(String name, int depth)isDefinedNotImplicit(String name)Is this name visible to the current scope and not an implicit variable ("it", "_1", etc).
| name | type | description |
|---|---|---|
| name | String | to be looked for |
Returns: -1 if it is not defined; -2 if it is implicit; or a location where the left-most 16 bits of number of scopes down it is and the right-most 16 bits represents its index in that scope.
isDefinedNotImplicit(String name, int depth)isImplicitVariable(int slot)Returns: whether the given slot contains an implicit variable ("it", "_1", etc).
keywordExists(String name)getKeywordIndices() · also: get_keyword_indicessetKeywordIndices(BitSet keywordIndices) · also: set_keyword_indicesGets the Local Scope relative to the current Scope. For LocalScopes this will be itself. Blocks will contain the LocalScope it contains.
Returns: localScope
makeArgumentScope()markImplicitVariable(int slot)Get the live CRef module associated with this scope.
Returns: the live module
getNumberOfVariables() · also: get_number_of_variablesgetOverlayModuleForRead() · also: get_overlay_module_for_readsetPreviousCRefScope(org.jruby.parser.StaticScope crefScope) · also: set_previous_c_ref_scopeisRuby2Keywords() · also: is_ruby2_keywordssetScopeType(org.jruby.ir.IRScopeType scopeType) · also: set_scope_typeFor all block or method associated with static scopes this will return the signature for that signature-providing scope. module bodies and other non-arity specific code will return null.
setSignature(org.jruby.runtime.Signature signature) · also: set_signatureThis happens in when first defining ArgsNodes or when reifying a method from AOT.
toString()getVariables() · also: get_variablessetVariables(String[] names) · also: set_variablesisWithinMethod() · also: is_within_methodDetermine if we happen to be within a method definition.
Returns: true if so