Bind.cpp 99 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274
  1. // Copyright (c) 2008 Roberto Raggi <[email protected]>
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. // THE SOFTWARE.
  20. #include "Bind.h"
  21. #include "AST.h"
  22. #include "TranslationUnit.h"
  23. #include "Control.h"
  24. #include "Names.h"
  25. #include "Symbols.h"
  26. #include "CoreTypes.h"
  27. #include "Literals.h"
  28. #include "Scope.h"
  29. #include "cppassert.h"
  30. #include <vector>
  31. #include <string>
  32. #include <memory>
  33. #include <algorithm>
  34. using namespace CPlusPlus;
  35. const int Bind::kMaxDepth(100);
  36. Bind::Bind(TranslationUnit *unit)
  37. : ASTVisitor(unit),
  38. _scope(0),
  39. _expression(0),
  40. _name(0),
  41. _declaratorId(0),
  42. _visibility(Symbol::Public),
  43. _objcVisibility(Symbol::Public),
  44. _methodKey(Function::NormalMethod),
  45. _skipFunctionBodies(false),
  46. _depth(0)
  47. {
  48. }
  49. bool Bind::skipFunctionBodies() const
  50. {
  51. return _skipFunctionBodies;
  52. }
  53. void Bind::setSkipFunctionBodies(bool skipFunctionBodies)
  54. {
  55. _skipFunctionBodies = skipFunctionBodies;
  56. }
  57. unsigned Bind::location(DeclaratorAST *ast, unsigned defaultLocation) const
  58. {
  59. if (! ast)
  60. return defaultLocation;
  61. else if (ast->core_declarator)
  62. return location(ast->core_declarator, defaultLocation);
  63. return ast->firstToken();
  64. }
  65. unsigned Bind::location(CoreDeclaratorAST *ast, unsigned defaultLocation) const
  66. {
  67. if (! ast)
  68. return defaultLocation;
  69. else if (NestedDeclaratorAST *nested = ast->asNestedDeclarator())
  70. return location(nested->declarator, defaultLocation);
  71. else if (DeclaratorIdAST *id = ast->asDeclaratorId())
  72. return location(id->name, defaultLocation);
  73. return ast->firstToken();
  74. }
  75. unsigned Bind::location(NameAST *name, unsigned defaultLocation) const
  76. {
  77. if (! name)
  78. return defaultLocation;
  79. else if (DestructorNameAST *dtor = name->asDestructorName())
  80. return location(dtor->unqualified_name, defaultLocation);
  81. else if (TemplateIdAST *templId = name->asTemplateId())
  82. return templId->identifier_token;
  83. else if (QualifiedNameAST *q = name->asQualifiedName()) {
  84. if (q->unqualified_name)
  85. return location(q->unqualified_name, defaultLocation);
  86. }
  87. return name->firstToken();
  88. }
  89. void Bind::setDeclSpecifiers(Symbol *symbol, const FullySpecifiedType &declSpecifiers)
  90. {
  91. if (! symbol)
  92. return;
  93. int storage = Symbol::NoStorage;
  94. if (declSpecifiers.isFriend())
  95. storage = Symbol::Friend;
  96. else if (declSpecifiers.isAuto())
  97. storage = Symbol::Auto;
  98. else if (declSpecifiers.isRegister())
  99. storage = Symbol::Register;
  100. else if (declSpecifiers.isStatic())
  101. storage = Symbol::Static;
  102. else if (declSpecifiers.isExtern())
  103. storage = Symbol::Extern;
  104. else if (declSpecifiers.isMutable())
  105. storage = Symbol::Mutable;
  106. else if (declSpecifiers.isTypedef())
  107. storage = Symbol::Typedef;
  108. symbol->setStorage(storage);
  109. if (Function *funTy = symbol->asFunction()) {
  110. if (declSpecifiers.isVirtual())
  111. funTy->setVirtual(true);
  112. }
  113. if (declSpecifiers.isDeprecated())
  114. symbol->setDeprecated(true);
  115. if (declSpecifiers.isUnavailable())
  116. symbol->setUnavailable(true);
  117. }
  118. Scope *Bind::switchScope(Scope *scope)
  119. {
  120. if (! scope)
  121. return _scope;
  122. std::swap(_scope, scope);
  123. return scope;
  124. }
  125. int Bind::switchVisibility(int visibility)
  126. {
  127. std::swap(_visibility, visibility);
  128. return visibility;
  129. }
  130. int Bind::switchObjCVisibility(int visibility)
  131. {
  132. std::swap(_objcVisibility, visibility);
  133. return visibility;
  134. }
  135. int Bind::switchMethodKey(int methodKey)
  136. {
  137. std::swap(_methodKey, methodKey);
  138. return methodKey;
  139. }
  140. void Bind::operator()(TranslationUnitAST *ast, Namespace *globalNamespace)
  141. {
  142. Scope *previousScope = switchScope(globalNamespace);
  143. translationUnit(ast);
  144. (void) switchScope(previousScope);
  145. }
  146. void Bind::operator()(DeclarationAST *ast, Scope *scope)
  147. {
  148. Scope *previousScope = switchScope(scope);
  149. declaration(ast);
  150. (void) switchScope(previousScope);
  151. }
  152. void Bind::operator()(StatementAST *ast, Scope *scope)
  153. {
  154. Scope *previousScope = switchScope(scope);
  155. statement(ast);
  156. (void) switchScope(previousScope);
  157. }
  158. FullySpecifiedType Bind::operator()(ExpressionAST *ast, Scope *scope)
  159. {
  160. Scope *previousScope = switchScope(scope);
  161. FullySpecifiedType ty = expression(ast);
  162. (void) switchScope(previousScope);
  163. return ty;
  164. }
  165. FullySpecifiedType Bind::operator()(NewTypeIdAST *ast, Scope *scope)
  166. {
  167. Scope *previousScope = switchScope(scope);
  168. FullySpecifiedType ty = newTypeId(ast);
  169. (void) switchScope(previousScope);
  170. return ty;
  171. }
  172. void Bind::statement(StatementAST *ast)
  173. {
  174. accept(ast);
  175. }
  176. Bind::ExpressionTy Bind::expression(ExpressionAST *ast)
  177. {
  178. ExpressionTy value = ExpressionTy();
  179. std::swap(_expression, value);
  180. accept(ast);
  181. std::swap(_expression, value);
  182. return value;
  183. }
  184. void Bind::declaration(DeclarationAST *ast)
  185. {
  186. accept(ast);
  187. }
  188. const Name *Bind::name(NameAST *ast)
  189. {
  190. const Name *value = 0;
  191. std::swap(_name, value);
  192. accept(ast);
  193. std::swap(_name, value);
  194. return value;
  195. }
  196. FullySpecifiedType Bind::specifier(SpecifierAST *ast, const FullySpecifiedType &init)
  197. {
  198. FullySpecifiedType value = init;
  199. std::swap(_type, value);
  200. accept(ast);
  201. std::swap(_type, value);
  202. return value;
  203. }
  204. FullySpecifiedType Bind::ptrOperator(PtrOperatorAST *ast, const FullySpecifiedType &init)
  205. {
  206. FullySpecifiedType value = init;
  207. std::swap(_type, value);
  208. accept(ast);
  209. std::swap(_type, value);
  210. return value;
  211. }
  212. FullySpecifiedType Bind::coreDeclarator(CoreDeclaratorAST *ast, const FullySpecifiedType &init)
  213. {
  214. FullySpecifiedType value = init;
  215. std::swap(_type, value);
  216. accept(ast);
  217. std::swap(_type, value);
  218. return value;
  219. }
  220. FullySpecifiedType Bind::postfixDeclarator(PostfixDeclaratorAST *ast, const FullySpecifiedType &init)
  221. {
  222. FullySpecifiedType value = init;
  223. std::swap(_type, value);
  224. accept(ast);
  225. std::swap(_type, value);
  226. return value;
  227. }
  228. bool Bind::preVisit(AST *)
  229. {
  230. ++_depth;
  231. if (_depth > kMaxDepth)
  232. return false;
  233. return true;
  234. }
  235. void Bind::postVisit(AST *)
  236. {
  237. --_depth;
  238. }
  239. // AST
  240. bool Bind::visit(ObjCSelectorArgumentAST *ast)
  241. {
  242. (void) ast;
  243. CPP_CHECK(!"unreachable");
  244. return false;
  245. }
  246. const Name *Bind::objCSelectorArgument(ObjCSelectorArgumentAST *ast, bool *hasArg)
  247. {
  248. if (! (ast && ast->name_token))
  249. return 0;
  250. if (ast->colon_token)
  251. *hasArg = true;
  252. return identifier(ast->name_token);
  253. }
  254. bool Bind::visit(GnuAttributeAST *ast)
  255. {
  256. (void) ast;
  257. CPP_CHECK(!"unreachable");
  258. return false;
  259. }
  260. void Bind::attribute(GnuAttributeAST *ast)
  261. {
  262. if (! ast)
  263. return;
  264. // unsigned identifier_token = ast->identifier_token;
  265. if (const Identifier *id = identifier(ast->identifier_token)) {
  266. if (id == control()->deprecatedId())
  267. _type.setDeprecated(true);
  268. else if (id == control()->unavailableId())
  269. _type.setUnavailable(true);
  270. }
  271. // unsigned lparen_token = ast->lparen_token;
  272. // unsigned tag_token = ast->tag_token;
  273. for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
  274. ExpressionTy value = this->expression(it->value);
  275. }
  276. // unsigned rparen_token = ast->rparen_token;
  277. }
  278. bool Bind::visit(DeclaratorAST *ast)
  279. {
  280. (void) ast;
  281. CPP_CHECK(!"unreachable");
  282. return false;
  283. }
  284. FullySpecifiedType Bind::declarator(DeclaratorAST *ast, const FullySpecifiedType &init, DeclaratorIdAST **declaratorId)
  285. {
  286. FullySpecifiedType type = init;
  287. if (! ast)
  288. return type;
  289. std::swap(_declaratorId, declaratorId);
  290. bool isAuto = false;
  291. const bool cxx11Enabled = translationUnit()->languageFeatures().cxx11Enabled;
  292. if (cxx11Enabled)
  293. isAuto = type.isAuto();
  294. for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
  295. type = this->specifier(it->value, type);
  296. if (type.isAuto())
  297. isAuto = true;
  298. }
  299. for (PtrOperatorListAST *it = ast->ptr_operator_list; it; it = it->next) {
  300. type = this->ptrOperator(it->value, type);
  301. }
  302. for (PostfixDeclaratorListAST *it = ast->postfix_declarator_list; it; it = it->next) {
  303. type = this->postfixDeclarator(it->value, type);
  304. }
  305. type = this->coreDeclarator(ast->core_declarator, type);
  306. for (SpecifierListAST *it = ast->post_attribute_list; it; it = it->next) {
  307. type = this->specifier(it->value, type);
  308. if (type.isAuto())
  309. isAuto = true;
  310. }
  311. if (!type->isFunctionType()) {
  312. ExpressionTy initializer = this->expression(ast->initializer);
  313. if (cxx11Enabled && isAuto) {
  314. type = initializer;
  315. type.setAuto(true);
  316. }
  317. }
  318. std::swap(_declaratorId, declaratorId);
  319. return type;
  320. }
  321. bool Bind::visit(QtPropertyDeclarationItemAST *ast)
  322. {
  323. (void) ast;
  324. CPP_CHECK(!"unreachable");
  325. return false;
  326. }
  327. bool Bind::visit(QtInterfaceNameAST *ast)
  328. {
  329. (void) ast;
  330. CPP_CHECK(!"unreachable");
  331. return false;
  332. }
  333. void Bind::qtInterfaceName(QtInterfaceNameAST *ast)
  334. {
  335. if (! ast)
  336. return;
  337. /*const Name *interface_name =*/ this->name(ast->interface_name);
  338. for (NameListAST *it = ast->constraint_list; it; it = it->next) {
  339. /*const Name *value =*/ this->name(it->value);
  340. }
  341. }
  342. bool Bind::visit(BaseSpecifierAST *ast)
  343. {
  344. (void) ast;
  345. CPP_CHECK(!"unreachable");
  346. return false;
  347. }
  348. void Bind::baseSpecifier(BaseSpecifierAST *ast, unsigned colon_token, Class *klass)
  349. {
  350. if (! ast)
  351. return;
  352. unsigned sourceLocation = location(ast->name, ast->firstToken());
  353. if (! sourceLocation)
  354. sourceLocation = std::max(colon_token, klass->sourceLocation());
  355. const Name *baseClassName = this->name(ast->name);
  356. BaseClass *baseClass = control()->newBaseClass(sourceLocation, baseClassName);
  357. if (ast->virtual_token)
  358. baseClass->setVirtual(true);
  359. if (ast->access_specifier_token) {
  360. const int visibility = visibilityForAccessSpecifier(tokenKind(ast->access_specifier_token));
  361. baseClass->setVisibility(visibility); // ### well, not exactly.
  362. }
  363. klass->addBaseClass(baseClass);
  364. ast->symbol = baseClass;
  365. }
  366. bool Bind::visit(CtorInitializerAST *ast)
  367. {
  368. (void) ast;
  369. CPP_CHECK(!"unreachable");
  370. return false;
  371. }
  372. void Bind::ctorInitializer(CtorInitializerAST *ast, Function *fun)
  373. {
  374. if (! ast)
  375. return;
  376. // unsigned colon_token = ast->colon_token;
  377. for (MemInitializerListAST *it = ast->member_initializer_list; it; it = it->next) {
  378. this->memInitializer(it->value, fun);
  379. }
  380. // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
  381. }
  382. bool Bind::visit(EnumeratorAST *ast)
  383. {
  384. (void) ast;
  385. CPP_CHECK(!"unreachable");
  386. return false;
  387. }
  388. void Bind::enumerator(EnumeratorAST *ast, Enum *symbol)
  389. {
  390. (void) symbol;
  391. if (! ast)
  392. return;
  393. // unsigned identifier_token = ast->identifier_token;
  394. // unsigned equal_token = ast->equal_token;
  395. /*ExpressionTy expression =*/ this->expression(ast->expression);
  396. if (ast->identifier_token) {
  397. const Name *name = identifier(ast->identifier_token);
  398. EnumeratorDeclaration *e = control()->newEnumeratorDeclaration(ast->identifier_token, name);
  399. e->setType(control()->integerType(IntegerType::Int)); // ### introduce IntegerType::Enumerator
  400. if (ExpressionAST *expr = ast->expression)
  401. e->setConstantValue(asStringLiteral(expr->firstToken(), expr->lastToken()));
  402. symbol->addMember(e);
  403. }
  404. }
  405. bool Bind::visit(DynamicExceptionSpecificationAST *ast)
  406. {
  407. (void) ast;
  408. CPP_CHECK(!"unreachable");
  409. return false;
  410. }
  411. FullySpecifiedType Bind::exceptionSpecification(ExceptionSpecificationAST *ast, const FullySpecifiedType &init)
  412. {
  413. FullySpecifiedType type = init;
  414. if (! ast)
  415. return type;
  416. if (DynamicExceptionSpecificationAST *dyn = ast->asDynamicExceptionSpecification()) {
  417. // unsigned throw_token = ast->throw_token;
  418. // unsigned lparen_token = ast->lparen_token;
  419. // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
  420. for (ExpressionListAST *it = dyn->type_id_list; it; it = it->next) {
  421. /*ExpressionTy value =*/ this->expression(it->value);
  422. }
  423. } else if (NoExceptSpecificationAST *no = ast->asNoExceptSpecification()) {
  424. /*ExpressionTy value =*/ this->expression(no->expression);
  425. }
  426. // unsigned rparen_token = ast->rparen_token;
  427. return type;
  428. }
  429. bool Bind::visit(MemInitializerAST *ast)
  430. {
  431. (void) ast;
  432. CPP_CHECK(!"unreachable");
  433. return false;
  434. }
  435. void Bind::memInitializer(MemInitializerAST *ast, Function *fun)
  436. {
  437. if (! ast)
  438. return;
  439. /*const Name *name =*/ this->name(ast->name);
  440. Scope *previousScope = switchScope(fun);
  441. this->expression(ast->expression);
  442. (void) switchScope(previousScope);
  443. }
  444. bool Bind::visit(NestedNameSpecifierAST *ast)
  445. {
  446. (void) ast;
  447. CPP_CHECK(!"unreachable");
  448. return false;
  449. }
  450. const Name *Bind::nestedNameSpecifier(NestedNameSpecifierAST *ast)
  451. {
  452. if (! ast)
  453. return 0;
  454. const Name *class_or_namespace_name = this->name(ast->class_or_namespace_name);
  455. return class_or_namespace_name;
  456. }
  457. bool Bind::visit(ExpressionListParenAST *ast)
  458. {
  459. // unsigned lparen_token = ast->lparen_token;
  460. for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
  461. /*ExpressionTy value =*/ this->expression(it->value);
  462. }
  463. // unsigned rparen_token = ast->rparen_token;
  464. return false;
  465. }
  466. void Bind::newPlacement(ExpressionListParenAST *ast)
  467. {
  468. if (! ast)
  469. return;
  470. // unsigned lparen_token = ast->lparen_token;
  471. for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
  472. ExpressionTy value = this->expression(it->value);
  473. }
  474. // unsigned rparen_token = ast->rparen_token;
  475. }
  476. bool Bind::visit(NewArrayDeclaratorAST *ast)
  477. {
  478. (void) ast;
  479. CPP_CHECK(!"unreachable");
  480. return false;
  481. }
  482. FullySpecifiedType Bind::newArrayDeclarator(NewArrayDeclaratorAST *ast, const FullySpecifiedType &init)
  483. {
  484. FullySpecifiedType type = init;
  485. if (! ast)
  486. return type;
  487. // unsigned lbracket_token = ast->lbracket_token;
  488. ExpressionTy expression = this->expression(ast->expression);
  489. // unsigned rbracket_token = ast->rbracket_token;
  490. return type;
  491. }
  492. bool Bind::visit(NewTypeIdAST *ast)
  493. {
  494. (void) ast;
  495. CPP_CHECK(!"unreachable");
  496. return false;
  497. }
  498. FullySpecifiedType Bind::newTypeId(NewTypeIdAST *ast)
  499. {
  500. FullySpecifiedType type;
  501. if (! ast)
  502. return type;
  503. for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
  504. type = this->specifier(it->value, type);
  505. }
  506. for (PtrOperatorListAST *it = ast->ptr_operator_list; it; it = it->next) {
  507. type = this->ptrOperator(it->value, type);
  508. }
  509. for (NewArrayDeclaratorListAST *it = ast->new_array_declarator_list; it; it = it->next) {
  510. type = this->newArrayDeclarator(it->value, type);
  511. }
  512. return type;
  513. }
  514. bool Bind::visit(OperatorAST *ast)
  515. {
  516. (void) ast;
  517. CPP_CHECK(!"unreachable");
  518. return false;
  519. }
  520. OperatorNameId::Kind Bind::cppOperator(OperatorAST *ast)
  521. {
  522. OperatorNameId::Kind kind = OperatorNameId::InvalidOp;
  523. if (! ast)
  524. return kind;
  525. // unsigned op_token = ast->op_token;
  526. // unsigned open_token = ast->open_token;
  527. // unsigned close_token = ast->close_token;
  528. switch (tokenKind(ast->op_token)) {
  529. case T_NEW:
  530. if (ast->open_token)
  531. kind = OperatorNameId::NewArrayOp;
  532. else
  533. kind = OperatorNameId::NewOp;
  534. break;
  535. case T_DELETE:
  536. if (ast->open_token)
  537. kind = OperatorNameId::DeleteArrayOp;
  538. else
  539. kind = OperatorNameId::DeleteOp;
  540. break;
  541. case T_PLUS:
  542. kind = OperatorNameId::PlusOp;
  543. break;
  544. case T_MINUS:
  545. kind = OperatorNameId::MinusOp;
  546. break;
  547. case T_STAR:
  548. kind = OperatorNameId::StarOp;
  549. break;
  550. case T_SLASH:
  551. kind = OperatorNameId::SlashOp;
  552. break;
  553. case T_PERCENT:
  554. kind = OperatorNameId::PercentOp;
  555. break;
  556. case T_CARET:
  557. kind = OperatorNameId::CaretOp;
  558. break;
  559. case T_AMPER:
  560. kind = OperatorNameId::AmpOp;
  561. break;
  562. case T_PIPE:
  563. kind = OperatorNameId::PipeOp;
  564. break;
  565. case T_TILDE:
  566. kind = OperatorNameId::TildeOp;
  567. break;
  568. case T_EXCLAIM:
  569. kind = OperatorNameId::ExclaimOp;
  570. break;
  571. case T_EQUAL:
  572. kind = OperatorNameId::EqualOp;
  573. break;
  574. case T_LESS:
  575. kind = OperatorNameId::LessOp;
  576. break;
  577. case T_GREATER:
  578. kind = OperatorNameId::GreaterOp;
  579. break;
  580. case T_PLUS_EQUAL:
  581. kind = OperatorNameId::PlusEqualOp;
  582. break;
  583. case T_MINUS_EQUAL:
  584. kind = OperatorNameId::MinusEqualOp;
  585. break;
  586. case T_STAR_EQUAL:
  587. kind = OperatorNameId::StarEqualOp;
  588. break;
  589. case T_SLASH_EQUAL:
  590. kind = OperatorNameId::SlashEqualOp;
  591. break;
  592. case T_PERCENT_EQUAL:
  593. kind = OperatorNameId::PercentEqualOp;
  594. break;
  595. case T_CARET_EQUAL:
  596. kind = OperatorNameId::CaretEqualOp;
  597. break;
  598. case T_AMPER_EQUAL:
  599. kind = OperatorNameId::AmpEqualOp;
  600. break;
  601. case T_PIPE_EQUAL:
  602. kind = OperatorNameId::PipeEqualOp;
  603. break;
  604. case T_LESS_LESS:
  605. kind = OperatorNameId::LessLessOp;
  606. break;
  607. case T_GREATER_GREATER:
  608. kind = OperatorNameId::GreaterGreaterOp;
  609. break;
  610. case T_LESS_LESS_EQUAL:
  611. kind = OperatorNameId::LessLessEqualOp;
  612. break;
  613. case T_GREATER_GREATER_EQUAL:
  614. kind = OperatorNameId::GreaterGreaterEqualOp;
  615. break;
  616. case T_EQUAL_EQUAL:
  617. kind = OperatorNameId::EqualEqualOp;
  618. break;
  619. case T_EXCLAIM_EQUAL:
  620. kind = OperatorNameId::ExclaimEqualOp;
  621. break;
  622. case T_LESS_EQUAL:
  623. kind = OperatorNameId::LessEqualOp;
  624. break;
  625. case T_GREATER_EQUAL:
  626. kind = OperatorNameId::GreaterEqualOp;
  627. break;
  628. case T_AMPER_AMPER:
  629. kind = OperatorNameId::AmpAmpOp;
  630. break;
  631. case T_PIPE_PIPE:
  632. kind = OperatorNameId::PipePipeOp;
  633. break;
  634. case T_PLUS_PLUS:
  635. kind = OperatorNameId::PlusPlusOp;
  636. break;
  637. case T_MINUS_MINUS:
  638. kind = OperatorNameId::MinusMinusOp;
  639. break;
  640. case T_COMMA:
  641. kind = OperatorNameId::CommaOp;
  642. break;
  643. case T_ARROW_STAR:
  644. kind = OperatorNameId::ArrowStarOp;
  645. break;
  646. case T_ARROW:
  647. kind = OperatorNameId::ArrowOp;
  648. break;
  649. case T_LPAREN:
  650. kind = OperatorNameId::FunctionCallOp;
  651. break;
  652. case T_LBRACKET:
  653. kind = OperatorNameId::ArrayAccessOp;
  654. break;
  655. default:
  656. kind = OperatorNameId::InvalidOp;
  657. } // switch
  658. return kind;
  659. }
  660. bool Bind::visit(ParameterDeclarationClauseAST *ast)
  661. {
  662. (void) ast;
  663. CPP_CHECK(!"unreachable");
  664. return false;
  665. }
  666. void Bind::parameterDeclarationClause(ParameterDeclarationClauseAST *ast, unsigned lparen_token, Function *fun)
  667. {
  668. if (! ast)
  669. return;
  670. if (! fun) {
  671. translationUnit()->warning(lparen_token, "undefined function");
  672. return;
  673. }
  674. Scope *previousScope = switchScope(fun);
  675. for (ParameterDeclarationListAST *it = ast->parameter_declaration_list; it; it = it->next) {
  676. this->declaration(it->value);
  677. }
  678. if (ast->dot_dot_dot_token)
  679. fun->setVariadic(true);
  680. (void) switchScope(previousScope);
  681. }
  682. bool Bind::visit(TranslationUnitAST *ast)
  683. {
  684. (void) ast;
  685. CPP_CHECK(!"unreachable");
  686. return false;
  687. }
  688. void Bind::translationUnit(TranslationUnitAST *ast)
  689. {
  690. if (! ast)
  691. return;
  692. for (DeclarationListAST *it = ast->declaration_list; it; it = it->next) {
  693. this->declaration(it->value);
  694. }
  695. }
  696. bool Bind::visit(ObjCProtocolRefsAST *ast)
  697. {
  698. (void) ast;
  699. CPP_CHECK(!"unreachable");
  700. return false;
  701. }
  702. void Bind::objCProtocolRefs(ObjCProtocolRefsAST *ast, Symbol *objcClassOrProtocol)
  703. {
  704. if (! ast)
  705. return;
  706. for (NameListAST *it = ast->identifier_list; it; it = it->next) {
  707. const Name *protocolName = this->name(it->value);
  708. ObjCBaseProtocol *baseProtocol = control()->newObjCBaseProtocol(it->value->firstToken(), protocolName);
  709. if (ObjCClass *klass = objcClassOrProtocol->asObjCClass())
  710. klass->addProtocol(baseProtocol);
  711. else if (ObjCProtocol *proto = objcClassOrProtocol->asObjCProtocol())
  712. proto->addProtocol(baseProtocol);
  713. }
  714. }
  715. bool Bind::visit(ObjCMessageArgumentAST *ast)
  716. {
  717. (void) ast;
  718. CPP_CHECK(!"unreachable");
  719. return false;
  720. }
  721. void Bind::objCMessageArgument(ObjCMessageArgumentAST *ast)
  722. {
  723. if (! ast)
  724. return;
  725. ExpressionTy parameter_value_expression = this->expression(ast->parameter_value_expression);
  726. }
  727. bool Bind::visit(ObjCTypeNameAST *ast)
  728. {
  729. (void) ast;
  730. CPP_CHECK(!"unreachable");
  731. return false;
  732. }
  733. FullySpecifiedType Bind::objCTypeName(ObjCTypeNameAST *ast)
  734. {
  735. if (! ast)
  736. return FullySpecifiedType();
  737. // unsigned type_qualifier_token = ast->type_qualifier_token;
  738. ExpressionTy type_id = this->expression(ast->type_id);
  739. return type_id;
  740. }
  741. bool Bind::visit(ObjCInstanceVariablesDeclarationAST *ast)
  742. {
  743. (void) ast;
  744. CPP_CHECK(!"unreachable");
  745. return false;
  746. }
  747. void Bind::objCInstanceVariablesDeclaration(ObjCInstanceVariablesDeclarationAST *ast, ObjCClass *klass)
  748. {
  749. (void) klass;
  750. if (! ast)
  751. return;
  752. // unsigned lbrace_token = ast->lbrace_token;
  753. for (DeclarationListAST *it = ast->instance_variable_list; it; it = it->next) {
  754. this->declaration(it->value);
  755. }
  756. // unsigned rbrace_token = ast->rbrace_token;
  757. }
  758. bool Bind::visit(ObjCPropertyAttributeAST *ast)
  759. {
  760. (void) ast;
  761. CPP_CHECK(!"unreachable");
  762. return false;
  763. }
  764. void Bind::objCPropertyAttribute(ObjCPropertyAttributeAST *ast)
  765. {
  766. if (! ast)
  767. return;
  768. // unsigned attribute_identifier_token = ast->attribute_identifier_token;
  769. // unsigned equals_token = ast->equals_token;
  770. /*const Name *method_selector =*/ this->name(ast->method_selector);
  771. }
  772. bool Bind::visit(ObjCMessageArgumentDeclarationAST *ast)
  773. {
  774. (void) ast;
  775. CPP_CHECK(!"unreachable");
  776. return false;
  777. }
  778. void Bind::objCMessageArgumentDeclaration(ObjCMessageArgumentDeclarationAST *ast, ObjCMethod *method)
  779. {
  780. if (! ast)
  781. return;
  782. FullySpecifiedType type = this->objCTypeName(ast->type_name);
  783. for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
  784. type = this->specifier(it->value, type);
  785. }
  786. const Name *param_name = this->name(ast->param_name);
  787. Argument *arg = control()->newArgument(location(ast->param_name, ast->firstToken()), param_name);
  788. arg->setType(type);
  789. ast->argument = arg;
  790. method->addMember(arg);
  791. }
  792. bool Bind::visit(ObjCMethodPrototypeAST *ast)
  793. {
  794. (void) ast;
  795. CPP_CHECK(!"unreachable");
  796. return false;
  797. }
  798. ObjCMethod *Bind::objCMethodPrototype(ObjCMethodPrototypeAST *ast)
  799. {
  800. if (! ast)
  801. return 0;
  802. // unsigned method_type_token = ast->method_type_token;
  803. FullySpecifiedType returnType = this->objCTypeName(ast->type_name);
  804. const Name *selector = this->name(ast->selector);
  805. const unsigned sourceLocation = location(ast->selector, ast->firstToken());
  806. ObjCMethod *method = control()->newObjCMethod(sourceLocation, selector);
  807. // ### set the offsets
  808. method->setReturnType(returnType);
  809. if (isObjCClassMethod(tokenKind(ast->method_type_token)))
  810. method->setStorage(Symbol::Static);
  811. method->setVisibility(_objcVisibility);
  812. ast->symbol = method;
  813. Scope *previousScope = switchScope(method);
  814. for (ObjCMessageArgumentDeclarationListAST *it = ast->argument_list; it; it = it->next) {
  815. this->objCMessageArgumentDeclaration(it->value, method);
  816. }
  817. (void) switchScope(previousScope);
  818. if (ast->dot_dot_dot_token)
  819. method->setVariadic(true);
  820. FullySpecifiedType specifiers;
  821. for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
  822. specifiers = this->specifier(it->value, specifiers);
  823. }
  824. //setDeclSpecifiers(method, specifiers);
  825. return method;
  826. }
  827. bool Bind::visit(ObjCSynthesizedPropertyAST *ast)
  828. {
  829. (void) ast;
  830. CPP_CHECK(!"unreachable");
  831. return false;
  832. }
  833. void Bind::objCSynthesizedProperty(ObjCSynthesizedPropertyAST *ast)
  834. {
  835. if (! ast)
  836. return;
  837. // unsigned property_identifier_token = ast->property_identifier_token;
  838. // unsigned equals_token = ast->equals_token;
  839. // unsigned alias_identifier_token = ast->alias_identifier_token;
  840. }
  841. bool Bind::visit(LambdaIntroducerAST *ast)
  842. {
  843. (void) ast;
  844. CPP_CHECK(!"unreachable");
  845. return false;
  846. }
  847. void Bind::lambdaIntroducer(LambdaIntroducerAST *ast)
  848. {
  849. if (! ast)
  850. return;
  851. // unsigned lbracket_token = ast->lbracket_token;
  852. this->lambdaCapture(ast->lambda_capture);
  853. // unsigned rbracket_token = ast->rbracket_token;
  854. }
  855. bool Bind::visit(LambdaCaptureAST *ast)
  856. {
  857. (void) ast;
  858. CPP_CHECK(!"unreachable");
  859. return false;
  860. }
  861. void Bind::lambdaCapture(LambdaCaptureAST *ast)
  862. {
  863. if (! ast)
  864. return;
  865. // unsigned default_capture_token = ast->default_capture_token;
  866. for (CaptureListAST *it = ast->capture_list; it; it = it->next) {
  867. this->capture(it->value);
  868. }
  869. }
  870. bool Bind::visit(CaptureAST *ast)
  871. {
  872. (void) ast;
  873. CPP_CHECK(!"unreachable");
  874. return false;
  875. }
  876. void Bind::capture(CaptureAST *ast)
  877. {
  878. if (! ast)
  879. return;
  880. name(ast->identifier);
  881. }
  882. bool Bind::visit(LambdaDeclaratorAST *ast)
  883. {
  884. (void) ast;
  885. CPP_CHECK(!"unreachable");
  886. return false;
  887. }
  888. Function *Bind::lambdaDeclarator(LambdaDeclaratorAST *ast)
  889. {
  890. if (! ast)
  891. return 0;
  892. Function *fun = control()->newFunction(0, 0);
  893. fun->setStartOffset(tokenAt(ast->firstToken()).utf16charsBegin());
  894. fun->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd());
  895. FullySpecifiedType type;
  896. if (ast->trailing_return_type)
  897. type = this->trailingReturnType(ast->trailing_return_type, type);
  898. ast->symbol = fun;
  899. // unsigned lparen_token = ast->lparen_token;
  900. this->parameterDeclarationClause(ast->parameter_declaration_clause, ast->lparen_token, fun);
  901. // unsigned rparen_token = ast->rparen_token;
  902. for (SpecifierListAST *it = ast->attributes; it; it = it->next) {
  903. type = this->specifier(it->value, type);
  904. }
  905. // unsigned mutable_token = ast->mutable_token;
  906. type = this->exceptionSpecification(ast->exception_specification, type);
  907. if (!type.isValid())
  908. type.setType(control()->voidType());
  909. fun->setReturnType(type);
  910. return fun;
  911. }
  912. bool Bind::visit(TrailingReturnTypeAST *ast)
  913. {
  914. (void) ast;
  915. CPP_CHECK(!"unreachable");
  916. return false;
  917. }
  918. FullySpecifiedType Bind::trailingReturnType(TrailingReturnTypeAST *ast, const FullySpecifiedType &init)
  919. {
  920. FullySpecifiedType type = init;
  921. if (! ast)
  922. return type;
  923. // unsigned arrow_token = ast->arrow_token;
  924. for (SpecifierListAST *it = ast->attributes; it; it = it->next) {
  925. type = this->specifier(it->value, type);
  926. }
  927. for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
  928. type = this->specifier(it->value, type);
  929. }
  930. DeclaratorIdAST *declaratorId = 0;
  931. type = this->declarator(ast->declarator, type, &declaratorId);
  932. return type;
  933. }
  934. const StringLiteral *Bind::asStringLiteral(unsigned firstToken, unsigned lastToken)
  935. {
  936. std::string buffer;
  937. for (unsigned index = firstToken; index != lastToken; ++index) {
  938. const Token &tk = tokenAt(index);
  939. if (index != firstToken && (tk.whitespace() || tk.newline()))
  940. buffer += ' ';
  941. buffer += tk.spell();
  942. }
  943. return control()->stringLiteral(buffer.c_str(), unsigned(buffer.size()));
  944. }
  945. // StatementAST
  946. bool Bind::visit(QtMemberDeclarationAST *ast)
  947. {
  948. const Name *name = 0;
  949. if (tokenKind(ast->q_token) == T_Q_D)
  950. name = control()->identifier("d");
  951. else
  952. name = control()->identifier("q");
  953. FullySpecifiedType declTy = this->expression(ast->type_id);
  954. if (tokenKind(ast->q_token) == T_Q_D) {
  955. if (NamedType *namedTy = declTy->asNamedType()) {
  956. if (const Identifier *nameId = namedTy->name()->asNameId()) {
  957. std::string privateClass;
  958. privateClass += nameId->identifier()->chars();
  959. privateClass += "Private";
  960. const Name *privName = control()->identifier(privateClass.c_str(), unsigned(privateClass.size()));
  961. declTy.setType(control()->namedType(privName));
  962. }
  963. }
  964. }
  965. Declaration *symbol = control()->newDeclaration(/*generated*/ 0, name);
  966. symbol->setType(control()->pointerType(declTy));
  967. _scope->addMember(symbol);
  968. return false;
  969. }
  970. bool Bind::visit(CaseStatementAST *ast)
  971. {
  972. ExpressionTy expression = this->expression(ast->expression);
  973. this->statement(ast->statement);
  974. return false;
  975. }
  976. bool Bind::visit(CompoundStatementAST *ast)
  977. {
  978. Block *block = control()->newBlock(ast->firstToken());
  979. unsigned startScopeToken = ast->lbrace_token ? ast->lbrace_token : ast->firstToken();
  980. block->setStartOffset(tokenAt(startScopeToken).utf16charsEnd());
  981. block->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd());
  982. ast->symbol = block;
  983. _scope->addMember(block);
  984. Scope *previousScope = switchScope(block);
  985. for (StatementListAST *it = ast->statement_list; it; it = it->next) {
  986. this->statement(it->value);
  987. }
  988. (void) switchScope(previousScope);
  989. return false;
  990. }
  991. bool Bind::visit(DeclarationStatementAST *ast)
  992. {
  993. this->declaration(ast->declaration);
  994. return false;
  995. }
  996. bool Bind::visit(DoStatementAST *ast)
  997. {
  998. this->statement(ast->statement);
  999. ExpressionTy expression = this->expression(ast->expression);
  1000. return false;
  1001. }
  1002. bool Bind::visit(ExpressionOrDeclarationStatementAST *ast)
  1003. {
  1004. this->statement(ast->expression);
  1005. this->statement(ast->declaration);
  1006. return false;
  1007. }
  1008. bool Bind::visit(ExpressionStatementAST *ast)
  1009. {
  1010. ExpressionTy expression = this->expression(ast->expression);
  1011. // unsigned semicolon_token = ast->semicolon_token;
  1012. return false;
  1013. }
  1014. bool Bind::visit(ForeachStatementAST *ast)
  1015. {
  1016. Block *block = control()->newBlock(ast->firstToken());
  1017. const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
  1018. block->setStartOffset(tokenAt(startScopeToken).utf16charsEnd());
  1019. block->setEndOffset(tokenAt(ast->lastToken()).utf16charsBegin());
  1020. _scope->addMember(block);
  1021. ast->symbol = block;
  1022. Scope *previousScope = switchScope(block);
  1023. FullySpecifiedType type;
  1024. for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
  1025. type = this->specifier(it->value, type);
  1026. }
  1027. DeclaratorIdAST *declaratorId = 0;
  1028. type = this->declarator(ast->declarator, type, &declaratorId);
  1029. const StringLiteral *initializer = 0;
  1030. if (type.isAuto() && translationUnit()->languageFeatures().cxx11Enabled) {
  1031. ExpressionTy exprType = this->expression(ast->expression);
  1032. ArrayType* arrayType = 0;
  1033. arrayType = exprType->asArrayType();
  1034. if (arrayType != 0)
  1035. type = arrayType->elementType();
  1036. else if (ast->expression != 0) {
  1037. unsigned startOfExpression = ast->expression->firstToken();
  1038. unsigned endOfExpression = ast->expression->lastToken();
  1039. const StringLiteral *sl = asStringLiteral(startOfExpression, endOfExpression);
  1040. const std::string buff = std::string("*") + sl->chars() + ".begin()";
  1041. initializer = control()->stringLiteral(buff.c_str(), unsigned(buff.size()));
  1042. }
  1043. }
  1044. if (declaratorId && declaratorId->name) {
  1045. unsigned sourceLocation = location(declaratorId->name, ast->firstToken());
  1046. Declaration *decl = control()->newDeclaration(sourceLocation, declaratorId->name->name);
  1047. decl->setType(type);
  1048. decl->setInitializer(initializer);
  1049. block->addMember(decl);
  1050. }
  1051. /*ExpressionTy initializer =*/ this->expression(ast->initializer);
  1052. /*ExpressionTy expression =*/ this->expression(ast->expression);
  1053. this->statement(ast->statement);
  1054. (void) switchScope(previousScope);
  1055. return false;
  1056. }
  1057. bool Bind::visit(RangeBasedForStatementAST *ast)
  1058. {
  1059. Block *block = control()->newBlock(ast->firstToken());
  1060. const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
  1061. block->setStartOffset(tokenAt(startScopeToken).utf16charsEnd());
  1062. block->setEndOffset(tokenAt(ast->lastToken()).utf16charsBegin());
  1063. _scope->addMember(block);
  1064. ast->symbol = block;
  1065. Scope *previousScope = switchScope(block);
  1066. FullySpecifiedType type;
  1067. for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
  1068. type = this->specifier(it->value, type);
  1069. }
  1070. DeclaratorIdAST *declaratorId = 0;
  1071. type = this->declarator(ast->declarator, type, &declaratorId);
  1072. const StringLiteral *initializer = 0;
  1073. if (type.isAuto() && translationUnit()->languageFeatures().cxx11Enabled) {
  1074. ExpressionTy exprType = this->expression(ast->expression);
  1075. ArrayType* arrayType = 0;
  1076. arrayType = exprType->asArrayType();
  1077. if (arrayType != 0)
  1078. type = arrayType->elementType();
  1079. else if (ast->expression != 0) {
  1080. unsigned startOfExpression = ast->expression->firstToken();
  1081. unsigned endOfExpression = ast->expression->lastToken();
  1082. const StringLiteral *sl = asStringLiteral(startOfExpression, endOfExpression);
  1083. const std::string buff = std::string("*") + sl->chars() + ".begin()";
  1084. initializer = control()->stringLiteral(buff.c_str(), unsigned(buff.size()));
  1085. }
  1086. }
  1087. if (declaratorId && declaratorId->name) {
  1088. unsigned sourceLocation = location(declaratorId->name, ast->firstToken());
  1089. Declaration *decl = control()->newDeclaration(sourceLocation, declaratorId->name->name);
  1090. decl->setType(type);
  1091. decl->setInitializer(initializer);
  1092. block->addMember(decl);
  1093. }
  1094. /*ExpressionTy expression =*/ this->expression(ast->expression);
  1095. this->statement(ast->statement);
  1096. (void) switchScope(previousScope);
  1097. return false;
  1098. }
  1099. bool Bind::visit(ForStatementAST *ast)
  1100. {
  1101. Block *block = control()->newBlock(ast->firstToken());
  1102. const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
  1103. block->setStartOffset(tokenAt(startScopeToken).utf16charsEnd());
  1104. block->setEndOffset(tokenAt(ast->lastToken()).utf16charsBegin());
  1105. _scope->addMember(block);
  1106. ast->symbol = block;
  1107. Scope *previousScope = switchScope(block);
  1108. this->statement(ast->initializer);
  1109. /*ExpressionTy condition =*/ this->expression(ast->condition);
  1110. // unsigned semicolon_token = ast->semicolon_token;
  1111. /*ExpressionTy expression =*/ this->expression(ast->expression);
  1112. // unsigned rparen_token = ast->rparen_token;
  1113. this->statement(ast->statement);
  1114. (void) switchScope(previousScope);
  1115. return false;
  1116. }
  1117. bool Bind::visit(IfStatementAST *ast)
  1118. {
  1119. Block *block = control()->newBlock(ast->firstToken());
  1120. const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
  1121. block->setStartOffset(tokenAt(startScopeToken).utf16charsEnd());
  1122. block->setEndOffset(tokenAt(ast->lastToken()).utf16charsBegin());
  1123. _scope->addMember(block);
  1124. ast->symbol = block;
  1125. Scope *previousScope = switchScope(block);
  1126. /*ExpressionTy condition =*/ this->expression(ast->condition);
  1127. this->statement(ast->statement);
  1128. this->statement(ast->else_statement);
  1129. (void) switchScope(previousScope);
  1130. return false;
  1131. }
  1132. bool Bind::visit(LabeledStatementAST *ast)
  1133. {
  1134. // unsigned label_token = ast->label_token;
  1135. // unsigned colon_token = ast->colon_token;
  1136. this->statement(ast->statement);
  1137. return false;
  1138. }
  1139. bool Bind::visit(BreakStatementAST *ast)
  1140. {
  1141. (void) ast;
  1142. // unsigned break_token = ast->break_token;
  1143. // unsigned semicolon_token = ast->semicolon_token;
  1144. return false;
  1145. }
  1146. bool Bind::visit(ContinueStatementAST *ast)
  1147. {
  1148. (void) ast;
  1149. // unsigned continue_token = ast->continue_token;
  1150. // unsigned semicolon_token = ast->semicolon_token;
  1151. return false;
  1152. }
  1153. bool Bind::visit(GotoStatementAST *ast)
  1154. {
  1155. (void) ast;
  1156. // unsigned goto_token = ast->goto_token;
  1157. // unsigned identifier_token = ast->identifier_token;
  1158. // unsigned semicolon_token = ast->semicolon_token;
  1159. return false;
  1160. }
  1161. bool Bind::visit(ReturnStatementAST *ast)
  1162. {
  1163. ExpressionTy expression = this->expression(ast->expression);
  1164. return false;
  1165. }
  1166. bool Bind::visit(SwitchStatementAST *ast)
  1167. {
  1168. Block *block = control()->newBlock(ast->firstToken());
  1169. const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
  1170. block->setStartOffset(tokenAt(startScopeToken).utf16charsEnd());
  1171. block->setEndOffset(tokenAt(ast->lastToken()).utf16charsBegin());
  1172. _scope->addMember(block);
  1173. ast->symbol = block;
  1174. Scope *previousScope = switchScope(block);
  1175. /*ExpressionTy condition =*/ this->expression(ast->condition);
  1176. this->statement(ast->statement);
  1177. (void) switchScope(previousScope);
  1178. return false;
  1179. }
  1180. bool Bind::visit(TryBlockStatementAST *ast)
  1181. {
  1182. // unsigned try_token = ast->try_token;
  1183. this->statement(ast->statement);
  1184. for (CatchClauseListAST *it = ast->catch_clause_list; it; it = it->next) {
  1185. this->statement(it->value);
  1186. }
  1187. return false;
  1188. }
  1189. bool Bind::visit(CatchClauseAST *ast)
  1190. {
  1191. Block *block = control()->newBlock(ast->firstToken());
  1192. const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
  1193. block->setStartOffset(tokenAt(startScopeToken).utf16charsEnd());
  1194. block->setEndOffset(tokenAt(ast->lastToken()).utf16charsBegin());
  1195. _scope->addMember(block);
  1196. ast->symbol = block;
  1197. Scope *previousScope = switchScope(block);
  1198. this->declaration(ast->exception_declaration);
  1199. // unsigned rparen_token = ast->rparen_token;
  1200. this->statement(ast->statement);
  1201. (void) switchScope(previousScope);
  1202. return false;
  1203. }
  1204. bool Bind::visit(WhileStatementAST *ast)
  1205. {
  1206. Block *block = control()->newBlock(ast->firstToken());
  1207. const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
  1208. block->setStartOffset(tokenAt(startScopeToken).utf16charsEnd());
  1209. block->setEndOffset(tokenAt(ast->lastToken()).utf16charsBegin());
  1210. _scope->addMember(block);
  1211. ast->symbol = block;
  1212. Scope *previousScope = switchScope(block);
  1213. /*ExpressionTy condition =*/ this->expression(ast->condition);
  1214. this->statement(ast->statement);
  1215. (void) switchScope(previousScope);
  1216. return false;
  1217. }
  1218. bool Bind::visit(ObjCFastEnumerationAST *ast)
  1219. {
  1220. Block *block = control()->newBlock(ast->firstToken());
  1221. const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken();
  1222. block->setStartOffset(tokenAt(startScopeToken).utf16charsEnd());
  1223. block->setEndOffset(tokenAt(ast->lastToken()).utf16charsBegin());
  1224. _scope->addMember(block);
  1225. ast->symbol = block;
  1226. Scope *previousScope = switchScope(block);
  1227. FullySpecifiedType type;
  1228. for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
  1229. type = this->specifier(it->value, type);
  1230. }
  1231. DeclaratorIdAST *declaratorId = 0;
  1232. type = this->declarator(ast->declarator, type, &declaratorId);
  1233. if (declaratorId && declaratorId->name) {
  1234. unsigned sourceLocation = location(declaratorId->name, ast->firstToken());
  1235. Declaration *decl = control()->newDeclaration(sourceLocation, declaratorId->name->name);
  1236. decl->setType(type);
  1237. block->addMember(decl);
  1238. }
  1239. /*ExpressionTy initializer =*/ this->expression(ast->initializer);
  1240. /*ExpressionTy fast_enumeratable_expression =*/ this->expression(ast->fast_enumeratable_expression);
  1241. this->statement(ast->statement);
  1242. (void) switchScope(previousScope);
  1243. return false;
  1244. }
  1245. bool Bind::visit(ObjCSynchronizedStatementAST *ast)
  1246. {
  1247. // unsigned synchronized_token = ast->synchronized_token;
  1248. // unsigned lparen_token = ast->lparen_token;
  1249. ExpressionTy synchronized_object = this->expression(ast->synchronized_object);
  1250. // unsigned rparen_token = ast->rparen_token;
  1251. this->statement(ast->statement);
  1252. return false;
  1253. }
  1254. // ExpressionAST
  1255. bool Bind::visit(IdExpressionAST *ast)
  1256. {
  1257. /*const Name *name =*/ this->name(ast->name);
  1258. return false;
  1259. }
  1260. bool Bind::visit(CompoundExpressionAST *ast)
  1261. {
  1262. // unsigned lparen_token = ast->lparen_token;
  1263. this->statement(ast->statement);
  1264. // unsigned rparen_token = ast->rparen_token;
  1265. return false;
  1266. }
  1267. bool Bind::visit(CompoundLiteralAST *ast)
  1268. {
  1269. // unsigned lparen_token = ast->lparen_token;
  1270. ExpressionTy type_id = this->expression(ast->type_id);
  1271. // unsigned rparen_token = ast->rparen_token;
  1272. ExpressionTy initializer = this->expression(ast->initializer);
  1273. return false;
  1274. }
  1275. bool Bind::visit(QtMethodAST *ast)
  1276. {
  1277. // unsigned method_token = ast->method_token;
  1278. // unsigned lparen_token = ast->lparen_token;
  1279. FullySpecifiedType type;
  1280. DeclaratorIdAST *declaratorId = 0;
  1281. type = this->declarator(ast->declarator, type, &declaratorId);
  1282. // unsigned rparen_token = ast->rparen_token;
  1283. return false;
  1284. }
  1285. bool Bind::visit(BinaryExpressionAST *ast)
  1286. {
  1287. ExpressionTy left_expression = this->expression(ast->left_expression);
  1288. // unsigned binary_op_token = ast->binary_op_token;
  1289. ExpressionTy right_expression = this->expression(ast->right_expression);
  1290. return false;
  1291. }
  1292. bool Bind::visit(CastExpressionAST *ast)
  1293. {
  1294. // unsigned lparen_token = ast->lparen_token;
  1295. ExpressionTy type_id = this->expression(ast->type_id);
  1296. // unsigned rparen_token = ast->rparen_token;
  1297. ExpressionTy expression = this->expression(ast->expression);
  1298. return false;
  1299. }
  1300. bool Bind::visit(ConditionAST *ast)
  1301. {
  1302. FullySpecifiedType type;
  1303. for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
  1304. type = this->specifier(it->value, type);
  1305. }
  1306. DeclaratorIdAST *declaratorId = 0;
  1307. type = this->declarator(ast->declarator, type, &declaratorId);
  1308. if (declaratorId && declaratorId->name) {
  1309. unsigned sourceLocation = location(declaratorId->name, ast->firstToken());
  1310. Declaration *decl = control()->newDeclaration(sourceLocation, declaratorId->name->name);
  1311. decl->setType(type);
  1312. _scope->addMember(decl);
  1313. }
  1314. return false;
  1315. }
  1316. bool Bind::visit(ConditionalExpressionAST *ast)
  1317. {
  1318. ExpressionTy condition = this->expression(ast->condition);
  1319. // unsigned question_token = ast->question_token;
  1320. ExpressionTy left_expression = this->expression(ast->left_expression);
  1321. // unsigned colon_token = ast->colon_token;
  1322. ExpressionTy right_expression = this->expression(ast->right_expression);
  1323. return false;
  1324. }
  1325. bool Bind::visit(CppCastExpressionAST *ast)
  1326. {
  1327. // unsigned cast_token = ast->cast_token;
  1328. // unsigned less_token = ast->less_token;
  1329. ExpressionTy type_id = this->expression(ast->type_id);
  1330. // unsigned greater_token = ast->greater_token;
  1331. // unsigned lparen_token = ast->lparen_token;
  1332. ExpressionTy expression = this->expression(ast->expression);
  1333. // unsigned rparen_token = ast->rparen_token;
  1334. return false;
  1335. }
  1336. bool Bind::visit(DeleteExpressionAST *ast)
  1337. {
  1338. // unsigned scope_token = ast->scope_token;
  1339. // unsigned delete_token = ast->delete_token;
  1340. // unsigned lbracket_token = ast->lbracket_token;
  1341. // unsigned rbracket_token = ast->rbracket_token;
  1342. ExpressionTy expression = this->expression(ast->expression);
  1343. return false;
  1344. }
  1345. bool Bind::visit(ArrayInitializerAST *ast)
  1346. {
  1347. // unsigned lbrace_token = ast->lbrace_token;
  1348. for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
  1349. ExpressionTy value = this->expression(it->value);
  1350. }
  1351. // unsigned rbrace_token = ast->rbrace_token;
  1352. return false;
  1353. }
  1354. bool Bind::visit(NewExpressionAST *ast)
  1355. {
  1356. // unsigned scope_token = ast->scope_token;
  1357. // unsigned new_token = ast->new_token;
  1358. this->newPlacement(ast->new_placement);
  1359. // unsigned lparen_token = ast->lparen_token;
  1360. ExpressionTy type_id = this->expression(ast->type_id);
  1361. // unsigned rparen_token = ast->rparen_token;
  1362. this->newTypeId(ast->new_type_id);
  1363. this->expression(ast->new_initializer);
  1364. return false;
  1365. }
  1366. bool Bind::visit(TypeidExpressionAST *ast)
  1367. {
  1368. // unsigned typeid_token = ast->typeid_token;
  1369. // unsigned lparen_token = ast->lparen_token;
  1370. ExpressionTy expression = this->expression(ast->expression);
  1371. // unsigned rparen_token = ast->rparen_token;
  1372. return false;
  1373. }
  1374. bool Bind::visit(TypenameCallExpressionAST *ast)
  1375. {
  1376. // unsigned typename_token = ast->typename_token;
  1377. /*const Name *name =*/ this->name(ast->name);
  1378. this->expression(ast->expression);
  1379. return false;
  1380. }
  1381. bool Bind::visit(TypeConstructorCallAST *ast)
  1382. {
  1383. FullySpecifiedType type;
  1384. for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
  1385. type = this->specifier(it->value, type);
  1386. }
  1387. this->expression(ast->expression);
  1388. return false;
  1389. }
  1390. bool Bind::visit(SizeofExpressionAST *ast)
  1391. {
  1392. // unsigned sizeof_token = ast->sizeof_token;
  1393. // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
  1394. // unsigned lparen_token = ast->lparen_token;
  1395. ExpressionTy expression = this->expression(ast->expression);
  1396. // unsigned rparen_token = ast->rparen_token;
  1397. return false;
  1398. }
  1399. bool Bind::visit(PointerLiteralAST *ast)
  1400. {
  1401. (void) ast;
  1402. // unsigned literal_token = ast->literal_token;
  1403. return false;
  1404. }
  1405. bool Bind::visit(NumericLiteralAST *ast)
  1406. {
  1407. (void) ast;
  1408. // unsigned literal_token = ast->literal_token;
  1409. return false;
  1410. }
  1411. bool Bind::visit(BoolLiteralAST *ast)
  1412. {
  1413. (void) ast;
  1414. // unsigned literal_token = ast->literal_token;
  1415. return false;
  1416. }
  1417. bool Bind::visit(ThisExpressionAST *ast)
  1418. {
  1419. (void) ast;
  1420. // unsigned this_token = ast->this_token;
  1421. return false;
  1422. }
  1423. bool Bind::visit(NestedExpressionAST *ast)
  1424. {
  1425. // unsigned lparen_token = ast->lparen_token;
  1426. ExpressionTy expression = this->expression(ast->expression);
  1427. // unsigned rparen_token = ast->rparen_token;
  1428. return false;
  1429. }
  1430. bool Bind::visit(StringLiteralAST *ast)
  1431. {
  1432. // unsigned literal_token = ast->literal_token;
  1433. ExpressionTy next = this->expression(ast->next);
  1434. return false;
  1435. }
  1436. bool Bind::visit(ThrowExpressionAST *ast)
  1437. {
  1438. // unsigned throw_token = ast->throw_token;
  1439. ExpressionTy expression = this->expression(ast->expression);
  1440. return false;
  1441. }
  1442. bool Bind::visit(TypeIdAST *ast)
  1443. {
  1444. FullySpecifiedType type;
  1445. for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
  1446. type = this->specifier(it->value, type);
  1447. }
  1448. DeclaratorIdAST *declaratorId = 0;
  1449. type = this->declarator(ast->declarator, type, &declaratorId);
  1450. _expression = type;
  1451. return false;
  1452. }
  1453. bool Bind::visit(UnaryExpressionAST *ast)
  1454. {
  1455. // unsigned unary_op_token = ast->unary_op_token;
  1456. ExpressionTy expression = this->expression(ast->expression);
  1457. return false;
  1458. }
  1459. bool Bind::visit(ObjCMessageExpressionAST *ast)
  1460. {
  1461. // unsigned lbracket_token = ast->lbracket_token;
  1462. /*ExpressionTy receiver_expression =*/ this->expression(ast->receiver_expression);
  1463. /*const Name *selector =*/ this->name(ast->selector);
  1464. for (ObjCMessageArgumentListAST *it = ast->argument_list; it; it = it->next) {
  1465. this->objCMessageArgument(it->value);
  1466. }
  1467. // unsigned rbracket_token = ast->rbracket_token;
  1468. return false;
  1469. }
  1470. bool Bind::visit(ObjCProtocolExpressionAST *ast)
  1471. {
  1472. (void) ast;
  1473. // unsigned protocol_token = ast->protocol_token;
  1474. // unsigned lparen_token = ast->lparen_token;
  1475. // unsigned identifier_token = ast->identifier_token;
  1476. // unsigned rparen_token = ast->rparen_token;
  1477. return false;
  1478. }
  1479. bool Bind::visit(ObjCEncodeExpressionAST *ast)
  1480. {
  1481. // unsigned encode_token = ast->encode_token;
  1482. FullySpecifiedType type = this->objCTypeName(ast->type_name);
  1483. return false;
  1484. }
  1485. bool Bind::visit(ObjCSelectorExpressionAST *ast)
  1486. {
  1487. // unsigned selector_token = ast->selector_token;
  1488. // unsigned lparen_token = ast->lparen_token;
  1489. /*const Name *selector =*/ this->name(ast->selector);
  1490. // unsigned rparen_token = ast->rparen_token;
  1491. return false;
  1492. }
  1493. bool Bind::visit(LambdaExpressionAST *ast)
  1494. {
  1495. this->lambdaIntroducer(ast->lambda_introducer);
  1496. if (Function *function = this->lambdaDeclarator(ast->lambda_declarator)) {
  1497. _scope->addMember(function);
  1498. Scope *previousScope = switchScope(function);
  1499. this->statement(ast->statement);
  1500. (void) switchScope(previousScope);
  1501. } else {
  1502. this->statement(ast->statement);
  1503. }
  1504. return false;
  1505. }
  1506. bool Bind::visit(BracedInitializerAST *ast)
  1507. {
  1508. // unsigned lbrace_token = ast->lbrace_token;
  1509. for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
  1510. /*ExpressionTy value =*/ this->expression(it->value);
  1511. }
  1512. // unsigned comma_token = ast->comma_token;
  1513. // unsigned rbrace_token = ast->rbrace_token;
  1514. return false;
  1515. }
  1516. static int methodKeyForInvokableToken(int kind)
  1517. {
  1518. if (kind == T_Q_SIGNAL)
  1519. return Function::SignalMethod;
  1520. else if (kind == T_Q_SLOT)
  1521. return Function::SlotMethod;
  1522. else if (kind == T_Q_INVOKABLE)
  1523. return Function::InvokableMethod;
  1524. return Function::NormalMethod;
  1525. }
  1526. // DeclarationAST
  1527. bool Bind::visit(SimpleDeclarationAST *ast)
  1528. {
  1529. int methodKey = _methodKey;
  1530. if (ast->qt_invokable_token)
  1531. methodKey = methodKeyForInvokableToken(tokenKind(ast->qt_invokable_token));
  1532. // unsigned qt_invokable_token = ast->qt_invokable_token;
  1533. FullySpecifiedType type;
  1534. for (SpecifierListAST *it = ast->decl_specifier_list; it; it = it->next) {
  1535. type = this->specifier(it->value, type);
  1536. }
  1537. List<Symbol *> **symbolTail = &ast->symbols;
  1538. if (! ast->declarator_list) {
  1539. ElaboratedTypeSpecifierAST *elabTypeSpec = 0;
  1540. for (SpecifierListAST *it = ast->decl_specifier_list; ! elabTypeSpec && it; it = it->next)
  1541. elabTypeSpec = it->value->asElaboratedTypeSpecifier();
  1542. if (elabTypeSpec && tokenKind(elabTypeSpec->classkey_token) != T_TYPENAME) {
  1543. unsigned sourceLocation = elabTypeSpec->firstToken();
  1544. const Name *name = 0;
  1545. if (elabTypeSpec->name) {
  1546. sourceLocation = location(elabTypeSpec->name, sourceLocation);
  1547. name = elabTypeSpec->name->name;
  1548. }
  1549. ensureValidClassName(&name, sourceLocation);
  1550. ForwardClassDeclaration *decl = control()->newForwardClassDeclaration(sourceLocation, name);
  1551. setDeclSpecifiers(decl, type);
  1552. _scope->addMember(decl);
  1553. *symbolTail = new (translationUnit()->memoryPool()) List<Symbol *>(decl);
  1554. symbolTail = &(*symbolTail)->next;
  1555. }
  1556. }
  1557. for (DeclaratorListAST *it = ast->declarator_list; it; it = it->next) {
  1558. DeclaratorIdAST *declaratorId = 0;
  1559. FullySpecifiedType declTy = this->declarator(it->value, type.qualifiedType(), &declaratorId);
  1560. const Name *declName = 0;
  1561. unsigned sourceLocation = location(it->value, ast->firstToken());
  1562. if (declaratorId && declaratorId->name)
  1563. declName = declaratorId->name->name;
  1564. Declaration *decl = control()->newDeclaration(sourceLocation, declName);
  1565. decl->setType(declTy);
  1566. setDeclSpecifiers(decl, type);
  1567. if (Function *fun = decl->type()->asFunctionType()) {
  1568. fun->setEnclosingScope(_scope);
  1569. fun->setSourceLocation(sourceLocation, translationUnit());
  1570. setDeclSpecifiers(fun, type);
  1571. if (declaratorId && declaratorId->name)
  1572. fun->setName(declaratorId->name->name); // update the function name
  1573. }
  1574. else if (declTy.isAuto()) {
  1575. const ExpressionAST *initializer = it->value->initializer;
  1576. if (!initializer && declaratorId)
  1577. translationUnit()->error(location(declaratorId->name, ast->firstToken()), "auto-initialized variable must have an initializer");
  1578. else if (initializer) {
  1579. unsigned startOfExpression = initializer->firstToken();
  1580. unsigned endOfExpression = initializer->lastToken();
  1581. decl->setInitializer(asStringLiteral(startOfExpression, endOfExpression));
  1582. }
  1583. }
  1584. else
  1585. {
  1586. // ATOMIC BEGIN
  1587. // store initializer
  1588. const ExpressionAST *initializer = it->value->initializer;
  1589. if (initializer)
  1590. {
  1591. unsigned startOfExpression = initializer->firstToken();
  1592. unsigned endOfExpression = initializer->lastToken();
  1593. decl->setInitializer(asStringLiteral(startOfExpression, endOfExpression));
  1594. }
  1595. // ATOMIC END
  1596. }
  1597. if (_scope->isClass()) {
  1598. decl->setVisibility(_visibility);
  1599. if (Function *funTy = decl->type()->asFunctionType()) {
  1600. funTy->setMethodKey(methodKey);
  1601. bool pureVirtualInit = it->value->equal_token
  1602. && it->value->initializer
  1603. && it->value->initializer->asNumericLiteral();
  1604. if (funTy->isVirtual() && pureVirtualInit)
  1605. funTy->setPureVirtual(true);
  1606. }
  1607. }
  1608. _scope->addMember(decl);
  1609. *symbolTail = new (translationUnit()->memoryPool()) List<Symbol *>(decl);
  1610. symbolTail = &(*symbolTail)->next;
  1611. }
  1612. return false;
  1613. }
  1614. bool Bind::visit(EmptyDeclarationAST *ast)
  1615. {
  1616. (void) ast;
  1617. unsigned semicolon_token = ast->semicolon_token;
  1618. if (_scope && (_scope->isClass() || _scope->isNamespace())) {
  1619. const Token &tk = tokenAt(semicolon_token);
  1620. if (! tk.generated())
  1621. translationUnit()->warning(semicolon_token, "extra `;'");
  1622. }
  1623. return false;
  1624. }
  1625. bool Bind::visit(AccessDeclarationAST *ast)
  1626. {
  1627. const int accessSpecifier = tokenKind(ast->access_specifier_token);
  1628. _visibility = visibilityForAccessSpecifier(accessSpecifier);
  1629. if (ast->slots_token)
  1630. _methodKey = Function::SlotMethod;
  1631. else if (accessSpecifier == T_Q_SIGNALS)
  1632. _methodKey = Function::SignalMethod;
  1633. else
  1634. _methodKey = Function::NormalMethod;
  1635. return false;
  1636. }
  1637. bool Bind::visit(QtObjectTagAST *ast)
  1638. {
  1639. (void) ast;
  1640. // unsigned q_object_token = ast->q_object_token;
  1641. return false;
  1642. }
  1643. bool Bind::visit(QtPrivateSlotAST *ast)
  1644. {
  1645. // unsigned q_private_slot_token = ast->q_private_slot_token;
  1646. // unsigned lparen_token = ast->lparen_token;
  1647. // unsigned dptr_token = ast->dptr_token;
  1648. // unsigned dptr_lparen_token = ast->dptr_lparen_token;
  1649. // unsigned dptr_rparen_token = ast->dptr_rparen_token;
  1650. // unsigned comma_token = ast->comma_token;
  1651. FullySpecifiedType type;
  1652. for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
  1653. type = this->specifier(it->value, type);
  1654. }
  1655. DeclaratorIdAST *declaratorId = 0;
  1656. type = this->declarator(ast->declarator, type, &declaratorId);
  1657. // unsigned rparen_token = ast->rparen_token;
  1658. return false;
  1659. }
  1660. static void qtPropertyAttribute(TranslationUnit *unit, ExpressionAST *expression,
  1661. int *flags,
  1662. QtPropertyDeclaration::Flag flag,
  1663. QtPropertyDeclaration::Flag function)
  1664. {
  1665. if (!expression)
  1666. return;
  1667. *flags &= ~function & ~flag;
  1668. if (BoolLiteralAST *boollit = expression->asBoolLiteral()) {
  1669. const int kind = unit->tokenAt(boollit->literal_token).kind();
  1670. if (kind == T_TRUE)
  1671. *flags |= flag;
  1672. } else {
  1673. *flags |= function;
  1674. }
  1675. }
  1676. bool Bind::visit(QtPropertyDeclarationAST *ast)
  1677. {
  1678. // unsigned property_specifier_token = ast->property_specifier_token;
  1679. // unsigned lparen_token = ast->lparen_token;
  1680. ExpressionTy type_id = this->expression(ast->type_id);
  1681. const Name *property_name = this->name(ast->property_name);
  1682. unsigned sourceLocation = ast->firstToken();
  1683. if (ast->property_name)
  1684. sourceLocation = ast->property_name->firstToken();
  1685. QtPropertyDeclaration *propertyDeclaration = control()->newQtPropertyDeclaration(sourceLocation, property_name);
  1686. propertyDeclaration->setType(type_id);
  1687. int flags = QtPropertyDeclaration::DesignableFlag
  1688. | QtPropertyDeclaration::ScriptableFlag
  1689. | QtPropertyDeclaration::StoredFlag;
  1690. for (QtPropertyDeclarationItemListAST *it = ast->property_declaration_item_list; it; it = it->next) {
  1691. if (!it->value || !it->value->item_name_token)
  1692. continue;
  1693. this->expression(it->value->expression);
  1694. std::string name = spell(it->value->item_name_token);
  1695. if (name == "CONSTANT") {
  1696. flags |= QtPropertyDeclaration::ConstantFlag;
  1697. } else if (name == "FINAL") {
  1698. flags |= QtPropertyDeclaration::FinalFlag;
  1699. } else if (name == "READ") {
  1700. flags |= QtPropertyDeclaration::ReadFunction;
  1701. } else if (name == "WRITE") {
  1702. flags |= QtPropertyDeclaration::WriteFunction;
  1703. } else if (name == "MEMBER") {
  1704. flags |= QtPropertyDeclaration::MemberVariable;
  1705. } else if (name == "RESET") {
  1706. flags |= QtPropertyDeclaration::ResetFunction;
  1707. } else if (name == "NOTIFY") {
  1708. flags |= QtPropertyDeclaration::NotifyFunction;
  1709. } else if (name == "REVISION") {
  1710. // ### handle REVISION property
  1711. } else if (name == "DESIGNABLE") {
  1712. qtPropertyAttribute(translationUnit(), it->value->expression, &flags,
  1713. QtPropertyDeclaration::DesignableFlag, QtPropertyDeclaration::DesignableFunction);
  1714. } else if (name == "SCRIPTABLE") {
  1715. qtPropertyAttribute(translationUnit(), it->value->expression, &flags,
  1716. QtPropertyDeclaration::ScriptableFlag, QtPropertyDeclaration::ScriptableFunction);
  1717. } else if (name == "STORED") {
  1718. qtPropertyAttribute(translationUnit(), it->value->expression, &flags,
  1719. QtPropertyDeclaration::StoredFlag, QtPropertyDeclaration::StoredFunction);
  1720. } else if (name == "USER") {
  1721. qtPropertyAttribute(translationUnit(), it->value->expression, &flags,
  1722. QtPropertyDeclaration::UserFlag, QtPropertyDeclaration::UserFunction);
  1723. }
  1724. }
  1725. propertyDeclaration->setFlags(flags);
  1726. _scope->addMember(propertyDeclaration);
  1727. // unsigned rparen_token = ast->rparen_token;
  1728. return false;
  1729. }
  1730. bool Bind::visit(QtEnumDeclarationAST *ast)
  1731. {
  1732. // unsigned enum_specifier_token = ast->enum_specifier_token;
  1733. // unsigned lparen_token = ast->lparen_token;
  1734. for (NameListAST *it = ast->enumerator_list; it; it = it->next) {
  1735. const Name *value = this->name(it->value);
  1736. if (!value)
  1737. continue;
  1738. QtEnum *qtEnum = control()->newQtEnum(it->value->firstToken(), value);
  1739. _scope->addMember(qtEnum);
  1740. }
  1741. // unsigned rparen_token = ast->rparen_token;
  1742. return false;
  1743. }
  1744. bool Bind::visit(QtFlagsDeclarationAST *ast)
  1745. {
  1746. // unsigned flags_specifier_token = ast->flags_specifier_token;
  1747. // unsigned lparen_token = ast->lparen_token;
  1748. for (NameListAST *it = ast->flag_enums_list; it; it = it->next) {
  1749. /*const Name *value =*/ this->name(it->value);
  1750. }
  1751. // unsigned rparen_token = ast->rparen_token;
  1752. return false;
  1753. }
  1754. bool Bind::visit(QtInterfacesDeclarationAST *ast)
  1755. {
  1756. // unsigned interfaces_token = ast->interfaces_token;
  1757. // unsigned lparen_token = ast->lparen_token;
  1758. for (QtInterfaceNameListAST *it = ast->interface_name_list; it; it = it->next) {
  1759. this->qtInterfaceName(it->value);
  1760. }
  1761. // unsigned rparen_token = ast->rparen_token;
  1762. return false;
  1763. }
  1764. bool Bind::visit(AliasDeclarationAST *ast)
  1765. {
  1766. if (!ast->name)
  1767. return false;
  1768. const Name *name = this->name(ast->name);
  1769. FullySpecifiedType ty = expression(ast->typeId);
  1770. ty.setTypedef(true);
  1771. Declaration *decl = control()->newDeclaration(ast->name->firstToken(), name);
  1772. decl->setType(ty);
  1773. decl->setStorage(Symbol::Typedef);
  1774. ast->symbol = decl;
  1775. if (_scope->isClass())
  1776. decl->setVisibility(_visibility);
  1777. _scope->addMember(decl);
  1778. return false;
  1779. }
  1780. bool Bind::visit(AsmDefinitionAST *ast)
  1781. {
  1782. (void) ast;
  1783. // unsigned asm_token = ast->asm_token;
  1784. // unsigned volatile_token = ast->volatile_token;
  1785. // unsigned lparen_token = ast->lparen_token;
  1786. // unsigned rparen_token = ast->rparen_token;
  1787. // unsigned semicolon_token = ast->semicolon_token;
  1788. return false;
  1789. }
  1790. bool Bind::visit(ExceptionDeclarationAST *ast)
  1791. {
  1792. FullySpecifiedType type;
  1793. for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
  1794. type = this->specifier(it->value, type);
  1795. }
  1796. DeclaratorIdAST *declaratorId = 0;
  1797. type = this->declarator(ast->declarator, type, &declaratorId);
  1798. const Name *argName = 0;
  1799. if (declaratorId && declaratorId->name)
  1800. argName = declaratorId->name->name;
  1801. Argument *arg = control()->newArgument(location(declaratorId, ast->firstToken()), argName);
  1802. arg->setType(type);
  1803. _scope->addMember(arg);
  1804. // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
  1805. return false;
  1806. }
  1807. bool Bind::visit(FunctionDefinitionAST *ast)
  1808. {
  1809. int methodKey = _methodKey;
  1810. if (ast->qt_invokable_token)
  1811. methodKey = methodKeyForInvokableToken(tokenKind(ast->qt_invokable_token));
  1812. FullySpecifiedType declSpecifiers;
  1813. for (SpecifierListAST *it = ast->decl_specifier_list; it; it = it->next) {
  1814. declSpecifiers = this->specifier(it->value, declSpecifiers);
  1815. }
  1816. DeclaratorIdAST *declaratorId = 0;
  1817. FullySpecifiedType type = this->declarator(ast->declarator, declSpecifiers.qualifiedType(), &declaratorId);
  1818. Function *fun = type->asFunctionType();
  1819. ast->symbol = fun;
  1820. if (fun) {
  1821. setDeclSpecifiers(fun, declSpecifiers);
  1822. fun->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd());
  1823. if (_scope->isClass()) {
  1824. fun->setVisibility(_visibility);
  1825. fun->setMethodKey(methodKey);
  1826. }
  1827. if (declaratorId && declaratorId->name) {
  1828. fun->setSourceLocation(location(declaratorId, ast->firstToken()), translationUnit());
  1829. fun->setName(declaratorId->name->name);
  1830. }
  1831. _scope->addMember(fun);
  1832. } else
  1833. translationUnit()->warning(ast->firstToken(), "expected a function declarator");
  1834. this->ctorInitializer(ast->ctor_initializer, fun);
  1835. if (fun && ! _skipFunctionBodies && ast->function_body) {
  1836. Scope *previousScope = switchScope(fun);
  1837. this->statement(ast->function_body);
  1838. (void) switchScope(previousScope);
  1839. }
  1840. return false;
  1841. }
  1842. bool Bind::visit(LinkageBodyAST *ast)
  1843. {
  1844. // unsigned lbrace_token = ast->lbrace_token;
  1845. for (DeclarationListAST *it = ast->declaration_list; it; it = it->next) {
  1846. this->declaration(it->value);
  1847. }
  1848. // unsigned rbrace_token = ast->rbrace_token;
  1849. return false;
  1850. }
  1851. bool Bind::visit(LinkageSpecificationAST *ast)
  1852. {
  1853. // unsigned extern_token = ast->extern_token;
  1854. // unsigned extern_type_token = ast->extern_type_token;
  1855. this->declaration(ast->declaration);
  1856. return false;
  1857. }
  1858. bool Bind::visit(NamespaceAST *ast)
  1859. {
  1860. // unsigned namespace_token = ast->namespace_token;
  1861. // unsigned identifier_token = ast->identifier_token;
  1862. FullySpecifiedType type;
  1863. for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
  1864. type = this->specifier(it->value, type);
  1865. }
  1866. unsigned sourceLocation = ast->firstToken();
  1867. const Name *namespaceName = 0;
  1868. if (ast->identifier_token) {
  1869. sourceLocation = ast->identifier_token;
  1870. namespaceName = identifier(ast->identifier_token);
  1871. }
  1872. Namespace *ns = control()->newNamespace(sourceLocation, namespaceName);
  1873. ns->setStartOffset(tokenAt(sourceLocation).utf16charsEnd()); // the scope starts after the namespace or the identifier token.
  1874. ns->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd());
  1875. ns->setInline(ast->inline_token != 0);
  1876. ast->symbol = ns;
  1877. _scope->addMember(ns);
  1878. Scope *previousScope = switchScope(ns);
  1879. this->declaration(ast->linkage_body);
  1880. (void) switchScope(previousScope);
  1881. return false;
  1882. }
  1883. bool Bind::visit(NamespaceAliasDefinitionAST *ast)
  1884. {
  1885. unsigned sourceLocation = ast->firstToken();
  1886. const Name *name = 0;
  1887. if (ast->namespace_name_token) {
  1888. sourceLocation = ast->namespace_name_token;
  1889. name = identifier(ast->namespace_name_token);
  1890. }
  1891. NamespaceAlias *namespaceAlias = control()->newNamespaceAlias(sourceLocation, name);
  1892. namespaceAlias->setNamespaceName(this->name(ast->name));
  1893. _scope->addMember(namespaceAlias);
  1894. return false;
  1895. }
  1896. bool Bind::visit(ParameterDeclarationAST *ast)
  1897. {
  1898. FullySpecifiedType type;
  1899. for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
  1900. type = this->specifier(it->value, type);
  1901. }
  1902. DeclaratorIdAST *declaratorId = 0;
  1903. type = this->declarator(ast->declarator, type, &declaratorId);
  1904. // unsigned equal_token = ast->equal_token;
  1905. ExpressionTy expression = this->expression(ast->expression);
  1906. const Name *argName = 0;
  1907. if (declaratorId && declaratorId->name)
  1908. argName = declaratorId->name->name;
  1909. Argument *arg = control()->newArgument(location(declaratorId, ast->firstToken()), argName);
  1910. arg->setType(type);
  1911. if (ast->expression) {
  1912. unsigned startOfExpression = ast->expression->firstToken();
  1913. unsigned endOfExpression = ast->expression->lastToken();
  1914. arg->setInitializer(asStringLiteral(startOfExpression, endOfExpression));
  1915. }
  1916. _scope->addMember(arg);
  1917. ast->symbol = arg;
  1918. return false;
  1919. }
  1920. bool Bind::visit(TemplateDeclarationAST *ast)
  1921. {
  1922. Template *templ = control()->newTemplate(ast->firstToken(), 0);
  1923. templ->setStartOffset(tokenAt(ast->firstToken()).utf16charsBegin());
  1924. templ->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd());
  1925. ast->symbol = templ;
  1926. Scope *previousScope = switchScope(templ);
  1927. for (DeclarationListAST *it = ast->template_parameter_list; it; it = it->next) {
  1928. this->declaration(it->value);
  1929. }
  1930. // unsigned greater_token = ast->greater_token;
  1931. this->declaration(ast->declaration);
  1932. (void) switchScope(previousScope);
  1933. if (Symbol *decl = templ->declaration()) {
  1934. templ->setSourceLocation(decl->sourceLocation(), translationUnit());
  1935. templ->setName(decl->name());
  1936. }
  1937. _scope->addMember(templ);
  1938. return false;
  1939. }
  1940. bool Bind::visit(TypenameTypeParameterAST *ast)
  1941. {
  1942. unsigned sourceLocation = location(ast->name, ast->firstToken());
  1943. // unsigned classkey_token = ast->classkey_token;
  1944. // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
  1945. const Name *name = this->name(ast->name);
  1946. ExpressionTy type_id = this->expression(ast->type_id);
  1947. TypenameArgument *arg = control()->newTypenameArgument(sourceLocation, name);
  1948. arg->setType(type_id);
  1949. ast->symbol = arg;
  1950. _scope->addMember(arg);
  1951. return false;
  1952. }
  1953. bool Bind::visit(TemplateTypeParameterAST *ast)
  1954. {
  1955. unsigned sourceLocation = location(ast->name, ast->firstToken());
  1956. // unsigned template_token = ast->template_token;
  1957. // unsigned less_token = ast->less_token;
  1958. // ### process the template prototype
  1959. #if 0
  1960. for (DeclarationListAST *it = ast->template_parameter_list; it; it = it->next) {
  1961. this->declaration(it->value);
  1962. }
  1963. #endif
  1964. // unsigned greater_token = ast->greater_token;
  1965. // unsigned class_token = ast->class_token;
  1966. // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
  1967. const Name *name = this->name(ast->name);
  1968. ExpressionTy type_id = this->expression(ast->type_id);
  1969. // ### introduce TemplateTypeArgument
  1970. TypenameArgument *arg = control()->newTypenameArgument(sourceLocation, name);
  1971. arg->setType(type_id);
  1972. ast->symbol = arg;
  1973. _scope->addMember(arg);
  1974. return false;
  1975. }
  1976. bool Bind::visit(UsingAST *ast)
  1977. {
  1978. unsigned sourceLocation = location(ast->name, ast->firstToken());
  1979. const Name *name = this->name(ast->name);
  1980. UsingDeclaration *symbol = control()->newUsingDeclaration(sourceLocation, name);
  1981. ast->symbol = symbol;
  1982. _scope->addMember(symbol);
  1983. return false;
  1984. }
  1985. bool Bind::visit(UsingDirectiveAST *ast)
  1986. {
  1987. unsigned sourceLocation = location(ast->name, ast->firstToken());
  1988. const Name *name = this->name(ast->name);
  1989. UsingNamespaceDirective *symbol = control()->newUsingNamespaceDirective(sourceLocation, name);
  1990. ast->symbol = symbol;
  1991. _scope->addMember(symbol);
  1992. return false;
  1993. }
  1994. bool Bind::visit(ObjCClassForwardDeclarationAST *ast)
  1995. {
  1996. FullySpecifiedType declSpecifiers;
  1997. for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
  1998. declSpecifiers = this->specifier(it->value, declSpecifiers);
  1999. }
  2000. List<ObjCForwardClassDeclaration *> **symbolTail = &ast->symbols;
  2001. // unsigned class_token = ast->class_token;
  2002. for (NameListAST *it = ast->identifier_list; it; it = it->next) {
  2003. const Name *name = this->name(it->value);
  2004. const unsigned sourceLocation = location(it->value, ast->firstToken());
  2005. ObjCForwardClassDeclaration *fwd = control()->newObjCForwardClassDeclaration(sourceLocation, name);
  2006. setDeclSpecifiers(fwd, declSpecifiers);
  2007. _scope->addMember(fwd);
  2008. *symbolTail = new (translationUnit()->memoryPool()) List<ObjCForwardClassDeclaration *>(fwd);
  2009. symbolTail = &(*symbolTail)->next;
  2010. }
  2011. return false;
  2012. }
  2013. unsigned Bind::calculateScopeStart(ObjCClassDeclarationAST *ast) const
  2014. {
  2015. if (ast->inst_vars_decl)
  2016. if (unsigned pos = ast->inst_vars_decl->lbrace_token)
  2017. return tokenAt(pos).utf16charsEnd();
  2018. if (ast->protocol_refs)
  2019. if (unsigned pos = ast->protocol_refs->lastToken())
  2020. return tokenAt(pos - 1).utf16charsEnd();
  2021. if (ast->superclass)
  2022. if (unsigned pos = ast->superclass->lastToken())
  2023. return tokenAt(pos - 1).utf16charsEnd();
  2024. if (ast->colon_token)
  2025. return tokenAt(ast->colon_token).utf16charsEnd();
  2026. if (ast->rparen_token)
  2027. return tokenAt(ast->rparen_token).utf16charsEnd();
  2028. if (ast->category_name)
  2029. if (unsigned pos = ast->category_name->lastToken())
  2030. return tokenAt(pos - 1).utf16charsEnd();
  2031. if (ast->lparen_token)
  2032. return tokenAt(ast->lparen_token).utf16charsEnd();
  2033. if (ast->class_name)
  2034. if (unsigned pos = ast->class_name->lastToken())
  2035. return tokenAt(pos - 1).utf16charsEnd();
  2036. return tokenAt(ast->firstToken()).utf16charsBegin();
  2037. }
  2038. bool Bind::visit(ObjCClassDeclarationAST *ast)
  2039. {
  2040. FullySpecifiedType declSpecifiers;
  2041. for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
  2042. declSpecifiers = this->specifier(it->value, declSpecifiers);
  2043. }
  2044. const Name *class_name = this->name(ast->class_name);
  2045. const Name *category_name = this->name(ast->category_name);
  2046. const unsigned sourceLocation = location(ast->class_name, ast->firstToken());
  2047. ObjCClass *klass = control()->newObjCClass(sourceLocation, class_name);
  2048. ast->symbol = klass;
  2049. _scope->addMember(klass);
  2050. klass->setStartOffset(calculateScopeStart(ast));
  2051. klass->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd());
  2052. if (ast->interface_token)
  2053. klass->setInterface(true);
  2054. klass->setCategoryName(category_name);
  2055. Scope *previousScope = switchScope(klass);
  2056. if (const Name *superclass = this->name(ast->superclass)) {
  2057. ObjCBaseClass *superKlass = control()->newObjCBaseClass(ast->superclass->firstToken(), superclass);
  2058. klass->setBaseClass(superKlass);
  2059. }
  2060. this->objCProtocolRefs(ast->protocol_refs, klass);
  2061. const int previousObjCVisibility = switchObjCVisibility(Function::Protected);
  2062. this->objCInstanceVariablesDeclaration(ast->inst_vars_decl, klass);
  2063. (void) switchObjCVisibility(Function::Public);
  2064. for (DeclarationListAST *it = ast->member_declaration_list; it; it = it->next) {
  2065. this->declaration(it->value);
  2066. }
  2067. (void) switchObjCVisibility(previousObjCVisibility);
  2068. (void) switchScope(previousScope);
  2069. return false;
  2070. }
  2071. bool Bind::visit(ObjCProtocolForwardDeclarationAST *ast)
  2072. {
  2073. FullySpecifiedType declSpecifiers;
  2074. for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
  2075. declSpecifiers = this->specifier(it->value, declSpecifiers);
  2076. }
  2077. List<ObjCForwardProtocolDeclaration *> **symbolTail = &ast->symbols;
  2078. // unsigned class_token = ast->class_token;
  2079. for (NameListAST *it = ast->identifier_list; it; it = it->next) {
  2080. const Name *name = this->name(it->value);
  2081. const unsigned sourceLocation = location(it->value, ast->firstToken());
  2082. ObjCForwardProtocolDeclaration *fwd = control()->newObjCForwardProtocolDeclaration(sourceLocation, name);
  2083. setDeclSpecifiers(fwd, declSpecifiers);
  2084. _scope->addMember(fwd);
  2085. *symbolTail = new (translationUnit()->memoryPool()) List<ObjCForwardProtocolDeclaration *>(fwd);
  2086. symbolTail = &(*symbolTail)->next;
  2087. }
  2088. return false;
  2089. }
  2090. unsigned Bind::calculateScopeStart(ObjCProtocolDeclarationAST *ast) const
  2091. {
  2092. if (ast->protocol_refs)
  2093. if (unsigned pos = ast->protocol_refs->lastToken())
  2094. return tokenAt(pos - 1).utf16charsEnd();
  2095. if (ast->name)
  2096. if (unsigned pos = ast->name->lastToken())
  2097. return tokenAt(pos - 1).utf16charsEnd();
  2098. return tokenAt(ast->firstToken()).utf16charsBegin();
  2099. }
  2100. bool Bind::visit(ObjCProtocolDeclarationAST *ast)
  2101. {
  2102. FullySpecifiedType type;
  2103. for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
  2104. type = this->specifier(it->value, type);
  2105. }
  2106. // unsigned protocol_token = ast->protocol_token;
  2107. const Name *name = this->name(ast->name);
  2108. const unsigned sourceLocation = location(ast->name, ast->firstToken());
  2109. ObjCProtocol *protocol = control()->newObjCProtocol(sourceLocation, name);
  2110. protocol->setStartOffset(calculateScopeStart(ast));
  2111. protocol->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd());
  2112. ast->symbol = protocol;
  2113. _scope->addMember(protocol);
  2114. Scope *previousScope = switchScope(protocol);
  2115. const int previousObjCVisibility = switchObjCVisibility(Function::Public);
  2116. this->objCProtocolRefs(ast->protocol_refs, protocol);
  2117. for (DeclarationListAST *it = ast->member_declaration_list; it; it = it->next) {
  2118. this->declaration(it->value);
  2119. }
  2120. (void) switchObjCVisibility(previousObjCVisibility);
  2121. (void) switchScope(previousScope);
  2122. return false;
  2123. }
  2124. bool Bind::visit(ObjCVisibilityDeclarationAST *ast)
  2125. {
  2126. _objcVisibility = visibilityForObjCAccessSpecifier(tokenKind(ast->visibility_token));
  2127. return false;
  2128. }
  2129. bool Bind::visit(ObjCPropertyDeclarationAST *ast)
  2130. {
  2131. (void) ast;
  2132. FullySpecifiedType type;
  2133. for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
  2134. type = this->specifier(it->value, type);
  2135. }
  2136. // unsigned property_token = ast->property_token;
  2137. // unsigned lparen_token = ast->lparen_token;
  2138. for (ObjCPropertyAttributeListAST *it = ast->property_attribute_list; it; it = it->next) {
  2139. this->objCPropertyAttribute(it->value);
  2140. }
  2141. // unsigned rparen_token = ast->rparen_token;
  2142. this->declaration(ast->simple_declaration);
  2143. // List<ObjCPropertyDeclaration *> *symbols = ast->symbols;
  2144. return false;
  2145. }
  2146. bool Bind::visit(ObjCMethodDeclarationAST *ast)
  2147. {
  2148. ObjCMethod *method = this->objCMethodPrototype(ast->method_prototype);
  2149. if (! ast->function_body) {
  2150. const Name *name = method->name();
  2151. unsigned sourceLocation = ast->firstToken();
  2152. Declaration *decl = control()->newDeclaration(sourceLocation, name);
  2153. decl->setType(method);
  2154. _scope->addMember(decl);
  2155. } else if (! _skipFunctionBodies && ast->function_body) {
  2156. Scope *previousScope = switchScope(method);
  2157. this->statement(ast->function_body);
  2158. (void) switchScope(previousScope);
  2159. _scope->addMember(method);
  2160. } else if (method) {
  2161. _scope->addMember(method);
  2162. }
  2163. return false;
  2164. }
  2165. bool Bind::visit(ObjCSynthesizedPropertiesDeclarationAST *ast)
  2166. {
  2167. // unsigned synthesized_token = ast->synthesized_token;
  2168. for (ObjCSynthesizedPropertyListAST *it = ast->property_identifier_list; it; it = it->next) {
  2169. this->objCSynthesizedProperty(it->value);
  2170. }
  2171. // unsigned semicolon_token = ast->semicolon_token;
  2172. return false;
  2173. }
  2174. bool Bind::visit(ObjCDynamicPropertiesDeclarationAST *ast)
  2175. {
  2176. // unsigned dynamic_token = ast->dynamic_token;
  2177. for (NameListAST *it = ast->property_identifier_list; it; it = it->next) {
  2178. /*const Name *value =*/ this->name(it->value);
  2179. }
  2180. // unsigned semicolon_token = ast->semicolon_token;
  2181. return false;
  2182. }
  2183. // NameAST
  2184. bool Bind::visit(ObjCSelectorAST *ast) // ### review
  2185. {
  2186. std::vector<const Name *> arguments;
  2187. bool hasArgs = false;
  2188. for (ObjCSelectorArgumentListAST *it = ast->selector_argument_list; it; it = it->next) {
  2189. if (const Name *selector_argument = this->objCSelectorArgument(it->value, &hasArgs))
  2190. arguments.push_back(selector_argument);
  2191. }
  2192. if (! arguments.empty()) {
  2193. _name = control()->selectorNameId(&arguments[0], unsigned(arguments.size()), hasArgs);
  2194. ast->name = _name;
  2195. }
  2196. return false;
  2197. }
  2198. bool Bind::visit(QualifiedNameAST *ast)
  2199. {
  2200. for (NestedNameSpecifierListAST *it = ast->nested_name_specifier_list; it; it = it->next) {
  2201. const Name *class_or_namespace_name = this->nestedNameSpecifier(it->value);
  2202. if (_name || ast->global_scope_token)
  2203. _name = control()->qualifiedNameId(_name, class_or_namespace_name);
  2204. else
  2205. _name = class_or_namespace_name;
  2206. }
  2207. const Name *unqualified_name = this->name(ast->unqualified_name);
  2208. if (_name || ast->global_scope_token)
  2209. _name = control()->qualifiedNameId(_name, unqualified_name);
  2210. else
  2211. _name = unqualified_name;
  2212. ast->name = _name;
  2213. return false;
  2214. }
  2215. bool Bind::visit(OperatorFunctionIdAST *ast)
  2216. {
  2217. const OperatorNameId::Kind op = this->cppOperator(ast->op);
  2218. ast->name = _name = control()->operatorNameId(op);
  2219. return false;
  2220. }
  2221. bool Bind::visit(ConversionFunctionIdAST *ast)
  2222. {
  2223. FullySpecifiedType type;
  2224. for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
  2225. type = this->specifier(it->value, type);
  2226. }
  2227. for (PtrOperatorListAST *it = ast->ptr_operator_list; it; it = it->next) {
  2228. type = this->ptrOperator(it->value, type);
  2229. }
  2230. ast->name = _name = control()->conversionNameId(type);
  2231. return false;
  2232. }
  2233. bool Bind::visit(AnonymousNameAST *ast)
  2234. {
  2235. ast->name = _name = control()->anonymousNameId(ast->class_token);
  2236. return false;
  2237. }
  2238. bool Bind::visit(SimpleNameAST *ast)
  2239. {
  2240. const Identifier *id = identifier(ast->identifier_token);
  2241. _name = id;
  2242. ast->name = _name;
  2243. return false;
  2244. }
  2245. bool Bind::visit(DestructorNameAST *ast)
  2246. {
  2247. _name = control()->destructorNameId(name(ast->unqualified_name));
  2248. ast->name = _name;
  2249. return false;
  2250. }
  2251. bool Bind::visit(TemplateIdAST *ast)
  2252. {
  2253. // collect the template parameters
  2254. std::vector<FullySpecifiedType> templateArguments;
  2255. for (ExpressionListAST *it = ast->template_argument_list; it; it = it->next) {
  2256. ExpressionTy value = this->expression(it->value);
  2257. templateArguments.push_back(value);
  2258. }
  2259. const Identifier *id = identifier(ast->identifier_token);
  2260. const int tokenKindBeforeIdentifier(translationUnit()->tokenKind(ast->identifier_token - 1));
  2261. const bool isSpecialization = (tokenKindBeforeIdentifier == T_CLASS ||
  2262. tokenKindBeforeIdentifier == T_STRUCT);
  2263. if (templateArguments.empty())
  2264. _name = control()->templateNameId(id, isSpecialization);
  2265. else
  2266. _name = control()->templateNameId(id, isSpecialization, &templateArguments[0],
  2267. unsigned(templateArguments.size()));
  2268. ast->name = _name;
  2269. return false;
  2270. }
  2271. // SpecifierAST
  2272. bool Bind::visit(SimpleSpecifierAST *ast)
  2273. {
  2274. switch (tokenKind(ast->specifier_token)) {
  2275. case T_IDENTIFIER: {
  2276. const Identifier *id = tokenAt(ast->specifier_token).identifier;
  2277. if (id->match(control()->cpp11Override())) {
  2278. if (_type.isOverride())
  2279. translationUnit()->error(ast->specifier_token, "duplicate `override'");
  2280. _type.setOverride(true);
  2281. }
  2282. else if (id->match(control()->cpp11Final())) {
  2283. if (_type.isFinal())
  2284. translationUnit()->error(ast->specifier_token, "duplicate `final'");
  2285. _type.setFinal(true);
  2286. }
  2287. }
  2288. break;
  2289. case T_CONST:
  2290. if (_type.isConst())
  2291. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2292. _type.setConst(true);
  2293. break;
  2294. case T_VOLATILE:
  2295. if (_type.isVolatile())
  2296. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2297. _type.setVolatile(true);
  2298. break;
  2299. case T_FRIEND:
  2300. if (_type.isFriend())
  2301. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2302. _type.setFriend(true);
  2303. break;
  2304. case T_AUTO:
  2305. if (!translationUnit()->languageFeatures().cxx11Enabled) {
  2306. if (_type.isAuto())
  2307. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2308. }
  2309. _type.setAuto(true);
  2310. break;
  2311. case T_REGISTER:
  2312. if (_type.isRegister())
  2313. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2314. _type.setRegister(true);
  2315. break;
  2316. case T_STATIC:
  2317. if (_type.isStatic())
  2318. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2319. _type.setStatic(true);
  2320. break;
  2321. case T_EXTERN:
  2322. if (_type.isExtern())
  2323. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2324. _type.setExtern(true);
  2325. break;
  2326. case T_MUTABLE:
  2327. if (_type.isMutable())
  2328. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2329. _type.setMutable(true);
  2330. break;
  2331. case T_TYPEDEF:
  2332. if (_type.isTypedef())
  2333. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2334. _type.setTypedef(true);
  2335. break;
  2336. case T_INLINE:
  2337. if (_type.isInline())
  2338. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2339. _type.setInline(true);
  2340. break;
  2341. case T_VIRTUAL:
  2342. if (_type.isVirtual())
  2343. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2344. _type.setVirtual(true);
  2345. break;
  2346. case T_EXPLICIT:
  2347. if (_type.isExplicit())
  2348. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2349. _type.setExplicit(true);
  2350. break;
  2351. case T_SIGNED:
  2352. if (_type.isSigned())
  2353. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2354. _type.setSigned(true);
  2355. break;
  2356. case T_UNSIGNED:
  2357. if (_type.isUnsigned())
  2358. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2359. _type.setUnsigned(true);
  2360. break;
  2361. case T_CHAR:
  2362. if (_type)
  2363. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2364. _type.setType(control()->integerType(IntegerType::Char));
  2365. break;
  2366. case T_CHAR16_T:
  2367. if (_type)
  2368. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2369. _type.setType(control()->integerType(IntegerType::Char16));
  2370. break;
  2371. case T_CHAR32_T:
  2372. if (_type)
  2373. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2374. _type.setType(control()->integerType(IntegerType::Char32));
  2375. break;
  2376. case T_WCHAR_T:
  2377. if (_type)
  2378. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2379. _type.setType(control()->integerType(IntegerType::WideChar));
  2380. break;
  2381. case T_BOOL:
  2382. if (_type)
  2383. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2384. _type.setType(control()->integerType(IntegerType::Bool));
  2385. break;
  2386. case T_SHORT:
  2387. if (_type) {
  2388. IntegerType *intType = control()->integerType(IntegerType::Int);
  2389. if (_type.type() != intType)
  2390. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2391. }
  2392. _type.setType(control()->integerType(IntegerType::Short));
  2393. break;
  2394. case T_INT:
  2395. if (_type) {
  2396. Type *tp = _type.type();
  2397. IntegerType *shortType = control()->integerType(IntegerType::Short);
  2398. IntegerType *longType = control()->integerType(IntegerType::Long);
  2399. IntegerType *longLongType = control()->integerType(IntegerType::LongLong);
  2400. if (tp == shortType || tp == longType || tp == longLongType)
  2401. break;
  2402. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2403. }
  2404. _type.setType(control()->integerType(IntegerType::Int));
  2405. break;
  2406. case T_LONG:
  2407. if (_type) {
  2408. Type *tp = _type.type();
  2409. IntegerType *intType = control()->integerType(IntegerType::Int);
  2410. IntegerType *longType = control()->integerType(IntegerType::Long);
  2411. FloatType *doubleType = control()->floatType(FloatType::Double);
  2412. if (tp == longType) {
  2413. _type.setType(control()->integerType(IntegerType::LongLong));
  2414. break;
  2415. } else if (tp == doubleType) {
  2416. _type.setType(control()->floatType(FloatType::LongDouble));
  2417. break;
  2418. } else if (tp != intType) {
  2419. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2420. }
  2421. }
  2422. _type.setType(control()->integerType(IntegerType::Long));
  2423. break;
  2424. case T_FLOAT:
  2425. if (_type)
  2426. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2427. _type.setType(control()->floatType(FloatType::Float));
  2428. break;
  2429. case T_DOUBLE:
  2430. if (_type) {
  2431. IntegerType *longType = control()->integerType(IntegerType::Long);
  2432. if (_type.type() == longType) {
  2433. _type.setType(control()->floatType(FloatType::LongDouble));
  2434. break;
  2435. }
  2436. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2437. }
  2438. _type.setType(control()->floatType(FloatType::Double));
  2439. break;
  2440. case T_VOID:
  2441. if (_type)
  2442. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2443. _type.setType(control()->voidType());
  2444. break;
  2445. default:
  2446. break;
  2447. } // switch
  2448. return false;
  2449. }
  2450. bool Bind::visit(AlignmentSpecifierAST *ast)
  2451. {
  2452. // Prevent visiting the type-id or alignment expression from changing the currently
  2453. // calculated type:
  2454. expression(ast->typeIdExprOrAlignmentExpr);
  2455. return false;
  2456. }
  2457. bool Bind::visit(GnuAttributeSpecifierAST *ast)
  2458. {
  2459. // unsigned attribute_token = ast->attribute_token;
  2460. // unsigned first_lparen_token = ast->first_lparen_token;
  2461. // unsigned second_lparen_token = ast->second_lparen_token;
  2462. for (GnuAttributeListAST *it = ast->attribute_list; it; it = it->next) {
  2463. this->attribute(it->value);
  2464. }
  2465. // unsigned first_rparen_token = ast->first_rparen_token;
  2466. // unsigned second_rparen_token = ast->second_rparen_token;
  2467. return false;
  2468. }
  2469. bool Bind::visit(TypeofSpecifierAST *ast)
  2470. {
  2471. ExpressionTy expression = this->expression(ast->expression);
  2472. _type = expression;
  2473. return false;
  2474. }
  2475. bool Bind::visit(DecltypeSpecifierAST *ast)
  2476. {
  2477. _type = this->expression(ast->expression);
  2478. return false;
  2479. }
  2480. bool Bind::visit(ClassSpecifierAST *ast)
  2481. {
  2482. // unsigned classkey_token = ast->classkey_token;
  2483. unsigned sourceLocation = ast->firstToken();
  2484. unsigned startScopeOffset = tokenAt(sourceLocation).utf16charsEnd(); // at the end of the class key
  2485. for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
  2486. _type = this->specifier(it->value, _type);
  2487. }
  2488. const Name *className = this->name(ast->name);
  2489. if (ast->name && ! ast->name->asAnonymousName()) {
  2490. sourceLocation = location(ast->name, sourceLocation);
  2491. startScopeOffset = tokenAt(sourceLocation).utf16charsEnd(); // at the end of the class name
  2492. if (QualifiedNameAST *q = ast->name->asQualifiedName()) {
  2493. if (q->unqualified_name) {
  2494. sourceLocation = q->unqualified_name->firstToken();
  2495. startScopeOffset = tokenAt(q->unqualified_name->lastToken() - 1).utf16charsEnd(); // at the end of the unqualified name
  2496. }
  2497. }
  2498. ensureValidClassName(&className, sourceLocation);
  2499. }
  2500. Class *klass = control()->newClass(sourceLocation, className);
  2501. klass->setStartOffset(startScopeOffset);
  2502. klass->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd());
  2503. _scope->addMember(klass);
  2504. if (_scope->isClass())
  2505. klass->setVisibility(_visibility);
  2506. // set the class key
  2507. unsigned classKey = tokenKind(ast->classkey_token);
  2508. if (classKey == T_CLASS)
  2509. klass->setClassKey(Class::ClassKey);
  2510. else if (classKey == T_STRUCT)
  2511. klass->setClassKey(Class::StructKey);
  2512. else if (classKey == T_UNION)
  2513. klass->setClassKey(Class::UnionKey);
  2514. _type.setType(klass);
  2515. Scope *previousScope = switchScope(klass);
  2516. const int previousVisibility = switchVisibility(visibilityForClassKey(classKey));
  2517. const int previousMethodKey = switchMethodKey(Function::NormalMethod);
  2518. for (BaseSpecifierListAST *it = ast->base_clause_list; it; it = it->next) {
  2519. this->baseSpecifier(it->value, ast->colon_token, klass);
  2520. }
  2521. // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
  2522. for (DeclarationListAST *it = ast->member_specifier_list; it; it = it->next) {
  2523. this->declaration(it->value);
  2524. }
  2525. (void) switchMethodKey(previousMethodKey);
  2526. (void) switchVisibility(previousVisibility);
  2527. (void) switchScope(previousScope);
  2528. ast->symbol = klass;
  2529. return false;
  2530. }
  2531. bool Bind::visit(NamedTypeSpecifierAST *ast)
  2532. {
  2533. _type.setType(control()->namedType(this->name(ast->name)));
  2534. return false;
  2535. }
  2536. bool Bind::visit(ElaboratedTypeSpecifierAST *ast)
  2537. {
  2538. // unsigned classkey_token = ast->classkey_token;
  2539. for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
  2540. _type = this->specifier(it->value, _type);
  2541. }
  2542. _type.setType(control()->namedType(this->name(ast->name)));
  2543. return false;
  2544. }
  2545. bool Bind::visit(EnumSpecifierAST *ast)
  2546. {
  2547. unsigned sourceLocation = location(ast->name, ast->firstToken());
  2548. const Name *enumName = this->name(ast->name);
  2549. Enum *e = control()->newEnum(sourceLocation, enumName);
  2550. e->setStartOffset(tokenAt(sourceLocation).utf16charsEnd()); // at the end of the enum or identifier token.
  2551. e->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd());
  2552. if (ast->key_token)
  2553. e->setScoped(true);
  2554. ast->symbol = e;
  2555. _scope->addMember(e);
  2556. if (_scope->isClass())
  2557. e->setVisibility(_visibility);
  2558. Scope *previousScope = switchScope(e);
  2559. for (EnumeratorListAST *it = ast->enumerator_list; it; it = it->next) {
  2560. this->enumerator(it->value, e);
  2561. }
  2562. (void) switchScope(previousScope);
  2563. return false;
  2564. }
  2565. // PtrOperatorAST
  2566. bool Bind::visit(PointerToMemberAST *ast)
  2567. {
  2568. const Name *memberName = 0;
  2569. for (NestedNameSpecifierListAST *it = ast->nested_name_specifier_list; it; it = it->next) {
  2570. const Name *class_or_namespace_name = this->nestedNameSpecifier(it->value);
  2571. if (memberName || ast->global_scope_token)
  2572. memberName = control()->qualifiedNameId(memberName, class_or_namespace_name);
  2573. else
  2574. memberName = class_or_namespace_name;
  2575. }
  2576. FullySpecifiedType type(control()->pointerToMemberType(memberName, _type));
  2577. for (SpecifierListAST *it = ast->cv_qualifier_list; it; it = it->next) {
  2578. type = this->specifier(it->value, type);
  2579. }
  2580. _type = type;
  2581. return false;
  2582. }
  2583. bool Bind::visit(PointerAST *ast)
  2584. {
  2585. if (_type->isReferenceType())
  2586. translationUnit()->error(ast->firstToken(), "cannot declare pointer to a reference");
  2587. FullySpecifiedType type(control()->pointerType(_type));
  2588. for (SpecifierListAST *it = ast->cv_qualifier_list; it; it = it->next) {
  2589. type = this->specifier(it->value, type);
  2590. }
  2591. _type = type;
  2592. return false;
  2593. }
  2594. bool Bind::visit(ReferenceAST *ast)
  2595. {
  2596. const bool rvalueRef = (tokenKind(ast->reference_token) == T_AMPER_AMPER);
  2597. if (_type->isReferenceType())
  2598. translationUnit()->error(ast->firstToken(), "cannot declare reference to a reference");
  2599. FullySpecifiedType type(control()->referenceType(_type, rvalueRef));
  2600. _type = type;
  2601. return false;
  2602. }
  2603. // PostfixAST
  2604. bool Bind::visit(CallAST *ast)
  2605. {
  2606. /*ExpressionTy base_expression =*/ this->expression(ast->base_expression);
  2607. // unsigned lparen_token = ast->lparen_token;
  2608. for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
  2609. /*ExpressionTy value =*/ this->expression(it->value);
  2610. }
  2611. // unsigned rparen_token = ast->rparen_token;
  2612. return false;
  2613. }
  2614. bool Bind::visit(ArrayAccessAST *ast)
  2615. {
  2616. /*ExpressionTy base_expression =*/ this->expression(ast->base_expression);
  2617. // unsigned lbracket_token = ast->lbracket_token;
  2618. /*ExpressionTy expression =*/ this->expression(ast->expression);
  2619. // unsigned rbracket_token = ast->rbracket_token;
  2620. return false;
  2621. }
  2622. bool Bind::visit(PostIncrDecrAST *ast)
  2623. {
  2624. ExpressionTy base_expression = this->expression(ast->base_expression);
  2625. // unsigned incr_decr_token = ast->incr_decr_token;
  2626. return false;
  2627. }
  2628. bool Bind::visit(MemberAccessAST *ast)
  2629. {
  2630. ExpressionTy base_expression = this->expression(ast->base_expression);
  2631. // unsigned access_token = ast->access_token;
  2632. // unsigned template_token = ast->template_token;
  2633. /*const Name *member_name =*/ this->name(ast->member_name);
  2634. return false;
  2635. }
  2636. // CoreDeclaratorAST
  2637. bool Bind::visit(DeclaratorIdAST *ast)
  2638. {
  2639. /*const Name *name =*/ this->name(ast->name);
  2640. *_declaratorId = ast;
  2641. return false;
  2642. }
  2643. bool Bind::visit(NestedDeclaratorAST *ast)
  2644. {
  2645. _type = this->declarator(ast->declarator, _type, _declaratorId);
  2646. return false;
  2647. }
  2648. // PostfixDeclaratorAST
  2649. bool Bind::visit(FunctionDeclaratorAST *ast)
  2650. {
  2651. Function *fun = control()->newFunction(0, 0);
  2652. fun->setStartOffset(tokenAt(ast->firstToken()).utf16charsBegin());
  2653. fun->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd());
  2654. if (ast->trailing_return_type)
  2655. _type = this->trailingReturnType(ast->trailing_return_type, _type);
  2656. fun->setReturnType(_type);
  2657. // unsigned lparen_token = ast->lparen_token;
  2658. this->parameterDeclarationClause(ast->parameter_declaration_clause, ast->lparen_token, fun);
  2659. // unsigned rparen_token = ast->rparen_token;
  2660. FullySpecifiedType type(fun);
  2661. for (SpecifierListAST *it = ast->cv_qualifier_list; it; it = it->next) {
  2662. type = this->specifier(it->value, type);
  2663. }
  2664. // propagate the cv-qualifiers
  2665. fun->setConst(type.isConst());
  2666. fun->setVolatile(type.isVolatile());
  2667. fun->setOverride(type.isOverride());
  2668. fun->setFinal(type.isFinal());
  2669. this->exceptionSpecification(ast->exception_specification, type);
  2670. if (ast->as_cpp_initializer != 0) {
  2671. fun->setAmbiguous(true);
  2672. /*ExpressionTy as_cpp_initializer =*/ this->expression(ast->as_cpp_initializer);
  2673. }
  2674. ast->symbol = fun;
  2675. _type = type;
  2676. return false;
  2677. }
  2678. bool Bind::visit(ArrayDeclaratorAST *ast)
  2679. {
  2680. ExpressionTy expression = this->expression(ast->expression);
  2681. FullySpecifiedType type(control()->arrayType(_type));
  2682. _type = type;
  2683. return false;
  2684. }
  2685. void Bind::ensureValidClassName(const Name **name, unsigned sourceLocation)
  2686. {
  2687. if (!*name)
  2688. return;
  2689. const QualifiedNameId *qName = (*name)->asQualifiedNameId();
  2690. const Name *uqName = qName ? qName->name() : *name;
  2691. if (!uqName->isNameId() && !uqName->isTemplateNameId()) {
  2692. translationUnit()->error(sourceLocation, "expected a class-name");
  2693. *name = uqName->identifier();
  2694. if (qName)
  2695. *name = control()->qualifiedNameId(qName->base(), *name);
  2696. }
  2697. }
  2698. int Bind::visibilityForAccessSpecifier(int tokenKind)
  2699. {
  2700. switch (tokenKind) {
  2701. case T_PUBLIC:
  2702. return Symbol::Public;
  2703. case T_PROTECTED:
  2704. return Symbol::Protected;
  2705. case T_PRIVATE:
  2706. return Symbol::Private;
  2707. case T_Q_SIGNALS:
  2708. return Symbol::Protected;
  2709. default:
  2710. return Symbol::Public;
  2711. }
  2712. }
  2713. int Bind::visibilityForClassKey(int tokenKind)
  2714. {
  2715. switch (tokenKind) {
  2716. case T_CLASS:
  2717. return Symbol::Private;
  2718. case T_STRUCT:
  2719. case T_UNION:
  2720. return Symbol::Public;
  2721. default:
  2722. return Symbol::Public;
  2723. }
  2724. }
  2725. int Bind::visibilityForObjCAccessSpecifier(int tokenKind)
  2726. {
  2727. switch (tokenKind) {
  2728. case T_AT_PUBLIC:
  2729. return Symbol::Public;
  2730. case T_AT_PROTECTED:
  2731. return Symbol::Protected;
  2732. case T_AT_PRIVATE:
  2733. return Symbol::Private;
  2734. case T_AT_PACKAGE:
  2735. return Symbol::Package;
  2736. default:
  2737. return Symbol::Protected;
  2738. }
  2739. }
  2740. bool Bind::isObjCClassMethod(int tokenKind)
  2741. {
  2742. switch (tokenKind) {
  2743. case T_PLUS:
  2744. return true;
  2745. case T_MINUS:
  2746. default:
  2747. return false;
  2748. }
  2749. }