Class: IDL::AST::Leaf

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_name, _enclosure) ⇒ Leaf

Returns a new instance of Leaf.



89
90
91
92
93
94
95
96
97
98
99
100
101
# 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

Instance Attribute Details

#annotationsObject (readonly)

Returns the value of attribute annotations.



82
83
84
# File 'lib/ridl/node.rb', line 82

def annotations
  @annotations
end

#enclosureObject

Returns the value of attribute enclosure.



83
84
85
# File 'lib/ridl/node.rb', line 83

def enclosure
  @enclosure
end

#internObject (readonly)

Returns the value of attribute intern.



82
83
84
# File 'lib/ridl/node.rb', line 82

def intern
  @intern
end

#nameObject (readonly)

Returns the value of attribute name.



82
83
84
# File 'lib/ridl/node.rb', line 82

def name
  @name
end

#prefixObject

Returns the value of attribute prefix.



82
83
84
# File 'lib/ridl/node.rb', line 82

def prefix
  @prefix
end

#scopesObject (readonly)

Returns the value of attribute scopes.



82
83
84
# File 'lib/ridl/node.rb', line 82

def scopes
  @scopes
end

Instance Method Details

#has_annotations?Boolean

Returns:

  • (Boolean)


206
207
208
# File 'lib/ridl/node.rb', line 206

def has_annotations?
  !@annotations.empty?
end

#instantiate(instantiation_context, _enclosure, _params = {}) ⇒ Object



138
139
140
# 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?Boolean

Returns:

  • (Boolean)


214
215
216
# File 'lib/ridl/node.rb', line 214

def is_local?
  false
end

#is_template?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/ridl/node.rb', line 134

def is_template?
  @enclosure && @enclosure.is_template?
end

#lm_nameObject



103
104
105
# File 'lib/ridl/node.rb', line 103

def lm_name
  @lm_name ||= @name.checked_name.dup
end

#lm_scopesObject



107
108
109
# 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_dumpObject



123
124
125
# 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) ⇒ Object



127
128
129
130
131
132
# 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

#replace_prefix(pfx) ⇒ Object



190
191
192
# File 'lib/ridl/node.rb', line 190

def replace_prefix(pfx)
  self.prefix = pfx
end

#repository_idObject



194
195
196
197
198
199
200
201
202
203
204
# 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) ⇒ Object



210
211
212
# File 'lib/ridl/node.rb', line 210

def resolve(_name)
  nil
end

#scoped_lm_nameObject



119
120
121
# File 'lib/ridl/node.rb', line 119

def scoped_lm_name
  @scoped_lm_name ||= lm_scopes.join("::").freeze
end

#scoped_nameObject



115
116
117
# File 'lib/ridl/node.rb', line 115

def scoped_name
  @scoped_name ||= @scopes.collect { |s| s.name }.join("::").freeze
end

#set_repo_id(id) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# 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) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# 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

#typenameObject



85
86
87
# File 'lib/ridl/node.rb', line 85

def typename
  self.class.name
end

#unescaped_nameObject



111
112
113
# File 'lib/ridl/node.rb', line 111

def unescaped_name
  @name.unescaped_name
end