Studying note of GCC-3.4.6 source (62)

4.3.1.7.6.            Other C++ components with C linkage
4.3.1.7.6.1.      Part complying standard

Walk tegother with c_common_nodes_and_builtins for a long journey, now we return back to cxx_init_decl_processing. Note that current_lang_name is still lang_name_c, which indicates nodes constructed below are still of C linkage. Nodes created between line 3002~3009 are used in interface between C++ and Java (i.e., extern “Java” …).

 

cxx_init_decl_processing (continue)

 

3002     java_byte_type_node = record_builtin_java_type ("__java_byte", 8);

3003     java_short_type_node = record_builtin_java_type ("__java_short", 16);

3004     java_int_type_node = record_builtin_java_type ("__java_int", 32);

3005     java_long_type_node = record_builtin_java_type ("__java_long", 64);

3006     java_float_type_node = record_builtin_java_type ("__java_float", -32);

3007     java_double_type_node = record_builtin_java_type ("__java_double", -64);

3008     java_char_type_node = record_builtin_java_type ("__java_char", -16);

3009     java_boolean_type_node = record_builtin_java_type ("__java_boolean", -1);

3010  

3011     integer_two_node = build_int_2 (2, 0);

3012     TREE_TYPE (integer_two_node) = integer_type_node;

3013     integer_three_node = build_int_2 (3, 0);

3014     TREE_TYPE (integer_three_node) = integer_type_node;

3015  

3016     record_builtin_type (RID_BOOL, "bool", boolean_type_node);

3017     truthvalue_type_node = boolean_type_node;

3018     truthvalue_false_node = boolean_false_node;

3019     truthvalue_true_node = boolean_true_node;

3020  

3021     empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);

3022  

3023   #if 0

3024     record_builtin_type (RID_MAX, NULL, string_type_node);

3025   #endif

3026  

3027     delta_type_node = ptrdiff_type_node;

3028     vtable_index_type = ptrdiff_type_node;

3029  

3030     vtt_parm_type = build_pointer_type (const_ptr_type_node);

3031     void_ftype = build_function_type (void_type_node, void_list_node);

3032     void_ftype_ptr = build_function_type (void_type_node,

3033                                    tree_cons (NULL_TREE,

3034                                             ptr_type_node,

3035                                             void_list_node));

3036     void_ftype_ptr

3037       = build_exception_variant (void_ftype_ptr, empty_except_spec);

 

At line 3016, boolean_type_node is pushed into the global namespace, and boolean_*_node already defined in global_tree. Then it uses these nodes to define truthvalue_type_node, truthvalue_false_node and truthvalue_true_node in c_global_trees, which are the boolean type and value really used by the compiler. The benefit of doing so is that different language can appoint its boolean type and value. As an example, in C, boolean is of type int (i.e, integer_type_node), and its values are integer_one_node and integer_zero_node.

At line 3028, vtable_index_type is the type used for index into vtable in class. vtt_parm_type is used for VTT (virtual table table) which is required if a class has virtual bases, it is type is const void**. While void_ftype claims as “void(*)(void)”, and void_ftype_ptr at line 3032 as “void(*)(void*)”. Further, at line 3036 the finial type of void_ftype_ptr is “void(*)(void*) throw()”, which is created by build_exception_variant.

 

973    tree

974    build_exception_variant (tree type, tree raises)                                                   in tree.c

975    {

976      tree v = TYPE_MAIN_VARIANT (type);

977      int type_quals = TYPE_QUALS (type);

978   

979      for (; v; v = TYPE_NEXT_VARIANT (v))

980        if (TYPE_QUALS (v) == type_quals

981             && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (v), 1)

982           && (*targetm.comp_type_attributes) (type, v))

983          return v;

984   

985      /* Need to build a new variant.  */

986      v = build_type_copy (type);

987      TYPE_RAISES_EXCEPTIONS (v) = raises;

988      return v;

989    }

4.3.1.7.6.2.      Part of externsion

