Class: Rubycc::Type::Pointer
- Inherits:
-
Data
- Object
- Data
- Rubycc::Type::Pointer
- 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
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
-
#alignment ⇒ Object
A 64-bit address is 8-byte aligned.
- #arithmetic? ⇒ Boolean
- #array? ⇒ Boolean
- #bool? ⇒ Boolean
- #char? ⇒ Boolean
- #float? ⇒ Boolean
- #function? ⇒ Boolean
- #int? ⇒ Boolean
- #integer? ⇒ Boolean
- #pointer? ⇒ Boolean
-
#size ⇒ Object
Every pointer is a 64-bit address, so 8 bytes wide.
- #struct? ⇒ Boolean
-
#to_s ⇒ Object
Renders as a C declarator.
- #void? ⇒ Boolean
Instance Attribute Details
#target ⇒ Object (readonly)
Returns the value of attribute target
340 341 342 |
# File 'lib/rubycc/type.rb', line 340 def target @target end |
Instance Method Details
#alignment ⇒ Object
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
361 362 363 |
# File 'lib/rubycc/type.rb', line 361 def arithmetic? false end |
#array? ⇒ Boolean
369 370 371 |
# File 'lib/rubycc/type.rb', line 369 def array? false end |
#bool? ⇒ Boolean
365 366 367 |
# File 'lib/rubycc/type.rb', line 365 def bool? false end |
#char? ⇒ Boolean
349 350 351 |
# File 'lib/rubycc/type.rb', line 349 def char? false end |
#float? ⇒ Boolean
381 382 383 |
# File 'lib/rubycc/type.rb', line 381 def float? false end |
#function? ⇒ Boolean
377 378 379 |
# File 'lib/rubycc/type.rb', line 377 def function? false end |
#int? ⇒ Boolean
345 346 347 |
# File 'lib/rubycc/type.rb', line 345 def int? false end |
#integer? ⇒ Boolean
357 358 359 |
# File 'lib/rubycc/type.rb', line 357 def integer? false end |
#pointer? ⇒ Boolean
341 342 343 |
# File 'lib/rubycc/type.rb', line 341 def pointer? true end |
#size ⇒ Object
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
373 374 375 |
# File 'lib/rubycc/type.rb', line 373 def struct? false end |
#to_s ⇒ Object
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
353 354 355 |
# File 'lib/rubycc/type.rb', line 353 def void? false end |