Class: Rubycc::Type::FunctionType
- Inherits:
-
Data
- Object
- Data
- Rubycc::Type::FunctionType
- Defined in:
- lib/rubycc/type.rb
Overview
A function type (6.7.6.3): its return_type, the ordered param_types
(an array of the parameter Types after the array/function adjustments the
parser applies — "(void)" and "()" both yield an empty array) and
variadic, true for a prototype ending in "..." (a variable argument list
after the named parameters, "int (const char *, ...)"). For a variadic
type param_types holds only the fixed, named parameters. Being a Data,
two function types are equal exactly when their return type, parameter
types and variadic flag all match, so "int (int)" == "int (int)" but a
variadic "int (int, ...)" differs from the fixed "int (int)"; this makes a
function-pointer signature check reject a variadic/non-variadic mismatch on
its own.
A function type is not an object type: it has no storage width, so #size and #alignment raise (a well-formed program measures a pointer to a function, never the function itself, and the parser rejects a bare function type wherever an object is required). It is reached in this subset only through a pointer (a function pointer, Pointer with a FunctionType target) or as the very type a function declarator builds; #function? tells it apart from every object type.
Instance Attribute Summary collapse
-
#param_types ⇒ Object
readonly
Returns the value of attribute param_types.
-
#return_type ⇒ Object
readonly
Returns the value of attribute return_type.
-
#variadic ⇒ Object
readonly
Returns the value of attribute variadic.
Instance Method Summary collapse
- #alignment ⇒ Object
- #arithmetic? ⇒ Boolean
- #array? ⇒ Boolean
- #bool? ⇒ Boolean
- #char? ⇒ Boolean
- #float? ⇒ Boolean
- #function? ⇒ Boolean
- #int? ⇒ Boolean
- #integer? ⇒ Boolean
-
#parameter_list_string ⇒ Object
The parenthesized parameter list as it appears in a C declarator, used both by #to_s and by Pointer#to_s for a function pointer.
- #pointer? ⇒ Boolean
-
#size ⇒ Object
A function type has no storage, so it cannot be laid out; every path that could reach one where a size is needed (sizeof, a member layout, a variable) rejects it first with a proper diagnostic, so a raise here is a missing guard.
- #struct? ⇒ Boolean
-
#to_s ⇒ Object
Renders like a C function declarator with the name elided: the return type, a space, then the bracketed parameter list ("int (int, char *)", "void (void)").
- #void? ⇒ Boolean
Instance Attribute Details
#param_types ⇒ Object (readonly)
Returns the value of attribute param_types
526 527 528 |
# File 'lib/rubycc/type.rb', line 526 def param_types @param_types end |
#return_type ⇒ Object (readonly)
Returns the value of attribute return_type
526 527 528 |
# File 'lib/rubycc/type.rb', line 526 def return_type @return_type end |
#variadic ⇒ Object (readonly)
Returns the value of attribute variadic
526 527 528 |
# File 'lib/rubycc/type.rb', line 526 def variadic @variadic end |
Instance Method Details
#alignment ⇒ Object
579 580 581 |
# File 'lib/rubycc/type.rb', line 579 def alignment raise "function type has no alignment" end |
#arithmetic? ⇒ Boolean
547 548 549 |
# File 'lib/rubycc/type.rb', line 547 def arithmetic? false end |
#array? ⇒ Boolean
555 556 557 |
# File 'lib/rubycc/type.rb', line 555 def array? false end |
#bool? ⇒ Boolean
551 552 553 |
# File 'lib/rubycc/type.rb', line 551 def bool? false end |
#char? ⇒ Boolean
535 536 537 |
# File 'lib/rubycc/type.rb', line 535 def char? false end |
#float? ⇒ Boolean
567 568 569 |
# File 'lib/rubycc/type.rb', line 567 def float? false end |
#function? ⇒ Boolean
563 564 565 |
# File 'lib/rubycc/type.rb', line 563 def function? true end |
#int? ⇒ Boolean
531 532 533 |
# File 'lib/rubycc/type.rb', line 531 def int? false end |
#integer? ⇒ Boolean
543 544 545 |
# File 'lib/rubycc/type.rb', line 543 def integer? false end |
#parameter_list_string ⇒ Object
The parenthesized parameter list as it appears in a C declarator, used both by #to_s and by Pointer#to_s for a function pointer. An empty list renders "void" (a prototype taking no arguments); a variadic type ends in ", ..." after its named parameters ("char *, ..."). A variadic type always has at least one named parameter (ISO C forbids a lone "..."), so the empty-list "void" spelling is never variadic.
589 590 591 592 593 594 |
# File 'lib/rubycc/type.rb', line 589 def parameter_list_string return "..." if param_types.empty? && variadic base = param_types.empty? ? "void" : param_types.map(&:to_s).join(", ") variadic ? "#{base}, ..." : base end |
#pointer? ⇒ Boolean
527 528 529 |
# File 'lib/rubycc/type.rb', line 527 def pointer? false end |
#size ⇒ Object
A function type has no storage, so it cannot be laid out; every path that could reach one where a size is needed (sizeof, a member layout, a variable) rejects it first with a proper diagnostic, so a raise here is a missing guard.
575 576 577 |
# File 'lib/rubycc/type.rb', line 575 def size raise "function type has no size" end |
#struct? ⇒ Boolean
559 560 561 |
# File 'lib/rubycc/type.rb', line 559 def struct? false end |
#to_s ⇒ Object
Renders like a C function declarator with the name elided: the return type, a space, then the bracketed parameter list ("int (int, char *)", "void (void)").
599 600 601 |
# File 'lib/rubycc/type.rb', line 599 def to_s "#{return_type} (#{parameter_list_string})" end |
#void? ⇒ Boolean
539 540 541 |
# File 'lib/rubycc/type.rb', line 539 def void? false end |