Studying note of GCC-3.4.6 source (157)
来源:互联网 发布:局域网传输软件 编辑:程序博客网 时间:2024/06/10 18:32
5.13.4.2. Iterate - emitting tinfo
Now all tinfos need code emitted have been chained into unemitted_tinfo_decls,then in finish_fileat line 2628, emit_tinfo_decldetermines whether the tinfo of decl needs be emitted, returns true if so. Belowsee that doing_runtimeis set as 1 in emit_support_tinfoswhich is invoked at line 2571 infinish_filebefore.
Then at pointinvoking class_initializer(emit_tinfo_declàget_pseudo_ti_init), argument trail will be tree in below figure. Note thatVAR_DECL of tinfo of base has been generated with initializers (desc isthe 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 returninit;
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 namefor 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 theNTBS array variable. */
749 tree name_type = build_cplus_array_type
750 (build_qualified_type(char_type_node, TYPE_QUAL_CONST),
751 NULL_TREE);
752 treename_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 nameof the string containing the type's name has a
764 specialname. */
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 sawa definition of this type, so we need to
785 tell thecompiler that this is an exported class, as
786 indeed all ofthe __*_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 topoint 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_declis 1, the function creates the VAR_DECL of vtable for this type of tinfo, andthis VRA_DECL is marked as external, but within which cp_finish_decl does nothing.
Finally, var_initin emit_tinfo_declat line 1452 is the following tree. And var_init will be used as initializer for thistinfo. And at line 1461 inemit_tinfo_decl,declis the VAR_DECL of the tinfo, as we have seen in former section, cp_finish_declhas nothing to do.
If emit_tinfo_decl returnssuccessfully, it means the intermediate tree has been changed, forces toiterate the DO WHILE loop again.
- Studying note of GCC-3.4.6 source (157)
- Studying note of GCC-3.4.6 source (6)
- Studying note of GCC-3.4.6 source (1)
- Studying note of GCC-3.4.6 source (2)
- Studying note of GCC-3.4.6 source (3)
- Studying note of GCC-3.4.6 source (4)
- Studying note of GCC-3.4.6 source (5)
- Studying note of GCC-3.4.6 source (7)
- Studying note of GCC-3.4.6 source (8)
- Studying note of GCC-3.4.6 source (9)
- Studying note of GCC-3.4.6 source (10)
- Studying note of GCC-3.4.6 source (10 cont1)
- Studying note of GCC-3.4.6 source (10 cont2)
- Studying note of GCC-3.4.6 source (10 cont3)
- Studying note of GCC-3.4.6 source (10 cont4)
- Studying note of GCC-3.4.6 source (11)
- Studying note of GCC-3.4.6 source (12)
- Studying note of GCC-3.4.6 source (13)
- JSON2 实例
- 很好很强大!
- vb picturebox 加载网络图片的两种方法,分无缓存加载和有缓存加载
- 数据库系统的模型和结构
- GCC-3.4.6源代码学习笔记(157)
- Studying note of GCC-3.4.6 source (157)
- GCC-3.4.6源代码学习笔记(158)
- Studying note of GCC-3.4.6 source (158)
- GCC-3.4.6源代码学习笔记(159)
- Studying note of GCC-3.4.6 source (159)
- GCC-3.4.6源代码学习笔记(160)
- Studying note of GCC-3.4.6 source (160)
- java中的单实例模式
- printf输出各种格式(转)