jruby/docs BETA
Navigation
org.jruby.parser 23
C ArgsTailHolder
C JavaSignatureParser
C NodeExits
C Parser
C ParserConfiguration
C ParserManager
I ParserProvider
C ParserProviderDefault
C ParserServiceLoader
I ParserState
C ParserSyntaxException
E ParserType
C ProductionState
I ReOptions
C RubyParser
C RubyParserBase
C RubyParserResult
C ScopedParserState
C StaticScope
C StaticScopeFactory
C TokenInfo
C YYDebug
C YyTables
StaticScope — members 73
F MAX_SPECIALIZED_SIZE() int
F IMPLICIT() int
M add_assign(line, symbol_id, value) AssignableNode
M add_implicit_variable_this_scope(name) int
M add_variable(name) int
M add_variable_name(name) int
M add_variable_this_scope(name) int
M all_names_in_scope() String[]
M argument_scope?() boolean
M assign(line, name, value) AssignableNode
M assign(line, symbol_id, value, top_scope, depth) AssignableNode
M assign_keyword(line, symbol_id, value) AssignableNode
M block_scope?() boolean
C capture_parent_refinements(context)
M collect_all_variables(context, collection_factory, collection_populator) T
M collect_implicit_variables(context, collection_factory, collection_populator) T
M collect_variables(collection_factory, collection_populator) T
M collect_variables(context, collection_factory, collection_populator) T
M collect_variables(context, collection_factory, collection_populator, implicit) T
M construct(parent) DynamicScope
M declare(line, symbol_id, depth) Node
M declare(line, symbol_id) Node
M determine_module() RubyModule
M dummy_scope() DynamicScope
M duplicate() StaticScope
M enclosing_scope() StaticScope
C enclosing_scope=(parent)
M exists(name) int
M exists_and_not_implicit(name) int
M file() String
C file=(file)
M first_keyword_index() int
M get_constant(interned_name) IRubyObject
M get_constant(context, interned_name) IRubyObject
M get_constant_defined(interned_name) IRubyObject
M get_constant_defined(context, interned_name) IRubyObject
M get_constant_defined_no_object(interned_name) IRubyObject
M get_constant_inner(interned_name) IRubyObject
M get_local_variables(runtime) RubyArray
M get_local_variables(context) RubyArray
M get_overlay_module_for_write(context) RubyModule
M get_scoped_constant(context, interned_name) IRubyObject
M instance_variable_names() Collection<String>
C instance_variable_names=(ivar_writes)
M ir_scope() IRScope
C ir_scope=(ir_scope)
M is_defined(name) int
M is_defined(name, depth) int
M is_defined_not_implicit(name) int
M is_defined_not_implicit(name, depth) int
M is_implicit_variable(slot) boolean
M keyword_exists(name) boolean
M keyword_indices() BitSet
C keyword_indices=(keyword_indices)
M local_scope() StaticScope
C make_argument_scope()
C mark_implicit_variable(slot)
M module() RubyModule
C module=(module)
M number_of_variables() int
M overlay_module_for_read() RubyModule
M previous_c_ref_scope() StaticScope
C previous_c_ref_scope=(cref_scope)
M ruby2_keywords?() boolean
M scope_type() IRScopeType
C scope_type=(scope_type)
M signature() Signature
C signature=(signature)
M to_string() String
M type() Type
M variables() String[]
C variables=(names)
M within_method?() boolean

org.jruby.parser.StaticScope

class implements Serializable implements Cloneable 73 members

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).

Constants

constanttypenote
MAX_SPECIALIZED_SIZE int
IMPLICIT int

Instance Methods

add_assign

AssignableNode add_assign ( int line, RubySymbol symbol_id, Node value )
Java: addAssign(int line, org.jruby.RubySymbol symbolID, org.jruby.ast.Node value)

add_implicit_variable_this_scope

int add_implicit_variable_this_scope ( String name )
Java: 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.

nametypedescription
nameStringof new variable

Returns: index of variable

add_variable

int add_variable ( String name )
Java: addVariable(String name)

Add a new variable to this (current) scope unless it is already defined in any reachable scope.

nametypedescription
nameStringof new variable

Returns: index+depth merged location of scope

add_variable_name

int add_variable_name ( String name )
Java: addVariableName(String name)

add_variable_this_scope

int add_variable_this_scope ( String name )
Java: addVariableThisScope(String name)

Add a new variable to this (current) scope unless it is already defined in the current scope.

nametypedescription
nameStringof new variable

Returns: index of variable

all_names_in_scope

String[] all_names_in_scope ( )
Java: getAllNamesInScope() · also: get_all_names_in_scope

Get 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)

argument_scope?

boolean argument_scope? ( )
Java: isArgumentScope() · also: is_argument_scope

Argument 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

AssignableNode assign ( int line, RubySymbol name, Node value )
Java: 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

