#include <type_rep.h>
Public Types | |
enum | Qualifier { q_Const, q_Volatile, q_Restrict } |
enum | Kind { k_Fundamental, k_Pointer = 'P', k_Reference = 'R', k_Function = 'F', k_Array = 'A', k_Member = 'M', k_Userdef = 'Q', k_Ellipsis = 'E', k_Template = 'T', k_Nothing = 'O' } |
Public Methods | |
bool | is_qualified (Qualifier q) const |
bool | is_qualified () const |
void | add_qualifier (Qualifier q) |
void | remove_qualifier (Qualifier q) |
bool | is_valid () const |
void | copy_qualifiers (const Type &other) |
const std::string & | get_encoded_type () const |
Type | get_unqualified_type () const |
bool | operator== (const Type &rhs) const |
bool | operator!= (const Type &rhs) const |
bool | is_more_qualified_than (const Type &other) const |
bool | is_same_qualified_as (const Type &other) const |
bool | is_same_unqualified_type (const Type &other) const |
Type () | |
Create an empty, invalid type. More... | |
Type (std::string encoded) | |
Create a type containing the specified encoded signature. More... | |
Type::Kind | get_kind () const |
Return kind of this type. More... | |
Type | make_pointer_type () const |
Create pointer type (pointer-to-this). More... | |
Type | make_reference_type () const |
Create reference type (reference-to-this). More... | |
Type | make_array_type (Ptree *dimension) const |
Create array type (array[dimension]-of-this). More... | |
Type | make_member_type (Type membertype) const |
Create member type (member-membertype-of-this). More... | |
Type | get_basis_type () const |
Given a type "reference-to-T", "pointer-to-T" or "array-of-T", return the T. More... | |
Type | sans_reference () const |
Returns this type with reference removed. More... | |
Type | sans_array () const |
Type | get_class_type () const |
Given a type "pointer-to-member-of-CLASS-which-has-type-T", return CLASS. More... | |
Type | get_member_type () const |
Given a type "pointer-to-member-of-CLASS-which-has-type-T", return T. More... | |
Type | get_return_type () const |
Given a type "function returning T", return T. More... | |
std::string | get_function_signature () const |
Given a function type, return its signature. More... | |
Type | get_function_arg (int n) const |
Given a type "function(a0,a1,a2...) returning T", return a_i. More... | |
int | get_num_function_args () const |
Given a type "function(a0..a_n-1)", return n. More... | |
int | get_template_argindex () const |
Given type "N'th template argument", return N. More... | |
std::string | get_human_readable_type () const |
Return a human-readable description of this type. More... | |
bool | is_void () const |
True iff this type is void. More... | |
bool | is_float () const |
True iff this type is a floating-point type. More... | |
bool | is_int () const |
True iff this type is an integral type. More... | |
bool | is_complete () const |
True iff this type is complete. More... | |
bool | is_object_type () const |
Object types, 3.9p9. More... | |
bool | is_arithmetic_type () const |
Arithmetic types, 3.9.1p8. More... | |
bool | is_scalar_type () const |
Scalar types, 3.9p10. More... | |
bool | is_pod () const |
True if type is POD (3.9p10). More... | |
bool | is_aggregate () const |
bool | is_compound_type () const |
Compound types, 3.9.2. More... | |
bool | is_enum_type () const |
bool | is_class_type () const |
Type_symbol * | get_type_symbol () const |
Given a user-defined type, return the corresponding Type_symbol. More... | |
Type | with_qualifier (Type::Qualifier q) const |
Return this type, with qualifier /q/ added. More... | |
Type | with_first_arg (Type t) const |
When this is "function-taking-args-a,b,c", return "function-taking-args-t,a,b,c". More... | |
Type | with_qualifiers (const Type &other) const |
Return this type, with the qualifiers from /other/ added. More... | |
Type | get_promoted_integer () const |
Integral promotions, 4.5. More... | |
bool | is_qualification_convertible_to (Type t) const |
True iff this type can be qualification-converted to /t/. More... | |
Static Public Methods | |
Type | get_named_type (std::string name) |
Create type symbol for type with mangled name /name/. More... | |
Static Public Attributes | |
const int | ignore_qual = 0 |
Private Methods | |
Type (std::string code, int qualifiers) | |
std::string | encode_qualifiers (std::string prefix) const |
Internal: construct a new type. More... | |
Static Private Methods | |
std::string | eat_type (std::string s) |
Given a string <Type>NNN, return NNN. More... | |
Private Attributes | |
std::string | code |
int | qualifiers |
Friends | |
class | Function_type_maker |
In the future, this should probably be replaced by a proper dynamic data structure which allows easier representation of some subtleties.
How gcc does it: every type has a "main variant", of these we have sub-variants (cv-qualified types) which are created on demand. In addition, we have derived types (ref/ptr/array) for each.
Definition at line 75 of file type_rep.h.
|
Definition at line 85 of file type_rep.h. Referenced by get_kind(), and is_qualification_convertible_to(). |
|
Definition at line 80 of file type_rep.h. Referenced by add_qualifier(), is_qualified(), remove_qualifier(), and with_qualifier(). |
|
Create an empty, invalid type.
Definition at line 22 of file type_rep.cc. Referenced by get_basis_type(), get_class_type(), get_function_arg(), get_member_type(), get_named_type(), get_promoted_integer(), get_return_type(), get_unqualified_type(), make_array_type(), make_member_type(), make_pointer_type(), make_reference_type(), with_qualifier(), and with_qualifiers(). |
|
Create a type containing the specified encoded signature. This is used to construct types internally and should not be called by user code. Still public for flexibility. Definition at line 32 of file type_rep.cc. References add_qualifier(), code, q_Const, q_Restrict, and q_Volatile. |
|
Definition at line 53 of file type_rep.cc. |
|
Definition at line 101 of file type_rep.h. References Qualifier, and qualifiers. Referenced by Class_symbol::finish_definition(), parse_qualifier(), Expr_annotator::process_member_access(), Type(), and Expr_annotator::visit_name(). |
|
Definition at line 105 of file type_rep.h. References qualifiers. Referenced by Function_symbol::add_signature(), Implicit_conversion::convert_to_rvalue(), Simple_declaration_reader::declare_variable(), and Type_reader::Type_reader(). |
|
Given a string <Type>NNN, return NNN.
Definition at line 246 of file type_rep.cc. References compile_error(). Referenced by get_class_type(), get_function_arg(), get_function_signature(), get_member_type(), get_num_function_args(), and get_return_type(). |
|
Internal: construct a new type. "prefix" is the new prefix (a Kind maybe) Definition at line 86 of file type_rep.cc. References code, is_qualified(), q_Const, q_Restrict, and q_Volatile. Referenced by Function_type_maker::add_parameter(), make_array_type(), Function_type_maker::make_function_type(), make_member_type(), make_pointer_type(), make_reference_type(), and with_first_arg(). |
|
|
Given a type "pointer-to-member-of-CLASS-which-has-type-T", return CLASS.
Definition at line 158 of file type_rep.cc. References code, eat_type(), get_kind(), k_Member, and Type(). Referenced by gen_builtin_conversions(), get_composite_mptr_type(), get_human_readable_type(), get_merged_cv_type(), Function_signature::has_pointer_type(), is_qualification_convertible_to(), Expr_annotator::process_pm_expr(), Implicit_conversion::scs_is_better_than(), try_reinterpret_cast(), and Expr_annotator::try_static_cast(). |
|
Definition at line 107 of file type_rep.h. References code. Referenced by Function_symbol::add_signature(), Overload_resolver::dump(), ICS_Step::dump(), Symbol_name::get_mangled_function_name(), make_declaration(), make_sizeof_expr(), print_annotated_tree(), and Expr_annotator::visit_new(). |
|
Given a type "function(a0,a1,a2...) returning T", return a_i.
Definition at line 206 of file type_rep.cc. References code, eat_type(), get_kind(), k_Function, and Type(). Referenced by Overload_resolver::add_signature_with_type(), gen_constructors(), Class_symbol::get_copy_ctor(), get_human_readable_type(), Class_symbol::implicit_assignment_operator_style(), and Class_symbol::implicit_copy_ctor_is_const(). |
|
Given a function type, return its signature. The signature is an opaque string which encodes the parameters. Definition at line 193 of file type_rep.cc. References code, eat_type(), get_kind(), and k_Function. Referenced by Class_scope::add_function_decl(), Function_symbol::add_signature(), and Symbol_name::get_mangled_function_name(). |
|
Return a human-readable description of this type.
Definition at line 315 of file type_rep.cc. References code, get_basis_type(), get_class_type(), get_function_arg(), get_kind(), get_member_type(), get_num_function_args(), get_return_type(), is_qualified(), k_Array, k_Ellipsis, k_Function, k_Fundamental, k_Member, k_Nothing, k_Pointer, k_Reference, k_Template, k_Userdef, q_Const, q_Restrict, and q_Volatile. Referenced by Expr_result::convert_to_bool(), Simple_declaration_reader::declare_variable(), Expr_annotator::do_funcall(), Variable_symbol::dump(), Typedef_symbol::dump(), ICS_Step::dump(), Function_signature::dump(), Init_handler::get_default_initializer_for_type(), Expr_annotator::visit_array(), Expr_annotator::visit_assign(), Expr_annotator::visit_new(), Annotator::visit_return(), and Annotator::visit_switch(). |
|
|
Given a type "pointer-to-member-of-CLASS-which-has-type-T", return T.
Definition at line 169 of file type_rep.cc. References code, eat_type(), get_kind(), k_Member, and Type(). Referenced by gen_builtin_conversions(), get_composite_mptr_type(), get_human_readable_type(), get_merged_cv_type(), Function_signature::has_pointer_type(), is_qualification_convertible_to(), Expr_annotator::process_pm_expr(), try_reinterpret_cast(), and Expr_annotator::try_static_cast(). |
|
Create type symbol for type with mangled name /name/.
Definition at line 61 of file type_rep.cc. References Type(). Referenced by Type_symbol::get_type(). |
|
Given a type "function(a0..a_n-1)", return n.
Definition at line 219 of file type_rep.cc. References code, eat_type(), get_kind(), and k_Function. Referenced by Overload_resolver::add_signature_with_type(), Simple_declaration_reader::declare_variable(), gen_constructors(), Class_symbol::get_copy_ctor(), and get_human_readable_type(). |
|
Integral promotions, 4.5. Returns the type after integral promotions, with cv-qualifiers removed. This also "expands" enums. Definition at line 513 of file type_rep.cc. References code, Symbol::get_kind(), get_type_symbol(), int_type(), Symbol::k_Enum, Type(), and uint_type(). Referenced by binary_addeq_predicate(), binary_inteq_predicate(), binary_multeq_predicate(), Expr_result::do_integral_promotions(), fundamental_conversion_type(), unary_bitnot_predicate(), unary_minus_predicate(), unary_plus_predicate(), and Expr_annotator::visit_assign(). |
|
Given a type "function returning T", return T.
Definition at line 179 of file type_rep.cc. References code, eat_type(), get_kind(), k_Function, and Type(). Referenced by Overload_resolver::add_builtin_binary_ops(), Overload_resolver::add_builtin_incdec(), Class_scope::add_function_decl(), Function_symbol::add_signature(), Simple_declaration_reader::declare_variable(), Expr_annotator::do_funcall(), get_human_readable_type(), and Function_signature::get_return_type(). |
|
Given type "N'th template argument", return N.
Definition at line 233 of file type_rep.cc. References code, get_kind(), and k_Template. |
|
|
|
Definition at line 459 of file type_rep.cc. References get_kind(), get_type_symbol(), Class_symbol::is_aggregate(), is_valid(), k_Array, and k_Userdef. |
|
Arithmetic types, 3.9.1p8. "Integral and floating types are collectively called arithmetic types". Definition at line 404 of file type_rep.cc. References is_float(), and is_int(). Referenced by Overload_resolver::add_builtin_incdec(), binary_addeq_predicate(), binary_multeq_predicate(), Expr_result::convert_to_bool(), do_usual_conversions(), index_predicate(), is_pod(), is_scalar_type(), Expr_annotator::process_binary_operator(), Expr_annotator::process_unary_operator(), unary_minus_predicate(), unary_plus_predicate(), Expr_annotator::visit_assign(), Expr_annotator::visit_cond(), and Expr_annotator::visit_postfix(). |
|
|
True iff this type is complete. 3.9p6 Definition at line 378 of file type_rep.cc. References get_kind(), Symbol::get_status(), get_type_symbol(), is_void(), k_Userdef, and Symbol::st_Defined. Referenced by check_ptr_arith(), Expr_result::convert_to_rvalue(), make_sizeof_expr(), Expr_annotator::process_unary_operator(), and Expr_annotator::visit_postfix(). |
|
Compound types, 3.9.2. "Compound types can be constructed in the following ways: arrays [...], functions [...], pointers [...], references [...], classes [...], unions [...], enumerations [...], pointers to non-static class members [...]". Essentially, anything that's not fundamental. Definition at line 402 of file type_rep.h. References get_kind(), and k_Fundamental. |
|
Definition at line 479 of file type_rep.cc. References Symbol::get_kind(), get_kind(), get_type_symbol(), Symbol::k_Enum, and k_Userdef. Referenced by Class_scope::add_variable(), binary_addeq_predicate(), binary_inteq_predicate(), binary_multeq_predicate(), Expr_result::convert_to_bool(), do_usual_conversions(), index_predicate(), is_scalar_type(), try_reinterpret_cast(), Expr_annotator::try_static_cast(), unary_bitnot_predicate(), unary_minus_predicate(), unary_plus_predicate(), Expr_annotator::visit_array(), Expr_annotator::visit_assign(), Annotator::visit_case(), Expr_annotator::visit_cond(), Expr_annotator::visit_infix(), and Annotator::visit_switch(). |
|
True iff this type is a floating-point type.
Definition at line 390 of file type_rep.h. References code. Referenced by binary_multeq_predicate(), fundamental_conversion_type(), is_arithmetic_type(), is_int(), Expr_annotator::process_binary_operator(), and Expr_annotator::process_unary_operator(). |
|
True iff this type is an integral type.
Definition at line 369 of file type_rep.cc. References code, get_kind(), is_float(), is_void(), and k_Fundamental. Referenced by Class_scope::add_variable(), binary_addeq_predicate(), binary_inteq_predicate(), binary_multeq_predicate(), fundamental_conversion_type(), gen_builtin_conversions(), is_arithmetic_type(), Expr_result::is_npc(), Expr_annotator::process_binary_operator(), Expr_annotator::process_unary_operator(), Enum_symbol::process_value(), try_reinterpret_cast(), Expr_annotator::try_static_cast(), unary_bitnot_predicate(), Expr_annotator::visit_array(), Expr_annotator::visit_assign(), Annotator::visit_case(), and Annotator::visit_switch(). |
|
Definition at line 114 of file type_rep.h. References qualifiers. Referenced by Implicit_conversion::convert_reference(), Implicit_conversion::convert_to_rvalue(), Function_signature::has_pointer_type(), is_covariant_or_same(), is_qualification_convertible_to(), Expr_annotator::process_pm_expr(), try_reinterpret_cast(), and Expr_annotator::try_static_cast(). |
|
Object types, 3.9p9. "An object type is a type that is not a function type, not a reference type, and not a reference type" Definition at line 392 of file type_rep.cc. References get_kind(), is_void(), k_Function, and k_Reference. Referenced by Overload_resolver::add_builtin_incdec(), binary_addeq_predicate(), check_ptr_arith(), unary_delete_or_arrow_predicate(), unary_deref_predicate(), Expr_annotator::visit_delete(), Expr_annotator::visit_new(), and Expr_annotator::visit_pm(). |
|
True if type is POD (3.9p10).
Definition at line 434 of file type_rep.cc. References get_basis_type(), get_kind(), get_type_symbol(), is_arithmetic_type(), Class_symbol::is_pod(), is_valid(), k_Array, k_Fundamental, k_Member, k_Pointer, and k_Userdef. Referenced by Class_scope::add_variable(). |
|
True iff this type can be qualification-converted to /t/. 4.4. Definition at line 563 of file type_rep.cc. References get_basis_type(), get_class_type(), get_kind(), get_member_type(), is_more_qualified_than(), is_qualified(), is_same_qualified_as(), is_same_unqualified_type(), k_Member, k_Pointer, k_Reference, Kind, and q_Const. Referenced by gen_builtin_conversions(). |
|
Definition at line 100 of file type_rep.h. References qualifiers. Referenced by encode_qualifiers(), and get_human_readable_type(). |
|
Definition at line 99 of file type_rep.h. References Qualifier, and qualifiers. Referenced by Overload_resolver::add_builtin_incdec(), Function_symbol::add_signature(), Namespace_scope::add_variable(), Class_scope::add_variable(), gen_candidates(), Symbol_name::get_mangled_function_name(), Class_symbol::implicit_assignment_operator_style(), Class_symbol::implicit_copy_ctor_is_const(), Expr_result::is_modifyable_lvalue(), is_qualification_convertible_to(), parse_qualifier(), Expr_annotator::process_member_access(), and Expr_annotator::visit_name(). |
|
Definition at line 115 of file type_rep.h. References ignore_qual, and qualifiers. Referenced by is_covariant_or_same(), and is_qualification_convertible_to(). |
|
|
Scalar types, 3.9p10. "Arithmetic types, enumeration types, pointer types and pointer to member types, and cv-qualified versions of these types are collectively called scalar types." Definition at line 415 of file type_rep.cc. References get_kind(), is_arithmetic_type(), is_enum_type(), k_Fundamental, k_Member, k_Pointer, and k_Userdef. Referenced by Init_handler::get_default_initializer_for_type(), Init_handler::make_constructor_call(), Init_handler::process_brace(), and Init_handler::process_initializer(). |
|
|
True iff this type is void.
Definition at line 382 of file type_rep.h. References code. Referenced by Simple_declaration_reader::declare_variable(), fundamental_conversion_type(), gen_builtin_conversions(), generate_implicit_conversion(), get_composite_pointer_type(), is_complete(), is_int(), is_object_type(), Expr_annotator::process_unary_operator(), Expr_annotator::try_static_cast(), Expr_annotator::visit_assign(), Expr_annotator::visit_cond(), Annotator::visit_return(), and Expr_annotator::visit_throw(). |
|
Create array type (array[dimension]-of-this).
Definition at line 101 of file type_rep.cc. References encode_qualifiers(), and Type(). Referenced by Declaration_reader::parse_declarator_internal(), and Expr_annotator::visit_leaf(). |
|
Create member type (member-membertype-of-this). let c = classtype m = membertype then "m c::*" is c.make_member_type(m) Definition at line 114 of file type_rep.cc. References encode_qualifiers(), and Type(). Referenced by enumerate_conversion_ops(), gen_builtin_conversions(), get_composite_mptr_type(), get_merged_cv_type(), Function_signature::get_pointer_type(), Declaration_reader::parse_declarator_internal(), and Expr_annotator::visit_unary(). |
|
Create pointer type (pointer-to-this).
Definition at line 364 of file type_rep.h. References encode_qualifiers(), and Type(). Referenced by Function_type_maker::add_parameter(), Expr_result::convert_to_fpointer(), Expr_result::convert_to_pointer(), Implicit_conversion::convert_to_rvalue(), Simple_declaration_reader::declare_variable(), Expr_annotator::do_funcall(), gen_builtin_conversions(), get_composite_pointer_type(), Symbol_name::get_mangled_function_name(), get_merged_cv_type(), index_predicate(), make_this(), Declaration_reader::parse_declarator_internal(), print_annotated_tree(), Expr_annotator::process_unary_operator(), and Expr_annotator::visit_new(). |
|
Create reference type (reference-to-this).
Definition at line 372 of file type_rep.h. References encode_qualifiers(), and Type(). Referenced by Overload_resolver::add_builtin_binary_ops(), Overload_resolver::add_builtin_incdec(), Function_symbol::add_signature(), Overload_resolver::add_signature_with_type(), Class_symbol::finish_definition(), generate_ics_for_ternary(), Declaration_reader::parse_declarator_internal(), and unary_deref_predicate(). |
|
Definition at line 112 of file type_rep.h. References code, ignore_qual, and qualifiers. |
|
Definition at line 111 of file type_rep.h. References code, ignore_qual, and qualifiers. |
|
Definition at line 102 of file type_rep.h. References Qualifier, and qualifiers. |
|
Definition at line 146 of file type_rep.cc. References get_basis_type(), get_kind(), and k_Array. Referenced by Class_scope::add_variable(), and Expr_annotator::visit_new(). |
|
Returns this type with reference removed. That is, a variable declared as type T denotes an lvalue of type T.sans_reference(). Definition at line 135 of file type_rep.cc. References get_basis_type(), get_kind(), and k_Reference. Referenced by binary_addeq_predicate(), binary_inteq_predicate(), binary_multeq_predicate(), Class_symbol::get_copy_ctor(), index_predicate(), and Expr_annotator::visit_name(). |
|
When this is "function-taking-args-a,b,c", return "function-taking-args-t,a,b,c". This is needed to make surrogate-functions for overloading. Definition at line 420 of file type_rep.h. References code, encode_qualifiers(), get_kind(), and k_Function. Referenced by Function_symbol::add_signature(), and Expr_annotator::do_funcall(). |
|
Return this type, with qualifier /q/ added.
Definition at line 410 of file type_rep.h. References code, Qualifier, qualifiers, and Type(). Referenced by make_this(). |
|
Return this type, with the qualifiers from /other/ added.
Definition at line 431 of file type_rep.h. References code, qualifiers, and Type(). Referenced by Implicit_conversion::convert_reference(), Implicit_conversion::convert_to_rvalue(), gen_builtin_conversions(), get_composite_mptr_type(), get_composite_pointer_type(), get_merged_cv_type(), Expr_annotator::process_member_access(), Expr_annotator::process_pm_expr(), and Expr_annotator::visit_cond(). |
|
Definition at line 78 of file type_rep.h. |
|
Definition at line 76 of file type_rep.h. Referenced by encode_qualifiers(), get_basis_type(), get_class_type(), get_encoded_type(), get_function_arg(), get_function_signature(), get_human_readable_type(), get_kind(), get_member_type(), get_num_function_args(), get_promoted_integer(), get_return_type(), get_template_argindex(), get_type_symbol(), get_unqualified_type(), is_float(), is_int(), is_same_unqualified_type(), is_valid(), is_void(), operator!=(), operator==(), Type(), with_first_arg(), with_qualifier(), and with_qualifiers(). |
|
Definition at line 97 of file type_rep.h. Referenced by is_same_qualified_as(), operator!=(), and operator==(). |
|
Definition at line 77 of file type_rep.h. Referenced by add_qualifier(), copy_qualifiers(), is_more_qualified_than(), is_qualified(), is_same_qualified_as(), operator!=(), operator==(), remove_qualifier(), with_qualifier(), and with_qualifiers(). |