Class: IDL::AST::Node

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

Overview

Leaf

Direct Known Subclasses

BitMask, BitSet, Derivable, Module, Operation, Porttype, Struct, Union

Instance Attribute Summary

Attributes inherited from Leaf

#annotations, #enclosure, #intern, #name, #prefix, #scopes

Instance Method Summary collapse

Methods inherited from Leaf

#has_annotations?, #instantiate, #is_local?, #is_template?, #lm_name, #lm_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.



234
235
236
237
238
239
# File 'lib/ridl/node.rb', line 234

def initialize(name, enclosure)
  super
  @introduced = {}
  @children = []
  introduce(self)
end

Instance Method Details

#define(_type, _name, params = {}) ⇒ Object



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/ridl/node.rb', line 270

def define(_type, _name, params = {})
  unless is_definable?(_type)
    raise "#{_type} 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 "#{_name} is already defined as a type of #{node.typename}"
    end

    node = redefine(node, params)
  end
  node
end

#introduce(node) ⇒ Object



251
252
253
254
# File 'lib/ridl/node.rb', line 251

def introduce(node)
  n = (@introduced[node.intern] ||= node)
  raise "#{node.name} is already introduced as a #{n.scoped_name} of #{n.typename}." if n != node
end

#is_definable?(_type) ⇒ Boolean

Returns:

  • (Boolean)


264
265
266
267
268
# File 'lib/ridl/node.rb', line 264

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

#marshal_dumpObject



241
242
243
# File 'lib/ridl/node.rb', line 241

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

#marshal_load(vars) ⇒ Object



245
246
247
248
249
# File 'lib/ridl/node.rb', line 245

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

#match_members(&block) ⇒ Object



302
303
304
# File 'lib/ridl/node.rb', line 302

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

#redefine(node, _params) ⇒ Object



260
261
262
# File 'lib/ridl/node.rb', line 260

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

#replace_prefix(pfx) ⇒ Object



310
311
312
313
# File 'lib/ridl/node.rb', line 310

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

#resolve(_name) ⇒ Object



292
293
294
295
296
# File 'lib/ridl/node.rb', line 292

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

#select_members(&block) ⇒ Object



306
307
308
# File 'lib/ridl/node.rb', line 306

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

#undo_introduction(node) ⇒ Object



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

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

#walk_members(&block) ⇒ Object



298
299
300
# File 'lib/ridl/node.rb', line 298

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