ctrump/ast/types.c File Reference

C99 構文木定義. More...

#include "ctrump/ast/types.h"
#include <stdlib.h>
#include "ctrump/ast/builtin-types.def"
#include <stdio.h>

Include dependency graph for types.c:

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_texpralloc_texpr (struct ctrump_type_env *env)
 texpr を作る
struct ctrump_texprctrump_alloc_texpr (struct ctrump_type_env *env, enum ctrump_texpr_code code)
 allocate new texpr
struct ctrump_texprctrump_get_typedef_name (struct ctrump_type_env *env, struct ctrump_texpr *orig_type, const struct ctrump_symbol *name)
 get typedefed type
struct ctrump_texprctrump_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_texprctrump_get_qualified_type (struct ctrump_type_env *env, struct ctrump_texpr *orig_t, int qual_flags)
 get qualified type
struct ctrump_texprctrump_get_unqualified_type (struct ctrump_texpr *texpr)
 get unqualified type
struct ctrump_texprctrump_get_pointer_type (struct ctrump_type_env *env, struct ctrump_texpr *texpr)
 get pointer type
struct ctrump_texprctrump_get_incomplete_array_type (struct ctrump_type_env *env, struct ctrump_texpr *texpr)
 get incomplete array type
struct ctrump_texprctrump_get_varlen_array_type (struct ctrump_type_env *env, struct ctrump_texpr *texpr)
 get varlen array type
struct ctrump_texprctrump_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_texprctrump_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_texprctrump_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_texprctrump_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_texprctrump_texpr_apply_unary_pointer_conversion (struct ctrump_type_env *env, struct ctrump_texpr *texpr)
 return pointer type
struct ctrump_texprctrump_retrieve_pointer_type (struct ctrump_texpr *t)
 return type of pointed by `type'
struct ctrump_texprctrump_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_texprctrump_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)


Detailed Description

C99 構文木定義.

Definition in file types.c.


Define Documentation

#define DEFINE_BUILTIN_TYPE ( str_name,
code,
sym   )     ctrump_builtin_##str_name.id = id++;

Definition at line 39 of file types.c.

#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,                        \
    };

Definition at line 39 of file types.c.


Function Documentation

static struct ctrump_texpr* alloc_texpr ( struct ctrump_type_env env  )  [static, read]

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 
)

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

Parameters:
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]

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.

Parameters:
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.

Parameters:
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]

void ctrump_get_functype_next ( struct ctrump_type_env env,
struct ctrump_get_functype_iterator iter,
struct ctrump_texpr arg 
)

struct ctrump_texpr* ctrump_get_incomplete_array_type ( struct ctrump_type_env env,
struct ctrump_texpr texpr 
) [read]

get incomplete array type

Parameters:
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]

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

Parameters:
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]

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]

struct ctrump_texpr* ctrump_get_qualified_type ( struct ctrump_type_env env,
struct ctrump_texpr texpr,
int  qual_flags 
) [read]

get qualified type

Parameters:
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

Parameters:
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

Parameters:
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

Parameters:
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  ) 

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'

Parameters:
type pointer or array type
Returns:
pointed type or NULL if type is not pointer

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'

Parameters:
type pointer type
Returns:
pointed type or NULL if type is not pointer

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]

int ctrump_texpr_is_pointer ( struct ctrump_texpr texpr  ) 

void ctrump_type_env_destroy ( struct ctrump_type_env env  ) 

release env resource

Parameters:
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

Parameters:
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  ) 

int ctrump_type_is_scalar ( const struct ctrump_texpr type  ) 


Variable Documentation

型が浮動少数かどうかを示すテーブル (texpr_code -> int)

Definition at line 579 of file types.c.

Referenced by ctrump_type_is_float().

型がスカラ型かどうかを示すテーブル (texpr_code -> int)

Definition at line 611 of file types.c.

Referenced by ctrump_type_is_scalar().


Generated on Tue Mar 31 20:19:24 2009 for ctrump by  doxygen 1.5.6