Class: Duby::AST::StaticScope
- Inherits:
-
Object
- Object
- Duby::AST::StaticScope
- Defined in:
- lib/duby/ast.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
Returns the value of attribute parent.
- #self_type ⇒ Object
Instance Method Summary collapse
- #<<(name) ⇒ Object
- #add_child(scope) ⇒ Object
- #binding_type(defining_class = nil, duby = nil) ⇒ Object
- #binding_type=(type) ⇒ Object
- #captured?(name) ⇒ Boolean
- #children ⇒ Object
- #has_binding? ⇒ Boolean
- #include?(name, include_parent = true) ⇒ Boolean
-
#initialize(parent = nil) ⇒ StaticScope
constructor
A new instance of StaticScope.
- #remove_child(scope) ⇒ Object
Constructor Details
#initialize(parent = nil) ⇒ StaticScope
Returns a new instance of StaticScope.
249 250 251 252 253 |
# File 'lib/duby/ast.rb', line 249 def initialize(parent=nil) @vars = {} @parent = parent @children = {} end |
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
246 247 248 |
# File 'lib/duby/ast.rb', line 246 def parent @parent end |
#self_type ⇒ Object
292 293 294 295 296 297 |
# File 'lib/duby/ast.rb', line 292 def self_type if @self_type.nil? && parent @self_type = parent.self_type end @self_type end |
Instance Method Details
#<<(name) ⇒ Object
255 256 257 |
# File 'lib/duby/ast.rb', line 255 def <<(name) @vars[name] = true end |
#add_child(scope) ⇒ Object
278 279 280 |
# File 'lib/duby/ast.rb', line 278 def add_child(scope) @children[scope] = true end |
#binding_type(defining_class = nil, duby = nil) ⇒ Object
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/duby/ast.rb', line 299 def binding_type(defining_class=nil, duby=nil) @binding_type ||= begin if parent parent.binding_type(defining_class, duby) else name = "#{defining_class.name}$#{duby.tmp}" factory = Duby::AST.type_factory if factory factory.declare_type(name) else Duby::AST::TypeReference.new(name, false, false) end end end end |
#binding_type=(type) ⇒ Object
315 316 317 318 319 320 321 |
# File 'lib/duby/ast.rb', line 315 def binding_type=(type) if parent parent.binding_type = type else @binding_type = type end end |
#captured?(name) ⇒ Boolean
264 265 266 267 268 269 270 271 272 |
# File 'lib/duby/ast.rb', line 264 def captured?(name) if !include?(name, false) return false elsif parent && parent.include?(name) return true else return children.any? {|child| child.include?(name, false)} end end |
#children ⇒ Object
274 275 276 |
# File 'lib/duby/ast.rb', line 274 def children @children.keys end |
#has_binding? ⇒ Boolean
323 324 325 |
# File 'lib/duby/ast.rb', line 323 def has_binding? @binding_type != nil || (parent && parent.has_binding?) end |
#include?(name, include_parent = true) ⇒ Boolean
259 260 261 262 |
# File 'lib/duby/ast.rb', line 259 def include?(name, include_parent=true) @vars.include?(name) || (include_parent && parent && parent.include?(name)) end |
#remove_child(scope) ⇒ Object
282 283 284 |
# File 'lib/duby/ast.rb', line 282 def remove_child(scope) @children.delete(scope) end |