Class: IDL::AST::Node

Inherits:
Leaf
  • Object
show all
Defined in:
lib/ridl/node.rb

Overview

Leaf

Direct Known Subclasses

Derivable, Module, Operation, Porttype, Struct, Union

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, #unescaped_name

Constructor Details

#initialize(name, enclosure) ⇒ Node

Returns a new instance of Node.



255
256
257
258
259
260
# File 'lib/ridl/node.rb', line 255

def initialize(name, enclosure)
  super
  @introduced = Hash.new
  @children = []
  introduce(self)
end

Instance Method Details

#define(_type, _name, params = Hash.new) ⇒ Object



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/ridl/node.rb', line 292

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

Raises:

  • (RuntimeError)


272
273
274
275
276
# File 'lib/ridl/node.rb', line 272

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

Returns:

  • (Boolean)


286
287
288
289
290
# File 'lib/ridl/node.rb', line 286

def is_definable?(_type)
  self.class::DEFINABLE.any? do |target|
    _type.ancestors.include? target
  end
end

#marshal_dumpObject



262
263
264
# File 'lib/ridl/node.rb', line 262

def marshal_dump
  super() << @children << @introduced
end

#marshal_load(vars) ⇒ Object



266
267
268
269
270
# File 'lib/ridl/node.rb', line 266

def marshal_load(vars)
  @introduced = vars.pop
  @children = vars.pop
  super(vars)
end

#match_members(&block) ⇒ Object



324
325
326
# File 'lib/ridl/node.rb', line 324

def match_members(&block)
  !(@children.find(&block)).nil?
end

#redefine(node, params) ⇒ Object

Raises:

  • (RuntimeError)


282
283
284
# File 'lib/ridl/node.rb', line 282

def redefine(node, params)
  raise RuntimeError, "\"#{node.name}\" is already defined."
end

#replace_prefix(pfx) ⇒ Object



332
333
334
335
# File 'lib/ridl/node.rb', line 332

def replace_prefix(pfx)
  super
  walk_members { |m| m.replace_prefix(pfx) }
end

#resolve(_name) ⇒ Object



314
315
316
317
318
# File 'lib/ridl/node.rb', line 314

def resolve(_name)
  node = search_enclosure(_name)
  @introduced[node.intern] = node unless node.nil?
  node
end

#select_members(&block) ⇒ Object



328
329
330
# File 'lib/ridl/node.rb', line 328

def select_members(&block)
  @children.select(&block)
end

#undo_introduction(node) ⇒ Object



278
279
280
# File 'lib/ridl/node.rb', line 278

def undo_introduction(node)
  @introduced.delete(node.intern)
end

#walk_members(&block) ⇒ Object



320
321
322
# File 'lib/ridl/node.rb', line 320

def walk_members(&block)
  @children.each(&block)
end