This part of preparation is: push node for unknown_type, node for vtable entry type, node for vtable type into global namespace; push namespace __cxxabiv1 into global namespace; at last pushes global_type_node into global namespace. See that __cxxabiv1 mentions C++ ABI version 1. In wikipedia, the definition of ABI is:

In computer software, an application binary interface (ABI) describes the low-level interface between an application (or any type of) program and the operating system or another application.

ABIs cover details such as data type, size, and alignment; the calling convention, which controls how functions' arguments are passed and return values retrieved; the system call numbers and how an application should make system calls to the operating system; and in the case of a complete operating system ABI, the binary format of object files, program libraries and so on. A complete ABI, such as the Intel Binary Compatibility Standard (iBCS),[1] allows a program from one operating system supporting that ABI to run without modifications on any other such system, provided that necessary shared libraries are present, and similar prerequisites are fulfilled.

Other ABIs standardize details such as the C++ name mangling,[2] exception propagation,[3] and calling convention between compilers on the same platform, but do not require cross-platform compatibility.

An ABI should not be confused with an application programming interface (API) which defines a library of routines to call, data structures to manipulate, and/or object classes to use in the construction of an application using that particular (often language specific) API.

 

cxx_init_decl_processing (continue)

 

3039     /* C++ extensions */

3040  

3041     unknown_type_node = make_node (UNKNOWN_TYPE);

3042     record_unknown_type (unknown_type_node, "unknown type");

3043  

3044     /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node.  */

3045     TREE_TYPE (unknown_type_node) = unknown_type_node;

3046  

3047     /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same

3048        result.  */

3049     TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;

3050     TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;

3051  

3052     {

3053       /* Make sure we get a unique function type, so we can give

3054          its pointer type a name.  (This wins for gdb.) */

3055       tree vfunc_type = make_node (FUNCTION_TYPE);

3056       TREE_TYPE (vfunc_type) = integer_type_node;

3057       TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;

3058       layout_type (vfunc_type);

3059  

3060       vtable_entry_type = build_pointer_type (vfunc_type);

3061     }

3062     record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);

3063  

3064     vtbl_type_node

3065       = build_cplus_array_type (vtable_entry_type, NULL_TREE);

3066     layout_type (vtbl_type_node);

3067     vtbl_type_node = build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);

3068     record_builtin_type (RID_MAX, NULL, vtbl_type_node);

3069     vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);

3070     layout_type (vtbl_ptr_type_node);

3071     record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);

3072  

3073     push_namespace (get_identifier ("__cxxabiv1"));

3074     abi_node = current_namespace;

3075     pop_namespace ();

3076  

3077     global_type_node = make_node (LANG_TYPE);

3078     record_unknown_type (global_type_node, "global type");

 

In above code, UNKNOWN_TYPE is the alias of LANG_TYPE which is a language-specific kind of type. Its meaning is defined by the language front end. layout_type does not know how to lay this out, so the front-end must do so manually. They are pushed into the current namespace by record_unknown_type.

 

2872   static void

2873   record_unknown_type (tree type, const char* name)                                           in decl.c

2874   {

2875     tree decl = pushdecl (build_decl (TYPE_DECL, get_identifier (name), type));

2876     /* Make sure the "unknown type" typedecl gets ignored for debug info.  */

2877     DECL_IGNORED_P (decl) = 1;

2878     TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;

2879     TYPE_SIZE (type) = TYPE_SIZE (void_type_node);

2880     TYPE_ALIGN (type) = 1;

2881     TYPE_USER_ALIGN (type) = 0;

2882     TYPE_MODE (type) = TYPE_MODE (void_type_node);

2883   }

 

Here pay attention to the type of vtable_entry_type, it is pointer to the function type returns integer and takes no argument. However it’s form is trivial, because it is used just to indicate the special type of entry of vtable. Also similar is vtbl_type_node’s purpose.

 

你可能感兴趣的:(java,exception,tree,Integer,application,Build)