Class: IDL::AST::Node
Overview
Instance Attribute Summary
Attributes inherited from Leaf
#annotations, #enclosure, #intern, #lm_name, #name, #prefix, #scopes
Instance Method Summary
collapse
Methods inherited from Leaf
#_set_prefix, #has_annotations?, #instantiate, #is_local?, #is_template?, #lm_name_for_scope, #parsed_name_scope, #repo_scopes, #repository_id, #scoped_lm_name, #scoped_name, #set_repo_id, #set_repo_version, #typename
Constructor Details
#initialize(name, enclosure) ⇒ Node
Returns a new instance of Node.
251
252
253
254
255
256
|
# File 'lib/ridl/node.rb', line 251
def initialize(name, enclosure)
super
@introduced = Hash.new
@children = []
introduce(self)
end
|
Instance Method Details
#define(_type, _name, params = Hash.new) ⇒ Object
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
# File 'lib/ridl/node.rb', line 288
def define(_type, _name, params = Hash.new)
if not is_definable?(_type)
raise RuntimeError,
"#{_type.to_s} is not definable in #{self.typename}."
end
node = search_self(_name)
if node.nil?
node = _type.new(_name, self, params)
node.annotations.concat(params[:annotations])
node.prefix = @prefix
introduce(node)
@children << node
else
if _type != node.class
raise RuntimeError,
"#{_name} is already defined as a type of #{node.typename}"
end
node = redefine(node, params)
end
node
end
|
#introduce(node) ⇒ Object
268
269
270
271
272
|
# File 'lib/ridl/node.rb', line 268
def introduce(node)
n = (@introduced[node.intern] ||= node)
raise RuntimeError,
"#{node.name} is already introduced as a #{n.scoped_name} of #{n.typename}." if n != node
end
|
#is_definable?(_type) ⇒ Boolean
282
283
284
285
286
|
# File 'lib/ridl/node.rb', line 282
def is_definable?(_type)
self.class::DEFINABLE.any? do |target|
_type.ancestors.include? target
end
end
|
#marshal_dump ⇒ Object
258
259
260
|
# File 'lib/ridl/node.rb', line 258
def marshal_dump
super() << @children << @introduced
end
|
#marshal_load(vars) ⇒ Object
262
263
264
265
266
|
# File 'lib/ridl/node.rb', line 262
def marshal_load(vars)
@introduced = vars.pop
@children = vars.pop
super(vars)
end
|
#match_members(&block) ⇒ Object
320
321
322
|
# File 'lib/ridl/node.rb', line 320
def match_members(&block)
!(@children.find { |c| yield(c) }).nil?
end
|
#redefine(node, params) ⇒ Object
278
279
280
|
# File 'lib/ridl/node.rb', line 278
def redefine(node, params)
raise RuntimeError, "\"#{node.name}\" is already defined."
end
|
#replace_prefix(pfx) ⇒ Object
324
325
326
327
|
# File 'lib/ridl/node.rb', line 324
def replace_prefix(pfx)
super
walk_members { |m| m.replace_prefix(pfx) }
end
|
#resolve(_name) ⇒ Object
310
311
312
313
314
|
# File 'lib/ridl/node.rb', line 310
def resolve(_name)
node = search_enclosure(_name)
@introduced[node.intern] = node unless node.nil?
node
end
|
#undo_introduction(node) ⇒ Object
274
275
276
|
# File 'lib/ridl/node.rb', line 274
def undo_introduction(node)
@introduced.delete(node.intern)
end
|
#walk_members(&block) ⇒ Object
316
317
318
|
# File 'lib/ridl/node.rb', line 316
def walk_members(&block)
@children.each { |c| yield(c) }
end
|