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

📄 gxxint.texi

📁 gcc-2.95.3 Linux下最常用的C编译器
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
get_binfo (VF_BASETYPE_VALUE (vfield), t, 0)@end example@noindentwhere @samp{t} is the type that has the given vfield.@exampleget_binfo (VF_BASETYPE_VALUE (vfield), t, 0)@end example@noindentwill return the binfo for the given vfield.May or may not be set at @code{modify_vtable_entries} time.  Set at@code{finish_base_struct} time.What things can this be used on:	TREE_LISTs that are vfields@item VF_DERIVED_VALUEIdentifies the type of the most derived class of the vfield, excludingthe class this vfield is for.Set at @code{finish_base_struct} time.What things can this be used on:	TREE_LISTs that are vfields@item VF_NORMAL_VALUEIdentifies the type of the most derived class of the vfield, includingthe class this vfield is for.Set at @code{finish_base_struct} time.What things can this be used on:	TREE_LISTs that are vfields@item WRITABLE_VTABLESThis is a option that can be defined when building the compiler, thatwill cause the compiler to output vtables into the data segment so thatthe vtables maybe written.  This is undefined by default, becausenormally the vtables should be unwritable.  People that implement objectI/O facilities may, or people that want to change the dynamic type ofobjects may want to have the vtables writable.  Another way of achievingthis would be to make a copy of the vtable into writable memory, but thedrawback there is that that method only changes the type for one object.@end table@node Typical Behavior, Coding Conventions, Macros, Top@section Typical Behavior@cindex parse errorsWhenever seemingly normal code fails with errors like@code{syntax error at `\@{'}, it's highly likely that grokdeclarator isreturning a NULL_TREE for whatever reason.@node Coding Conventions, Templates, Typical Behavior, Top@section Coding ConventionsIt should never be that case that trees are modified in-place by theback-end, @emph{unless} it is guaranteed that the semantics are the sameno matter how shared the tree structure is.  @file{fold-const.c} stillhas some cases where this is not true, but rms hypothesizes that thiswill never be a problem.@node Templates, Access Control, Coding Conventions, Top@section TemplatesA template is represented by a @code{TEMPLATE_DECL}.  The specificfields used are:@table @code@item DECL_TEMPLATE_RESULTThe generic decl on which instantiations are based.  This looks justlike any other decl.@item DECL_TEMPLATE_PARMSThe parameters to this template.@end tableThe generic decl is parsed as much like any other decl as possible,given the parameterization.  The template decl is not built up until thegeneric decl has been completed.  For template classes, a template declis generated for each member function and static data member, as well.Template members of template classes are represented by a TEMPLATE_DECLfor the class' parameters around another TEMPLATE_DECL for the member'sparameters.All declarations that are instantiations or specializations of templatesrefer to their template and parameters through DECL_TEMPLATE_INFO.How should I handle parsing member functions with the proper paramdecls?  Set them up again or try to use the same ones?  Currently we dothe former.  We can probably do this without any extra machinery instore_pending_inline, by deducing the parameters from the decl indo_pending_inlines.  PRE_PARSED_TEMPLATE_DECL?If a base is a parm, we can't check anything about it.  If a base is nota parm, we need to check it for name binding.  Do finish_base_struct ifno bases are parameterized (only if none, including indirect, areparms).  Nah, don't bother trying to do any of this until instantiation-- we only need to do name binding in advance.Always set up method vec and fields, inc. synthesized methods.  Really?We can't know the types of the copy folks, or whether we need adestructor, or can have a default ctor, until we know our bases andfields.  Otherwise, we can assume and fix ourselves later.  Hopefully.@node Access Control, Error Reporting, Templates, Top@section Access ControlThe function compute_access returns one of three values:@table @code@item access_publicmeans that the field can be accessed by the current lexical scope.@item access_protectedmeans that the field cannot be accessed by the current lexical scopebecause it is protected.@item access_privatemeans that the field cannot be accessed by the current lexical scopebecause it is private.@end tableDECL_ACCESS is used for access declarations; alter_access creates a listof types and accesses for a given decl.Formerly, DECL_@{PUBLIC,PROTECTED,PRIVATE@} corresponded to the returncodes of compute_access and were used as a cache for compute_access.Now they are not used at all.TREE_PROTECTED and TREE_PRIVATE are used to record the access levelsgranted by the containing class.  BEWARE: TREE_PUBLIC means somethingcompletely unrelated to access control!@node Error Reporting, Parser, Access Control, Top@section Error ReportingThe C++ front-end uses a call-back mechanism to allow functions to printout reasonable strings for types and functions without putting extralogic in the functions where errors are found.  The interface is throughthe @code{cp_error} function (or @code{cp_warning}, etc.).  Thesyntax is exactly like that of @code{error}, except that a few moreconversions are supported:@itemize @bullet@item%C indicates a value of `enum tree_code'.@item%D indicates a *_DECL node.@item%E indicates a *_EXPR node.@item%L indicates a value of `enum languages'.@item%P indicates the name of a parameter (i.e. "this", "1", "2", ...)@item%T indicates a *_TYPE node.@item%O indicates the name of an operator (MODIFY_EXPR -> "operator =").@end itemizeThere is some overlap between these; for instance, any of the nodeoptions can be used for printing an identifier (though only @code{%D}tries to decipher function names).For a more verbose message (@code{class foo} as opposed to just @code{foo},including the return type for functions), use @code{%#c}.To have the line number on the error message indicate the line of theDECL, use @code{cp_error_at} and its ilk; to indicate which argument you want,use @code{%+D}, or it will default to the first.@node Parser, Exception Handling, Error Reporting, Top@section ParserSome comments on the parser:The @code{after_type_declarator} / @code{notype_declarator} hack isnecessary in order to allow redeclarations of @code{TYPENAME}s, forinstance@exampletypedef int foo;class A @{  char *foo;@};@end exampleIn the above, the first @code{foo} is parsed as a @code{notype_declarator},and the second as a @code{after_type_declarator}.Ambiguities:There are currently four reduce/reduce ambiguities in the parser.  They are:1) Between @code{template_parm} and@code{named_class_head_sans_basetype}, for the tokens @code{aggridentifier}.  This situation occurs in code looking like@exampletemplate <class T> class A @{ @};@end exampleIt is ambiguous whether @code{class T} should be parsed as thedeclaration of a template type parameter named @code{T} or an unnamedconstant parameter of type @code{class T}.  Section 14.6, paragraph 3 ofthe January '94 working paper states that the first interpretation isthe correct one.  This ambiguity results in two reduce/reduce conflicts.2) Between @code{primary} and @code{type_id} for code like @samp{int()}in places where both can be accepted, such as the argument to@code{sizeof}.  Section 8.1 of the pre-San Diego working paper specifiesthat these ambiguous constructs will be interpreted as @code{typename}s.This ambiguity results in six reduce/reduce conflicts between@samp{absdcl} and @samp{functional_cast}.3) Between @code{functional_cast} and@code{complex_direct_notype_declarator}, for various token strings.This situation occurs in code looking like@exampleint (*a);@end exampleThis code is ambiguous; it could be a declaration of the variable@samp{a} as a pointer to @samp{int}, or it could be a functional cast of@samp{*a} to @samp{int}.  Section 6.8 specifies that the formerinterpretation is correct.  This ambiguity results in 7 reduce/reduceconflicts.  Another aspect of this ambiguity is code like 'int (x[2]);',which is resolved at the '[' and accounts for 6 reduce/reduce conflictsbetween @samp{direct_notype_declarator} and@samp{primary}/@samp{overqualified_id}.  Finally, there are 4 r/rconflicts between @samp{expr_or_declarator} and @samp{primary} over codelike 'int (a);', which could probably be resolved but would alsoprobably be more trouble than it's worth.  In all, this situationaccounts for 17 conflicts.  Ack!The second case above is responsible for the failure to parse 'LinppFileppfile (String (argv[1]), &outs, argc, argv);' (from Rogue WaveMath.h++) as an object declaration, and must be fixed so that it doesnot resolve until later.4) Indirectly between @code{after_type_declarator} and @code{parm}, fortype names.  This occurs in (as one example) code like@exampletypedef int foo, bar;class A @{  foo (bar);@};@end exampleWhat is @code{bar} inside the class definition?  We currently interpretit as a @code{parm}, as does Cfront, but IBM xlC interprets it as an@code{after_type_declarator}.  I believe that xlC is correct, in lightof 7.1p2, which says "The longest sequence of @i{decl-specifiers} thatcould possibly be a type name is taken as the @i{decl-specifier-seq} ofa @i{declaration}."  However, it seems clear that this rule must beviolated in the case of constructors.  This ambiguity accounts for 8conflicts.Unlike the others, this ambiguity is not recognized by the Working Paper.@node  Exception Handling, Free Store, Parser, Top@section Exception HandlingNote, exception handling in g++ is still under development.  This section describes the mapping of C++ exceptions in the C++front-end, into the back-end exception handling framework.The basic mechanism of exception handling in the back-end isunwind-protect a la elisp.  This is a general, robust, and languageindependent representation for exceptions.The C++ front-end exceptions are mapping into the unwind-protectsemantics by the C++ front-end.  The mapping is describe below.When -frtti is used, rtti is used to do exception object type checking,when it isn't used, the encoded name for the type of the object beingthrown is used instead.  All code that originates exceptions, even codethat throws exceptions as a side effect, like dynamic casting, and allcode that catches exceptions must be compiled with either -frtti, or-fno-rtti.  It is not possible to mix rtti base exception handlingobjects with code that doesn't use rtti.  The exceptions to this, arecode that doesn't catch or throw exceptions, catch (...), and code thatjust rethrows an exception.Currently we use the normal mangling used in building functions names(int's are "i", const char * is PCc) to build the non-rtti base typedescriptors for exception handling.  These descriptors are just plainNULL terminated strings, and internally they are passed around as char*.In C++, all cleanups should be protected by exception regions.  Theregion starts just after the reason why the cleanup is created hasended.  For example, with an automatic variable, that has a constructor,it would be right after the constructor is run.  The region ends justbefore the finalization is expanded.  Since the backend may expand thecleanup multiple times along different paths, once for normal end of theregion, once for non-local gotos, once for returns, etc, the backendmust take special care to protect the finalization expansion, if theexpansion is for any other reason than normal region end, and it is`inline' (it is inside the exception region).  The backend can eitherchoose to move them out of line, or it can created an exception regionover the finalization to protect it, and in the handler associated withit, it would not run the finalization as it otherwise would have, butrather just rethrow to the outer handler, careful to skip the normalhandler for the original region.In Ada, they will use the more runtime intensive approach of havingfewer regions, but at the cost of additional work at run time, to keep alist of things that need cleanups.  When a variable has finishedconstruction, they add the cleanup to the list, when the come to the endof the lifetime of the variable, the run the list down.  If the take ahit before the section finishes normally, they examine the list foractions to perform.  I hope they add this logic into the back-end, as itwould be nice to get that alternative approach in C++.On an rs6000, xlC stores exception objects on that stack, under the tryblock.  When is unwinds down into a handler, the frame pointer isadjusted back to the normal value for the frame in which the handlerresides, and the stack pointer is left unchanged from the time at whichthe object was thrown.  This is so that there is always someplace forthe exception object, and nothing can overwrite it, once we startthrowing.  The only bad part, is that the stack remains large.The below points out some things that work in g++'s exception handling.All completely constructed temps and local variables are cleaned up inall unwinded scopes.  Completely constructed parts of partiallyconstructed objects are cleaned up.  This includes partially builtarrays.  Exception specifications are now handled.  Thrown objects arenow cleaned up all the time.  We can now tell if we have an activeexception being thrown or not (__eh_type != 0).  We use this to callterminate if someone does a throw; without there being an activeexception object.  uncaught_exception () works.  Exception handlingshould work right if you optimize.  Exception handling should work with-fpic or -fPIC.The below points out some flaws in g++'s exception handling, as it nowstands.Only exact type matching or reference matching of throw types works when-fno-rtti is used.  Only works on a SPARC (like Suns) (both -mflat and-mno-flat models work), SPARClite, Hitachi SH, i386, arm, rs6000,PowerPC, Alpha, mips, VAX, m68k and z8k machines.  SPARC v9 may notwork.  HPPA is mostly done, but throwing between a shared library anduser code doesn't yet work.  Some targets have support for data-drivenunwinding.  Partial support is in for all other machines, but a stackunwinder called __unwind_function has to be written, and added tolibgcc2 for them.  The new EH code doesn't rely upon the__unwind_function for C++ code, instead it creates per functionunwinders right inside the function, unfortunately, on many platformsthe definition of RETURN_ADDR_RTX in the tm.h file for the machine portis wrong.  See below for details on __unwind_function.  RTL_EXPRs for EHcond variables for && and || exprs should probably be wrapped inUNSAVE_EXPRs, and RTL_EXPRs tweaked so that they can be unsaved.We only do pointer conversions on exception matching a la 15.3 p2 case3: `A handler with type T, const T, T&, or const T& is a match for athrow-expression with an object of type E if [3]T is a pointer type andE is a pointer type that can be converted to T by a standard pointerconversion (_conv.ptr_) not involving conversions to pointers to privateor protected base classes.' when -frtti is given.

⌨️ 快捷键说明

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