Class: IDL::AST::Module

Inherits:
Node show all
Defined in:
lib/ridl/node.rb,
lib/ridl/node.rb

Overview

Forward declarations

Direct Known Subclasses

Include, TemplateModule

Constant Summary collapse

NAMETYPE =
:class
DEFINABLE =
[
  IDL::AST::Module, IDL::AST::Interface, IDL::AST::Valuebox, IDL::AST::Valuetype, IDL::AST::Const, IDL::AST::Struct,
  IDL::AST::Union, IDL::AST::Enum, IDL::AST::Enumerator, IDL::AST::Typedef, IDL::AST::Include,
  IDL::AST::Home, IDL::AST::Porttype, IDL::AST::Component, IDL::AST::Connector
]

Instance Attribute Summary collapse

Attributes inherited from Leaf

#enclosure, #intern, #lm_name, #name, #prefix, #scopes

Instance Method Summary collapse

Methods inherited from Node

#define, #introduce, #is_definable?, #match_members, #resolve, #select_members, #walk_members

Methods inherited from Leaf

#has_annotations?, #is_local?, #is_template?, #lm_name_for_scope, #parsed_name_scope, #repository_id, #resolve, #scoped_lm_name, #scoped_name, #set_repo_id, #set_repo_version, #typename, #unescaped_name

Constructor Details

#initialize(_name, _enclosure, params) ⇒ Module

Returns a new instance of Module.



415
416
417
418
419
420
421
422
423
# File 'lib/ridl/node.rb', line 415

def initialize(_name, _enclosure, params)
  super(_name, _enclosure)
  @anchor = params[:anchor]
  @prefix = params[:prefix] || @prefix
  @not_in_repo_id = params[:not_in_repo_id]
  @template = params[:template]
  @template_params = (params[:template_params] || []).dup
  @next = nil
end

Instance Attribute Details

#anchorObject (readonly)

Returns the value of attribute anchor.



414
415
416
# File 'lib/ridl/node.rb', line 414

def anchor
  @anchor
end

#nextObject (readonly)

Returns the value of attribute next.



414
415
416
# File 'lib/ridl/node.rb', line 414

def next
  @next
end

#templateObject (readonly)

Returns the value of attribute template.



414
415
416
# File 'lib/ridl/node.rb', line 414

def template
  @template
end

#template_paramsObject (readonly)

Returns the value of attribute template_params.



414
415
416
# File 'lib/ridl/node.rb', line 414

def template_params
  @template_params
end

Instance Method Details

#_set_prefix(pfx) ⇒ Object



576
577
578
579
580
581
582
# File 'lib/ridl/node.rb', line 576

def _set_prefix(pfx)
  if @anchor.nil?
    self._set_prefix_(pfx)
  else
    @anchor._set_prefix_(pfx)
  end
end

#annotationsObject



446
447
448
# File 'lib/ridl/node.rb', line 446

def annotations
  (has_anchor? ? self.anchor : self).get_annotations
end

#has_anchor?Boolean

Returns:

  • (Boolean)


425
426
427
# File 'lib/ridl/node.rb', line 425

def has_anchor?
  !@anchor.nil?
end

#instantiate(_context, _enclosure) ⇒ Object



460
461
462
# File 'lib/ridl/node.rb', line 460

def instantiate(_context, _enclosure)
  super(_context, _enclosure, {})
end

#is_templated?Boolean

Returns:

  • (Boolean)


429
430
431
# File 'lib/ridl/node.rb', line 429

def is_templated?
  @template ? true : false
end

#marshal_dumpObject



450
451
452
# File 'lib/ridl/node.rb', line 450

def marshal_dump
  super() << @anchor << @next
end

#marshal_load(vars) ⇒ Object



454
455
456
457
458
# File 'lib/ridl/node.rb', line 454

def marshal_load(vars)
  @next = vars.pop
  @anchor = vars.pop
  super(vars)
end

#redefine(node, params) ⇒ Object

Raises:

  • (RuntimeError)


468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
# File 'lib/ridl/node.rb', line 468

