#include "ctrump/ast/types.h"
#include <stdlib.h>
#include "ctrump/ast/builtin-types.def"
#include <stdio.h>
Go to the source code of this file.
Defines | |
#define | DEFINE_BUILTIN_TYPE(str_name, c, sym) |
#define | DEFINE_BUILTIN_TYPE(str_name, code, sym) ctrump_builtin_##str_name.id = id++; |
Functions | |
static struct ctrump_texpr * | alloc_texpr (struct ctrump_type_env *env) |
texpr を作る | |
struct ctrump_texpr * | ctrump_alloc_texpr (struct ctrump_type_env *env, enum ctrump_texpr_code code) |
allocate new texpr | |
struct ctrump_texpr * | ctrump_get_typedef_name (struct ctrump_type_env *env, struct ctrump_texpr *orig_type, const struct ctrump_symbol *name) |
get typedefed type | |
struct ctrump_texpr * | ctrump_get_qualified_attr_type (struct ctrump_type_env *env, struct ctrump_texpr *orig_t, int qual_flags, const struct ctrump_gccext_attribute *attr) |
get qualified(const, restrict, volatile) and gcc attributed type | |
struct ctrump_texpr * | ctrump_get_qualified_type (struct ctrump_type_env *env, struct ctrump_texpr *orig_t, int qual_flags) |
get qualified type | |
struct ctrump_texpr * | ctrump_get_unqualified_type (struct ctrump_texpr *texpr) |
get unqualified type | |
struct ctrump_texpr * | ctrump_get_pointer_type (struct ctrump_type_env *env, struct ctrump_texpr *texpr) |
get pointer type | |
struct ctrump_texpr * | ctrump_get_incomplete_array_type (struct ctrump_type_env *env, struct ctrump_texpr *texpr) |
get incomplete array type | |
struct ctrump_texpr * | ctrump_get_varlen_array_type (struct ctrump_type_env *env, struct ctrump_texpr *texpr) |
get varlen array type | |
struct ctrump_texpr * | ctrump_get_array_type (struct ctrump_type_env *env, struct ctrump_texpr *texpr, int size) |
get array type | |
void | ctrump_get_functype_begin (struct ctrump_get_functype_iterator *iter, struct ctrump_type_env *env, struct ctrump_texpr *ret_type, int num_args) |
get function type initialiezr You can get function type with calling functions, `get_functype_begin', `get_functype_next', `get_functype_end' as follows: | |
void | ctrump_get_functype_next (struct ctrump_type_env *env, struct ctrump_get_functype_iterator *iter, struct ctrump_texpr *arg) |
get function type | |
struct ctrump_texpr * | ctrump_get_functype_end (struct ctrump_type_env *env, struct ctrump_get_functype_iterator *iter, int has_unspec_arg) |
get function type | |
void | ctrump_get_functype_cancel (struct ctrump_get_functype_iterator *iter) |
cancel get function type This function releases some resource. | |
struct ctrump_texpr * | ctrump_get_incomplete_struct_type (struct ctrump_type_env *env, enum ctrump_texpr_code code, const struct ctrump_symbol *name) |
get incomplete struct type | |
void | ctrump_complete_struct_type (struct ctrump_record_type *record_type, int nfield, struct ctrump_record_type_field *fields, struct ctrump_gccext_attribute *attr) |
convert incomplete type to complete type | |
struct ctrump_texpr * | ctrump_get_incomplete_enum_type (struct ctrump_type_env *env, const struct ctrump_symbol *name) |
void | ctrump_complete_enum_type (struct ctrump_enum_type *enum_type, int nfield, struct ctrump_enum_type_field *fields) |
void | ctrump_type_env_init (struct ctrump_type_env *env, int is_char_signed) |
init type environment | |
void | ctrump_type_env_destroy (struct ctrump_type_env *env) |
release env resource | |
int | ctrump_texpr_is_pointer (struct ctrump_texpr *texpr) |
return 1 if texpr is pointer type | |
struct ctrump_texpr * | ctrump_texpr_apply_unary_pointer_conversion (struct ctrump_type_env *env, struct ctrump_texpr *texpr) |
return pointer type | |
struct ctrump_texpr * | ctrump_retrieve_pointer_type (struct ctrump_texpr *t) |
return type of pointed by `type' | |
struct ctrump_texpr * | ctrump_retrieve_address_type (struct ctrump_texpr *t) |
return type of pointed or arrayed by `type' | |
struct ctrump_gccext_attribute | ctrump_merge_attr (const struct ctrump_gccext_attribute *decl_attr, const struct ctrump_gccext_attribute *var_attr) |
変数に付けられたGCC attributeと宣言に付けられたGCC attributeをマージ | |
int | ctrump_type_is_float (const struct ctrump_texpr *texpr) |
int | ctrump_type_is_scalar (const struct ctrump_texpr *type) |
struct ctrump_texpr * | ctrump_retrieve_typedef_name (struct ctrump_texpr *type) |
typedef された型の指す型を取得 | |
int | ctrump_is_scalar_type (const struct ctrump_texpr *type) |
型がスカラ型かどうか | |
Variables | |
const int | ctrump_builtin_type_is_float_table [] |
型が浮動少数かどうかを示すテーブル (texpr_code -> int) | |
const int | ctrump_builtin_type_is_scalar_table [] |
型がスカラ型かどうかを示すテーブル (texpr_code -> int) |
Definition in file types.c.
#define DEFINE_BUILTIN_TYPE | ( | str_name, | |||
code, | |||||
sym | ) | ctrump_builtin_##str_name.id = id++; |
#define DEFINE_BUILTIN_TYPE | ( | str_name, | |||
c, | |||||
sym | ) |
Value:
struct ctrump_texpr ctrump_builtin_##str_name = { \ .code = CTRUMP_TYPE_BUILTIN, \ .u.builtin.code = c, \ .u.builtin.name = sym, \ .pointer_type = NULL, \ .incomplete_array_type = NULL, \ .array_types = NULL, \ .func_types = NULL, \ .qualified_types = NULL, \ };
static struct ctrump_texpr* alloc_texpr | ( | struct ctrump_type_env * | env | ) | [static, read] |
texpr を作る
Definition at line 60 of file types.c.
References ctrump_texpr::array_types, ctrump_mempool_alloc, ctrump_texpr::func_types, ctrump_type_env::id, ctrump_texpr::id, ctrump_texpr::incomplete_array_type, ctrump_texpr::pointer_type, ctrump_texpr::qualified_types, and ctrump_type_env::type_allocator.
Referenced by ctrump_alloc_texpr(), ctrump_get_array_type(), ctrump_get_functype_end(), ctrump_get_incomplete_array_type(), ctrump_get_incomplete_enum_type(), ctrump_get_incomplete_struct_type(), ctrump_get_pointer_type(), ctrump_get_qualified_attr_type(), ctrump_get_typedef_name(), and ctrump_get_varlen_array_type().
struct ctrump_texpr* ctrump_alloc_texpr | ( | struct ctrump_type_env * | env, | |
enum ctrump_texpr_code | code | |||
) | [read] |
allocate new texpr
Definition at line 78 of file types.c.
References alloc_texpr(), and ctrump_texpr::code.
void ctrump_complete_enum_type | ( | struct ctrump_enum_type * | enum_type, | |
int | nfield, | |||
struct ctrump_enum_type_field * | fields | |||
) |
Definition at line 422 of file types.c.
References ctrump_enum_type::fields, ctrump_enum_type::is_completed, and ctrump_enum_type::nfield.
void ctrump_complete_struct_type | ( | struct ctrump_record_type * | record_type, | |
int | nfield, | |||
struct ctrump_record_type_field * | fields, | |||
struct ctrump_gccext_attribute * | attr | |||
) |
convert incomplete type to complete type
record_type | target type | |
nfield |
Definition at line 399 of file types.c.
References ctrump_record_type::attr, ctrump_record_type::fields, ctrump_record_type::is_completed, and ctrump_record_type::nfield.
Referenced by ctrump_env_handle_record_decls().
struct ctrump_texpr* ctrump_get_array_type | ( | struct ctrump_type_env * | env, | |
struct ctrump_texpr * | texpr, | |||
int | size | |||
) | [read] |
get array type
env | type environment | |
texpr | targe ttype | |
size | number of element |
Definition at line 247 of file types.c.
References alloc_texpr(), ctrump_texpr::array, ctrump_array_type::array_of, ctrump_texpr::array_types, ctrump_array_type_chain::chain, ctrump_texpr::code, ctrump_mempool_alloc, CTRUMP_TYPE_ARRAY, ctrump_array_type::size, ctrump_array_type_chain::size, ctrump_array_type_chain::t, ctrump_type_env::type_allocator, and ctrump_texpr::u.
Referenced by build_array_type(), and ctrump_env_handle_decl_node().
void ctrump_get_functype_begin | ( | struct ctrump_get_functype_iterator * | iter, | |
struct ctrump_type_env * | env, | |||
struct ctrump_texpr * | ret_type, | |||
int | num_args | |||
) |
get function type initialiezr You can get function type with calling functions, `get_functype_begin', `get_functype_next', `get_functype_end' as follows:
---------------------------------------- struct ctrump_texpr *args[N]; struct ctrump_texpr *ret_type; struct ctrump_texpr *func_type; struct ctrump_get_functype_iterator iter; int has_unspec_arg;
ctrump_get_functype_begin(&iter, env, ret_type, N);
for (i=0; i<N; i++) { ctrump_get_functype_next(env, iter, args[i]); }
func_type = ctrump_get_functype_end(env, iter, has_unspec_arg); ----------------------------------------
`func_type' has type of function.
typeget | iter iterator | |
env | type environment | |
ret_type | return type of function | |
num_args | number of args |
Definition at line 283 of file types.c.
References ctrump_func_type_node::arg_type, ctrump_get_functype_iterator::args, ctrump_func_type_node::brother, ctrump_func_type_node::child, ctrump_mempool_alloc, ctrump_get_functype_iterator::cur, ctrump_get_functype_iterator::cur_arg, ctrump_func_type_node::func_type, ctrump_texpr::func_types, ctrump_get_functype_iterator::ret, and ctrump_type_env::type_allocator.
Referenced by build_func_type(), and ctrump_env_handle_decl_node().
void ctrump_get_functype_cancel | ( | struct ctrump_get_functype_iterator * | iter | ) |
cancel get function type This function releases some resource.
iter | iterator |
Definition at line 379 of file types.c.
References ctrump_get_functype_iterator::args.
Referenced by build_func_type().
struct ctrump_texpr* ctrump_get_functype_end | ( | struct ctrump_type_env * | env, | |
struct ctrump_get_functype_iterator * | iter, | |||
int | has_unspec_arg | |||
) | [read] |
get function type
env | type environment | |
iter | iterator |
Definition at line 345 of file types.c.
References alloc_texpr(), ctrump_function_type::arg_num, ctrump_get_functype_iterator::args, ctrump_function_type::args, ctrump_texpr::code, ctrump_mempool_alloc, CTRUMP_TYPE_FUNC, ctrump_get_functype_iterator::cur, ctrump_get_functype_iterator::cur_arg, ctrump_texpr::func, ctrump_func_type_node::func_type, ctrump_function_type::has_unspecified_arg, ctrump_get_functype_iterator::ret, ctrump_function_type::ret, ctrump_type_env::type_allocator, and ctrump_texpr::u.
Referenced by build_func_type(), and ctrump_env_handle_decl_node().
void ctrump_get_functype_next | ( | struct ctrump_type_env * | env, | |
struct ctrump_get_functype_iterator * | iter, | |||
struct ctrump_texpr * | arg | |||
) |
get function type
env | type environment | |
iter | iterator | |
arg | Nth arg type |
Definition at line 311 of file types.c.
References ctrump_func_type_node::arg_type, ctrump_get_functype_iterator::args, ctrump_func_type_node::brother, ctrump_func_type_node::child, ctrump_mempool_alloc, ctrump_get_functype_iterator::cur, ctrump_get_functype_iterator::cur_arg, ctrump_func_type_node::func_type, and ctrump_type_env::type_allocator.
Referenced by build_func_type(), and ctrump_env_handle_decl_node().
struct ctrump_texpr* ctrump_get_incomplete_array_type | ( | struct ctrump_type_env * | env, | |
struct ctrump_texpr * | texpr | |||
) | [read] |
get incomplete array type
env | type environment | |
texpr | type |
Definition at line 217 of file types.c.
References alloc_texpr(), ctrump_texpr::code, CTRUMP_TYPE_INCOMPLETE_ARRAY, ctrump_texpr::incomplete_array_of, ctrump_texpr::incomplete_array_type, and ctrump_texpr::u.
struct ctrump_texpr* ctrump_get_incomplete_enum_type | ( | struct ctrump_type_env * | env, | |
const struct ctrump_symbol * | name | |||
) | [read] |
Definition at line 411 of file types.c.
References alloc_texpr(), ctrump_texpr::code, CTRUMP_TYPE_ENUM, ctrump_texpr::enum_, ctrump_enum_type::is_completed, ctrump_enum_type::name, and ctrump_texpr::u.
struct ctrump_texpr* ctrump_get_incomplete_struct_type | ( | struct ctrump_type_env * | env, | |
enum ctrump_texpr_code | code, | |||
const struct ctrump_symbol * | name | |||
) | [read] |
get incomplete struct type
env | type environment | |
code | CTRUMP_TYPE_UNION or CTRUMP_TYPE_STRUCT, |
Definition at line 386 of file types.c.
References alloc_texpr(), ctrump_texpr::code, and ctrump_texpr::u.
Referenced by build_incomplete_field_type(), and build_struct().
struct ctrump_texpr* ctrump_get_pointer_type | ( | struct ctrump_type_env * | env, | |
struct ctrump_texpr * | texpr | |||
) | [read] |
get pointer type
env | type environment | |
texpr | type |
Definition at line 199 of file types.c.
References alloc_texpr(), ctrump_texpr::code, CTRUMP_TYPE_POINTER, ctrump_texpr::pointer_to, ctrump_texpr::pointer_type, and ctrump_texpr::u.
Referenced by build_pointer_type(), ctrump_env_handle_decl_node(), and ctrump_texpr_apply_unary_pointer_conversion().
struct ctrump_texpr* ctrump_get_qualified_attr_type | ( | struct ctrump_type_env * | env, | |
struct ctrump_texpr * | texpr, | |||
int | qual_flags, | |||
const struct ctrump_gccext_attribute * | attr | |||
) | [read] |
get qualified(const, restrict, volatile) and gcc attributed type
env | type environment | |
texpr | target type | |
qual_flags | combination of qualifier flags | |
attr | gcc attribute |
Definition at line 102 of file types.c.
References ctrump_gccext_attribute::aligned, alloc_texpr(), ctrump_qualified_type_chain::attr, ctrump_qualified_type::attr, ctrump_qualified_type_chain::chain, ctrump_texpr::code, CTRUMP_ALIGN_UNSPECIFIED, ctrump_mempool_alloc, CTRUMP_TYPE_QUALIFIED, ctrump_gccext_attribute::flags, ctrump_qualified_type_chain::qual_flags, ctrump_qualified_type::qual_flags, ctrump_texpr::qualified, ctrump_texpr::qualified_types, ctrump_qualified_type_chain::type, ctrump_type_env::type_allocator, ctrump_texpr::u, and ctrump_qualified_type::unqualified_type.
Referenced by build_qualified_type(), ctrump_env_handle_decl(), ctrump_env_handle_decl_node(), and ctrump_get_qualified_type().
struct ctrump_texpr* ctrump_get_qualified_type | ( | struct ctrump_type_env * | env, | |
struct ctrump_texpr * | texpr, | |||
int | qual_flags | |||
) | [read] |
get qualified type
env | type environment | |
texpr | target type | |
qual_flags | combination of qualifier flags |
Definition at line 172 of file types.c.
References ctrump_gccext_attribute::aligned, ctrump_qualified_type::attr, ctrump_texpr::code, CTRUMP_ALIGN_UNSPECIFIED, ctrump_get_qualified_attr_type(), CTRUMP_TYPE_QUALIFIED, ctrump_gccext_attribute::flags, ctrump_texpr::qualified, and ctrump_texpr::u.
Referenced by ctrump_env_handle_decl_node().
struct ctrump_texpr* ctrump_get_typedef_name | ( | struct ctrump_type_env * | env, | |
struct ctrump_texpr * | orig_type, | |||
const struct ctrump_symbol * | name | |||
) | [read] |
get typedefed type
env | type env | |
orig_type | original type | |
name | name of type |
Definition at line 87 of file types.c.
References alloc_texpr(), ctrump_texpr::code, CTRUMP_TYPE_TYPEDEF_NAME, ctrump_typedef_name::def_name, ctrump_typedef_name::defined_to, ctrump_texpr::typedef_name, and ctrump_texpr::u.
Referenced by build_typedef_name().
struct ctrump_texpr* ctrump_get_unqualified_type | ( | struct ctrump_texpr * | texpr | ) | [read] |
get unqualified type
texpr | type |
Definition at line 188 of file types.c.
References ctrump_texpr::code, CTRUMP_TYPE_QUALIFIED, ctrump_texpr::qualified, ctrump_texpr::u, and ctrump_qualified_type::unqualified_type.
Referenced by recog_array_access(), and struct_field_offset().
struct ctrump_texpr* ctrump_get_varlen_array_type | ( | struct ctrump_type_env * | env, | |
struct ctrump_texpr * | texpr | |||
) | [read] |
get varlen array type
texpr | type |
Definition at line 236 of file types.c.
References alloc_texpr(), ctrump_texpr::code, CTRUMP_TYPE_VARLEN_ARRAY, ctrump_texpr::u, and ctrump_texpr::varlen_array_of.
int ctrump_is_scalar_type | ( | const struct ctrump_texpr * | type | ) |
型がスカラ型かどうか
Definition at line 697 of file types.c.
References ctrump_texpr::code, CTRUMP_TYPE_ARRAY, CTRUMP_TYPE_INCOMPLETE_ARRAY, CTRUMP_TYPE_STRUCT, CTRUMP_TYPE_UNION, and CTRUMP_TYPE_VARLEN_ARRAY.
Referenced by append_nd_subscript(), and append_record_member_ref().
struct ctrump_gccext_attribute ctrump_merge_attr | ( | const struct ctrump_gccext_attribute * | decl_attr, | |
const struct ctrump_gccext_attribute * | var_attr | |||
) | [read] |
変数に付けられたGCC attributeと宣言に付けられたGCC attributeをマージ
Definition at line 563 of file types.c.
References ctrump_gccext_attribute::aligned, CTRUMP_ALIGN_UNSPECIFIED, and ctrump_gccext_attribute::flags.
Referenced by print_texpr_abstract_declarator(), and print_texpr_spec().
struct ctrump_texpr* ctrump_retrieve_address_type | ( | struct ctrump_texpr * | type | ) | [read] |
return type of pointed or arrayed by `type'
type | pointer or array type |
Definition at line 536 of file types.c.
References ctrump_texpr::array, ctrump_array_type::array_of, ctrump_texpr::code, CTRUMP_TYPE_ARRAY, CTRUMP_TYPE_POINTER, CTRUMP_TYPE_QUALIFIED, CTRUMP_TYPE_TYPEDEF_NAME, ctrump_typedef_name::defined_to, ctrump_texpr::pointer_to, ctrump_texpr::qualified, ctrump_texpr::typedef_name, ctrump_texpr::u, and ctrump_qualified_type::unqualified_type.
Referenced by retrieve_address_type().
struct ctrump_texpr* ctrump_retrieve_pointer_type | ( | struct ctrump_texpr * | type | ) | [read] |
return type of pointed by `type'
type | pointer type |
Definition at line 514 of file types.c.
References ctrump_texpr::code, CTRUMP_TYPE_POINTER, CTRUMP_TYPE_QUALIFIED, CTRUMP_TYPE_TYPEDEF_NAME, ctrump_typedef_name::defined_to, ctrump_texpr::pointer_to, ctrump_texpr::qualified, ctrump_texpr::typedef_name, ctrump_texpr::u, and ctrump_qualified_type::unqualified_type.
Referenced by append_record_member_ref(), and retrieve_pointer_type().
struct ctrump_texpr* ctrump_retrieve_typedef_name | ( | struct ctrump_texpr * | type | ) | [read] |
typedef された型の指す型を取得
Definition at line 687 of file types.c.
References ctrump_texpr::code, CTRUMP_TYPE_TYPEDEF_NAME, ctrump_typedef_name::defined_to, ctrump_texpr::typedef_name, and ctrump_texpr::u.
Referenced by struct_field_offset().
struct ctrump_texpr* ctrump_texpr_apply_unary_pointer_conversion | ( | struct ctrump_type_env * | env, | |
struct ctrump_texpr * | type | |||
) | [read] |
return pointer type
Definition at line 484 of file types.c.
References ctrump_texpr::array, ctrump_array_type::array_of, ctrump_texpr::code, ctrump_get_pointer_type(), CTRUMP_TYPE_ARRAY, CTRUMP_TYPE_FUNC, CTRUMP_TYPE_POINTER, CTRUMP_TYPE_QUALIFIED, CTRUMP_TYPE_TYPEDEF_NAME, ctrump_typedef_name::defined_to, ctrump_texpr::qualified, ctrump_texpr::typedef_name, ctrump_texpr::u, and ctrump_qualified_type::unqualified_type.
Referenced by type_apply_unary_pointer_conversion().
int ctrump_texpr_is_pointer | ( | struct ctrump_texpr * | texpr | ) |
return 1 if texpr is pointer type
Definition at line 462 of file types.c.
References ctrump_texpr::code, CTRUMP_TYPE_POINTER, CTRUMP_TYPE_QUALIFIED, CTRUMP_TYPE_TYPEDEF_NAME, ctrump_typedef_name::defined_to, ctrump_texpr::qualified, ctrump_texpr::typedef_name, ctrump_texpr::u, and ctrump_qualified_type::unqualified_type.
Referenced by is_pointer_type().
void ctrump_type_env_destroy | ( | struct ctrump_type_env * | env | ) |
release env resource
env | type environment |
Definition at line 454 of file types.c.
References ctrump_mempool_destroy(), and ctrump_type_env::type_allocator.
Referenced by typeenv_dealloc().
void ctrump_type_env_init | ( | struct ctrump_type_env * | env, | |
int | is_char_signed | |||
) |
init type environment
env | type environment | |
is_char_signed | 1 if char is signed |
Definition at line 433 of file types.c.
References ctrump_type_env::builtin_char_type, ctrump_mempool_init(), ctrump_type_env::id, and ctrump_type_env::type_allocator.
Referenced by ctrump_indent(), ctrump_prog_file2pprint_format(), and typeenv_Init().
int ctrump_type_is_float | ( | const struct ctrump_texpr * | texpr | ) |
Definition at line 647 of file types.c.
References ctrump_texpr::builtin, ctrump_builtin_type::code, ctrump_texpr::code, ctrump_builtin_type_is_float_table, CTRUMP_TYPE_BUILTIN, and ctrump_texpr::u.
Referenced by ctrump_is_bitconvertion_on_type_conversion(), and ssa_node_store_expr().
int ctrump_type_is_scalar | ( | const struct ctrump_texpr * | type | ) |
Definition at line 654 of file types.c.
References ctrump_texpr::builtin, ctrump_builtin_type::code, ctrump_texpr::code, ctrump_builtin_type_is_scalar_table, CTRUMP_TYPE_ARRAY, CTRUMP_TYPE_BUILTIN, CTRUMP_TYPE_ENUM, CTRUMP_TYPE_FUNC, CTRUMP_TYPE_INCOMPLETE_ARRAY, CTRUMP_TYPE_POINTER, CTRUMP_TYPE_QUALIFIED, CTRUMP_TYPE_STRUCT, CTRUMP_TYPE_TYPEDEF_NAME, CTRUMP_TYPE_UNION, CTRUMP_TYPE_VARLEN_ARRAY, ctrump_typedef_name::defined_to, ctrump_texpr::qualified, ctrump_texpr::typedef_name, ctrump_texpr::u, and ctrump_qualified_type::unqualified_type.
Referenced by ctrump_is_bitconvertion_on_type_conversion().
const int ctrump_builtin_type_is_float_table[] |
型が浮動少数かどうかを示すテーブル (texpr_code -> int)
Definition at line 579 of file types.c.
Referenced by ctrump_type_is_float().
const int ctrump_builtin_type_is_scalar_table[] |
型がスカラ型かどうかを示すテーブル (texpr_code -> int)
Definition at line 611 of file types.c.
Referenced by ctrump_type_is_scalar().