Class: AdLint::Cc1::Variable

Inherits:
TypedObject show all
Defined in:
lib/adlint/cc1/object.rb

Overview

DESCRIPTION

Variable class hierarchy

Variable
  <-- ScopedVariable
        <-- OuterVariable
              <-- NamedVariable --------> Nameable <<module>>
                    <-- AliasVariable        ^
              <-- TemporaryVariable          |
              <-- InnerVariable -------------+
                    <-- ArrayElementVariable
                    <-- CompositeMemberVariable

Direct Known Subclasses

ScopedVariable

Instance Attribute Summary

Attributes inherited from TypedObject

#type

Attributes inherited from Object

#declarations_and_definitions

Attributes included from Bindable

#binding

Instance Method Summary collapse

Methods inherited from TypedObject

#to_pointer, #to_pointer_value, #to_value, #to_variable

Methods inherited from Object

#declared_as_auto?, #declared_as_extern?, #declared_as_register?, #declared_as_static?, #designated_by_lvalue?, #storage_class_specifiers, #temporary?

Methods included from Bindable

#be_alias_to, #bind_to

Constructor Details

#initialize(mem, dcl_or_def, type) ⇒ Variable

Returns a new instance of Variable.



212
213
214
215
# File 'lib/adlint/cc1/object.rb', line 212

def initialize(mem, dcl_or_def, type)
  super(type, dcl_or_def)
  relate_to_memory(mem)
end

Instance Method Details

#assign!(val, src = nil, br = nil) ⇒ Object



245
246
247
248
249
250
251
252
# File 'lib/adlint/cc1/object.rb', line 245

def assign!(val, src = nil, br = nil)
  # NOTE: Length of the incomplete array type should be deducted while
  #       initializer evaluation.  So, adjustment of the assigning value
  #       can be done at this point by Value#coerce_to(type).
  # NOTE: Domain of the assigning value must be narrowed before writing to
  #       the memory by Value#coerce_to(type).
  binding.memory.write(val.coerce_to(type), src, br)
end

#begin_value_versioningObject



288
289
290
# File 'lib/adlint/cc1/object.rb', line 288

def begin_value_versioning
  value.begin_versioning
end

#end_value_versioningObject



292
293
294
# File 'lib/adlint/cc1/object.rb', line 292

def end_value_versioning
  value.end_versioning
end

#enter_value_versioning_groupObject



280
281
282
# File 'lib/adlint/cc1/object.rb', line 280

def enter_value_versioning_group
  value.enter_versioning_group
end

#function?Boolean

Returns:

  • (Boolean)


217
218
219
# File 'lib/adlint/cc1/object.rb', line 217

def function?
  false
end

#inner?Boolean

Returns:

  • (Boolean)


233
234
235
# File 'lib/adlint/cc1/object.rb', line 233

def inner?
  subclass_responsibility
end

#leave_value_versioning_group(raise_complement) ⇒ Object



284
285
286
# File 'lib/adlint/cc1/object.rb', line 284

def leave_value_versioning_group(raise_complement)
  value.leave_versioning_group(raise_complement)
end

#nameObject



225
226
227
# File 'lib/adlint/cc1/object.rb', line 225

def name
  subclass_responsibility
end

#named?Boolean

Returns:

  • (Boolean)


229
230
231
# File 'lib/adlint/cc1/object.rb', line 229

def named?
  false
end

#narrow_value_domain!(op, val) ⇒ Object



258
259
260
261
262
263
264
265
266
267
# File 'lib/adlint/cc1/object.rb', line 258

def narrow_value_domain!(op, val)
  assign!(type.arbitrary_value) unless self.value

  self.value.narrow_domain!(op, val.coerce_to(type))
  # NOTE: Write via memory to correctly propagate inner variable's
  #       mutation to its outer variable.
  binding.memory._cascade_update(nil, nil)

  self.value.exist?
end

#outer?Boolean

Returns:

  • (Boolean)


237
238
239
# File 'lib/adlint/cc1/object.rb', line 237

def outer?
  !inner?
end

#rollback_all_value_versions!Object



300
301
302
# File 'lib/adlint/cc1/object.rb', line 300

def rollback_all_value_versions!
  value.rollback_all_versions!
end

#thin_latest_value_version!(with_rollback) ⇒ Object



296
297
298
# File 'lib/adlint/cc1/object.rb', line 296

def thin_latest_value_version!(with_rollback)
  value.thin_latest_version!(with_rollback)
end

#uninitialize!Object



254
255
256
# File 'lib/adlint/cc1/object.rb', line 254

def uninitialize!
  assign!(self.type.undefined_value)
end

#valueObject



241
242
243
# File 'lib/adlint/cc1/object.rb', line 241

def value
  binding.memory.read
end

#variable?Boolean

Returns:

  • (Boolean)


221
222
223
# File 'lib/adlint/cc1/object.rb', line 221

def variable?
  true
end

#widen_value_domain!(op, val) ⇒ Object



269
270
271
272
273
274
275
276
277
278
# File 'lib/adlint/cc1/object.rb', line 269

def widen_value_domain!(op, val)
  assign!(type.nil_value) unless self.value

  self.value.widen_domain!(op, val.coerce_to(type))
  # NOTE: Write via memory to correctly propagate inner variable's
  #       mutation to its outer variable.
  binding.memory._cascade_update(nil, nil)

  self.value.exist?
end