Class: CType::Pointer

Inherits:
Object
  • Object
show all
Includes:
BaseReference, Qualifiers
Defined in:
lib/caphir/ctype.rb

Overview

Base

Instance Attribute Summary

Attributes included from BaseReference

#base_type

Instance Method Summary collapse

Methods included from Qualifiers

#add_qualifier

Constructor Details

#initialize(type_qualifiers = []) ⇒ Pointer



355
356
357
358
359
360
361
362
363
# File 'lib/caphir/ctype.rb', line 355

def initialize(type_qualifiers=[])
  @const = false
  @volatile = false
  @restrict = false
  @base_type = nil
  type_qualifiers.each do |q|
    add_qualifier(q)
  end # do
end

Instance Method Details

#evaluate(identifier) ⇒ Object



365
366
367
368
369
370
371
372
373
374
# File 'lib/caphir/ctype.rb', line 365

def evaluate(identifier)
  return self if identifier.empty?
  if identifier =~ /\A->/
    self.base_type.evaluate('.' + $')
  elsif identifier =~ /\A\[.+?\]/
    self.base_type.evaluate($')
  else
    CType.evaluation_error(identifier)
  end
end

#to_init_s(ident = nil) ⇒ Object



379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/caphir/ctype.rb', line 379

def to_init_s(ident=nil)
  str = '*'
  str << ' const' if @const
  str << ' volatile' if @volatile
  str << ' restrict' if @restrict
  str << ' ' << ident if ident
  if @base_type.class == Type and (@base_type.function? or @base_type.array?)
    # then parens are required
    str[0,0] = '('
    str << ')'
  end
  if @base_type
    @base_type.to_init_s(str)
  else
    str
  end
end

#to_sObject



376
377
378
# File 'lib/caphir/ctype.rb', line 376

def to_s
  to_init_s()
end