Class: Rubycc::Type::Pointer

Inherits:
Data
  • Object
show all
Defined in:
lib/rubycc/type.rb

Overview

A pointer to target (itself a Type). Being a Data, two pointers are equal exactly when their targets are, giving "int *" == "int *".

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#targetObject (readonly)

Returns the value of attribute target

Returns:

  • (Object)

    the current value of target



340
341
342
# File 'lib/rubycc/type.rb', line 340

def target
  @target
end

Instance Method Details

#alignmentObject

A 64-bit address is 8-byte aligned. A pointer to an incomplete type is still a complete, 8-byte pointer, which is exactly what lets a struct hold a pointer to itself.



393
394
395
# File 'lib/rubycc/type.rb', line 393

def alignment
  8
end

#arithmetic?Boolean

Returns:

  • (Boolean)


361
362
363
# File 'lib/rubycc/type.rb', line 361

def arithmetic?
  false
end

#array?Boolean

Returns:

  • (Boolean)


369
370
371
# File 'lib/rubycc/type.rb', line 369

def array?
  false
end

#bool?Boolean

Returns:

  • (Boolean)


365
366
367
# File 'lib/rubycc/type.rb', line 365

def bool?
  false
end

#char?Boolean

Returns:

  • (Boolean)


349
350
351
# File 'lib/rubycc/type.rb', line 349

def char?
  false
end

#float?Boolean

Returns:

  • (Boolean)


381
382
383
# File 'lib/rubycc/type.rb', line 381

def float?
  false
end

#function?Boolean

Returns:

  • (Boolean)


377
378
379
# File 'lib/rubycc/type.rb', line 377

def function?
  false
end

#int?Boolean

Returns:

  • (Boolean)


345
346
347
# File 'lib/rubycc/type.rb', line 345

def int?
  false
end

#integer?Boolean

Returns:

  • (Boolean)


357
358
359
# File 'lib/rubycc/type.rb', line 357

def integer?
  false
end

#pointer?Boolean

Returns:

  • (Boolean)


341
342
343
# File 'lib/rubycc/type.rb', line 341

def pointer?
  true
end

#sizeObject

Every pointer is a 64-bit address, so 8 bytes wide.



386
387
388
# File 'lib/rubycc/type.rb', line 386

def size
  8
end

#struct?Boolean

Returns:

  • (Boolean)


373
374
375
# File 'lib/rubycc/type.rb', line 373

def struct?
  false
end

#to_sObject

Renders as a C declarator. A pointer to a function or an array cannot be spelled by simply suffixing a "", since the postfix "()" / "[]" would then bind tighter than the star; C parenthesizes the star instead, so a pointer to "int (int)" is written "int ()(int)" and a pointer to "int [3]" is "int (*)[3]". Every other target uses the plain suffix form: a space before the first star, deeper levels stacking with no gap ("int *", "int **").



404
405
406
407
408
409
410
411
412
413
414
# File 'lib/rubycc/type.rb', line 404

def to_s
  if target.function?
    "#{target.return_type} (*)(#{target.parameter_list_string})"
  elsif target.array?
    "#{target.element} (*)[#{target.length}]"
  elsif target.pointer?
    "#{target}*"
  else
    "#{target} *"
  end
end

#void?Boolean

Returns:

  • (Boolean)


353
354
355
# File 'lib/rubycc/type.rb', line 353

def void?
  false
end