class IDL::AST::Leaf

Attributes

annotations[R]
enclosure[RW]
intern[R]
name[R]
prefix[R]
scopes[R]

Public Class Methods

new(_name, _enclosure) click to toggle source
# File lib/ridl/node.rb, line 89
def initialize(_name, _enclosure)
  _name ||= ''
  _name = IDL::Scanner::Identifier.new(_name, _name) unless IDL::Scanner::Identifier === _name
  @name = _name
  @lm_name = nil
  @intern = _name.rjust(1).downcase.intern
  @enclosure = _enclosure
  @scopes = if @enclosure then (@enclosure.scopes.dup << self) else [] end
  @prefix = ''
  @repo_id = nil
  @repo_ver = nil
  @annotations = Annotations.new
end

Public Instance Methods

has_annotations?() click to toggle source
# File lib/ridl/node.rb, line 206
def has_annotations?
  !@annotations.empty?
end
instantiate(instantiation_context, _enclosure, _params = {}) click to toggle source
# File lib/ridl/node.rb, line 138
def instantiate(instantiation_context, _enclosure, _params = {})
  (instantiation_context[self] = self.class.new(self.name, _enclosure, _params)).copy_from(self, instantiation_context)
end
is_local?() click to toggle source
# File lib/ridl/node.rb, line 214
def is_local?
  false
end
is_template?() click to toggle source
# File lib/ridl/node.rb, line 134
def is_template?
  @enclosure && @enclosure.is_template?
end
lm_name() click to toggle source
# File lib/ridl/node.rb, line 103
def lm_name
  @lm_name ||= @name.checked_name.dup
end
lm_scopes() click to toggle source
# File lib/ridl/node.rb, line 107
def lm_scopes
  @lm_scopes ||= if @enclosure then (@enclosure.lm_scopes.dup << lm_name) else [] end
end
marshal_dump() click to toggle source
# File lib/ridl/node.rb, line 123
def marshal_dump
  [@name, lm_name, @intern, @enclosure, @scopes, @prefix, @repo_id, @repo_ver, @annotations]
end
marshal_load(vars) click to toggle source
# File lib/ridl/node.rb, line 127
def marshal_load(vars)
  @name, @lm_name, @intern, @enclosure, @scopes, @prefix, @repo_id, @repo_ver, @annotations = vars
  @scoped_name = nil
  @scoped_lm_name = nil
  @lm_scopes = nil
end
prefix=(pfx) click to toggle source
# File lib/ridl/node.rb, line 181
def prefix=(pfx)
  unless pfx.to_s.empty?
    raise 'ID prefix should not start or end with \'/\'' if pfx[0, 1] == '/' or pfx[-1, 1] == '/'
    raise "ID prefix should not start with one of '#{REPO_ID_XCHARS.join("', '")}'" if REPO_ID_XCHARS.include?(pfx[0, 1])
    raise 'Invalid ID prefix! Only a..z, A..Z, 0..9, \'.\', \'-\', \'_\' or \'\/\' allowed' unless REPO_ID_RE =~ pfx
  end
  self.set_prefix(pfx)
end
replace_prefix(pfx) click to toggle source
# File lib/ridl/node.rb, line 190
def replace_prefix(pfx)
  self.prefix = pfx
end
repository_id() click to toggle source
# File lib/ridl/node.rb, line 194
def repository_id
  if @repo_id.nil?
    @repo_ver = "1.0" unless @repo_ver
    format("IDL:%s%s:%s",
            if @prefix.empty? then "" else @prefix + "/" end,
            self.scopes.collect { |s| s.name }.join("/"),
            @repo_ver)
  else
    @repo_id
  end
end
resolve(_name) click to toggle source
# File lib/ridl/node.rb, line 210
def resolve(_name)
  nil
end
scoped_lm_name() click to toggle source
# File lib/ridl/node.rb, line 119
def scoped_lm_name
  @scoped_lm_name ||= lm_scopes.join("::").freeze
end
scoped_name() click to toggle source
# File lib/ridl/node.rb, line 115
def scoped_name
  @scoped_name ||= @scopes.collect { |s| s.name }.join("::").freeze
end
set_repo_id(id) click to toggle source
# File lib/ridl/node.rb, line 142
def set_repo_id(id)
  if @repo_id
    if id != @repo_id
      raise "#{self.scoped_name} already has a different repository ID assigned: #{@repo_id}"
    end
  end
  id_arr = id.split(':')
  if @repo_ver
    if id_arr.first != 'IDL' or id_arr.last != @repo_ver
      raise "supplied repository ID (#{id}) does not match previously assigned repository version for #{self.scoped_name} = #{@repo_ver}"
    end
  end
  # check validity of IDL format repo IDs
  if id_arr.first == 'IDL'
    id_arr.shift
    id_str = id_arr.shift.to_s
    raise 'ID identifiers should not start or end with \'/\'' if id_str[0, 1] == '/' or id_str[-1, 1] == '/'
    raise "ID identifiers should not start with one of '#{REPO_ID_XCHARS.join("', '")}'" if REPO_ID_XCHARS.include?(id_str[0, 1])
    raise 'Invalid ID! Only a..z, A..Z, 0..9, \'.\', \'-\', \'_\' or \'\/\' allowed for identifiers' unless REPO_ID_RE =~ id_str
  end
  @repo_id = id
end
set_repo_version(ma, mi) click to toggle source
# File lib/ridl/node.rb, line 165
def set_repo_version(ma, mi)
  ver = "#{ma}.#{mi}"
  if @repo_ver
    if ver != @repo_ver
      raise "#{self.scoped_name} already has a repository version assigned: #{@repo_ver}"
    end
  end
  if @repo_id
    l = @repo_id.split(':')
    if l.last != ver
      raise "supplied repository version (#{ver}) does not match previously assigned repository ID for #{self.scoped_name}: #{@repo_id}"
    end
  end
  @repo_ver = ver
end
typename() click to toggle source
# File lib/ridl/node.rb, line 85
def typename
  self.class.name
end
unescaped_name() click to toggle source
# File lib/ridl/node.rb, line 111
def unescaped_name
  @name.unescaped_name
end

Protected Instance Methods

copy_from(template, _) click to toggle source
# File lib/ridl/node.rb, line 224
def copy_from(template, _)
  @prefix = template.instance_variable_get(:@prefix)
  @repo_id = template.instance_variable_get(:@repo_id)
  @repo_ver = template.instance_variable_get(:@repo_ver)
  @annotations = template.instance_variable_get(:@annotations)
  self
end
set_prefix(pfx) click to toggle source
# File lib/ridl/node.rb, line 220
def set_prefix(pfx)
  @prefix = pfx.to_s
end