AssignableNode assign ( int line, RubySymbol symbol_id, Node value, StaticScope top_scope, int depth )
Java: assign(int line, org.jruby.RubySymbol symbolID, org.jruby.ast.Node value, org.jruby.parser.StaticScope topScope, int depth)

assign_keyword

AssignableNode assign_keyword ( int line, RubySymbol symbol_id, Node value )
Java: 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).

block_scope?

boolean block_scope? ( )
Java: isBlockScope() · also: is_block_scope

capture_parent_refinements

capture_parent_refinements ( ThreadContext context )
Java: captureParentRefinements(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.

collect_all_variables

T collect_all_variables ( ThreadContext context, BiFunction<ThreadContext,Integer,T> collection_factory, BiConsumer<T,String> collection_populator )
Java: 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.

nametypedescription
collection_factoryjava.util.function.BiFunction<org.jruby.runtime.ThreadContext,Integer,T>used to construct the collection
collection_populatorjava.util.function.BiConsumer<T,String>used to pass values into the collection

Returns: populated collection

collect_implicit_variables

T collect_implicit_variables ( ThreadContext context, BiFunction<ThreadContext,Integer,T> collection_factory, BiConsumer<T,String> collection_populator )
Java: 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.

nametypedescription
collection_factoryjava.util.function.BiFunction<org.jruby.runtime.ThreadContext,Integer,T>used to construct the collection
collection_populatorjava.util.function.BiConsumer<T,String>used to pass values into the collection

Returns: populated collection

collect_variables

T collect_variables ( IntFunction<T> collection_factory, BiConsumer<T,String> collection_populator )
Java: collectVariables(java.util.function.IntFunction<T> collectionFactory, java.util.function.BiConsumer<T,String> collectionPopulator)

collect_variables

T collect_variables ( ThreadContext context, BiFunction<ThreadContext,Integer,T> collection_factory, BiConsumer<T,String> collection_populator )
Java: 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.

nametypedescription
collection_factoryjava.util.function.BiFunction<org.jruby.runtime.ThreadContext,Integer,T>used to construct the collection
collection_populatorjava.util.function.BiConsumer<T,String>used to pass values into the collection

Returns: populated collection

collect_variables

T collect_variables ( ThreadContext context, BiFunction<ThreadContext,Integer,T> collection_factory, BiConsumer<T,String> collection_populator, Boolean implicit )
Java: 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

DynamicScope construct ( DynamicScope parent )
Java: construct(org.jruby.runtime.DynamicScope parent)

declare

Node declare ( int line, RubySymbol symbol_id, int depth )
Java: declare(int line, org.jruby.RubySymbol symbolID, int depth)

declare

Node declare ( int line, RubySymbol symbol_id )
Java: declare(int line, org.jruby.RubySymbol symbolID)

Make a DVar or LocalVar node based on scoping logic

nametypedescription
lineintthe location that in the source that the new node will come from
symbol_idorg.jruby.RubySymbolof the variable to be created is named

Returns: a DVarNode or LocalVarNode Note: This is private code made public only for parser.

determine_module

RubyModule determine_module ( )
Java: determineModule()

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

dummy_scope

DynamicScope dummy_scope ( )
Java: getDummyScope() · also: get_dummy_scope

duplicate

StaticScope duplicate ( )
Java: duplicate()

enclosing_scope

StaticScope enclosing_scope ( )
Java: getEnclosingScope() · also: get_enclosing_scope

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

enclosing_scope=

enclosing_scope= ( StaticScope parent )
Java: setEnclosingScope(org.jruby.parser.StaticScope parent) · also: set_enclosing_scope

exists

int exists ( String name )
Java: exists(String name)

Does the variable exist?

nametypedescription
nameStringof the variable to find

Returns: index of variable or -1 if it does not exist

exists_and_not_implicit

int exists_and_not_implicit ( String name )
Java: existsAndNotImplicit(String name)

Does the variable exist and not implicit?

nametypedescription
nameStringof the variable to find

Returns: index of variable; -1 if it does not exist; -2 if is implicit.

file

String file ( )
Java: getFile() · also: get_file

file=

file= ( String file )
Java: setFile(String file) · also: set_file

first_keyword_index

int first_keyword_index ( )
Java: getFirstKeywordIndex() · also: get_first_keyword_index

get_constant

IRubyObject get_constant ( String interned_name )
Java: getConstant(String internedName)

get_constant

IRubyObject get_constant ( ThreadContext context, String interned_name )
Java: getConstant(org.jruby.runtime.ThreadContext context, String internedName)

get_constant_defined

IRubyObject get_constant_defined ( String interned_name )
Java: getConstantDefined(String internedName)

get_constant_defined

IRubyObject get_constant_defined ( ThreadContext context, String interned_name )
Java: 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

get_constant_defined_no_object

IRubyObject get_constant_defined_no_object ( String interned_name )
Java: getConstantDefinedNoObject(String internedName)

get_constant_inner

IRubyObject get_constant_inner ( String interned_name )
Java: getConstantInner(String internedName)

get_local_variables

RubyArray get_local_variables ( Ruby runtime )
Java: getLocalVariables(org.jruby.Ruby runtime)

get_local_variables

RubyArray get_local_variables ( ThreadContext context )
Java: getLocalVariables(org.jruby.runtime.ThreadContext context)

Get a Ruby Array of all local variables.

nametypedescription
contextorg.jruby.runtime.ThreadContextthe current context

Returns: populated RubyArray

get_overlay_module_for_write

RubyModule get_overlay_module_for_write ( ThreadContext context )
Java: getOverlayModuleForWrite(org.jruby.runtime.ThreadContext context)

get_scoped_constant

IRubyObject get_scoped_constant ( ThreadContext context, String interned_name )
Java: getScopedConstant(org.jruby.runtime.ThreadContext context, String internedName)

instance_variable_names

Collection<String> instance_variable_names ( )
Java: getInstanceVariableNames() · also: get_instance_variable_names

instance_variable_names=

instance_variable_names= ( Collection<String> ivar_writes )
Java: setInstanceVariableNames(Collection<String> ivarWrites) · also: set_instance_variable_names

ir_scope

IRScope ir_scope ( )
Java: getIRScope() · also: get_ir_scope

ir_scope=

ir_scope= ( IRScope ir_scope )
Java: setIRScope(org.jruby.ir.IRScope irScope) · also: set_ir_scope

is_defined

int is_defined ( String name )
Java: isDefined(String name)

Is this name in the visible to the current scope

nametypedescription
nameStringto 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

is_defined

int is_defined ( String name, int depth )
Java: isDefined(String name, int depth)

is_defined_not_implicit

int is_defined_not_implicit ( String name )
Java: isDefinedNotImplicit(String name)

Is this name visible to the current scope and not an implicit variable ("it", "_1", etc).

nametypedescription
nameStringto 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.

is_defined_not_implicit

int is_defined_not_implicit ( String name, int depth )
Java: isDefinedNotImplicit(String name, int depth)

is_implicit_variable

boolean is_implicit_variable ( int slot )
Java: isImplicitVariable(int slot)

Returns: whether the given slot contains an implicit variable ("it", "_1", etc).

keyword_exists

boolean keyword_exists ( String name )
Java: keywordExists(String name)

keyword_indices

BitSet keyword_indices ( )
Java: getKeywordIndices() · also: get_keyword_indices

keyword_indices=

keyword_indices= ( BitSet keyword_indices )
Java: setKeywordIndices(BitSet keywordIndices) · also: set_keyword_indices

local_scope

StaticScope local_scope ( )
Java: getLocalScope() · also: get_local_scope

Gets the Local Scope relative to the current Scope. For LocalScopes this will be itself. Blocks will contain the LocalScope it contains.

Returns: localScope

make_argument_scope

make_argument_scope ( )
Java: makeArgumentScope()

mark_implicit_variable

mark_implicit_variable ( int slot )
Java: markImplicitVariable(int slot)

module

RubyModule module ( )
Java: getModule() · also: get_module

Get the live CRef module associated with this scope.

Returns: the live module

module=

module= ( RubyModule module )
Java: setModule(org.jruby.RubyModule module) · also: set_module

number_of_variables

int number_of_variables ( )
Java: getNumberOfVariables() · also: get_number_of_variables

overlay_module_for_read

RubyModule overlay_module_for_read ( )
Java: getOverlayModuleForRead() · also: get_overlay_module_for_read

previous_c_ref_scope

StaticScope previous_c_ref_scope ( )
Java: getPreviousCRefScope() · also: get_previous_c_ref_scope

previous_c_ref_scope=

previous_c_ref_scope= ( StaticScope cref_scope )
Java: setPreviousCRefScope(org.jruby.parser.StaticScope crefScope) · also: set_previous_c_ref_scope

ruby2_keywords?

boolean ruby2_keywords? ( )
Java: isRuby2Keywords() · also: is_ruby2_keywords

scope_type

IRScopeType scope_type ( )
Java: getScopeType() · also: get_scope_type

scope_type=

scope_type= ( IRScopeType scope_type )
Java: setScopeType(org.jruby.ir.IRScopeType scopeType) · also: set_scope_type

signature

Signature signature ( )
Java: getSignature() · also: get_signature

For 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.

signature=

signature= ( Signature signature )
Java: setSignature(org.jruby.runtime.Signature signature) · also: set_signature

This happens in when first defining ArgsNodes or when reifying a method from AOT.

to_string

String to_string ( )
Java: toString()

type

StaticScope.Type type ( )
Java: getType() · also: get_type

variables

String[] variables ( )
Java: getVariables() · also: get_variables

variables=

variables= ( String[] names )
Java: setVariables(String[] names) · also: set_variables

within_method?

boolean within_method? ( )
Java: isWithinMethod() · also: is_within_method

Determine if we happen to be within a method definition.

Returns: true if so