Studying note of GCC-3.4.6 source (157)

    技术2025-02-26  40

    5.13.4.2.              Iterate - emitting tinfo

    Now all tinfos need code emitted have been chained into unemitted_tinfo_decls , then in finish_file at line 2628, emit_tinfo_decl determines whether the tinfo of decl needs be emitted, returns true if so. Below see that doing_runtime is set as 1 in emit_support_tinfos which is invoked at line 2571 in finish_file before.

    Then at point invoking class_initializer (emit_tinfo_decl à get_pseudo_ti_init ), argument trail will be tree in below figure. Note that VAR_DECL of tinfo of base has been generated with initializers (desc is the corresponding VAR_DECL for tinfo of current class).

     

    951    static tree

    952    class_initializer (tree desc, tree target, tree trail)                                                  in rtti.c

    953    {

    954      tree init = tinfo_base_init (desc, target);

    955     

    956      TREE_CHAIN (init) = trail;

    957      init = build_constructor (NULL_TREE, init);

    958      TREE_HAS_CONSTRUCTOR (init) = TREE_CONSTANT (init) = TREE_STATIC (init) = 1;

    959      return init; 

    960    }

     

    See that in class type_info, there is a “const char *” field name , block beginning at line 745 generates initializing code and the mangled name for this field.

     

    738    static tree

    739    tinfo_base_init (tree desc, tree target)                                                                in rtti.c

    740    {

    741      tree init = NULL_TREE;

    742      tree name_decl;

    743      tree vtable_ptr;

    744     

    745      {

    746        tree name_name;

    747       

    748        /* Generate the NTBS array variable.  */

    749        tree name_type = build_cplus_array_type

    750                       (build_qualified_type (char_type_node, TYPE_QUAL_CONST),

    751                        NULL_TREE);

    752         tree name_string = tinfo_name (target);

    753   

    754        name_name = mangle_typeinfo_string_for_type (target);

    755        name_decl = build_lang_decl (VAR_DECL, name_name, name_type);

    756       

    757        DECL_ARTIFICIAL (name_decl) = 1;

    758        TREE_READONLY (name_decl) = 1;

    759        TREE_STATIC (name_decl) = 1;

    760        DECL_EXTERNAL (name_decl) = 0;

    761        TREE_PUBLIC (name_decl) = 1;

    762        import_export_tinfo (name_decl, target, typeinfo_in_lib_p (target));

    763        /* External name of the string containing the type's name has a

    764          special name.  */

    765        SET_DECL_ASSEMBLER_NAME (name_decl,

    766                                       mangle_typeinfo_string_for_type (target));

    767        DECL_INITIAL (name_decl) = name_string;

    768        mark_used (name_decl);

    769        pushdecl_top_level_and_finish (name_decl, name_string);

    770      }

    771   

    772      vtable_ptr = TINFO_VTABLE_DECL (desc);

    773      if (!vtable_ptr)

    774      {

    775        tree real_type;

    776     

    777        push_nested_namespace (abi_node);

    778        real_type = xref_tag (class_type, TINFO_REAL_NAME (desc),

    779                          true, false);

    780        pop_nested_namespace (abi_node);

    781     

    782        if (!COMPLETE_TYPE_P (real_type))

    783        {

    784          /* We never saw a definition of this type, so we need to

    785            tell the compiler that this is an exported class, as

    786            indeed all of the __*_type_info classes are.  */

    787          SET_CLASSTYPE_INTERFACE_KNOWN (real_type);

    788          CLASSTYPE_INTERFACE_ONLY (real_type) = 1;

    789        }

    790   

    791        vtable_ptr = get_vtable_decl (real_type, /*complete=*/ 1);

    792        vtable_ptr = build_unary_op (ADDR_EXPR, vtable_ptr, 0);

    793   

    794        /* We need to point into the middle of the vtable.  */

    795        vtable_ptr = build

    796                   (PLUS_EXPR, TREE_TYPE (vtable_ptr), vtable_ptr,

    797                    size_binop (MULT_EXPR,

    798                        size_int (2 * TARGET_VTABLE_DATA_ENTRY_DISTANCE),

    799                        TYPE_SIZE_UNIT (vtable_entry_type )));

    800        TREE_CONSTANT (vtable_ptr) = 1;

    801   

    802        TINFO_VTABLE_DECL (desc) = vtable_ptr;

    803      }

    804   

    805      init = tree_cons (NULL_TREE, vtable_ptr, init);

    806     

    807      init = tree_cons (NULL_TREE, decay_conversion (name_decl), init);

    808     

    809      init = build_constructor (NULL_TREE, nreverse (init));

    810      TREE_HAS_CONSTRUCTOR (init) = TREE_CONSTANT (init) = TREE_STATIC (init) = 1;

    811       init = tree_cons (NULL_TREE, init, NULL_TREE);

    812     

    813      return init;

    814    }

     

    Notice that above at line 791, the last argument of get_vtable_decl is 1, the function creates the VAR_DECL of vtable for this type of tinfo, and this VRA_DECL is marked as external, but within which cp_finish_decl does nothing.

    Finally, var_init in emit_tinfo_decl at line 1452 is the following tree. And var_init will be used as initializer for this tinfo. And at line 1461 in emit_tinfo_decl , decl is the VAR_DECL of the tinfo, as we have seen in former section, cp_finish_decl has nothing to do.

    If emit_tinfo_decl returns successfully, it means the intermediate tree has been changed, forces to iterate the DO WHILE loop again.

    最新回复(0)