Class: Rubycc::Type::Array
- Inherits:
-
Data
- Object
- Data
- Rubycc::Type::Array
- Defined in:
- lib/rubycc/type.rb
Overview
A one-dimensional array of length elements, each of type element
(itself a Type: an int or a pointer in this subset). Two arrays are equal
when both their element type and length match.
A length of nil is an incomplete array type (6.7.2.1): an unbounded
"[]" whose element count is unknown. It reaches this subset as a struct's
flexible array member (the last member, "T name;", ISO C 6.7.2.1p18) and
nowhere a size is needed — #size raises, and every path that could demand
one (a variable, a plain sizeof/_Alignof of the array, an array-of-array
element) is rejected first by the parser or the generator's completeness
guard. A flexible array member still lays out (at its element's boundary,
contributing nothing to the struct's size), and an lvalue of this type
decays to a pointer to its element exactly as a bounded array does, so
"p->fam" indexes it.
Instance Attribute Summary collapse
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
Instance Method Summary collapse
-
#alignment ⇒ Object
An array is aligned like one of its elements: an
int [10]on a 4-byte boundary, astruct point [3]on the struct's boundary. - #arithmetic? ⇒ Boolean
- #array? ⇒ Boolean
- #bool? ⇒ Boolean
- #char? ⇒ Boolean
- #float? ⇒ Boolean
- #function? ⇒ Boolean
-
#incomplete? ⇒ Boolean
Whether this is an incomplete array — an unbounded "[]" with no element count, the shape a struct's flexible array member takes.
- #int? ⇒ Boolean
- #integer? ⇒ Boolean
- #pointer? ⇒ Boolean
-
#size ⇒ Object
The whole array's byte size: the element width times the count.
- #struct? ⇒ Boolean
-
#to_s ⇒ Object
Renders like a C array declarator: the element type, a space, then the bracketed length ("int [10]", "int * [4]"); an incomplete array shows an empty "[]" ("int []").
- #void? ⇒ Boolean
Instance Attribute Details
#element ⇒ Object (readonly)
Returns the value of attribute element
431 432 433 |
# File 'lib/rubycc/type.rb', line 431 def element @element end |
#length ⇒ Object (readonly)
Returns the value of attribute length
431 432 433 |
# File 'lib/rubycc/type.rb', line 431 def length @length end |
Instance Method Details
#alignment ⇒ Object
An array is aligned like one of its elements: an int [10] on a 4-byte
boundary, a struct point [3] on the struct's boundary.
495 496 497 |
# File 'lib/rubycc/type.rb', line 495 def alignment element.alignment end |
#arithmetic? ⇒ Boolean
452 453 454 |
# File 'lib/rubycc/type.rb', line 452 def arithmetic? false end |
#array? ⇒ Boolean
460 461 462 |
# File 'lib/rubycc/type.rb', line 460 def array? true end |
#bool? ⇒ Boolean
456 457 458 |
# File 'lib/rubycc/type.rb', line 456 def bool? false end |
#char? ⇒ Boolean
440 441 442 |
# File 'lib/rubycc/type.rb', line 440 def char? false end |
#float? ⇒ Boolean
472 473 474 |
# File 'lib/rubycc/type.rb', line 472 def float? false end |
#function? ⇒ Boolean
468 469 470 |
# File 'lib/rubycc/type.rb', line 468 def function? false end |
#incomplete? ⇒ Boolean
Whether this is an incomplete array — an unbounded "[]" with no element count, the shape a struct's flexible array member takes. It has no size, so every size-needing use is diagnosed before #size would raise.
479 480 481 |
# File 'lib/rubycc/type.rb', line 479 def incomplete? length.nil? end |
#int? ⇒ Boolean
436 437 438 |
# File 'lib/rubycc/type.rb', line 436 def int? false end |
#integer? ⇒ Boolean
448 449 450 |
# File 'lib/rubycc/type.rb', line 448 def integer? false end |
#pointer? ⇒ Boolean
432 433 434 |
# File 'lib/rubycc/type.rb', line 432 def pointer? false end |
#size ⇒ Object
The whole array's byte size: the element width times the count. An incomplete array ("[]") has no count and therefore no size; every path that could reach one where a size is needed rejects it first with a proper diagnostic, so a raise here is a missing guard.
487 488 489 490 491 |
# File 'lib/rubycc/type.rb', line 487 def size raise "incomplete array has no size" if length.nil? element.size * length end |
#struct? ⇒ Boolean
464 465 466 |
# File 'lib/rubycc/type.rb', line 464 def struct? false end |
#to_s ⇒ Object
Renders like a C array declarator: the element type, a space, then the bracketed length ("int [10]", "int * [4]"); an incomplete array shows an empty "[]" ("int []").
502 503 504 |
# File 'lib/rubycc/type.rb', line 502 def to_s "#{element} [#{length}]" end |
#void? ⇒ Boolean
444 445 446 |
# File 'lib/rubycc/type.rb', line 444 def void? false end |