Bind.cpp 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261
  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. if (_scope->isClass()) {
  1585. decl->setVisibility(_visibility);
  1586. if (Function *funTy = decl->type()->asFunctionType()) {
  1587. funTy->setMethodKey(methodKey);
  1588. bool pureVirtualInit = it->value->equal_token
  1589. && it->value->initializer
  1590. && it->value->initializer->asNumericLiteral();
  1591. if (funTy->isVirtual() && pureVirtualInit)
  1592. funTy->setPureVirtual(true);
  1593. }
  1594. }
  1595. _scope->addMember(decl);
  1596. *symbolTail = new (translationUnit()->memoryPool()) List<Symbol *>(decl);
  1597. symbolTail = &(*symbolTail)->next;
  1598. }
  1599. return false;
  1600. }
  1601. bool Bind::visit(EmptyDeclarationAST *ast)
  1602. {
  1603. (void) ast;
  1604. unsigned semicolon_token = ast->semicolon_token;
  1605. if (_scope && (_scope->isClass() || _scope->isNamespace())) {
  1606. const Token &tk = tokenAt(semicolon_token);
  1607. if (! tk.generated())
  1608. translationUnit()->warning(semicolon_token, "extra `;'");
  1609. }
  1610. return false;
  1611. }
  1612. bool Bind::visit(AccessDeclarationAST *ast)
  1613. {
  1614. const int accessSpecifier = tokenKind(ast->access_specifier_token);
  1615. _visibility = visibilityForAccessSpecifier(accessSpecifier);
  1616. if (ast->slots_token)
  1617. _methodKey = Function::SlotMethod;
  1618. else if (accessSpecifier == T_Q_SIGNALS)
  1619. _methodKey = Function::SignalMethod;
  1620. else
  1621. _methodKey = Function::NormalMethod;
  1622. return false;
  1623. }
  1624. bool Bind::visit(QtObjectTagAST *ast)
  1625. {
  1626. (void) ast;
  1627. // unsigned q_object_token = ast->q_object_token;
  1628. return false;
  1629. }
  1630. bool Bind::visit(QtPrivateSlotAST *ast)
  1631. {
  1632. // unsigned q_private_slot_token = ast->q_private_slot_token;
  1633. // unsigned lparen_token = ast->lparen_token;
  1634. // unsigned dptr_token = ast->dptr_token;
  1635. // unsigned dptr_lparen_token = ast->dptr_lparen_token;
  1636. // unsigned dptr_rparen_token = ast->dptr_rparen_token;
  1637. // unsigned comma_token = ast->comma_token;
  1638. FullySpecifiedType type;
  1639. for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
  1640. type = this->specifier(it->value, type);
  1641. }
  1642. DeclaratorIdAST *declaratorId = 0;
  1643. type = this->declarator(ast->declarator, type, &declaratorId);
  1644. // unsigned rparen_token = ast->rparen_token;
  1645. return false;
  1646. }
  1647. static void qtPropertyAttribute(TranslationUnit *unit, ExpressionAST *expression,
  1648. int *flags,
  1649. QtPropertyDeclaration::Flag flag,
  1650. QtPropertyDeclaration::Flag function)
  1651. {
  1652. if (!expression)
  1653. return;
  1654. *flags &= ~function & ~flag;
  1655. if (BoolLiteralAST *boollit = expression->asBoolLiteral()) {
  1656. const int kind = unit->tokenAt(boollit->literal_token).kind();
  1657. if (kind == T_TRUE)
  1658. *flags |= flag;
  1659. } else {
  1660. *flags |= function;
  1661. }
  1662. }
  1663. bool Bind::visit(QtPropertyDeclarationAST *ast)
  1664. {
  1665. // unsigned property_specifier_token = ast->property_specifier_token;
  1666. // unsigned lparen_token = ast->lparen_token;
  1667. ExpressionTy type_id = this->expression(ast->type_id);
  1668. const Name *property_name = this->name(ast->property_name);
  1669. unsigned sourceLocation = ast->firstToken();
  1670. if (ast->property_name)
  1671. sourceLocation = ast->property_name->firstToken();
  1672. QtPropertyDeclaration *propertyDeclaration = control()->newQtPropertyDeclaration(sourceLocation, property_name);
  1673. propertyDeclaration->setType(type_id);
  1674. int flags = QtPropertyDeclaration::DesignableFlag
  1675. | QtPropertyDeclaration::ScriptableFlag
  1676. | QtPropertyDeclaration::StoredFlag;
  1677. for (QtPropertyDeclarationItemListAST *it = ast->property_declaration_item_list; it; it = it->next) {
  1678. if (!it->value || !it->value->item_name_token)
  1679. continue;
  1680. this->expression(it->value->expression);
  1681. std::string name = spell(it->value->item_name_token);
  1682. if (name == "CONSTANT") {
  1683. flags |= QtPropertyDeclaration::ConstantFlag;
  1684. } else if (name == "FINAL") {
  1685. flags |= QtPropertyDeclaration::FinalFlag;
  1686. } else if (name == "READ") {
  1687. flags |= QtPropertyDeclaration::ReadFunction;
  1688. } else if (name == "WRITE") {
  1689. flags |= QtPropertyDeclaration::WriteFunction;
  1690. } else if (name == "MEMBER") {
  1691. flags |= QtPropertyDeclaration::MemberVariable;
  1692. } else if (name == "RESET") {
  1693. flags |= QtPropertyDeclaration::ResetFunction;
  1694. } else if (name == "NOTIFY") {
  1695. flags |= QtPropertyDeclaration::NotifyFunction;
  1696. } else if (name == "REVISION") {
  1697. // ### handle REVISION property
  1698. } else if (name == "DESIGNABLE") {
  1699. qtPropertyAttribute(translationUnit(), it->value->expression, &flags,
  1700. QtPropertyDeclaration::DesignableFlag, QtPropertyDeclaration::DesignableFunction);
  1701. } else if (name == "SCRIPTABLE") {
  1702. qtPropertyAttribute(translationUnit(), it->value->expression, &flags,
  1703. QtPropertyDeclaration::ScriptableFlag, QtPropertyDeclaration::ScriptableFunction);
  1704. } else if (name == "STORED") {
  1705. qtPropertyAttribute(translationUnit(), it->value->expression, &flags,
  1706. QtPropertyDeclaration::StoredFlag, QtPropertyDeclaration::StoredFunction);
  1707. } else if (name == "USER") {
  1708. qtPropertyAttribute(translationUnit(), it->value->expression, &flags,
  1709. QtPropertyDeclaration::UserFlag, QtPropertyDeclaration::UserFunction);
  1710. }
  1711. }
  1712. propertyDeclaration->setFlags(flags);
  1713. _scope->addMember(propertyDeclaration);
  1714. // unsigned rparen_token = ast->rparen_token;
  1715. return false;
  1716. }
  1717. bool Bind::visit(QtEnumDeclarationAST *ast)
  1718. {
  1719. // unsigned enum_specifier_token = ast->enum_specifier_token;
  1720. // unsigned lparen_token = ast->lparen_token;
  1721. for (NameListAST *it = ast->enumerator_list; it; it = it->next) {
  1722. const Name *value = this->name(it->value);
  1723. if (!value)
  1724. continue;
  1725. QtEnum *qtEnum = control()->newQtEnum(it->value->firstToken(), value);
  1726. _scope->addMember(qtEnum);
  1727. }
  1728. // unsigned rparen_token = ast->rparen_token;
  1729. return false;
  1730. }
  1731. bool Bind::visit(QtFlagsDeclarationAST *ast)
  1732. {
  1733. // unsigned flags_specifier_token = ast->flags_specifier_token;
  1734. // unsigned lparen_token = ast->lparen_token;
  1735. for (NameListAST *it = ast->flag_enums_list; it; it = it->next) {
  1736. /*const Name *value =*/ this->name(it->value);
  1737. }
  1738. // unsigned rparen_token = ast->rparen_token;
  1739. return false;
  1740. }
  1741. bool Bind::visit(QtInterfacesDeclarationAST *ast)
  1742. {
  1743. // unsigned interfaces_token = ast->interfaces_token;
  1744. // unsigned lparen_token = ast->lparen_token;
  1745. for (QtInterfaceNameListAST *it = ast->interface_name_list; it; it = it->next) {
  1746. this->qtInterfaceName(it->value);
  1747. }
  1748. // unsigned rparen_token = ast->rparen_token;
  1749. return false;
  1750. }
  1751. bool Bind::visit(AliasDeclarationAST *ast)
  1752. {
  1753. if (!ast->name)
  1754. return false;
  1755. const Name *name = this->name(ast->name);
  1756. FullySpecifiedType ty = expression(ast->typeId);
  1757. ty.setTypedef(true);
  1758. Declaration *decl = control()->newDeclaration(ast->name->firstToken(), name);
  1759. decl->setType(ty);
  1760. decl->setStorage(Symbol::Typedef);
  1761. ast->symbol = decl;
  1762. if (_scope->isClass())
  1763. decl->setVisibility(_visibility);
  1764. _scope->addMember(decl);
  1765. return false;
  1766. }
  1767. bool Bind::visit(AsmDefinitionAST *ast)
  1768. {
  1769. (void) ast;
  1770. // unsigned asm_token = ast->asm_token;
  1771. // unsigned volatile_token = ast->volatile_token;
  1772. // unsigned lparen_token = ast->lparen_token;
  1773. // unsigned rparen_token = ast->rparen_token;
  1774. // unsigned semicolon_token = ast->semicolon_token;
  1775. return false;
  1776. }
  1777. bool Bind::visit(ExceptionDeclarationAST *ast)
  1778. {
  1779. FullySpecifiedType type;
  1780. for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
  1781. type = this->specifier(it->value, type);
  1782. }
  1783. DeclaratorIdAST *declaratorId = 0;
  1784. type = this->declarator(ast->declarator, type, &declaratorId);
  1785. const Name *argName = 0;
  1786. if (declaratorId && declaratorId->name)
  1787. argName = declaratorId->name->name;
  1788. Argument *arg = control()->newArgument(location(declaratorId, ast->firstToken()), argName);
  1789. arg->setType(type);
  1790. _scope->addMember(arg);
  1791. // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
  1792. return false;
  1793. }
  1794. bool Bind::visit(FunctionDefinitionAST *ast)
  1795. {
  1796. int methodKey = _methodKey;
  1797. if (ast->qt_invokable_token)
  1798. methodKey = methodKeyForInvokableToken(tokenKind(ast->qt_invokable_token));
  1799. FullySpecifiedType declSpecifiers;
  1800. for (SpecifierListAST *it = ast->decl_specifier_list; it; it = it->next) {
  1801. declSpecifiers = this->specifier(it->value, declSpecifiers);
  1802. }
  1803. DeclaratorIdAST *declaratorId = 0;
  1804. FullySpecifiedType type = this->declarator(ast->declarator, declSpecifiers.qualifiedType(), &declaratorId);
  1805. Function *fun = type->asFunctionType();
  1806. ast->symbol = fun;
  1807. if (fun) {
  1808. setDeclSpecifiers(fun, declSpecifiers);
  1809. fun->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd());
  1810. if (_scope->isClass()) {
  1811. fun->setVisibility(_visibility);
  1812. fun->setMethodKey(methodKey);
  1813. }
  1814. if (declaratorId && declaratorId->name) {
  1815. fun->setSourceLocation(location(declaratorId, ast->firstToken()), translationUnit());
  1816. fun->setName(declaratorId->name->name);
  1817. }
  1818. _scope->addMember(fun);
  1819. } else
  1820. translationUnit()->warning(ast->firstToken(), "expected a function declarator");
  1821. this->ctorInitializer(ast->ctor_initializer, fun);
  1822. if (fun && ! _skipFunctionBodies && ast->function_body) {
  1823. Scope *previousScope = switchScope(fun);
  1824. this->statement(ast->function_body);
  1825. (void) switchScope(previousScope);
  1826. }
  1827. return false;
  1828. }
  1829. bool Bind::visit(LinkageBodyAST *ast)
  1830. {
  1831. // unsigned lbrace_token = ast->lbrace_token;
  1832. for (DeclarationListAST *it = ast->declaration_list; it; it = it->next) {
  1833. this->declaration(it->value);
  1834. }
  1835. // unsigned rbrace_token = ast->rbrace_token;
  1836. return false;
  1837. }
  1838. bool Bind::visit(LinkageSpecificationAST *ast)
  1839. {
  1840. // unsigned extern_token = ast->extern_token;
  1841. // unsigned extern_type_token = ast->extern_type_token;
  1842. this->declaration(ast->declaration);
  1843. return false;
  1844. }
  1845. bool Bind::visit(NamespaceAST *ast)
  1846. {
  1847. // unsigned namespace_token = ast->namespace_token;
  1848. // unsigned identifier_token = ast->identifier_token;
  1849. FullySpecifiedType type;
  1850. for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
  1851. type = this->specifier(it->value, type);
  1852. }
  1853. unsigned sourceLocation = ast->firstToken();
  1854. const Name *namespaceName = 0;
  1855. if (ast->identifier_token) {
  1856. sourceLocation = ast->identifier_token;
  1857. namespaceName = identifier(ast->identifier_token);
  1858. }
  1859. Namespace *ns = control()->newNamespace(sourceLocation, namespaceName);
  1860. ns->setStartOffset(tokenAt(sourceLocation).utf16charsEnd()); // the scope starts after the namespace or the identifier token.
  1861. ns->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd());
  1862. ns->setInline(ast->inline_token != 0);
  1863. ast->symbol = ns;
  1864. _scope->addMember(ns);
  1865. Scope *previousScope = switchScope(ns);
  1866. this->declaration(ast->linkage_body);
  1867. (void) switchScope(previousScope);
  1868. return false;
  1869. }
  1870. bool Bind::visit(NamespaceAliasDefinitionAST *ast)
  1871. {
  1872. unsigned sourceLocation = ast->firstToken();
  1873. const Name *name = 0;
  1874. if (ast->namespace_name_token) {
  1875. sourceLocation = ast->namespace_name_token;
  1876. name = identifier(ast->namespace_name_token);
  1877. }
  1878. NamespaceAlias *namespaceAlias = control()->newNamespaceAlias(sourceLocation, name);
  1879. namespaceAlias->setNamespaceName(this->name(ast->name));
  1880. _scope->addMember(namespaceAlias);
  1881. return false;
  1882. }
  1883. bool Bind::visit(ParameterDeclarationAST *ast)
  1884. {
  1885. FullySpecifiedType type;
  1886. for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
  1887. type = this->specifier(it->value, type);
  1888. }
  1889. DeclaratorIdAST *declaratorId = 0;
  1890. type = this->declarator(ast->declarator, type, &declaratorId);
  1891. // unsigned equal_token = ast->equal_token;
  1892. ExpressionTy expression = this->expression(ast->expression);
  1893. const Name *argName = 0;
  1894. if (declaratorId && declaratorId->name)
  1895. argName = declaratorId->name->name;
  1896. Argument *arg = control()->newArgument(location(declaratorId, ast->firstToken()), argName);
  1897. arg->setType(type);
  1898. if (ast->expression) {
  1899. unsigned startOfExpression = ast->expression->firstToken();
  1900. unsigned endOfExpression = ast->expression->lastToken();
  1901. arg->setInitializer(asStringLiteral(startOfExpression, endOfExpression));
  1902. }
  1903. _scope->addMember(arg);
  1904. ast->symbol = arg;
  1905. return false;
  1906. }
  1907. bool Bind::visit(TemplateDeclarationAST *ast)
  1908. {
  1909. Template *templ = control()->newTemplate(ast->firstToken(), 0);
  1910. templ->setStartOffset(tokenAt(ast->firstToken()).utf16charsBegin());
  1911. templ->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd());
  1912. ast->symbol = templ;
  1913. Scope *previousScope = switchScope(templ);
  1914. for (DeclarationListAST *it = ast->template_parameter_list; it; it = it->next) {
  1915. this->declaration(it->value);
  1916. }
  1917. // unsigned greater_token = ast->greater_token;
  1918. this->declaration(ast->declaration);
  1919. (void) switchScope(previousScope);
  1920. if (Symbol *decl = templ->declaration()) {
  1921. templ->setSourceLocation(decl->sourceLocation(), translationUnit());
  1922. templ->setName(decl->name());
  1923. }
  1924. _scope->addMember(templ);
  1925. return false;
  1926. }
  1927. bool Bind::visit(TypenameTypeParameterAST *ast)
  1928. {
  1929. unsigned sourceLocation = location(ast->name, ast->firstToken());
  1930. // unsigned classkey_token = ast->classkey_token;
  1931. // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
  1932. const Name *name = this->name(ast->name);
  1933. ExpressionTy type_id = this->expression(ast->type_id);
  1934. TypenameArgument *arg = control()->newTypenameArgument(sourceLocation, name);
  1935. arg->setType(type_id);
  1936. ast->symbol = arg;
  1937. _scope->addMember(arg);
  1938. return false;
  1939. }
  1940. bool Bind::visit(TemplateTypeParameterAST *ast)
  1941. {
  1942. unsigned sourceLocation = location(ast->name, ast->firstToken());
  1943. // unsigned template_token = ast->template_token;
  1944. // unsigned less_token = ast->less_token;
  1945. // ### process the template prototype
  1946. #if 0
  1947. for (DeclarationListAST *it = ast->template_parameter_list; it; it = it->next) {
  1948. this->declaration(it->value);
  1949. }
  1950. #endif
  1951. // unsigned greater_token = ast->greater_token;
  1952. // unsigned class_token = ast->class_token;
  1953. // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
  1954. const Name *name = this->name(ast->name);
  1955. ExpressionTy type_id = this->expression(ast->type_id);
  1956. // ### introduce TemplateTypeArgument
  1957. TypenameArgument *arg = control()->newTypenameArgument(sourceLocation, name);
  1958. arg->setType(type_id);
  1959. ast->symbol = arg;
  1960. _scope->addMember(arg);
  1961. return false;
  1962. }
  1963. bool Bind::visit(UsingAST *ast)
  1964. {
  1965. unsigned sourceLocation = location(ast->name, ast->firstToken());
  1966. const Name *name = this->name(ast->name);
  1967. UsingDeclaration *symbol = control()->newUsingDeclaration(sourceLocation, name);
  1968. ast->symbol = symbol;
  1969. _scope->addMember(symbol);
  1970. return false;
  1971. }
  1972. bool Bind::visit(UsingDirectiveAST *ast)
  1973. {
  1974. unsigned sourceLocation = location(ast->name, ast->firstToken());
  1975. const Name *name = this->name(ast->name);
  1976. UsingNamespaceDirective *symbol = control()->newUsingNamespaceDirective(sourceLocation, name);
  1977. ast->symbol = symbol;
  1978. _scope->addMember(symbol);
  1979. return false;
  1980. }
  1981. bool Bind::visit(ObjCClassForwardDeclarationAST *ast)
  1982. {
  1983. FullySpecifiedType declSpecifiers;
  1984. for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
  1985. declSpecifiers = this->specifier(it->value, declSpecifiers);
  1986. }
  1987. List<ObjCForwardClassDeclaration *> **symbolTail = &ast->symbols;
  1988. // unsigned class_token = ast->class_token;
  1989. for (NameListAST *it = ast->identifier_list; it; it = it->next) {
  1990. const Name *name = this->name(it->value);
  1991. const unsigned sourceLocation = location(it->value, ast->firstToken());
  1992. ObjCForwardClassDeclaration *fwd = control()->newObjCForwardClassDeclaration(sourceLocation, name);
  1993. setDeclSpecifiers(fwd, declSpecifiers);
  1994. _scope->addMember(fwd);
  1995. *symbolTail = new (translationUnit()->memoryPool()) List<ObjCForwardClassDeclaration *>(fwd);
  1996. symbolTail = &(*symbolTail)->next;
  1997. }
  1998. return false;
  1999. }
  2000. unsigned Bind::calculateScopeStart(ObjCClassDeclarationAST *ast) const
  2001. {
  2002. if (ast->inst_vars_decl)
  2003. if (unsigned pos = ast->inst_vars_decl->lbrace_token)
  2004. return tokenAt(pos).utf16charsEnd();
  2005. if (ast->protocol_refs)
  2006. if (unsigned pos = ast->protocol_refs->lastToken())
  2007. return tokenAt(pos - 1).utf16charsEnd();
  2008. if (ast->superclass)
  2009. if (unsigned pos = ast->superclass->lastToken())
  2010. return tokenAt(pos - 1).utf16charsEnd();
  2011. if (ast->colon_token)
  2012. return tokenAt(ast->colon_token).utf16charsEnd();
  2013. if (ast->rparen_token)
  2014. return tokenAt(ast->rparen_token).utf16charsEnd();
  2015. if (ast->category_name)
  2016. if (unsigned pos = ast->category_name->lastToken())
  2017. return tokenAt(pos - 1).utf16charsEnd();
  2018. if (ast->lparen_token)
  2019. return tokenAt(ast->lparen_token).utf16charsEnd();
  2020. if (ast->class_name)
  2021. if (unsigned pos = ast->class_name->lastToken())
  2022. return tokenAt(pos - 1).utf16charsEnd();
  2023. return tokenAt(ast->firstToken()).utf16charsBegin();
  2024. }
  2025. bool Bind::visit(ObjCClassDeclarationAST *ast)
  2026. {
  2027. FullySpecifiedType declSpecifiers;
  2028. for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
  2029. declSpecifiers = this->specifier(it->value, declSpecifiers);
  2030. }
  2031. const Name *class_name = this->name(ast->class_name);
  2032. const Name *category_name = this->name(ast->category_name);
  2033. const unsigned sourceLocation = location(ast->class_name, ast->firstToken());
  2034. ObjCClass *klass = control()->newObjCClass(sourceLocation, class_name);
  2035. ast->symbol = klass;
  2036. _scope->addMember(klass);
  2037. klass->setStartOffset(calculateScopeStart(ast));
  2038. klass->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd());
  2039. if (ast->interface_token)
  2040. klass->setInterface(true);
  2041. klass->setCategoryName(category_name);
  2042. Scope *previousScope = switchScope(klass);
  2043. if (const Name *superclass = this->name(ast->superclass)) {
  2044. ObjCBaseClass *superKlass = control()->newObjCBaseClass(ast->superclass->firstToken(), superclass);
  2045. klass->setBaseClass(superKlass);
  2046. }
  2047. this->objCProtocolRefs(ast->protocol_refs, klass);
  2048. const int previousObjCVisibility = switchObjCVisibility(Function::Protected);
  2049. this->objCInstanceVariablesDeclaration(ast->inst_vars_decl, klass);
  2050. (void) switchObjCVisibility(Function::Public);
  2051. for (DeclarationListAST *it = ast->member_declaration_list; it; it = it->next) {
  2052. this->declaration(it->value);
  2053. }
  2054. (void) switchObjCVisibility(previousObjCVisibility);
  2055. (void) switchScope(previousScope);
  2056. return false;
  2057. }
  2058. bool Bind::visit(ObjCProtocolForwardDeclarationAST *ast)
  2059. {
  2060. FullySpecifiedType declSpecifiers;
  2061. for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
  2062. declSpecifiers = this->specifier(it->value, declSpecifiers);
  2063. }
  2064. List<ObjCForwardProtocolDeclaration *> **symbolTail = &ast->symbols;
  2065. // unsigned class_token = ast->class_token;
  2066. for (NameListAST *it = ast->identifier_list; it; it = it->next) {
  2067. const Name *name = this->name(it->value);
  2068. const unsigned sourceLocation = location(it->value, ast->firstToken());
  2069. ObjCForwardProtocolDeclaration *fwd = control()->newObjCForwardProtocolDeclaration(sourceLocation, name);
  2070. setDeclSpecifiers(fwd, declSpecifiers);
  2071. _scope->addMember(fwd);
  2072. *symbolTail = new (translationUnit()->memoryPool()) List<ObjCForwardProtocolDeclaration *>(fwd);
  2073. symbolTail = &(*symbolTail)->next;
  2074. }
  2075. return false;
  2076. }
  2077. unsigned Bind::calculateScopeStart(ObjCProtocolDeclarationAST *ast) const
  2078. {
  2079. if (ast->protocol_refs)
  2080. if (unsigned pos = ast->protocol_refs->lastToken())
  2081. return tokenAt(pos - 1).utf16charsEnd();
  2082. if (ast->name)
  2083. if (unsigned pos = ast->name->lastToken())
  2084. return tokenAt(pos - 1).utf16charsEnd();
  2085. return tokenAt(ast->firstToken()).utf16charsBegin();
  2086. }
  2087. bool Bind::visit(ObjCProtocolDeclarationAST *ast)
  2088. {
  2089. FullySpecifiedType type;
  2090. for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
  2091. type = this->specifier(it->value, type);
  2092. }
  2093. // unsigned protocol_token = ast->protocol_token;
  2094. const Name *name = this->name(ast->name);
  2095. const unsigned sourceLocation = location(ast->name, ast->firstToken());
  2096. ObjCProtocol *protocol = control()->newObjCProtocol(sourceLocation, name);
  2097. protocol->setStartOffset(calculateScopeStart(ast));
  2098. protocol->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd());
  2099. ast->symbol = protocol;
  2100. _scope->addMember(protocol);
  2101. Scope *previousScope = switchScope(protocol);
  2102. const int previousObjCVisibility = switchObjCVisibility(Function::Public);
  2103. this->objCProtocolRefs(ast->protocol_refs, protocol);
  2104. for (DeclarationListAST *it = ast->member_declaration_list; it; it = it->next) {
  2105. this->declaration(it->value);
  2106. }
  2107. (void) switchObjCVisibility(previousObjCVisibility);
  2108. (void) switchScope(previousScope);
  2109. return false;
  2110. }
  2111. bool Bind::visit(ObjCVisibilityDeclarationAST *ast)
  2112. {
  2113. _objcVisibility = visibilityForObjCAccessSpecifier(tokenKind(ast->visibility_token));
  2114. return false;
  2115. }
  2116. bool Bind::visit(ObjCPropertyDeclarationAST *ast)
  2117. {
  2118. (void) ast;
  2119. FullySpecifiedType type;
  2120. for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
  2121. type = this->specifier(it->value, type);
  2122. }
  2123. // unsigned property_token = ast->property_token;
  2124. // unsigned lparen_token = ast->lparen_token;
  2125. for (ObjCPropertyAttributeListAST *it = ast->property_attribute_list; it; it = it->next) {
  2126. this->objCPropertyAttribute(it->value);
  2127. }
  2128. // unsigned rparen_token = ast->rparen_token;
  2129. this->declaration(ast->simple_declaration);
  2130. // List<ObjCPropertyDeclaration *> *symbols = ast->symbols;
  2131. return false;
  2132. }
  2133. bool Bind::visit(ObjCMethodDeclarationAST *ast)
  2134. {
  2135. ObjCMethod *method = this->objCMethodPrototype(ast->method_prototype);
  2136. if (! ast->function_body) {
  2137. const Name *name = method->name();
  2138. unsigned sourceLocation = ast->firstToken();
  2139. Declaration *decl = control()->newDeclaration(sourceLocation, name);
  2140. decl->setType(method);
  2141. _scope->addMember(decl);
  2142. } else if (! _skipFunctionBodies && ast->function_body) {
  2143. Scope *previousScope = switchScope(method);
  2144. this->statement(ast->function_body);
  2145. (void) switchScope(previousScope);
  2146. _scope->addMember(method);
  2147. } else if (method) {
  2148. _scope->addMember(method);
  2149. }
  2150. return false;
  2151. }
  2152. bool Bind::visit(ObjCSynthesizedPropertiesDeclarationAST *ast)
  2153. {
  2154. // unsigned synthesized_token = ast->synthesized_token;
  2155. for (ObjCSynthesizedPropertyListAST *it = ast->property_identifier_list; it; it = it->next) {
  2156. this->objCSynthesizedProperty(it->value);
  2157. }
  2158. // unsigned semicolon_token = ast->semicolon_token;
  2159. return false;
  2160. }
  2161. bool Bind::visit(ObjCDynamicPropertiesDeclarationAST *ast)
  2162. {
  2163. // unsigned dynamic_token = ast->dynamic_token;
  2164. for (NameListAST *it = ast->property_identifier_list; it; it = it->next) {
  2165. /*const Name *value =*/ this->name(it->value);
  2166. }
  2167. // unsigned semicolon_token = ast->semicolon_token;
  2168. return false;
  2169. }
  2170. // NameAST
  2171. bool Bind::visit(ObjCSelectorAST *ast) // ### review
  2172. {
  2173. std::vector<const Name *> arguments;
  2174. bool hasArgs = false;
  2175. for (ObjCSelectorArgumentListAST *it = ast->selector_argument_list; it; it = it->next) {
  2176. if (const Name *selector_argument = this->objCSelectorArgument(it->value, &hasArgs))
  2177. arguments.push_back(selector_argument);
  2178. }
  2179. if (! arguments.empty()) {
  2180. _name = control()->selectorNameId(&arguments[0], unsigned(arguments.size()), hasArgs);
  2181. ast->name = _name;
  2182. }
  2183. return false;
  2184. }
  2185. bool Bind::visit(QualifiedNameAST *ast)
  2186. {
  2187. for (NestedNameSpecifierListAST *it = ast->nested_name_specifier_list; it; it = it->next) {
  2188. const Name *class_or_namespace_name = this->nestedNameSpecifier(it->value);
  2189. if (_name || ast->global_scope_token)
  2190. _name = control()->qualifiedNameId(_name, class_or_namespace_name);
  2191. else
  2192. _name = class_or_namespace_name;
  2193. }
  2194. const Name *unqualified_name = this->name(ast->unqualified_name);
  2195. if (_name || ast->global_scope_token)
  2196. _name = control()->qualifiedNameId(_name, unqualified_name);
  2197. else
  2198. _name = unqualified_name;
  2199. ast->name = _name;
  2200. return false;
  2201. }
  2202. bool Bind::visit(OperatorFunctionIdAST *ast)
  2203. {
  2204. const OperatorNameId::Kind op = this->cppOperator(ast->op);
  2205. ast->name = _name = control()->operatorNameId(op);
  2206. return false;
  2207. }
  2208. bool Bind::visit(ConversionFunctionIdAST *ast)
  2209. {
  2210. FullySpecifiedType type;
  2211. for (SpecifierListAST *it = ast->type_specifier_list; it; it = it->next) {
  2212. type = this->specifier(it->value, type);
  2213. }
  2214. for (PtrOperatorListAST *it = ast->ptr_operator_list; it; it = it->next) {
  2215. type = this->ptrOperator(it->value, type);
  2216. }
  2217. ast->name = _name = control()->conversionNameId(type);
  2218. return false;
  2219. }
  2220. bool Bind::visit(AnonymousNameAST *ast)
  2221. {
  2222. ast->name = _name = control()->anonymousNameId(ast->class_token);
  2223. return false;
  2224. }
  2225. bool Bind::visit(SimpleNameAST *ast)
  2226. {
  2227. const Identifier *id = identifier(ast->identifier_token);
  2228. _name = id;
  2229. ast->name = _name;
  2230. return false;
  2231. }
  2232. bool Bind::visit(DestructorNameAST *ast)
  2233. {
  2234. _name = control()->destructorNameId(name(ast->unqualified_name));
  2235. ast->name = _name;
  2236. return false;
  2237. }
  2238. bool Bind::visit(TemplateIdAST *ast)
  2239. {
  2240. // collect the template parameters
  2241. std::vector<FullySpecifiedType> templateArguments;
  2242. for (ExpressionListAST *it = ast->template_argument_list; it; it = it->next) {
  2243. ExpressionTy value = this->expression(it->value);
  2244. templateArguments.push_back(value);
  2245. }
  2246. const Identifier *id = identifier(ast->identifier_token);
  2247. const int tokenKindBeforeIdentifier(translationUnit()->tokenKind(ast->identifier_token - 1));
  2248. const bool isSpecialization = (tokenKindBeforeIdentifier == T_CLASS ||
  2249. tokenKindBeforeIdentifier == T_STRUCT);
  2250. if (templateArguments.empty())
  2251. _name = control()->templateNameId(id, isSpecialization);
  2252. else
  2253. _name = control()->templateNameId(id, isSpecialization, &templateArguments[0],
  2254. unsigned(templateArguments.size()));
  2255. ast->name = _name;
  2256. return false;
  2257. }
  2258. // SpecifierAST
  2259. bool Bind::visit(SimpleSpecifierAST *ast)
  2260. {
  2261. switch (tokenKind(ast->specifier_token)) {
  2262. case T_IDENTIFIER: {
  2263. const Identifier *id = tokenAt(ast->specifier_token).identifier;
  2264. if (id->match(control()->cpp11Override())) {
  2265. if (_type.isOverride())
  2266. translationUnit()->error(ast->specifier_token, "duplicate `override'");
  2267. _type.setOverride(true);
  2268. }
  2269. else if (id->match(control()->cpp11Final())) {
  2270. if (_type.isFinal())
  2271. translationUnit()->error(ast->specifier_token, "duplicate `final'");
  2272. _type.setFinal(true);
  2273. }
  2274. }
  2275. break;
  2276. case T_CONST:
  2277. if (_type.isConst())
  2278. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2279. _type.setConst(true);
  2280. break;
  2281. case T_VOLATILE:
  2282. if (_type.isVolatile())
  2283. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2284. _type.setVolatile(true);
  2285. break;
  2286. case T_FRIEND:
  2287. if (_type.isFriend())
  2288. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2289. _type.setFriend(true);
  2290. break;
  2291. case T_AUTO:
  2292. if (!translationUnit()->languageFeatures().cxx11Enabled) {
  2293. if (_type.isAuto())
  2294. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2295. }
  2296. _type.setAuto(true);
  2297. break;
  2298. case T_REGISTER:
  2299. if (_type.isRegister())
  2300. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2301. _type.setRegister(true);
  2302. break;
  2303. case T_STATIC:
  2304. if (_type.isStatic())
  2305. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2306. _type.setStatic(true);
  2307. break;
  2308. case T_EXTERN:
  2309. if (_type.isExtern())
  2310. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2311. _type.setExtern(true);
  2312. break;
  2313. case T_MUTABLE:
  2314. if (_type.isMutable())
  2315. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2316. _type.setMutable(true);
  2317. break;
  2318. case T_TYPEDEF:
  2319. if (_type.isTypedef())
  2320. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2321. _type.setTypedef(true);
  2322. break;
  2323. case T_INLINE:
  2324. if (_type.isInline())
  2325. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2326. _type.setInline(true);
  2327. break;
  2328. case T_VIRTUAL:
  2329. if (_type.isVirtual())
  2330. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2331. _type.setVirtual(true);
  2332. break;
  2333. case T_EXPLICIT:
  2334. if (_type.isExplicit())
  2335. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2336. _type.setExplicit(true);
  2337. break;
  2338. case T_SIGNED:
  2339. if (_type.isSigned())
  2340. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2341. _type.setSigned(true);
  2342. break;
  2343. case T_UNSIGNED:
  2344. if (_type.isUnsigned())
  2345. translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
  2346. _type.setUnsigned(true);
  2347. break;
  2348. case T_CHAR:
  2349. if (_type)
  2350. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2351. _type.setType(control()->integerType(IntegerType::Char));
  2352. break;
  2353. case T_CHAR16_T:
  2354. if (_type)
  2355. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2356. _type.setType(control()->integerType(IntegerType::Char16));
  2357. break;
  2358. case T_CHAR32_T:
  2359. if (_type)
  2360. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2361. _type.setType(control()->integerType(IntegerType::Char32));
  2362. break;
  2363. case T_WCHAR_T:
  2364. if (_type)
  2365. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2366. _type.setType(control()->integerType(IntegerType::WideChar));
  2367. break;
  2368. case T_BOOL:
  2369. if (_type)
  2370. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2371. _type.setType(control()->integerType(IntegerType::Bool));
  2372. break;
  2373. case T_SHORT:
  2374. if (_type) {
  2375. IntegerType *intType = control()->integerType(IntegerType::Int);
  2376. if (_type.type() != intType)
  2377. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2378. }
  2379. _type.setType(control()->integerType(IntegerType::Short));
  2380. break;
  2381. case T_INT:
  2382. if (_type) {
  2383. Type *tp = _type.type();
  2384. IntegerType *shortType = control()->integerType(IntegerType::Short);
  2385. IntegerType *longType = control()->integerType(IntegerType::Long);
  2386. IntegerType *longLongType = control()->integerType(IntegerType::LongLong);
  2387. if (tp == shortType || tp == longType || tp == longLongType)
  2388. break;
  2389. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2390. }
  2391. _type.setType(control()->integerType(IntegerType::Int));
  2392. break;
  2393. case T_LONG:
  2394. if (_type) {
  2395. Type *tp = _type.type();
  2396. IntegerType *intType = control()->integerType(IntegerType::Int);
  2397. IntegerType *longType = control()->integerType(IntegerType::Long);
  2398. FloatType *doubleType = control()->floatType(FloatType::Double);
  2399. if (tp == longType) {
  2400. _type.setType(control()->integerType(IntegerType::LongLong));
  2401. break;
  2402. } else if (tp == doubleType) {
  2403. _type.setType(control()->floatType(FloatType::LongDouble));
  2404. break;
  2405. } else if (tp != intType) {
  2406. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2407. }
  2408. }
  2409. _type.setType(control()->integerType(IntegerType::Long));
  2410. break;
  2411. case T_FLOAT:
  2412. if (_type)
  2413. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2414. _type.setType(control()->floatType(FloatType::Float));
  2415. break;
  2416. case T_DOUBLE:
  2417. if (_type) {
  2418. IntegerType *longType = control()->integerType(IntegerType::Long);
  2419. if (_type.type() == longType) {
  2420. _type.setType(control()->floatType(FloatType::LongDouble));
  2421. break;
  2422. }
  2423. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2424. }
  2425. _type.setType(control()->floatType(FloatType::Double));
  2426. break;
  2427. case T_VOID:
  2428. if (_type)
  2429. translationUnit()->error(ast->specifier_token, "duplicate data type in declaration");
  2430. _type.setType(control()->voidType());
  2431. break;
  2432. default:
  2433. break;
  2434. } // switch
  2435. return false;
  2436. }
  2437. bool Bind::visit(AlignmentSpecifierAST *ast)
  2438. {
  2439. // Prevent visiting the type-id or alignment expression from changing the currently
  2440. // calculated type:
  2441. expression(ast->typeIdExprOrAlignmentExpr);
  2442. return false;
  2443. }
  2444. bool Bind::visit(GnuAttributeSpecifierAST *ast)
  2445. {
  2446. // unsigned attribute_token = ast->attribute_token;
  2447. // unsigned first_lparen_token = ast->first_lparen_token;
  2448. // unsigned second_lparen_token = ast->second_lparen_token;
  2449. for (GnuAttributeListAST *it = ast->attribute_list; it; it = it->next) {
  2450. this->attribute(it->value);
  2451. }
  2452. // unsigned first_rparen_token = ast->first_rparen_token;
  2453. // unsigned second_rparen_token = ast->second_rparen_token;
  2454. return false;
  2455. }
  2456. bool Bind::visit(TypeofSpecifierAST *ast)
  2457. {
  2458. ExpressionTy expression = this->expression(ast->expression);
  2459. _type = expression;
  2460. return false;
  2461. }
  2462. bool Bind::visit(DecltypeSpecifierAST *ast)
  2463. {
  2464. _type = this->expression(ast->expression);
  2465. return false;
  2466. }
  2467. bool Bind::visit(ClassSpecifierAST *ast)
  2468. {
  2469. // unsigned classkey_token = ast->classkey_token;
  2470. unsigned sourceLocation = ast->firstToken();
  2471. unsigned startScopeOffset = tokenAt(sourceLocation).utf16charsEnd(); // at the end of the class key
  2472. for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
  2473. _type = this->specifier(it->value, _type);
  2474. }
  2475. const Name *className = this->name(ast->name);
  2476. if (ast->name && ! ast->name->asAnonymousName()) {
  2477. sourceLocation = location(ast->name, sourceLocation);
  2478. startScopeOffset = tokenAt(sourceLocation).utf16charsEnd(); // at the end of the class name
  2479. if (QualifiedNameAST *q = ast->name->asQualifiedName()) {
  2480. if (q->unqualified_name) {
  2481. sourceLocation = q->unqualified_name->firstToken();
  2482. startScopeOffset = tokenAt(q->unqualified_name->lastToken() - 1).utf16charsEnd(); // at the end of the unqualified name
  2483. }
  2484. }
  2485. ensureValidClassName(&className, sourceLocation);
  2486. }
  2487. Class *klass = control()->newClass(sourceLocation, className);
  2488. klass->setStartOffset(startScopeOffset);
  2489. klass->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd());
  2490. _scope->addMember(klass);
  2491. if (_scope->isClass())
  2492. klass->setVisibility(_visibility);
  2493. // set the class key
  2494. unsigned classKey = tokenKind(ast->classkey_token);
  2495. if (classKey == T_CLASS)
  2496. klass->setClassKey(Class::ClassKey);
  2497. else if (classKey == T_STRUCT)
  2498. klass->setClassKey(Class::StructKey);
  2499. else if (classKey == T_UNION)
  2500. klass->setClassKey(Class::UnionKey);
  2501. _type.setType(klass);
  2502. Scope *previousScope = switchScope(klass);
  2503. const int previousVisibility = switchVisibility(visibilityForClassKey(classKey));
  2504. const int previousMethodKey = switchMethodKey(Function::NormalMethod);
  2505. for (BaseSpecifierListAST *it = ast->base_clause_list; it; it = it->next) {
  2506. this->baseSpecifier(it->value, ast->colon_token, klass);
  2507. }
  2508. // unsigned dot_dot_dot_token = ast->dot_dot_dot_token;
  2509. for (DeclarationListAST *it = ast->member_specifier_list; it; it = it->next) {
  2510. this->declaration(it->value);
  2511. }
  2512. (void) switchMethodKey(previousMethodKey);
  2513. (void) switchVisibility(previousVisibility);
  2514. (void) switchScope(previousScope);
  2515. ast->symbol = klass;
  2516. return false;
  2517. }
  2518. bool Bind::visit(NamedTypeSpecifierAST *ast)
  2519. {
  2520. _type.setType(control()->namedType(this->name(ast->name)));
  2521. return false;
  2522. }
  2523. bool Bind::visit(ElaboratedTypeSpecifierAST *ast)
  2524. {
  2525. // unsigned classkey_token = ast->classkey_token;
  2526. for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) {
  2527. _type = this->specifier(it->value, _type);
  2528. }
  2529. _type.setType(control()->namedType(this->name(ast->name)));
  2530. return false;
  2531. }
  2532. bool Bind::visit(EnumSpecifierAST *ast)
  2533. {
  2534. unsigned sourceLocation = location(ast->name, ast->firstToken());
  2535. const Name *enumName = this->name(ast->name);
  2536. Enum *e = control()->newEnum(sourceLocation, enumName);
  2537. e->setStartOffset(tokenAt(sourceLocation).utf16charsEnd()); // at the end of the enum or identifier token.
  2538. e->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd());
  2539. if (ast->key_token)
  2540. e->setScoped(true);
  2541. ast->symbol = e;
  2542. _scope->addMember(e);
  2543. if (_scope->isClass())
  2544. e->setVisibility(_visibility);
  2545. Scope *previousScope = switchScope(e);
  2546. for (EnumeratorListAST *it = ast->enumerator_list; it; it = it->next) {
  2547. this->enumerator(it->value, e);
  2548. }
  2549. (void) switchScope(previousScope);
  2550. return false;
  2551. }
  2552. // PtrOperatorAST
  2553. bool Bind::visit(PointerToMemberAST *ast)
  2554. {
  2555. const Name *memberName = 0;
  2556. for (NestedNameSpecifierListAST *it = ast->nested_name_specifier_list; it; it = it->next) {
  2557. const Name *class_or_namespace_name = this->nestedNameSpecifier(it->value);
  2558. if (memberName || ast->global_scope_token)
  2559. memberName = control()->qualifiedNameId(memberName, class_or_namespace_name);
  2560. else
  2561. memberName = class_or_namespace_name;
  2562. }
  2563. FullySpecifiedType type(control()->pointerToMemberType(memberName, _type));
  2564. for (SpecifierListAST *it = ast->cv_qualifier_list; it; it = it->next) {
  2565. type = this->specifier(it->value, type);
  2566. }
  2567. _type = type;
  2568. return false;
  2569. }
  2570. bool Bind::visit(PointerAST *ast)
  2571. {
  2572. if (_type->isReferenceType())
  2573. translationUnit()->error(ast->firstToken(), "cannot declare pointer to a reference");
  2574. FullySpecifiedType type(control()->pointerType(_type));
  2575. for (SpecifierListAST *it = ast->cv_qualifier_list; it; it = it->next) {
  2576. type = this->specifier(it->value, type);
  2577. }
  2578. _type = type;
  2579. return false;
  2580. }
  2581. bool Bind::visit(ReferenceAST *ast)
  2582. {
  2583. const bool rvalueRef = (tokenKind(ast->reference_token) == T_AMPER_AMPER);
  2584. if (_type->isReferenceType())
  2585. translationUnit()->error(ast->firstToken(), "cannot declare reference to a reference");
  2586. FullySpecifiedType type(control()->referenceType(_type, rvalueRef));
  2587. _type = type;
  2588. return false;
  2589. }
  2590. // PostfixAST
  2591. bool Bind::visit(CallAST *ast)
  2592. {
  2593. /*ExpressionTy base_expression =*/ this->expression(ast->base_expression);
  2594. // unsigned lparen_token = ast->lparen_token;
  2595. for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
  2596. /*ExpressionTy value =*/ this->expression(it->value);
  2597. }
  2598. // unsigned rparen_token = ast->rparen_token;
  2599. return false;
  2600. }
  2601. bool Bind::visit(ArrayAccessAST *ast)
  2602. {
  2603. /*ExpressionTy base_expression =*/ this->expression(ast->base_expression);
  2604. // unsigned lbracket_token = ast->lbracket_token;
  2605. /*ExpressionTy expression =*/ this->expression(ast->expression);
  2606. // unsigned rbracket_token = ast->rbracket_token;
  2607. return false;
  2608. }
  2609. bool Bind::visit(PostIncrDecrAST *ast)
  2610. {
  2611. ExpressionTy base_expression = this->expression(ast->base_expression);
  2612. // unsigned incr_decr_token = ast->incr_decr_token;
  2613. return false;
  2614. }
  2615. bool Bind::visit(MemberAccessAST *ast)
  2616. {
  2617. ExpressionTy base_expression = this->expression(ast->base_expression);
  2618. // unsigned access_token = ast->access_token;
  2619. // unsigned template_token = ast->template_token;
  2620. /*const Name *member_name =*/ this->name(ast->member_name);
  2621. return false;
  2622. }
  2623. // CoreDeclaratorAST
  2624. bool Bind::visit(DeclaratorIdAST *ast)
  2625. {
  2626. /*const Name *name =*/ this->name(ast->name);
  2627. *_declaratorId = ast;
  2628. return false;
  2629. }
  2630. bool Bind::visit(NestedDeclaratorAST *ast)
  2631. {
  2632. _type = this->declarator(ast->declarator, _type, _declaratorId);
  2633. return false;
  2634. }
  2635. // PostfixDeclaratorAST
  2636. bool Bind::visit(FunctionDeclaratorAST *ast)
  2637. {
  2638. Function *fun = control()->newFunction(0, 0);
  2639. fun->setStartOffset(tokenAt(ast->firstToken()).utf16charsBegin());
  2640. fun->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd());
  2641. if (ast->trailing_return_type)
  2642. _type = this->trailingReturnType(ast->trailing_return_type, _type);
  2643. fun->setReturnType(_type);
  2644. // unsigned lparen_token = ast->lparen_token;
  2645. this->parameterDeclarationClause(ast->parameter_declaration_clause, ast->lparen_token, fun);
  2646. // unsigned rparen_token = ast->rparen_token;
  2647. FullySpecifiedType type(fun);
  2648. for (SpecifierListAST *it = ast->cv_qualifier_list; it; it = it->next) {
  2649. type = this->specifier(it->value, type);
  2650. }
  2651. // propagate the cv-qualifiers
  2652. fun->setConst(type.isConst());
  2653. fun->setVolatile(type.isVolatile());
  2654. fun->setOverride(type.isOverride());
  2655. fun->setFinal(type.isFinal());
  2656. this->exceptionSpecification(ast->exception_specification, type);
  2657. if (ast->as_cpp_initializer != 0) {
  2658. fun->setAmbiguous(true);
  2659. /*ExpressionTy as_cpp_initializer =*/ this->expression(ast->as_cpp_initializer);
  2660. }
  2661. ast->symbol = fun;
  2662. _type = type;
  2663. return false;
  2664. }
  2665. bool Bind::visit(ArrayDeclaratorAST *ast)
  2666. {
  2667. ExpressionTy expression = this->expression(ast->expression);
  2668. FullySpecifiedType type(control()->arrayType(_type));
  2669. _type = type;
  2670. return false;
  2671. }
  2672. void Bind::ensureValidClassName(const Name **name, unsigned sourceLocation)
  2673. {
  2674. if (!*name)
  2675. return;
  2676. const QualifiedNameId *qName = (*name)->asQualifiedNameId();
  2677. const Name *uqName = qName ? qName->name() : *name;
  2678. if (!uqName->isNameId() && !uqName->isTemplateNameId()) {
  2679. translationUnit()->error(sourceLocation, "expected a class-name");
  2680. *name = uqName->identifier();
  2681. if (qName)
  2682. *name = control()->qualifiedNameId(qName->base(), *name);
  2683. }
  2684. }
  2685. int Bind::visibilityForAccessSpecifier(int tokenKind)
  2686. {
  2687. switch (tokenKind) {
  2688. case T_PUBLIC:
  2689. return Symbol::Public;
  2690. case T_PROTECTED:
  2691. return Symbol::Protected;
  2692. case T_PRIVATE:
  2693. return Symbol::Private;
  2694. case T_Q_SIGNALS:
  2695. return Symbol::Protected;
  2696. default:
  2697. return Symbol::Public;
  2698. }
  2699. }
  2700. int Bind::visibilityForClassKey(int tokenKind)
  2701. {
  2702. switch (tokenKind) {
  2703. case T_CLASS:
  2704. return Symbol::Private;
  2705. case T_STRUCT:
  2706. case T_UNION:
  2707. return Symbol::Public;
  2708. default:
  2709. return Symbol::Public;
  2710. }
  2711. }
  2712. int Bind::visibilityForObjCAccessSpecifier(int tokenKind)
  2713. {
  2714. switch (tokenKind) {
  2715. case T_AT_PUBLIC:
  2716. return Symbol::Public;
  2717. case T_AT_PROTECTED:
  2718. return Symbol::Protected;
  2719. case T_AT_PRIVATE:
  2720. return Symbol::Private;
  2721. case T_AT_PACKAGE:
  2722. return Symbol::Package;
  2723. default:
  2724. return Symbol::Protected;
  2725. }
  2726. }
  2727. bool Bind::isObjCClassMethod(int tokenKind)
  2728. {
  2729. switch (tokenKind) {
  2730. case T_PLUS:
  2731. return true;
  2732. case T_MINUS:
  2733. default:
  2734. return false;
  2735. }
  2736. }