E-COM-NET
首页
在线工具
Layui镜像站
SUI文档
联系我们
推荐频道
Java
PHP
C++
C
C#
Python
Ruby
go语言
Scala
Servlet
Vue
MySQL
NoSQL
Redis
CSS
Oracle
SQL Server
DB2
HBase
Http
HTML5
Spring
Ajax
Jquery
JavaScript
Json
XML
NodeJs
mybatis
Hibernate
算法
设计模式
shell
数据结构
大数据
JS
消息中间件
正则表达式
Tomcat
SQL
Nginx
Shiro
Maven
Linux
GCC-3.4.6
Studying note of
GCC-3.4.6
source (142 - continue)
OK.Nowlet’sseetheoutputofGCCforourinstance1.Example1:VtableforCC::_ZTV1C:12uentries0 0u //vbaseoffset4 0u //vcalloffset8 (int(*)(...))012 (int(*)(...))(&_ZTI1C)16 C::_ZTcv0_n1
wuhui_gdnt
·
2011-01-15 11:00
list
tree
null
Build
inheritance
construction
GCC-3.4.6
源代码学习笔记(142-续1)
好了,现在让我们看一下GCC对我们例1的输出。例1:VtableforCC::_ZTV1C:12uentries0 0u //vbaseoffset4 0u //vcalloffset8 (int(*)(...))012 (int(*)(...))(&_ZTI1C)16 C::_ZTcv0_n12_v0_n16_N1C1fEv //slotf
wuhui_gdnt
·
2011-01-15 11:00
list
tree
null
Build
inheritance
construction
Studying note of
GCC-3.4.6
source (142)
5.12.5.2.2.2.1.3.12. FinishthederivedRECORD_TYPE–generateVTTVirtualtabletable(VTT)isnotmandatoryforclass,sobuild_vttbelowmaygenerateVTTormaynot.Notedump_class_hierarchybelowatline5188,option–fdu
wuhui_gdnt
·
2011-01-15 10:00
object
Class
inheritance
Constructor
destructor
construction
GCC-3.4.6
源代码学习笔记(142)
5.12.5.2.2.2.1.3.12. 完成派生类RECORD_TYPE–生成VTT虚表表(VTT)对于类来说不是必需的,因此下面的build_vtt可能生成VTT,有可能不产生。注意下面5188行的dump_class_hierarchy,选项“–fdump-class-hierarchy”会促使该函数转储我们前一个看到的内容。 finish_struct_1(continue)
wuhui_gdnt
·
2011-01-15 10:00
Studying note of
GCC-3.4.6
source (141 - cont 2)
Thencheck_initializerisinvokedtoverifytheinitializers.Hereargumentflagsis0. 4463 statictree4464 check_initializer(treedecl,treeinit,intflags,tree*cleanup) indecl.c4465 {
wuhui_gdnt
·
2011-01-09 17:00
function
tree
null
reference
Constructor
initialization
Studying note of
GCC-3.4.6
source (141 - cont 1)
WhenfinishinghandlingofB1,build_vcall_and_vbase_vtbl_entriesreturnstotheinvocationofhandlingclassC.Thistimebuild_vbase_offset_vtbl_entriesdoesnothing,asbaseAhasbeenprocessedwithBINFO_VTABLE_PATH_MARKE
wuhui_gdnt
·
2011-01-09 17:00
GCC-3.4.6
源代码学习笔记(141-续1)
当完成B1的处理时,build_vcall_and_vbase_vtbl_entries返回到处理类C的最顶层的调用中。这一次,build_vbase_offset_vtbl_entries不做任何事,因为A的部分已经被处理,设置了BINFO_VTABLE_PATH_MARKED标记。而在build_vcall_offset_vtbl_entries中,对于类C,vid->generate_vca
wuhui_gdnt
·
2011-01-09 17:00
function
tree
null
Build
Constructor
initialization
Studying note of
GCC-3.4.6
source (141)
5.12.5.2.2.2.1.3.11. FinishthederivedRECORD_TYPE–finishvtableForourexampleoftemplateinstantiation,itcontainsnovtableasnovirtualfunctionsandvirtualbasesinvolved(C++probitstemplatefromhavingvirtua
wuhui_gdnt
·
2011-01-09 17:00
function
tree
Class
Build
hierarchy
inheritance
GCC-3.4.6
源代码学习笔记(141)
5.12.5.2.2.2.1.3.11. 完成派生类RECORD_TYPE–完成vtable对于我们的模板具现的例子,它不包含虚函数及涉及虚拟基类(C++不允许模板拥有虚函数,但可以使用虚拟基类)。不过,多态的概念十分重要,在这里值得我们深入研究。因此下面的讨论以前一节的例1及例2展开。在5159行,CLASSTYPE_VFIELDS是该类所有的包含的vtable(主要及次要)的域。其
wuhui_gdnt
·
2011-01-09 17:00
Studying note of
GCC-3.4.6
source (140 - continue)
Butwhat’sthunk?FollowingparagraphsareextractedfromcommentinthesourceofGCC.AthunkisanalternateentrypointforanordinaryFUNCTION_DECL.TheaddressoftheordinaryFUNCTION_DECLisgivenbytheDECL_INITIAL,whichisa
wuhui_gdnt
·
2011-01-03 11:00
function
tree
null
Class
Constructor
destructor
GCC-3.4.6
源代码学习笔记(140 - 续)
这里要解释一下什么是thunk。下面的段落摘自GCC源代码中的注释。Thunk是一个普通FUNCTION_DECL的一个替代入口(analternateentry)。普通FUNCTION_DECL的地址由DECL_INITIAL给出,它总是一个操作数是一个FUNCTION_DECL的ADDR_EXPR。这个thunk的任务是,或者在把控制权转给这个FUNCTION_DECL之前调整相应的this指
wuhui_gdnt
·
2011-01-03 11:00
function
tree
null
Class
Constructor
destructor
Studying note of
GCC-3.4.6
source (140)
5.12.5.2.2.2.1.3.10. FinishtheRECORD_TYPE–buildvtableRememberindetermine_primary_base,ifwefindaprimarybasewejustrememberitsvtable(recallthatitmustcontainvtable,elsewewouldn’thaveprimarybase),now
wuhui_gdnt
·
2011-01-03 11:00
function
struct
tree
Class
Build
inheritance
GCC-3.4.6
源代码学习笔记(140)
5.12.5.2.2.2.1.3.10. 完成派生类的RECORD_TYPE–构建vtable记得在determine_primary_base中,如果我们找到一个主要基类,我们只是记住它的vtable(记住它必须有vtable,否则我们不会有主要基类),现在我们需要属于自己的vtable。注意5057到5064行的断言,它们可以帮助我们尽早地发现不一致的情况。 finish_stru
wuhui_gdnt
·
2011-01-03 11:00
struct
function
tree
null
Build
inheritance
Studying note of
GCC-3.4.6
source (139 - cont 2)
InTYPE_FIELDSofclassnode,aFIELD_DECLisusedtorepresentanon-staticdatamember,aVAR_DECLisusedtorepresentastaticdatamember,andaTYPE_DECLisusedtorepresentatype.TheCONST_DECLforanenumerationconstantwillappe
wuhui_gdnt
·
2011-01-02 13:00
tree
layout
Integer
Class
hierarchy
alignment
Studying note of
GCC-3.4.6
source (139 - cont 1)
layout_class_type(continue) 4664 /*Createapointertoourvirtualfunctiontable. */4665 vptr=create_vtable_ptr(t,virtuals_p);4666 4667 /*Thevptrisalwaysthefirstthingintheclass. */4668 if(vptr)466
wuhui_gdnt
·
2011-01-02 13:00
tree
layout
Integer
Class
alignment
conflict
GCC-3.4.6
源代码学习笔记(139-续1)
layout_class_type(continue) 4664 /*Createapointertoourvirtualfunctiontable. */4665 vptr=create_vtable_ptr(t,virtuals_p);4666 4667 /*Thevptrisalwaysthefirstthingintheclass. */4668 if(vptr)466
wuhui_gdnt
·
2011-01-02 13:00
GCC-3.4.6
源代码学习笔记(139)
5.12.5.2.2.2.1.3.9. 完成派生类的RECORD_TYPE–布局回到finish_struct_1中,下面的keyed_classes是一个保存那些在这个编译单元中将可能发布vtable的类的tree_list。这个链表中的候选者是不含有非内联、非纯虚方法的类。换而言之,是仅含有纯虚方法或(及)内联虚方法的类。对于这样的类,在每个该类定义出现的编译单元中(如,通
wuhui_gdnt
·
2011-01-02 12:00
Studying note of
GCC-3.4.6
source (138)
5.12.5.2.2.2.1.3.8. FinishthederivedRECORD_TYPE–fillupmissingmethodsOncestudiedC++,thetextbooktoldmeifyoudidn’tdefineconstructorforaclass,thecompilermaygenerateitforyouinitsownway,togetherwi
wuhui_gdnt
·
2010-12-25 14:00
exception
tree
Build
Constructor
methods
destructor
GCC-3.4.6
源代码学习笔记(138)
5.12.5.2.2.2.1.3.8.完成派生类的RECORD_TYPE–补充缺少的方法以前学习C++时,书本告诉我们如果你不为一个类定义构造函数的话,编译器会以自己的方式为你产生,连带的可能还有析构函数,拷贝构造函数及赋值操作符。下面就是这个地方,编译器补充所缺少的方法。2629staticvoid2630add_implicitly_declared_members(treet,inclass
wuhui_gdnt
·
2010-12-25 14:00
exception
function
tree
Build
Constructor
destructor
Studying note of
GCC-3.4.6
source (137)
5.12.5.2.2.2.1.3.7. FinishthederivedRECORD_TYPE–verifymethodsNext,somefixmayneedbedoneiftisthederivedtype.RecallthatinC++,oncedeclaringamethodasvirtualinthebaseclass,lateralloverridesarecons
wuhui_gdnt
·
2010-12-25 14:00
Studying note of
GCC-3.4.6
source (136)
5.12.5.2.2.2.1.3.6. FinishthederivedRECORD_TYPE–verifymembersNextverifythevalidityofnon-methodfieldsofthetemplateinstantiation. check_bases_and_members(continue) 4169 /*Checkallthedatamemb
wuhui_gdnt
·
2010-12-25 14:00
tree
Class
reference
Constructor
destructor
Pointers
GCC-3.4.6
源代码学习笔记(136)
5.12.5.2.2.2.1.3.6. 完成派生类的RECORD_TYPE–验证成员接着验证模板具现体的非方法成员的有效性。 check_bases_and_members(continue) 4169 /*Checkallthedatamemberdeclarations. */4170 check_field_decls(t,&access_decls,4171
wuhui_gdnt
·
2010-12-25 14:00
Studying note of
GCC-3.4.6
source (135)
5.12.5.2.2.2.1.3.2. Instantiatebaseclass–finishAfterprocessingthebases(theyarechainedtegother),ininstantiate_class_templateatline5452,xref_basetypeiscalledtofillthebinfopart,inwhichparameter
wuhui_gdnt
·
2010-12-25 13:00
tree
Class
processing
Constructor
destructor
Instantiation
Studying note of
GCC-3.4.6
source (134)
5.12.5.2.2.2.1.3.1. Instantiatebaseclass–substitutingargumentforparameterThebaseclassmaydependsontemplateparameterasourexamplehere.Sotoinstantiatethederivedclass,itfirstneedsinstantiateitsba
wuhui_gdnt
·
2010-12-25 13:00
GCC-3.4.6
源代码学习笔记(134)
5.12.5.2.2.2.1.3.1. 具现基类–实参替换基类可能依赖于模板参数,就像这里我们的例子那样。因此要具现派生类,首先需要正确地具现其基类。在这里我们为了方便起见,在下面重新显示了“SmallObject”部分的中间树。“SmallObject”具有单个基类——“ThreadingModel”,其缺省类型是“SingleThreaded”,而且“SmallObject
wuhui_gdnt
·
2010-12-25 13:00
Studying note of
GCC-3.4.6
source (133)
5.12.5.2.2.2.1.3. GenerateRECORD_TYPEfortheinstantiationAtlast,atline10181incp_parser_init_declarator,cp_finish_declclosesthedeclaration.Asitisthedeclarationwithinafunction,anewDECL_STMTisinsertedin
wuhui_gdnt
·
2010-12-18 16:00
GCC-3.4.6
源代码学习笔记(133)
5.12.5.2.2.2.1.3. 为具现构建RECORD_TYPE最后,在cp_parser_init_declarator的10181行,cp_finish_decl完成这个声明。因为它是在一个函数中的声明,在下面4957行,一个新的DECL_STMT被插入到对应的stmt-tree,之后我们得到如下的中间树。(点此打开) 4786 void4787 cp_finish_decl(tr
wuhui_gdnt
·
2010-12-18 16:00
Studying note of
GCC-3.4.6
source (132)
5.12.5.2.2.2.1.2. CreatetheVAR_DECLNextincp_parser_simple_declaration,cp_parser_init_declaratorisinvokedtoparsethedeclaratorpart.Withcall-stackofcp_parser_declaratoràcp_parser_direct_declaratoràcp_p
wuhui_gdnt
·
2010-12-15 10:00
GCC-3.4.6
源代码学习笔记(132)
5.12.5.2.2.2.1.2. 构建VAR_DECL接下来在cp_parser_simple_declaration中,调用cp_parser_init_declarator来解析声明符部分。调用栈cp_parser_declaratoràcp_parser_direct_declaratoràcp_parser_declarator_idàcp_parser_id_expressionà
wuhui_gdnt
·
2010-12-15 10:00
function
tree
processing
deprecated
binding
attributes
Studying note of
GCC-3.4.6
source (131)
5.12.5.2.2.2.1.1.2. ReplacerestdefaultargumentsThesecondparameteristhenodepointedbytheredpointerinbelowfigure.Asthethirdparameterissimilar,wejustskipitinbelow.(Clickhereforopen)Thenatline383
wuhui_gdnt
·
2010-12-15 10:00
Studying note of
GCC-3.4.6
source (130)
5.12.5.2.2.2. HandlingthebodyBeforegoingdeeperintothefunction-body,whichformsanewbindingscopeofblock-scope,anypenddingaccessibilitycheckingsshouldbeperformedtofindouttheillegalvisitearly. cp_parser_fu
wuhui_gdnt
·
2010-12-13 17:00
GCC-3.4.6
源代码学习笔记(130)
5.12.5.2.2.2. 处理函数体函数体构成了一个新的块绑定域,在更深入进入该函数体前,要执行之前挂起的访问检查,以尽早发现违例的访问。 cp_parser_function_definition_from_specifiers_and_declarator(continue) 14329 /*Iftherewerenameslookedupinthedecl-specifier-seqtha
wuhui_gdnt
·
2010-12-13 17:00
function
tree
null
Class
processing
token
Studying note of
GCC-3.4.6
source (129)
5.12.5.2.2. Function-definition–bodypart5.12.5.2.2.1. PrepareforbodyparsingNowwegetthereturn-type-specifierindecl_specifiers,declaratorofCALL_EXPRanddeclares_class_or_enumof0.Rememberthatifwedef
wuhui_gdnt
·
2010-12-05 12:00
GCC-3.4.6
源代码学习笔记(129 续)
下面的DECL_MAIN_P返回非0值来表示遇到“main”函数,对于该函数一些有趣的限制。看到main函数不能被声明为inline,而且永远是公有可访问的。 grokfndecl(continue) 5642 if(ctype==NULL_TREE&&DECL_MAIN_P(decl))5643 {5644 if(processing_template_decl)5645
wuhui_gdnt
·
2010-12-05 11:00
function
tree
Integer
processing
interface
Instantiation
GCC-3.4.6
源代码学习笔记(129)
5.12.5.2.2. 函数定义–函数体部分5.12.5.2.2.1. 准备函数体解析现在我们在decl_specifiers中得到了return-type-specifier,declarator指向CALL_EXPR,而declares_class_or_enum为0。记得如果我们正在定义新类型,declares_class_or_enum是2,这在function-definit
wuhui_gdnt
·
2010-12-05 11:00
function
tree
null
token
attributes
Types
Studying note of
GCC-3.4.6
source (128)
5.12.5. ThethirdexampleNowwehavedefinitionof“SmallObject”,weusefollowing“main”functiontousethisclass,andseewhat’simmediatetreewillbecreated.usingnamespaceLoki;intmain(){SmallObjectlexer);6391 639
wuhui_gdnt
·
2010-11-26 13:00
Studying note of
GCC-3.4.6
source (127)
5.12.4.2.3.2. Buildnodesforbase-clauseNoticethatargumentbasereferstotheBOUND_TEMPLATE_TEMPLATE_PARMnodeforourexample,andaccessisaccess_public_node. 2242 tree2243 finish_base_specifier(treebase,treea
wuhui_gdnt
·
2010-11-05 10:00
GCC-3.4.6
源代码学习笔记(127)
5.12.4.2.3.2. 为base-clause构建节点注意参数base在我们的例子中指向的BOUND_TEMPLATE_TEMPLATE_PARM节点,access是access_public_node。 2242 tree2243 finish_base_specifier(treebase,treeaccess,boolvirtual_p) inseman
wuhui_gdnt
·
2010-11-05 10:00
list
tree
null
Class
Access
inheritance
Studying note of
GCC-3.4.6
source (126)
5.12.4.2.3.1.1.3. Generatetemplate-idSoasresult,forthisnon-typeargument,theIDENTIFIER_NODEof“chunkSize”isreturned.Similarlyisthenextargument“maxSmallObjectSize”.Soatexittingcoerce_template_parms,atl
wuhui_gdnt
·
2010-11-05 09:00
tree
Class
Parameters
templates
Instantiation
Constants
GCC-3.4.6
源代码学习笔记(126)
5.12.4.2.3.1.1.3. 生成template-id那么作为结果,对于这个非类型实参,“chunkSize”的IDENTIFIER_NODE被返回。类似的还有下一个实参“maxSmallObjectSize”。因此在lookup_template_class的4346行退出coerce_template_parms时,arglist为下图中标记为红色的节点。(点此打开)图111:构建
wuhui_gdnt
·
2010-11-05 09:00
GCC-3.4.6
源代码学习笔记(125)
5.12.4.2.3. 处理基类5.12.4.2.3.1. 解析base-clause“SmallObject”后的符号是:“:publicThreadingModel>”,它们表示了“SmallObject”所派生的基类。class-head的规则重现如下。class-head: class-keyidentifier[opt]base-clause[opt] class-ke
wuhui_gdnt
·
2010-11-05 09:00
struct
tree
Class
processing
token
nested
Studying note of
GCC-3.4.6
source (124)
5.12.4.2.2.2.3. Finishtemplate-idIftemplate-nameisanIDENTIFER_NODE,itmaybeamembertemplate;andifitisaTEMPLATE_DECLofclasstemplate,thetemplate-iditselfisaclass-name;andifitisFUNCTION_DECL,OVERLO
wuhui_gdnt
·
2010-11-05 09:00
GCC-3.4.6
源代码学习笔记(124)
5.12.4.2.2.2.3. 完成template-id如果模板名是一个IDENTIFER_NODE,它可能是一个成员模板;而如果它是应该类模板的TEMPLATE_DECL,template-id本身是一个类名;而如果是FUNCTION_DECL,OVERLOAD或METHOD_DECL,template-id就是一个函数名。因此如果模板名是一个类模板,template-id可能
wuhui_gdnt
·
2010-11-05 09:00
Studying note of
GCC-3.4.6
source (123)
5.12.4.2.2.2.2. ParseargumentlistThencp_parser_enclosed_template_argument_listisinvokedforparsingtheenclosedtemplateargumentlistwithinthetemplate-id.Beforethehandling,greater_than_is_operator_
wuhui_gdnt
·
2010-11-05 09:00
list
tree
null
token
attributes
Parsing
GCC-3.4.6
源代码学习笔记(123)
5.12.4.2.2.2.2. 解析实参列表然后调用cp_parser_enclosed_template_argument_list来解析template-id中所包含的模板实参列表。在这个处理之前,parser的greater_than_is_operator_p域将被设置为false,因为从现在起进来的“>”将不被视为操作符。而在实参列表中输入的“>>”将被解析作“>”和“>
wuhui_gdnt
·
2010-11-05 09:00
list
tree
null
token
attributes
Parsing
GCC-3.4.6
源代码学习笔记(122)
5.12.4.2.2. 类名查找在cp_parser_class_name的调用中,当且仅当关键字typename已经被使用来表示,在依赖类型中查找的名字应该被视为类型时,typename_keyword_p是true;当且仅当关键字template已经被使用来表示其次出现的名字是一个模板时,template_keyword_p是true;当且仅当下一个名字应该被视为类名(class-
wuhui_gdnt
·
2010-11-05 09:00
list
tree
delete
Access
token
Parsing
Studying note of
GCC-3.4.6
source (121)
5.12.4.2. Parseclass-headThetokenfollowsthetemplate-parameter-listis“class”whichdenotesthedefinition/declarationofaclass-template.Sameasthepreviousexample,alongwiththefollowingcallstack:cp
wuhui_gdnt
·
2010-11-05 08:00
struct
tree
Class
templates
nested
attributes
GCC-3.4.6
源代码学习笔记(121)
5.12.4.2. 解析class-head跟在template-parameter-list后的符号是“class”,这标记着这是类模板的定义/声明。与前面的例子相同,沿着下面的调用栈:cp_parser_template_declaration_after_exportàcp_parser_single_declarationàcp_parser_decl_specif
wuhui_gdnt
·
2010-11-05 08:00
struct
tree
Class
templates
nested
attributes
Studying note of
GCC-3.4.6
source (120)
5.12.4.1.2.1. Processnon-typeparameterAfterparsingthisnon-typetemplateparameter,nodoubt,nextitneedsprocessthisparametertofinishtherevelantsub-treeandinsertitintheintermediatetree. 2161 tree2162 proc
wuhui_gdnt
·
2010-11-05 08:00
GCC-3.4.6
源代码学习笔记(120)
5.12.4.1.2.1. 处理非类型参数在解析了这个非类型模板参数之后,下一步,需要处理这个参数来完成相关的子树并插入中间树。 2161 tree2162 process_template_parm(treelist,treenext) inpt.c2163 {2164 treeparm
wuhui_gdnt
·
2010-11-05 08:00
list
function
tree
null
processing
deprecated
上一页
1
2
3
4
5
6
7
8
下一页
按字母分类:
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
其他