def redefine(node, params)
  case node
  when IDL::AST::Include
    if node.enclosure == self
      return node
    else
      _inc = IDL::AST::Include.new(node.name, self, params)
      _inc.annotations.concat(params[:annotations])
      @children << _inc
      return _inc
    end
  when IDL::AST::Module
    # Module reopening
    _anchor = node.has_anchor? ? node.anchor : node
    _anchor.annotations.concat(params.delete(:annotations))
    _last = _anchor.find_last
    _params = params.merge({ :anchor => _anchor, :prefix => node.prefix })
    _next = IDL::AST::Module.new(node.name, self, _params)
    _last.set_next(_next)
    @children << _next
    return _next
  when IDL::AST::Interface
    node.annotations.concat(params[:annotations])
    return node if params[:forward]
    if node.is_defined?
      raise RuntimeError, "#{node.typename} \"#{node.name}\" is already defined."
    end
    if (node.is_abstract? != params[:abstract]) || (node.is_local? != params[:local]) || (node.is_pseudo? != params[:pseudo])
      raise RuntimeError, "\"attributes are not the same: \"#{node.name}\"."
    end

    _intf = IDL::AST::Interface.new(node.name, self, params)
    _intf.annotations.concat(node.annotations)
    _intf.prefix = node.prefix
    _intf.instance_variable_set(:@repo_ver, node.instance_variable_get(:@repo_ver))
    _intf.instance_variable_set(:@repo_id, node.instance_variable_get(:@repo_id))

    @children << _intf
    # replace forward node registration
    node.enclosure.undo_introduction(node)
    introduce(_intf)

    return _intf
  when IDL::AST::Valuetype
    node.annotations.concat(params[:annotations])
    return node if params[:forward]
    if node.is_defined?
      raise RuntimeError, "#{node.typename} \"#{node.name}\" is already defined."
    end
    if (node.is_abstract? != params[:abstract])
      raise RuntimeError, "\"attributes are not the same: \"#{node.name}\"."
    end

    _new_node = node.class.new(node.name, self, params)
    _new_node.annotations.concat(node.annotations)
    _new_node.prefix = node.prefix
    _new_node.instance_variable_set(:@repo_ver, node.instance_variable_get(:@repo_ver))
    _new_node.instance_variable_set(:@repo_id, node.instance_variable_get(:@repo_id))

    @children << _new_node
    # replace forward node registration
    node.enclosure.undo_introduction(node)
    introduce(_new_node)

    return _new_node
  when IDL::AST::Struct, IDL::AST::Union
    node.annotations.concat(params[:annotations])
    return node if params[:forward]
    if node.is_defined?
      raise RuntimeError, "#{node.typename} \"#{node.name}\" is already defined."
    end

    _new_node = node.class.new(node.name, self, params)
    _new_node.annotations.concat(node.annotations)
    _new_node.prefix = node.prefix
    _new_node.instance_variable_set(:@repo_ver, node.instance_variable_get(:@repo_ver))
    _new_node.instance_variable_set(:@repo_id, node.instance_variable_get(:@repo_id))

    node.switchtype = params[:switchtype] if node.is_a?(IDL::AST::Union)

    @children << _new_node
    # replace forward node registration
    node.enclosure.undo_introduction(node)
    introduce(_new_node)

    return _new_node
  end
  raise RuntimeError,
        "#{node.name} is already introduced as #{node.typename} #{node.scoped_name}."
end

#replace_prefix(pfx) ⇒ Object



567
568
569
570
571
572
573
574
# File 'lib/ridl/node.rb', line 567

def replace_prefix(pfx)
  self.prefix = pfx   # handles validation
  if @anchor.nil?
    self.replace_prefix_(pfx)
  else
    @anchor.replace_prefix_(pfx)
  end
end

#repo_scopesObject



464
465
466
# File 'lib/ridl/node.rb', line 464

def repo_scopes
  @repo_scopes ||= (@enclosure.nil? ? [] : (@not_in_repo_id ? @enclosure.repo_scopes.dup : (@enclosure.repo_scopes.dup << self)))
end

#template_param(param) ⇒ Object



433
434
435
436
437
438
439
440
441
442
443
444
# File 'lib/ridl/node.rb', line 433

def template_param(param)
  return nil unless @template
  param = param.to_s if ::Symbol === param
  if ::String === param
    @template.params.each_with_index do |tp, ix|
      return @template_params[ix] if tp.name == param
    end
    nil
  else
    @template_params[param] rescue nil
  end
end

#undo_introduction(node) ⇒ Object



559
560
561
562
563
564
565
# File 'lib/ridl/node.rb', line 559

def undo_introduction(node)
  _mod = (@anchor || self)
  while _mod
    _mod._undo_link_introduction(node)
    _mod = _mod.next
  end
end