Class: Steep::TypeInference::ConstantEnv
- Inherits:
-
Object
- Object
- Steep::TypeInference::ConstantEnv
- Defined in:
- lib/steep/type_inference/constant_env.rb
Instance Attribute Summary collapse
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
-
#initialize(builder:, context:) ⇒ ConstantEnv
constructor
ConstantEnv receives an optional Names::Module, not a Namespace, because this is a simulation of Ruby.
- #lookup(name) ⇒ Object
- #lookup0(name, namespace:) ⇒ Object
- #namespace ⇒ Object
- #signatures ⇒ Object
Constructor Details
#initialize(builder:, context:) ⇒ ConstantEnv
ConstantEnv receives an optional Names::Module, not a Namespace, because this is a simulation of Ruby. Any namespace is a module or class.
10 11 12 13 14 |
# File 'lib/steep/type_inference/constant_env.rb', line 10 def initialize(builder:, context:) @cache = {} @builder = builder @context = context end |
Instance Attribute Details
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
4 5 6 |
# File 'lib/steep/type_inference/constant_env.rb', line 4 def builder @builder end |
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
6 7 8 |
# File 'lib/steep/type_inference/constant_env.rb', line 6 def cache @cache end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
5 6 7 |
# File 'lib/steep/type_inference/constant_env.rb', line 5 def context @context end |
Instance Method Details
#lookup(name) ⇒ Object
28 29 30 |
# File 'lib/steep/type_inference/constant_env.rb', line 28 def lookup(name) cache[name] ||= lookup0(name, namespace: namespace) end |
#lookup0(name, namespace:) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/steep/type_inference/constant_env.rb', line 33 def lookup0(name, namespace:) full_name = name.in_namespace(namespace) case when signatures.module_name?(full_name) AST::Types::Name::Module.new(name: full_name) when signatures.class_name?(full_name) AST::Types::Name::Class.new(name: full_name, constructor: true) when signatures.const_name?(full_name) builder.absolute_type(signatures.find_const(name, current_module: namespace).type, current: namespace) else unless namespace.empty? lookup0(name, namespace: namespace.parent) end end end |
#namespace ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/steep/type_inference/constant_env.rb', line 20 def namespace @namespace ||= if context context.namespace.append(context.name) else AST::Namespace.root end end |
#signatures ⇒ Object
16 17 18 |
# File 'lib/steep/type_inference/constant_env.rb', line 16 def signatures builder.signatures end |