在gcc中,几乎所有的东西都是用树结构串起来的,从而形成所谓的general tree。tree可以看作是指向树节点的指针,所有的树节点都有一个共同的基类:tree_common。
在文件coretypes.h中,tree的定义如下:
#ifndef USED_FOR_TARGET
...
typedef union tree_node *tree;
...
#else
...
#define tree union _dont_use_tree_here_ *
...
#endif
可见,当USED_FOR_TARGET宏未被定义的时候,tree是指向联合类型tree_node的指针类型;否则,tree是一个定义为union _dont_use_tree_here_ *的宏。
在tree.h中,可以找到union tree_node的定义:
union tree_node
{
struct tree_common common;
struct tree_int_cst int_cst;
struct tree_real_cst real_cst;
struct tree_vector vector;
struct tree_string string;
struct tree_complex complex;
struct tree_identifier identifier;
struct tree_decl_minimal decl_minimal;
struct tree_decl_common decl_common;
struct tree_decl_with_rtl decl_with_rtl;
struct tree_decl_non_common decl_non_common;
struct tree_parm_decl parm_decl;
struct tree_decl_with_vis decl_with_vis;
struct tree_var_decl var_decl;
struct tree_field_decl field_decl;
struct tree_label_decl label_decl;
struct tree_result_decl result_decl;
struct tree_const_decl const_decl;
struct tree_type_decl type_decl;
struct tree_function_decl function_decl;
struct tree_type type;
struct tree_list list;
struct tree_vec vec;
struct tree_exp exp;
struct tree_ssa_name ssa_name;
struct tree_phi_node phi;
struct tree_block block;
struct tree_binfo binfo;
struct tree_statement_list stmt_list;
struct tree_value_handle value_handle;
struct tree_constructor constructor;
struct tree_memory_tag mtag;
struct tree_struct_field_tag sft;
struct tree_omp_clause omp_clause;
};
同样,tree_common的定义也在tree.h中:
struct tree_common
{
tree chain;
tree type;
union tree_ann_d *ann;
ENUM_BITFIELD(tree_code) code : 8;
unsigned side_effects_flag : 1;
unsigned constant_flag : 1;
unsigned addressable_flag : 1;
unsigned volatile_flag : 1;
unsigned readonly_flag : 1;
unsigned unsigned_flag : 1;
unsigned asm_written_flag: 1;
unsigned nowarning_flag : 1;
unsigned used_flag : 1;
unsigned nothrow_flag : 1;
unsigned static_flag : 1;
unsigned public_flag : 1;
unsigned private_flag : 1;
unsigned protected_flag : 1;
unsigned deprecated_flag : 1;
unsigned invariant_flag : 1;
unsigned lang_flag_0 : 1;
unsigned lang_flag_1 : 1;
unsigned lang_flag_2 : 1;
unsigned lang_flag_3 : 1;
unsigned lang_flag_4 : 1;
unsigned lang_flag_5 : 1;
unsigned lang_flag_6 : 1;
unsigned visited : 1;
};