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

📄 gxxint.texi

📁 gcc库的原代码,对编程有很大帮助.
💻 TEXI
📖 第 1 页 / 共 4 页
字号:
\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 mrs@@cygnus.com.@menu* Limitations of g++::          * Routines::                    * Implementation Specifics::    * Glossary::                    * Macros::                      * Typical Behavior::            * Coding Conventions::          * Templates::                   * Access Control::              * Error Reporting::             * Parser::                      * Copying Objects::             * Exception Handling::          * Free Store::                  * 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.@cindex pointers to members@itemPointers to members are only minimally supported, and there are placeswhere the grammar doesn't even properly accept them yet.@cindex multiple inheritance@item@code{this} will be wrong in virtual members functions defined in avirtual base class, when they are overridden in a derived class, whencalled via a non-left most object.An example would be:@exampleextern "C" int printf(const char*, ...);struct A @{ virtual void f() @{ @} @};struct B : virtual A @{ int b; B() : b(0) @{@} void f() @{ b++; @} @};struct C : B @{@};struct D : B @{@};struct E : C, D @{@};int main()@{  E e;  C& c = e; D& d = e;  c.f(); d.f();  printf ("C::b = %d, D::b = %d\n", e.C::b, e.D::b);  return 0;@}@end exampleThis will print out 2, 0, instead of 1,1.@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 Argument MatchingIn early 1993, the argument matching scheme in @sc{gnu} C++ changedsignificantly.  The original code was completely replaced with a newmethod that will, hopefully, be easier to understand and make fixingspecific cases much easier.The @samp{-fansi-overloading} option is used to enable the new code; atsome point in the future, it will become the default behavior of thecompiler.The file @file{cp-call.c} contains all of the new work, in the functions@code{rank_for_overload}, @code{compute_harshness},@code{compute_conversion_costs}, and @code{ideal_candidate}.Instead of using obscure numerical values, the quality of an argumentmatch is now represented by clear, individual codes.  The new datastructure @code{struct harshness} (it used to be an @code{unsigned}number) contains:@enumerate a@item the @samp{code} field, to signify what was involved in matching twoarguments;@item the @samp{distance} field, used in situations where inheritancedecides which function should be called (one is ``closer'' thananother);@item and the @samp{int_penalty} field, used by some codes as a tie-breaker.@end enumerateThe @samp{code} field is a number with a given bit set for each type ofcode, OR'd together.  The new codes are:@itemize @bullet@item @code{EVIL_CODE}The argument was not a permissible match.@item @code{CONST_CODE}Currently, this is only used by @code{compute_conversion_costs}, todistinguish when a non-@code{const} member function is called from a@code{const} member function.@item @code{ELLIPSIS_CODE}A match against an ellipsis @samp{...} is considered worse than all others.@item @code{USER_CODE}Used for a match involving a user-defined conversion.@item @code{STD_CODE}A match involving a standard conversion.@item @code{PROMO_CODE}A match involving an integral promotion.  For these, the@code{int_penalty} field is used to handle the ARM's rule (XXX cite)that a smaller @code{unsigned} type should promote to a @code{int}, notto an @code{unsigned int}.@item @code{QUAL_CODE}Used to mark use of qualifiers like @code{const} and @code{volatile}.@item @code{TRIVIAL_CODE}Used for trivial conversions.  The @samp{int_penalty} field is used by@code{convert_harshness} to communicate further penalty information backto @code{build_overload_call_real} when deciding which function shouldbe call.@end itemizeThe functions @code{convert_to_aggr} and @code{build_method_call} use@code{compute_conversion_costs} to rate each argument's suitability fora given candidate function (that's how we get the list of candidates for@code{ideal_candidate}).@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.@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.  There are some postscript drawings that can be used to betterunderstand from of the more complex data structures, contact Mike Stump(@code{mrs@@cygnus.com}) for information about them.@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.

⌨️ 快捷键说明

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