⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gxxint.texi

📁 gcc-2.95.3 Linux下最常用的C编译器
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
\input texinfo  @c -*-texinfo-*-@c %**start of header @setfilename g++int.info@settitle G++ internals@setchapternewpage odd@c %**end of header     @node Top, Limitations of g++, (dir), (dir)@chapter Internal Architecture of the CompilerThis is meant to describe the C++ front-end for gcc in detail.Questions and comments to Benjamin Kosnik @code{<bkoz@@cygnus.com>}.@menu* Limitations of g++::          * Routines::                    * Implementation Specifics::    * Glossary::                    * Macros::                      * Typical Behavior::            * Coding Conventions::          * Templates::                   * Access Control::              * Error Reporting::             * Parser::                      * Exception Handling::          * Free Store::                  * Mangling::  Function name mangling for C++ and Java* Vtables:: Two ways to do virtual functions* Concept Index::               @end menu@node Limitations of g++, Routines, Top, Top@section Limitations of g++@itemize @bullet@itemLimitations on input source code: 240 nesting levels with the parserstacksize (YYSTACKSIZE) set to 500 (the default), and requires around16.4k swap space per nesting level.  The parser needs about 2.09 *number of nesting levels worth of stackspace.@cindex pushdecl_class_level@itemI suspect there are other uses of pushdecl_class_level that do not callset_identifier_type_value in tandem with the call topushdecl_class_level.  It would seem to be an omission.@cindex access checking@itemAccess checking is unimplemented for nested types.@cindex @code{volatile}@item@code{volatile} is not implemented in general.@end itemize@node Routines, Implementation Specifics, Limitations of g++, Top@section RoutinesThis section describes some of the routines used in the C++ front-end.@code{build_vtable} and @code{prepare_fresh_vtable} is used only withinthe @file{cp-class.c} file, and only in @code{finish_struct} and@code{modify_vtable_entries}.@code{build_vtable}, @code{prepare_fresh_vtable}, and@code{finish_struct} are the only routines that set @code{DECL_VPARENT}.@code{finish_struct} can steal the virtual function table from parents,this prohibits related_vslot from working.  When finish_struct steals,we know that@exampleget_binfo (DECL_FIELD_CONTEXT (CLASSTYPE_VFIELD (t)), t, 0)@end example@noindentwill get the related binfo.@code{layout_basetypes} does something with the VIRTUALS.Supposedly (according to Tiemann) most of the breadth first searchingdone, like in @code{get_base_distance} and in @code{get_binfo} was notbecause of any design decision.  I have since found out the at least onepart of the compiler needs the notion of depth first binfo searching, Iam going to try and convert the whole thing, it should just work.  Theterm left-most refers to the depth first left-most node.  It uses@code{MAIN_VARIANT == type} as the condition to get left-most, becausethe things that have @code{BINFO_OFFSET}s of zero are shared and willhave themselves as their own @code{MAIN_VARIANT}s.  The non-shared rightones, are copies of the left-most one, hence if it is its own@code{MAIN_VARIANT}, we know it IS a left-most one, if it is not, it isa non-left-most one.@code{get_base_distance}'s path and distance matters in its use in:@itemize @bullet@item@code{prepare_fresh_vtable} (the code is probably wrong)@item@code{init_vfields} Depends upon distance probably in a safe way,build_offset_ref might use partial paths to do further lookups,hack_identifier is probably not properly checking access.@item@code{get_first_matching_virtual} probably should check for@code{get_base_distance} returning -2.@item@code{resolve_offset_ref} should be called in a more deterministicmanner.  Right now, it is called in some random contexts, like forarguments at @code{build_method_call} time, @code{default_conversion}time, @code{convert_arguments} time, @code{build_unary_op} time,@code{build_c_cast} time, @code{build_modify_expr} time,@code{convert_for_assignment} time, and@code{convert_for_initialization} time.But, there are still more contexts it needs to be called in, one was theever simple:@exampleif (obj.*pmi != 7)   @dots{}@end exampleSeems that the problems were due to the fact that @code{TREE_TYPE} ofthe @code{OFFSET_REF} was not a @code{OFFSET_TYPE}, but rather the typeof the referent (like @code{INTEGER_TYPE}).  This problem was fixed bychanging @code{default_conversion} to check @code{TREE_CODE (x)},instead of only checking @code{TREE_CODE (TREE_TYPE (x))} to see if itwas @code{OFFSET_TYPE}.@end itemize@node Implementation Specifics, Glossary, Routines, Top@section Implementation Specifics@itemize @bullet@item Explicit InitializationThe global list @code{current_member_init_list} contains the list ofmem-initializers specified in a constructor declaration.  For example:@examplefoo::foo() : a(1), b(2) @{@}@end example@noindentwill initialize @samp{a} with 1 and @samp{b} with 2.@code{expand_member_init} places each initialization (a with 1) on theglobal list.  Then, when the fndecl is being processed,@code{emit_base_init} runs down the list, initializing them.  It used tobe the case that g++ first ran down @code{current_member_init_list},then ran down the list of members initializing the ones that weren'texplicitly initialized.  Things were rewritten to perform theinitializations in order of declaration in the class.  So, for the aboveexample, @samp{a} and @samp{b} will be initialized in the order thatthey were declared:@exampleclass foo @{ public: int b; int a; foo (); @};@end example@noindentThus, @samp{b} will be initialized with 2 first, then @samp{a} will beinitialized with 1, regardless of how they're listed in the mem-initializer.@item The Explicit KeywordThe use of @code{explicit} on a constructor is used by @code{grokdeclarator}to set the field @code{DECL_NONCONVERTING_P}.  That value is used by@code{build_method_call} and @code{build_user_type_conversion_1} to decideif a particular constructor should be used as a candidate for conversions.@end itemize@node Glossary, Macros, Implementation Specifics, Top@section Glossary@table @r@item binfoThe main data structure in the compiler used to represent theinheritance relationships between classes.  The data in the binfo can beaccessed by the BINFO_ accessor macros.@item vtable@itemx virtual function tableThe virtual function table holds information used in virtual functiondispatching.  In the compiler, they are usually referred to as vtables,or vtbls.  The first index is not used in the normal way, I believe itis probably used for the virtual destructor. There are two forms ofvirtual tables, one that has offsets in addition to pointers, and oneusing thunks. @xref{Vtables}.@item vfieldvfields can be thought of as the base information needed to buildvtables.  For every vtable that exists for a class, there is a vfield.See also vtable and virtual function table pointer.  When a type is usedas a base class to another type, the virtual function table for thederived class can be based upon the vtable for the base class, justextended to include the additional virtual methods declared in thederived class.  The virtual function table from a virtual base class isnever reused in a derived class.  @code{is_normal} depends upon this.@item virtual function table pointerThese are @code{FIELD_DECL}s that are pointer types that point tovtables.  See also vtable and vfield.@end table@node Macros, Typical Behavior, Glossary, Top@section MacrosThis section describes some of the macros used on trees.  The listshould be alphabetical.  Eventually all macros should be documentedhere.@table @code@item BINFO_BASETYPESA vector of additional binfos for the types inherited by this basetype.The binfos are fully unshared (except for virtual bases, in whichcase the binfo structure is shared).   If this basetype describes type D as inherited in C,   and if the basetypes of D are E anf F,   then this vector contains binfos for inheritance of E and F by C.Has values of:	TREE_VECs@item BINFO_INHERITANCE_CHAINTemporarily used to represent specific inheritances.  It usually pointsto the binfo associated with the lesser derived type, but it can bereversed by reverse_path.  For example:@example	Z ZbY	least derived	|	Y YbX	|	X Xb	most derivedTYPE_BINFO (X) == XbBINFO_INHERITANCE_CHAIN (Xb) == YbXBINFO_INHERITANCE_CHAIN (Yb) == ZbYBINFO_INHERITANCE_CHAIN (Zb) == 0@end exampleNot sure is the above is really true, get_base_distance has is pointtowards the most derived type, opposite from above.Set by build_vbase_path, recursive_bounded_basetype_p,get_base_distance, lookup_field, lookup_fnfields, and reverse_path.What things can this be used on:	TREE_VECs that are binfos@item BINFO_OFFSETThe offset where this basetype appears in its containing type.BINFO_OFFSET slot holds the offset (in bytes) from the base of thecomplete object to the base of the part of the object that is allocatedon behalf of this `type'.  This is always 0 except when there ismultiple inheritance.Used on TREE_VEC_ELTs of the binfos BINFO_BASETYPES (...) for example.@item BINFO_VIRTUALSA unique list of functions for the virtual function table.  See alsoTYPE_BINFO_VIRTUALS.What things can this be used on:	TREE_VECs that are binfos@item BINFO_VTABLEUsed to find the VAR_DECL that is the virtual function table associatedwith this binfo.  See also TYPE_BINFO_VTABLE.  To get the virtualfunction table pointer, see CLASSTYPE_VFIELD.What things can this be used on:	TREE_VECs that are binfosHas values of:	VAR_DECLs that are virtual function tables@item BLOCK_SUPERCONTEXTIn the outermost scope of each function, it points to the FUNCTION_DECLnode.  It aids in better DWARF support of inline functions.@item CLASSTYPE_TAGSCLASSTYPE_TAGS is a linked (via TREE_CHAIN) list of member classes of aclass. TREE_PURPOSE is the name, TREE_VALUE is the type (pushclass scansthese and calls pushtag on them.)finish_struct scans these to produce TYPE_DECLs to add to theTYPE_FIELDS of the type.It is expected that name found in the TREE_PURPOSE slot is unique,resolve_scope_to_name is one such place that depends upon thisuniqueness.@item CLASSTYPE_METHOD_VECThe following is true after finish_struct has been called (on theclass?) but not before.  Before finish_struct is called, things aredifferent to some extent.  Contains a TREE_VEC of methods of the class.The TREE_VEC_LENGTH is the number of differently named methods plus onefor the 0th entry.  The 0th entry is always allocated, and reserved forctors and dtors.  If there are none, TREE_VEC_ELT(N,0) == NULL_TREE.Each entry of the TREE_VEC is a FUNCTION_DECL.  For each FUNCTION_DECL,there is a DECL_CHAIN slot.  If the FUNCTION_DECL is the last one with agiven name, the DECL_CHAIN slot is NULL_TREE.  Otherwise it is the nextmethod that has the same name (but a different signature).  It wouldseem that it is not true that because the DECL_CHAIN slot is used inthis way, we cannot call pushdecl to put the method in the global scope(cause that would overwrite the TREE_CHAIN slot), because they usedifferent _CHAINs.  finish_struct_methods setups up one version of theTREE_CHAIN slots on the FUNCTION_DECLs.friends are kept in TREE_LISTs, so that there's no need to use theirTREE_CHAIN slot for anything.Has values of:	TREE_VECs	@item CLASSTYPE_VFIELDSeems to be in the process of being renamed TYPE_VFIELD.  Use on typesto get the main virtual function table pointer.  To get the virtualfunction table use BINFO_VTABLE (TYPE_BINFO ()).Has values of:	FIELD_DECLs that are virtual function table pointersWhat things can this be used on:	RECORD_TYPEs@item DECL_CLASS_CONTEXTIdentifies the context that the _DECL was found in.  For virtual functiontables, it points to the type associated with the virtual functiontable.  See also DECL_CONTEXT, DECL_FIELD_CONTEXT and DECL_FCONTEXT.The difference between this and DECL_CONTEXT, is that for virtualsfunctions like:@examplestruct A@{  virtual int f ();@};struct B : A@{  int f ();@};DECL_CONTEXT (A::f) == ADECL_CLASS_CONTEXT (A::f) == A

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -