cppBison.yxx 111 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294
  1. /**
  2. * @file cppBison.yxx
  3. * @author drose
  4. * @date 1999-01-16
  5. */
  6. %{
  7. #include "cppBisonDefs.h"
  8. #include "cppParser.h"
  9. #include "cppClosureType.h"
  10. #include "cppExpression.h"
  11. #include "cppSimpleType.h"
  12. #include "cppExtensionType.h"
  13. #include "cppStructType.h"
  14. #include "cppEnumType.h"
  15. #include "cppFunctionType.h"
  16. #include "cppTBDType.h"
  17. #include "cppMakeProperty.h"
  18. #include "cppMakeSeq.h"
  19. #include "cppParameterList.h"
  20. #include "cppInstance.h"
  21. #include "cppClassTemplateParameter.h"
  22. #include "cppTemplateParameterList.h"
  23. #include "cppInstanceIdentifier.h"
  24. #include "cppTypedefType.h"
  25. #include "cppTypeDeclaration.h"
  26. #include "cppVisibility.h"
  27. #include "cppIdentifier.h"
  28. #include "cppScope.h"
  29. #include "cppTemplateScope.h"
  30. #include "cppNamespace.h"
  31. #include "cppUsing.h"
  32. using std::stringstream;
  33. using std::string;
  34. ////////////////////////////////////////////////////////////////////
  35. // Defining the interface to the parser.
  36. ////////////////////////////////////////////////////////////////////
  37. CPPScope *current_scope = nullptr;
  38. CPPScope *global_scope = nullptr;
  39. CPPPreprocessor *current_lexer = nullptr;
  40. static CPPStructType *current_struct = nullptr;
  41. static CPPEnumType *current_enum = nullptr;
  42. static int current_storage_class = 0;
  43. static CPPType *current_type = nullptr;
  44. static CPPExpression *current_expr = nullptr;
  45. static int publish_nest_level = 0;
  46. static CPPVisibility publish_previous;
  47. static YYLTYPE publish_loc;
  48. static std::vector<CPPScope *> last_scopes;
  49. static std::vector<int> last_storage_classes;
  50. static std::vector<CPPStructType *> last_structs;
  51. int yyparse();
  52. #define YYERROR_VERBOSE
  53. static void
  54. yyerror(const string &msg) {
  55. current_lexer->error(msg, current_lexer->_last_token_loc);
  56. }
  57. static void
  58. yyerror(YYLTYPE *loc, const string &msg) {
  59. current_lexer->error(msg, *loc);
  60. }
  61. static void
  62. yyerror(const string &msg, YYLTYPE &loc) {
  63. current_lexer->error(msg, loc);
  64. }
  65. static void
  66. yywarning(const string &msg, YYLTYPE &loc) {
  67. current_lexer->warning(msg, loc);
  68. }
  69. static int
  70. yylex(YYSTYPE *lval, YYLTYPE *lloc) {
  71. CPPToken token = current_lexer->get_next_token();
  72. *lval = token._lval;
  73. *lloc = token._lloc;
  74. return token._token;
  75. }
  76. void
  77. parse_cpp(CPPParser *cp) {
  78. CPPScope *old_scope = current_scope;
  79. CPPScope *old_global_scope = global_scope;
  80. CPPPreprocessor *old_lexer = current_lexer;
  81. current_scope = cp;
  82. global_scope = cp;
  83. current_lexer = cp;
  84. publish_nest_level = 0;
  85. yyparse();
  86. if (publish_nest_level != 0) {
  87. yyerror("Unclosed __begin_publish", publish_loc);
  88. publish_nest_level = 0;
  89. }
  90. current_scope = old_scope;
  91. global_scope = old_global_scope;
  92. current_lexer = old_lexer;
  93. }
  94. CPPExpression *
  95. parse_const_expr(CPPPreprocessor *pp, CPPScope *new_current_scope,
  96. CPPScope *new_global_scope) {
  97. CPPScope *old_scope = current_scope;
  98. CPPScope *old_global_scope = global_scope;
  99. CPPPreprocessor *old_lexer = current_lexer;
  100. CPPExpression *old_expr = current_expr;
  101. current_scope = new_current_scope;
  102. global_scope = new_global_scope;
  103. current_expr = nullptr;
  104. current_lexer = pp;
  105. yyparse();
  106. CPPExpression *result = current_expr;
  107. current_scope = old_scope;
  108. global_scope = old_global_scope;
  109. current_lexer = old_lexer;
  110. current_expr = old_expr;
  111. return result;
  112. }
  113. CPPType *
  114. parse_type(CPPPreprocessor *pp, CPPScope *new_current_scope,
  115. CPPScope *new_global_scope) {
  116. CPPScope *old_scope = current_scope;
  117. CPPScope *old_global_scope = global_scope;
  118. CPPPreprocessor *old_lexer = current_lexer;
  119. CPPType *old_type = current_type;
  120. current_scope = new_current_scope;
  121. global_scope = new_global_scope;
  122. current_type = nullptr;
  123. current_lexer = pp;
  124. yyparse();
  125. CPPType *result = current_type;
  126. current_scope = old_scope;
  127. global_scope = old_global_scope;
  128. current_lexer = old_lexer;
  129. current_type = old_type;
  130. return result;
  131. }
  132. static void
  133. push_scope(CPPScope *new_scope) {
  134. last_scopes.push_back(current_scope);
  135. if (new_scope != nullptr) {
  136. current_scope = new_scope;
  137. }
  138. }
  139. static void
  140. pop_scope() {
  141. assert(!last_scopes.empty());
  142. current_scope = last_scopes.back();
  143. last_scopes.pop_back();
  144. }
  145. static void
  146. push_storage_class(int new_storage_class) {
  147. last_storage_classes.push_back(current_storage_class);
  148. current_storage_class = new_storage_class;
  149. }
  150. static void
  151. pop_storage_class() {
  152. assert(!last_storage_classes.empty());
  153. current_storage_class = last_storage_classes.back();
  154. last_storage_classes.pop_back();
  155. }
  156. static void
  157. push_struct(CPPStructType *new_struct) {
  158. last_structs.push_back(current_struct);
  159. current_struct = new_struct;
  160. }
  161. static void
  162. pop_struct() {
  163. assert(!last_structs.empty());
  164. current_struct = last_structs.back();
  165. last_structs.pop_back();
  166. }
  167. %}
  168. /* This is a bison-specific declaration to enable recursive calls to
  169. yyparse(). It changes the calling sequence to yylex(), passing
  170. pointers to the current yylval and yylloc. Bison 2.7 introduces a
  171. different syntax that will also pass the current yylloc to yyerror,
  172. but we have to support Bison versions as old as 2.5 for now. */
  173. /*%define api.pure full*/
  174. %pure-parser
  175. %locations
  176. %token <u.real> REAL
  177. %token <u.integer> INTEGER
  178. %token <u.integer> CHAR_TOK
  179. %token <str> SIMPLE_STRING SIMPLE_IDENTIFIER
  180. %token <u.expr> STRING_LITERAL CUSTOM_LITERAL
  181. %token <u.identifier> IDENTIFIER TYPENAME_IDENTIFIER TYPEPACK_IDENTIFIER SCOPING
  182. %token <u.type> TYPEDEFNAME
  183. %token ELLIPSIS
  184. %token OROR
  185. %token ANDAND
  186. %token EQCOMPARE
  187. %token NECOMPARE
  188. %token LECOMPARE
  189. %token GECOMPARE
  190. %token LSHIFT
  191. %token RSHIFT
  192. %token POINTSAT_STAR
  193. %token DOT_STAR
  194. %token UNARY
  195. %token UNARY_NOT
  196. %token UNARY_NEGATE
  197. %token UNARY_MINUS
  198. %token UNARY_PLUS
  199. %token UNARY_STAR
  200. %token UNARY_REF
  201. %token POINTSAT
  202. %token SCOPE
  203. %token PLUSPLUS
  204. %token MINUSMINUS
  205. %token TIMESEQUAL
  206. %token DIVIDEEQUAL
  207. %token MODEQUAL
  208. %token PLUSEQUAL
  209. %token MINUSEQUAL
  210. %token OREQUAL
  211. %token ANDEQUAL
  212. %token XOREQUAL
  213. %token LSHIFTEQUAL
  214. %token RSHIFTEQUAL
  215. %token ATTR_LEFT
  216. %token ATTR_RIGHT
  217. %token KW_ALIGNAS
  218. %token KW_ALIGNOF
  219. %token KW_AUTO
  220. %token KW_BEGIN_PUBLISH
  221. %token KW_BLOCKING
  222. %token KW_BOOL
  223. %token KW_CATCH
  224. %token KW_CHAR
  225. %token KW_CHAR16_T
  226. %token KW_CHAR32_T
  227. %token KW_CLASS
  228. %token KW_CONST
  229. %token KW_CONSTEXPR
  230. %token KW_CONST_CAST
  231. %token KW_DECLTYPE
  232. %token KW_DEFAULT
  233. %token KW_DELETE
  234. %token KW_DOUBLE
  235. %token KW_DYNAMIC_CAST
  236. %token KW_ELSE
  237. %token KW_END_PUBLISH
  238. %token KW_ENUM
  239. %token KW_EXTENSION
  240. %token KW_EXTERN
  241. %token KW_EXPLICIT
  242. %token KW_PUBLISHED
  243. %token KW_FALSE
  244. %token KW_FINAL
  245. %token KW_FLOAT
  246. %token KW_FRIEND
  247. %token KW_FOR
  248. %token KW_GOTO
  249. %token KW_HAS_VIRTUAL_DESTRUCTOR
  250. %token KW_IF
  251. %token KW_INLINE
  252. %token KW_INT
  253. %token KW_IS_ABSTRACT
  254. %token KW_IS_BASE_OF
  255. %token KW_IS_CLASS
  256. %token KW_IS_CONSTRUCTIBLE
  257. %token KW_IS_CONVERTIBLE_TO
  258. %token KW_IS_DESTRUCTIBLE
  259. %token KW_IS_EMPTY
  260. %token KW_IS_ENUM
  261. %token KW_IS_FINAL
  262. %token KW_IS_FUNDAMENTAL
  263. %token KW_IS_POD
  264. %token KW_IS_POLYMORPHIC
  265. %token KW_IS_STANDARD_LAYOUT
  266. %token KW_IS_TRIVIAL
  267. %token KW_IS_UNION
  268. %token KW_LONG
  269. %token KW_MAKE_MAP_KEYS_SEQ
  270. %token KW_MAKE_MAP_PROPERTY
  271. %token KW_MAKE_PROPERTY
  272. %token KW_MAKE_PROPERTY2
  273. %token KW_MAKE_SEQ
  274. %token KW_MAKE_SEQ_PROPERTY
  275. %token KW_MUTABLE
  276. %token KW_NAMESPACE
  277. %token KW_NEW
  278. %token KW_NOEXCEPT
  279. %token KW_NULLPTR
  280. %token KW_OPERATOR
  281. %token KW_OVERRIDE
  282. %token KW_PRIVATE
  283. %token KW_PROTECTED
  284. %token KW_PUBLIC
  285. %token KW_REGISTER
  286. %token KW_REINTERPRET_CAST
  287. %token KW_RETURN
  288. %token KW_SHORT
  289. %token KW_SIGNED
  290. %token KW_SIZEOF
  291. %token KW_STATIC
  292. %token KW_STATIC_ASSERT
  293. %token KW_STATIC_CAST
  294. %token KW_STRUCT
  295. %token KW_TEMPLATE
  296. %token KW_THREAD_LOCAL
  297. %token KW_THROW
  298. %token KW_TRUE
  299. %token KW_TRY
  300. %token KW_TYPEDEF
  301. %token KW_TYPEID
  302. %token KW_TYPENAME
  303. %token KW_UNDERLYING_TYPE
  304. %token KW_UNION
  305. %token KW_UNSIGNED
  306. %token KW_USING
  307. %token KW_VIRTUAL
  308. %token KW_VOID
  309. %token KW_VOLATILE
  310. %token KW_WCHAR_T
  311. %token KW_WHILE
  312. /* These special tokens are used to set the starting state of the
  313. parser. The lexer places the appropriate one of these on the head
  314. of the input stream. */
  315. %token START_CPP
  316. %token START_CONST_EXPR
  317. %token START_TYPE
  318. %type <u.integer> storage_class
  319. %type <u.instance> constructor_prototype
  320. %type <u.instance> function_prototype
  321. %type <u.integer> function_post
  322. %type <str> function_operator
  323. %type <u.decl> template_formal_parameter
  324. %type <u.type> template_formal_parameter_type
  325. %type <u.inst_ident> instance_identifier
  326. %type <u.inst_ident> instance_identifier_and_maybe_trailing_return_type
  327. %type <u.param_list> function_parameter_list
  328. %type <u.param_list> function_parameters
  329. %type <u.param_list> formal_parameter_list
  330. %type <u.param_list> formal_parameters
  331. %type <u.closure_type> capture_list
  332. %type <u.capture> capture
  333. %type <u.expr> template_parameter_maybe_initialize
  334. %type <u.expr> maybe_initialize
  335. %type <u.expr> maybe_initialize_or_constructor_body
  336. %type <u.expr> maybe_initialize_or_function_body
  337. %type <u.instance> function_parameter
  338. %type <u.instance> formal_parameter
  339. %type <u.inst_ident> not_paren_formal_parameter_identifier
  340. %type <u.inst_ident> formal_parameter_identifier
  341. %type <u.inst_ident> parameter_pack_identifier
  342. %type <u.inst_ident> not_paren_empty_instance_identifier
  343. %type <u.inst_ident> empty_instance_identifier
  344. %type <u.type> type type_pack
  345. %type <u.decl> type_decl
  346. %type <u.decl> var_type_decl
  347. %type <u.type> predefined_type
  348. %type <u.type> full_type
  349. %type <u.struct_type> anonymous_struct
  350. %type <u.struct_type> named_struct
  351. %type <u.enum_type> enum
  352. %type <u.extension_enum> enum_keyword
  353. %type <u.extension_enum> struct_keyword
  354. %type <u.simple_type> simple_type
  355. %type <u.simple_type> simple_int_type
  356. %type <u.simple_type> simple_float_type
  357. %type <u.simple_type> simple_void_type
  358. %type <u.type> class_derivation_name
  359. %type <u.type> enum_element_type
  360. %type <u.type> maybe_trailing_return_type
  361. %type <u.identifier> maybe_comma_identifier
  362. /*%type <u.type> typedefname*/
  363. %type <u.identifier> name
  364. %type <u.identifier> name_no_final
  365. %type <u.expr> string_literal
  366. /* We need to treat KW_OPERATOR as a scopable keyword. */
  367. %type <u.identifier> KW_OPERATOR
  368. %type <u.expr> optional_const_expr
  369. %type <u.expr> optional_const_expr_comma
  370. %type <u.expr> const_expr_comma
  371. %type <u.expr> no_angle_bracket_const_expr
  372. %type <u.expr> const_expr
  373. %type <u.expr> const_operand
  374. %type <u.expr> formal_const_expr
  375. %type <u.expr> formal_const_operand
  376. /* Precedence rules. */
  377. %left IDENTIFIER TYPENAME_IDENTIFIER TYPEDEFNAME KW_ENUM ELLIPSIS KW_OPERATOR KW_TYPENAME KW_INT KW_SHORT KW_UNSIGNED KW_SIGNED KW_LONG KW_FLOAT KW_DOUBLE KW_CHAR KW_WCHAR_T KW_CHAR16_T KW_CHAR32_T KW_BOOL
  378. %left '{' ',' ';'
  379. %nonassoc KW_THROW
  380. %right ':'
  381. %right '='
  382. %right '?'
  383. %left OROR
  384. %left ANDAND
  385. %left '|'
  386. %left '^'
  387. %left '&'
  388. %left EQCOMPARE NECOMPARE
  389. %left LECOMPARE GECOMPARE '<' '>'
  390. %left LSHIFT RSHIFT
  391. %left '+' '-'
  392. %left '*' '/' '%'
  393. %left POINTSAT_STAR DOT_STAR
  394. %right UNARY PLUSPLUS MINUSMINUS '~'
  395. %left POINTSAT '.' '(' '['
  396. %right SCOPE
  397. %nonassoc KW_NEW KW_DELETE KW_TRY KW_CATCH
  398. %%
  399. grammar:
  400. START_CPP cpp
  401. | START_CONST_EXPR const_expr
  402. {
  403. current_expr = $2;
  404. }
  405. | START_TYPE full_type
  406. {
  407. current_type = $2;
  408. }
  409. ;
  410. cpp:
  411. empty
  412. | cpp ';'
  413. | cpp declaration
  414. ;
  415. constructor_inits:
  416. constructor_init
  417. | constructor_inits ',' constructor_init
  418. ;
  419. constructor_init:
  420. name '(' optional_const_expr_comma ')'
  421. {
  422. delete $3;
  423. }
  424. | name '(' optional_const_expr_comma ')' ELLIPSIS
  425. {
  426. delete $3;
  427. }
  428. | name '{' optional_const_expr_comma '}'
  429. {
  430. delete $3;
  431. }
  432. ;
  433. /* This is principally for the syntax: extern "C" { ... }.
  434. We use storage_class instead of simply KW_EXTERN to avoid
  435. shift/reduce conflicts with yacc's limited differentiation
  436. ability. */
  437. extern_c:
  438. storage_class '{'
  439. {
  440. push_storage_class((current_storage_class & ~CPPInstance::SC_c_binding) |
  441. ($1 & CPPInstance::SC_c_binding));
  442. }
  443. cpp '}'
  444. {
  445. pop_storage_class();
  446. }
  447. ;
  448. declaration:
  449. type_like_declaration
  450. | template_declaration
  451. | extern_c
  452. | namespace_declaration
  453. | friend_declaration
  454. | KW_TYPEDEF typedef_declaration
  455. | KW_BEGIN_PUBLISH
  456. {
  457. if (publish_nest_level != 0) {
  458. yyerror("Unclosed __begin_publish", publish_loc);
  459. publish_nest_level = 0;
  460. current_scope->set_current_vis(V_public);
  461. }
  462. publish_previous = current_scope->get_current_vis();
  463. publish_loc = @1;
  464. publish_nest_level++;
  465. current_scope->set_current_vis(V_published);
  466. }
  467. | KW_END_PUBLISH
  468. {
  469. if (publish_nest_level != 1) {
  470. yyerror("Unmatched __end_publish", @1);
  471. } else {
  472. current_scope->set_current_vis(publish_previous);
  473. }
  474. publish_nest_level = 0;
  475. }
  476. | KW_PUBLISHED ':'
  477. {
  478. current_scope->set_current_vis(V_published);
  479. }
  480. | KW_PUBLIC ':'
  481. {
  482. if (publish_nest_level > 0) {
  483. current_scope->set_current_vis(V_published);
  484. } else {
  485. current_scope->set_current_vis(V_public);
  486. }
  487. }
  488. | KW_PROTECTED ':'
  489. {
  490. current_scope->set_current_vis(V_protected);
  491. }
  492. | KW_PRIVATE ':'
  493. {
  494. current_scope->set_current_vis(V_private);
  495. }
  496. | KW_MAKE_PROPERTY '(' name ',' IDENTIFIER maybe_comma_identifier ')' ';'
  497. {
  498. CPPDeclaration *getter = $5->find_symbol(current_scope, global_scope, current_lexer);
  499. if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
  500. yyerror("Reference to non-existent or invalid getter: " + $5->get_fully_scoped_name(), @5);
  501. } else {
  502. CPPMakeProperty *make_property = new CPPMakeProperty($3, CPPMakeProperty::T_normal, current_scope, @1.file);
  503. make_property->_get_function = getter->as_function_group();
  504. if ($6 != nullptr) {
  505. CPPDeclaration *setter = $6->find_symbol(current_scope, global_scope, current_lexer);
  506. if (setter == nullptr || setter->get_subtype() != CPPDeclaration::ST_function_group) {
  507. yyerror("Reference to non-existent or invalid setter: " + $6->get_fully_scoped_name(), @6);
  508. } else {
  509. make_property->_set_function = setter->as_function_group();
  510. }
  511. }
  512. current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
  513. }
  514. }
  515. | KW_MAKE_PROPERTY '(' name ',' IDENTIFIER ',' IDENTIFIER ',' IDENTIFIER ')' ';'
  516. {
  517. CPPDeclaration *getter = $5->find_symbol(current_scope, global_scope, current_lexer);
  518. if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
  519. yyerror("Reference to non-existent or invalid getter: " + $5->get_fully_scoped_name(), @5);
  520. } else {
  521. CPPMakeProperty *make_property = new CPPMakeProperty($3, CPPMakeProperty::T_normal, current_scope, @1.file);
  522. make_property->_get_function = getter->as_function_group();
  523. CPPDeclaration *setter = $7->find_symbol(current_scope, global_scope, current_lexer);
  524. if (setter == nullptr || setter->get_subtype() != CPPDeclaration::ST_function_group) {
  525. yyerror("Reference to non-existent or invalid setter: " + $7->get_fully_scoped_name(), @7);
  526. } else {
  527. make_property->_set_function = setter->as_function_group();
  528. }
  529. CPPDeclaration *deleter = $9->find_symbol(current_scope, global_scope, current_lexer);
  530. if (deleter == nullptr || deleter->get_subtype() != CPPDeclaration::ST_function_group) {
  531. yyerror("reference to non-existent or invalid delete method: " + $9->get_fully_scoped_name(), @9);
  532. } else {
  533. make_property->_del_function = deleter->as_function_group();
  534. }
  535. current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
  536. }
  537. }
  538. | KW_MAKE_SEQ_PROPERTY '(' name ',' IDENTIFIER ',' IDENTIFIER ')' ';'
  539. {
  540. CPPDeclaration *length_getter = $5->find_symbol(current_scope, global_scope, current_lexer);
  541. if (length_getter == nullptr || length_getter->get_subtype() != CPPDeclaration::ST_function_group) {
  542. yyerror("reference to non-existent or invalid length method: " + $5->get_fully_scoped_name(), @5);
  543. length_getter = nullptr;
  544. }
  545. CPPDeclaration *getter = $7->find_symbol(current_scope, global_scope, current_lexer);
  546. if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
  547. yyerror("Reference to non-existent or invalid getter: " + $7->get_fully_scoped_name(), @7);
  548. getter = nullptr;
  549. }
  550. if (getter != nullptr && length_getter != nullptr) {
  551. CPPMakeProperty *make_property = new CPPMakeProperty($3, CPPMakeProperty::T_sequence, current_scope, @1.file);
  552. make_property->_get_function = getter->as_function_group();
  553. make_property->_length_function = length_getter->as_function_group();
  554. current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
  555. }
  556. }
  557. | KW_MAKE_SEQ_PROPERTY '(' name ',' IDENTIFIER ',' IDENTIFIER ',' IDENTIFIER ')' ';'
  558. {
  559. CPPDeclaration *length_getter = $5->find_symbol(current_scope, global_scope, current_lexer);
  560. if (length_getter == nullptr || length_getter->get_subtype() != CPPDeclaration::ST_function_group) {
  561. yyerror("reference to non-existent or invalid length method: " + $5->get_fully_scoped_name(), @5);
  562. length_getter = nullptr;
  563. }
  564. CPPDeclaration *getter = $7->find_symbol(current_scope, global_scope, current_lexer);
  565. if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
  566. yyerror("Reference to non-existent or invalid getter: " + $7->get_fully_scoped_name(), @7);
  567. getter = nullptr;
  568. }
  569. if (getter != nullptr && length_getter != nullptr) {
  570. CPPMakeProperty *make_property = new CPPMakeProperty($3, CPPMakeProperty::T_sequence, current_scope, @1.file);
  571. make_property->_get_function = getter->as_function_group();
  572. make_property->_length_function = length_getter->as_function_group();
  573. CPPDeclaration *setter = $9->find_symbol(current_scope, global_scope, current_lexer);
  574. if (setter == nullptr || setter->get_subtype() != CPPDeclaration::ST_function_group) {
  575. yyerror("Reference to non-existent or invalid setter: " + $9->get_fully_scoped_name(), @9);
  576. } else {
  577. make_property->_set_function = setter->as_function_group();
  578. }
  579. current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
  580. }
  581. }
  582. | KW_MAKE_SEQ_PROPERTY '(' name ',' IDENTIFIER ',' IDENTIFIER ',' IDENTIFIER ',' IDENTIFIER ')' ';'
  583. {
  584. CPPDeclaration *length_getter = $5->find_symbol(current_scope, global_scope, current_lexer);
  585. if (length_getter == nullptr || length_getter->get_subtype() != CPPDeclaration::ST_function_group) {
  586. yyerror("reference to non-existent or invalid length method: " + $5->get_fully_scoped_name(), @5);
  587. length_getter = nullptr;
  588. }
  589. CPPDeclaration *getter = $7->find_symbol(current_scope, global_scope, current_lexer);
  590. if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
  591. yyerror("Reference to non-existent or invalid getter: " + $7->get_fully_scoped_name(), @7);
  592. getter = nullptr;
  593. }
  594. if (getter != nullptr && length_getter != nullptr) {
  595. CPPMakeProperty *make_property = new CPPMakeProperty($3, CPPMakeProperty::T_sequence, current_scope, @1.file);
  596. make_property->_get_function = getter->as_function_group();
  597. make_property->_length_function = length_getter->as_function_group();
  598. CPPDeclaration *setter = $9->find_symbol(current_scope, global_scope, current_lexer);
  599. if (setter == nullptr || setter->get_subtype() != CPPDeclaration::ST_function_group) {
  600. yyerror("Reference to non-existent or invalid setter: " + $9->get_fully_scoped_name(), @9);
  601. } else {
  602. make_property->_set_function = setter->as_function_group();
  603. }
  604. CPPDeclaration *deleter = $11->find_symbol(current_scope, global_scope, current_lexer);
  605. if (deleter == nullptr || deleter->get_subtype() != CPPDeclaration::ST_function_group) {
  606. yyerror("reference to non-existent or invalid delete method: " + $11->get_fully_scoped_name(), @11);
  607. } else {
  608. make_property->_del_function = deleter->as_function_group();
  609. }
  610. current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
  611. }
  612. }
  613. | KW_MAKE_SEQ_PROPERTY '(' name ',' IDENTIFIER ',' IDENTIFIER ',' IDENTIFIER ',' IDENTIFIER ',' IDENTIFIER ')' ';'
  614. {
  615. CPPDeclaration *length_getter = $5->find_symbol(current_scope, global_scope, current_lexer);
  616. if (length_getter == nullptr || length_getter->get_subtype() != CPPDeclaration::ST_function_group) {
  617. yyerror("reference to non-existent or invalid length method: " + $5->get_fully_scoped_name(), @5);
  618. length_getter = nullptr;
  619. }
  620. CPPDeclaration *getter = $7->find_symbol(current_scope, global_scope, current_lexer);
  621. if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
  622. yyerror("Reference to non-existent or invalid getter: " + $7->get_fully_scoped_name(), @7);
  623. getter = nullptr;
  624. }
  625. if (getter != nullptr && length_getter != nullptr) {
  626. CPPMakeProperty *make_property = new CPPMakeProperty($3, CPPMakeProperty::T_sequence, current_scope, @1.file);
  627. make_property->_get_function = getter->as_function_group();
  628. make_property->_length_function = length_getter->as_function_group();
  629. CPPDeclaration *setter = $9->find_symbol(current_scope, global_scope, current_lexer);
  630. if (setter == nullptr || setter->get_subtype() != CPPDeclaration::ST_function_group) {
  631. yyerror("Reference to non-existent or invalid setter: " + $9->get_fully_scoped_name(), @9);
  632. } else {
  633. make_property->_set_function = setter->as_function_group();
  634. }
  635. CPPDeclaration *deleter = $11->find_symbol(current_scope, global_scope, current_lexer);
  636. if (deleter == nullptr || deleter->get_subtype() != CPPDeclaration::ST_function_group) {
  637. yyerror("reference to non-existent or invalid delete method: " + $11->get_fully_scoped_name(), @11);
  638. } else {
  639. make_property->_del_function = deleter->as_function_group();
  640. }
  641. CPPDeclaration *inserter = $13->find_symbol(current_scope, global_scope, current_lexer);
  642. if (inserter == nullptr || inserter->get_subtype() != CPPDeclaration::ST_function_group) {
  643. yyerror("reference to non-existent or invalid append method: " + $13->get_fully_scoped_name(), @13);
  644. } else {
  645. make_property->_insert_function = inserter->as_function_group();
  646. }
  647. current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
  648. }
  649. }
  650. | KW_MAKE_MAP_PROPERTY '(' name ',' IDENTIFIER ')' ';'
  651. {
  652. CPPDeclaration *getter = $5->find_symbol(current_scope, global_scope, current_lexer);
  653. if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
  654. yyerror("reference to non-existent or invalid item getter method: " + $5->get_fully_scoped_name(), @5);
  655. } else {
  656. CPPMakeProperty *make_property = new CPPMakeProperty($3, CPPMakeProperty::T_mapping, current_scope, @1.file);
  657. make_property->_get_function = getter->as_function_group();
  658. current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
  659. }
  660. }
  661. | KW_MAKE_MAP_PROPERTY '(' name ',' IDENTIFIER ',' IDENTIFIER ')' ';'
  662. {
  663. CPPDeclaration *getter = $7->find_symbol(current_scope, global_scope, current_lexer);
  664. if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
  665. yyerror("Reference to non-existent or invalid getter: " + $7->get_fully_scoped_name(), @7);
  666. } else {
  667. CPPMakeProperty *make_property;
  668. make_property = new CPPMakeProperty($3, CPPMakeProperty::T_mapping, current_scope, @1.file);
  669. make_property->_get_function = getter->as_function_group();
  670. CPPDeclaration *hasser = $5->find_symbol(current_scope, global_scope, current_lexer);
  671. if (hasser == nullptr || hasser->get_subtype() != CPPDeclaration::ST_function_group) {
  672. yyerror("reference to non-existent or invalid has/find method: " + $5->get_fully_scoped_name(), @5);
  673. } else {
  674. make_property->_has_function = hasser->as_function_group();
  675. }
  676. current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
  677. }
  678. }
  679. | KW_MAKE_MAP_PROPERTY '(' name ',' IDENTIFIER ',' IDENTIFIER ',' IDENTIFIER maybe_comma_identifier ')' ';'
  680. {
  681. CPPDeclaration *getter = $7->find_symbol(current_scope, global_scope, current_lexer);
  682. if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
  683. yyerror("Reference to non-existent or invalid getter: " + $7->get_fully_scoped_name(), @7);
  684. } else {
  685. CPPMakeProperty *make_property = new CPPMakeProperty($3, CPPMakeProperty::T_mapping, current_scope, @1.file);
  686. make_property->_get_function = getter->as_function_group();
  687. CPPDeclaration *hasser = $5->find_symbol(current_scope, global_scope, current_lexer);
  688. if (hasser == nullptr || hasser->get_subtype() != CPPDeclaration::ST_function_group) {
  689. yyerror("reference to non-existent or invalid has/find method: " + $5->get_fully_scoped_name(), @5);
  690. } else {
  691. make_property->_has_function = hasser->as_function_group();
  692. }
  693. CPPDeclaration *setter = $9->find_symbol(current_scope, global_scope, current_lexer);
  694. if (setter == nullptr || setter->get_subtype() != CPPDeclaration::ST_function_group) {
  695. yyerror("Reference to non-existent or invalid setter: " + $9->get_fully_scoped_name(), @9);
  696. } else {
  697. make_property->_set_function = setter->as_function_group();
  698. }
  699. if ($10 != nullptr) {
  700. CPPDeclaration *deleter = $10->find_symbol(current_scope, global_scope, current_lexer);
  701. if (deleter == nullptr || deleter->get_subtype() != CPPDeclaration::ST_function_group) {
  702. yyerror("reference to non-existent or invalid delete method: " + $10->get_fully_scoped_name(), @10);
  703. } else {
  704. make_property->_del_function = deleter->as_function_group();
  705. }
  706. }
  707. current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
  708. }
  709. }
  710. | KW_MAKE_MAP_KEYS_SEQ '(' name ',' IDENTIFIER ',' IDENTIFIER ')' ';'
  711. {
  712. CPPDeclaration *length_getter = $5->find_symbol(current_scope, global_scope, current_lexer);
  713. if (length_getter == nullptr || length_getter->get_subtype() != CPPDeclaration::ST_function_group) {
  714. yyerror("reference to non-existent or invalid length method: " + $5->get_fully_scoped_name(), @5);
  715. length_getter = nullptr;
  716. }
  717. CPPDeclaration *getter = $7->find_symbol(current_scope, global_scope, current_lexer);
  718. if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
  719. yyerror("reference to non-existent or invalid getter: " + $7->get_fully_scoped_name(), @7);
  720. getter = nullptr;
  721. }
  722. if (getter != nullptr && length_getter != nullptr) {
  723. CPPMakeProperty *make_property = nullptr;
  724. for (size_t i = 0; i < current_scope->_declarations.size(); ++i) {
  725. make_property = current_scope->_declarations[i]->as_make_property();
  726. if (make_property != nullptr) {
  727. if (make_property->get_fully_scoped_name() == $3->get_fully_scoped_name()) {
  728. break;
  729. } else {
  730. make_property = nullptr;
  731. }
  732. }
  733. }
  734. if (make_property != nullptr) {
  735. make_property->_get_key_function = getter->as_function_group();
  736. make_property->_length_function = length_getter->as_function_group();
  737. } else {
  738. yyerror("reference to non-existent MAKE_MAP_PROPERTY: " + $3->get_fully_scoped_name(), @3);
  739. }
  740. }
  741. }
  742. | KW_MAKE_PROPERTY2 '(' name ',' IDENTIFIER ',' IDENTIFIER ')' ';'
  743. {
  744. CPPDeclaration *getter = $7->find_symbol(current_scope, global_scope, current_lexer);
  745. if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
  746. yyerror("Reference to non-existent or invalid getter: " + $7->get_fully_scoped_name(), @7);
  747. } else {
  748. CPPMakeProperty *make_property;
  749. make_property = new CPPMakeProperty($3, CPPMakeProperty::T_normal,
  750. current_scope, @1.file);
  751. make_property->_get_function = getter->as_function_group();
  752. CPPDeclaration *hasser = $5->find_symbol(current_scope, global_scope, current_lexer);
  753. if (hasser == nullptr || hasser->get_subtype() != CPPDeclaration::ST_function_group) {
  754. yyerror("reference to non-existent or invalid has/find method: " + $5->get_fully_scoped_name(), @5);
  755. } else {
  756. make_property->_has_function = hasser->as_function_group();
  757. }
  758. current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
  759. }
  760. }
  761. | KW_MAKE_PROPERTY2 '(' name ',' IDENTIFIER ',' IDENTIFIER ',' IDENTIFIER ',' IDENTIFIER ')' ';'
  762. {
  763. CPPDeclaration *getter = $7->find_symbol(current_scope, global_scope, current_lexer);
  764. if (getter == nullptr || getter->get_subtype() != CPPDeclaration::ST_function_group) {
  765. yyerror("Reference to non-existent or invalid getter: " + $7->get_fully_scoped_name(), @7);
  766. } else {
  767. CPPMakeProperty *make_property;
  768. make_property = new CPPMakeProperty($3, CPPMakeProperty::T_normal,
  769. current_scope, @1.file);
  770. make_property->_get_function = getter->as_function_group();
  771. CPPDeclaration *hasser = $5->find_symbol(current_scope, global_scope, current_lexer);
  772. if (hasser == nullptr || hasser->get_subtype() != CPPDeclaration::ST_function_group) {
  773. yyerror("reference to non-existent or invalid has/find method: " + $5->get_fully_scoped_name(), @5);
  774. } else {
  775. make_property->_has_function = hasser->as_function_group();
  776. }
  777. CPPDeclaration *setter = $9->find_symbol(current_scope, global_scope, current_lexer);
  778. if (setter == nullptr || setter->get_subtype() != CPPDeclaration::ST_function_group) {
  779. yyerror("reference to non-existent or invalid setter: " + $9->get_fully_scoped_name(), @9);
  780. } else {
  781. make_property->_set_function = setter->as_function_group();
  782. }
  783. CPPDeclaration *clearer = $11->find_symbol(current_scope, global_scope, current_lexer);
  784. if (clearer == nullptr || clearer->get_subtype() != CPPDeclaration::ST_function_group) {
  785. yyerror("reference to non-existent or invalid clear method: " + $11->get_fully_scoped_name(), @11);
  786. } else {
  787. make_property->_clear_function = clearer->as_function_group();
  788. }
  789. current_scope->add_declaration(make_property, global_scope, current_lexer, @1);
  790. }
  791. }
  792. | KW_MAKE_SEQ '(' name ',' IDENTIFIER ',' IDENTIFIER ')' ';'
  793. {
  794. CPPDeclaration *length_getter = $5->find_symbol(current_scope, global_scope, current_lexer);
  795. if (length_getter == nullptr || length_getter->get_subtype() != CPPDeclaration::ST_function_group) {
  796. yyerror("reference to non-existent or invalid length method: " + $5->get_fully_scoped_name(), @5);
  797. length_getter = nullptr;
  798. }
  799. CPPDeclaration *element_getter = $7->find_symbol(current_scope, global_scope, current_lexer);
  800. if (element_getter == nullptr || element_getter->get_subtype() != CPPDeclaration::ST_function_group) {
  801. yyerror("reference to non-existent or invalid element method: " + $7->get_fully_scoped_name(), @5);
  802. element_getter = nullptr;
  803. }
  804. if (length_getter != nullptr && element_getter != nullptr) {
  805. CPPMakeSeq *make_seq = new CPPMakeSeq($3,
  806. length_getter->as_function_group(),
  807. element_getter->as_function_group(),
  808. current_scope, @1.file);
  809. current_scope->add_declaration(make_seq, global_scope, current_lexer, @1);
  810. }
  811. }
  812. | KW_STATIC_ASSERT '(' const_expr ',' string_literal ')' ';'
  813. {
  814. CPPExpression::Result result = $3->evaluate();
  815. if (result._type == CPPExpression::RT_error) {
  816. yywarning("static_assert requires a constant expression", @3);
  817. } else if (!result.as_boolean()) {
  818. stringstream str;
  819. str << *$5;
  820. yywarning("static_assert failed: " + str.str(), @3);
  821. }
  822. }
  823. | KW_STATIC_ASSERT '(' const_expr ')' ';'
  824. {
  825. // This alternative version of static_assert was introduced in C++17.
  826. CPPExpression::Result result = $3->evaluate();
  827. if (result._type == CPPExpression::RT_error) {
  828. yywarning("static_assert requires a constant expression", @3);
  829. } else if (!result.as_boolean()) {
  830. yywarning("static_assert failed", @3);
  831. }
  832. }
  833. ;
  834. friend_declaration:
  835. KW_FRIEND
  836. {
  837. CPPScope *new_scope = new CPPScope(current_scope, CPPNameComponent("temp"),
  838. V_public);
  839. push_scope(new_scope);
  840. }
  841. declaration
  842. {
  843. delete current_scope;
  844. pop_scope();
  845. }
  846. ;
  847. storage_class:
  848. empty
  849. {
  850. $$ = 0;
  851. }
  852. | KW_CONST storage_class
  853. {
  854. // This isn't really a storage class, but it helps with parsing.
  855. $$ = $2 | (int)CPPInstance::SC_const;
  856. }
  857. | KW_EXTERN storage_class
  858. {
  859. $$ = $2 | (int)CPPInstance::SC_extern;
  860. }
  861. | KW_EXTERN SIMPLE_STRING storage_class
  862. {
  863. $$ = $3 | (int)CPPInstance::SC_extern;
  864. if ($2 == "C") {
  865. $$ |= (int)CPPInstance::SC_c_binding;
  866. } else if ($2 == "C++") {
  867. $$ &= ~(int)CPPInstance::SC_c_binding;
  868. } else {
  869. yywarning("Ignoring unknown linkage type \"" + $2 + "\"", @2);
  870. }
  871. }
  872. | KW_STATIC storage_class
  873. {
  874. $$ = $2 | (int)CPPInstance::SC_static;
  875. }
  876. | KW_INLINE storage_class
  877. {
  878. $$ = $2 | (int)CPPInstance::SC_inline;
  879. }
  880. | KW_VIRTUAL storage_class
  881. {
  882. $$ = $2 | (int)CPPInstance::SC_virtual;
  883. }
  884. | KW_EXPLICIT storage_class
  885. {
  886. $$ = $2 | (int)CPPInstance::SC_explicit;
  887. }
  888. | KW_REGISTER storage_class
  889. {
  890. $$ = $2 | (int)CPPInstance::SC_register;
  891. }
  892. | KW_VOLATILE storage_class
  893. {
  894. $$ = $2 | (int)CPPInstance::SC_volatile;
  895. }
  896. | KW_MUTABLE storage_class
  897. {
  898. $$ = $2 | (int)CPPInstance::SC_mutable;
  899. }
  900. | KW_CONSTEXPR storage_class
  901. {
  902. $$ = $2 | (int)CPPInstance::SC_constexpr;
  903. }
  904. | KW_BLOCKING storage_class
  905. {
  906. $$ = $2 | (int)CPPInstance::SC_blocking;
  907. }
  908. | KW_EXTENSION storage_class
  909. {
  910. $$ = $2 | (int)CPPInstance::SC_extension;
  911. }
  912. | KW_THREAD_LOCAL storage_class
  913. {
  914. $$ = $2 | (int)CPPInstance::SC_thread_local;
  915. }
  916. | ATTR_LEFT attribute_specifiers ATTR_RIGHT storage_class
  917. {
  918. // Ignore attribute specifiers for now.
  919. $$ = $4;
  920. }
  921. | KW_ALIGNAS '(' const_expr ')' storage_class
  922. {
  923. $$ = $5;
  924. }
  925. | KW_ALIGNAS '(' type_decl ')' storage_class
  926. {
  927. $$ = $5;
  928. }
  929. ;
  930. attribute_specifiers:
  931. attribute_specifier
  932. | attribute_specifier ',' attribute_specifiers
  933. ;
  934. attribute_specifier:
  935. name
  936. | name '(' formal_parameter_list ')'
  937. | KW_USING name ':' attribute_specifier
  938. ;
  939. type_like_declaration:
  940. storage_class var_type_decl
  941. {
  942. // We don't need to push/pop type, because we can't nest
  943. // type_like_declaration.
  944. if ($2->as_type_declaration()) {
  945. current_type = $2->as_type_declaration()->_type;
  946. } else {
  947. current_type = $2->as_type();
  948. }
  949. push_storage_class($1);
  950. }
  951. multiple_instance_identifiers
  952. {
  953. pop_storage_class();
  954. }
  955. | storage_class type_decl ';'
  956. {
  957. // We don't really care about the storage class here. In fact, it's
  958. // not actually legal to define a class or struct using a particular
  959. // storage class, but we require it just to help yacc out in its
  960. // parsing.
  961. current_scope->add_declaration($2, global_scope, current_lexer, @2);
  962. }
  963. | storage_class constructor_prototype
  964. {
  965. if ($2 != nullptr) {
  966. // Push the scope so that the initializers can make use of things defined
  967. // in the class body.
  968. push_scope($2->get_scope(current_scope, global_scope));
  969. $2->_storage_class |= (current_storage_class | $1);
  970. }
  971. }
  972. maybe_initialize_or_constructor_body
  973. {
  974. if ($2 != nullptr) {
  975. pop_scope();
  976. current_scope->add_declaration($2, global_scope, current_lexer, @2);
  977. $2->set_initializer($4);
  978. }
  979. }
  980. | storage_class function_prototype maybe_initialize_or_function_body
  981. {
  982. if ($2 != nullptr) {
  983. $2->_storage_class |= (current_storage_class | $1);
  984. current_scope->add_declaration($2, global_scope, current_lexer, @2);
  985. $2->set_initializer($3);
  986. }
  987. }
  988. | using_declaration
  989. /* We don't need to include a rule for variables that point to
  990. functions, because we get those from the function_prototype
  991. definition. */
  992. ;
  993. multiple_instance_identifiers:
  994. instance_identifier_and_maybe_trailing_return_type maybe_initialize_or_function_body
  995. {
  996. if (current_storage_class & CPPInstance::SC_const) {
  997. $1->add_modifier(IIT_const);
  998. }
  999. CPPInstance *inst = new CPPInstance(current_type, $1,
  1000. current_storage_class,
  1001. @1.file);
  1002. inst->set_initializer($2);
  1003. current_scope->add_declaration(inst, global_scope, current_lexer, @1);
  1004. }
  1005. | instance_identifier_and_maybe_trailing_return_type maybe_initialize ',' multiple_instance_identifiers
  1006. {
  1007. if (current_storage_class & CPPInstance::SC_const) {
  1008. $1->add_modifier(IIT_const);
  1009. }
  1010. CPPInstance *inst = new CPPInstance(current_type, $1,
  1011. current_storage_class,
  1012. @1.file);
  1013. inst->set_initializer($2);
  1014. current_scope->add_declaration(inst, global_scope, current_lexer, @1);
  1015. }
  1016. ;
  1017. typedef_declaration:
  1018. storage_class var_type_decl
  1019. {
  1020. // We don't need to push/pop type, because we can't nest
  1021. // multiple_var_declarations.
  1022. if ($2->as_type_declaration()) {
  1023. current_type = $2->as_type_declaration()->_type;
  1024. } else {
  1025. current_type = $2->as_type();
  1026. }
  1027. push_storage_class($1);
  1028. }
  1029. typedef_instance_identifiers
  1030. {
  1031. pop_storage_class();
  1032. }
  1033. | storage_class function_prototype maybe_initialize_or_function_body
  1034. {
  1035. if ($2 != nullptr) {
  1036. CPPInstance *inst = $2->as_instance();
  1037. if (inst != nullptr) {
  1038. inst->_storage_class |= (current_storage_class | $1);
  1039. current_scope->add_declaration(inst, global_scope, current_lexer, @2);
  1040. CPPTypedefType *typedef_type = new CPPTypedefType(inst->_type, inst->_ident, current_scope);
  1041. current_scope->add_declaration(CPPType::new_type(typedef_type), global_scope, current_lexer, @2);
  1042. }
  1043. }
  1044. }
  1045. ;
  1046. typedef_instance_identifiers:
  1047. instance_identifier_and_maybe_trailing_return_type maybe_initialize_or_function_body
  1048. {
  1049. if (current_storage_class & CPPInstance::SC_const) {
  1050. $1->add_modifier(IIT_const);
  1051. }
  1052. CPPType *target_type = current_type;
  1053. CPPTypedefType *typedef_type = new CPPTypedefType(target_type, $1, current_scope, @1.file);
  1054. current_scope->add_declaration(CPPType::new_type(typedef_type), global_scope, current_lexer, @1);
  1055. }
  1056. | instance_identifier_and_maybe_trailing_return_type maybe_initialize ',' typedef_instance_identifiers
  1057. {
  1058. if (current_storage_class & CPPInstance::SC_const) {
  1059. $1->add_modifier(IIT_const);
  1060. }
  1061. CPPType *target_type = current_type;
  1062. CPPTypedefType *typedef_type = new CPPTypedefType(target_type, $1, current_scope, @1.file);
  1063. current_scope->add_declaration(CPPType::new_type(typedef_type), global_scope, current_lexer, @1);
  1064. }
  1065. ;
  1066. constructor_prototype:
  1067. /* Functions with implicit return types, and constructors */
  1068. IDENTIFIER '('
  1069. {
  1070. // Create a scope for this function.
  1071. CPPScope *scope = new CPPScope($1->get_scope(current_scope, global_scope),
  1072. $1->_names.back(), V_private);
  1073. // It still needs to be able to pick up any template arguments, if this is
  1074. // a definition for a method template. Add a fake "using" declaration to
  1075. // accomplish this.
  1076. scope->_using.insert(current_scope);
  1077. push_scope(scope);
  1078. }
  1079. function_parameter_list ')' function_post
  1080. {
  1081. CPPScope *scope = $1->get_scope(current_scope, global_scope);
  1082. CPPType *type;
  1083. std::string simple_name = $1->get_simple_name();
  1084. if (!simple_name.empty() && simple_name[0] == '~') {
  1085. // A destructor has no return type.
  1086. type = new CPPSimpleType(CPPSimpleType::T_void);
  1087. } else if (scope != nullptr && simple_name == scope->get_simple_name()) {
  1088. // Neither does a constructor.
  1089. type = new CPPSimpleType(CPPSimpleType::T_void);
  1090. } else {
  1091. // This isn't a constructor, so it has an implicit return type of
  1092. // int.
  1093. yywarning("function has no return type, assuming int", @1);
  1094. type = new CPPSimpleType(CPPSimpleType::T_int);
  1095. }
  1096. pop_scope();
  1097. CPPInstanceIdentifier *ii = new CPPInstanceIdentifier($1);
  1098. ii->add_func_modifier($4, $6);
  1099. $$ = new CPPInstance(type, ii, 0, @1.file);
  1100. }
  1101. /* This is a hack to support functions with the identifier enveloped by a
  1102. pair of parentheses. */
  1103. | TYPENAME_IDENTIFIER '(' IDENTIFIER ')' '('
  1104. {
  1105. // Create a scope for this function.
  1106. CPPScope *scope = new CPPScope($3->get_scope(current_scope, global_scope),
  1107. $3->_names.back(), V_private);
  1108. // It still needs to be able to pick up any template arguments, if this is
  1109. // a definition for a method template. Add a fake "using" declaration to
  1110. // accomplish this.
  1111. scope->_using.insert(current_scope);
  1112. push_scope(scope);
  1113. }
  1114. function_parameter_list ')' function_post
  1115. {
  1116. pop_scope();
  1117. CPPType *type = $1->find_type(current_scope, global_scope, false, current_lexer);
  1118. if (type == nullptr) {
  1119. yyerror(string("internal error resolving type ") + $1->get_fully_scoped_name(), @1);
  1120. }
  1121. assert(type != nullptr);
  1122. CPPInstanceIdentifier *ii = new CPPInstanceIdentifier($3);
  1123. ii->add_func_modifier($7, $9);
  1124. $$ = new CPPInstance(type, ii, 0, @1.file);
  1125. }
  1126. | TYPENAME_IDENTIFIER '('
  1127. {
  1128. // Create a scope for this function.
  1129. CPPScope *scope = new CPPScope($1->get_scope(current_scope, global_scope),
  1130. $1->_names.back(), V_private);
  1131. // It still needs to be able to pick up any template arguments, if this is
  1132. // a definition for a method template. Add a fake "using" declaration to
  1133. // accomplish this.
  1134. scope->_using.insert(current_scope);
  1135. push_scope(scope);
  1136. }
  1137. function_parameter_list ')' function_post
  1138. {
  1139. pop_scope();
  1140. CPPType *type;
  1141. if ($1->get_simple_name() == current_scope->get_simple_name()) {
  1142. // This is a constructor, and has no return.
  1143. type = new CPPSimpleType(CPPSimpleType::T_void);
  1144. } else {
  1145. // This isn't a constructor, so it has an implicit return type of
  1146. // int.
  1147. type = new CPPSimpleType(CPPSimpleType::T_int);
  1148. }
  1149. CPPInstanceIdentifier *ii = new CPPInstanceIdentifier($1);
  1150. ii->add_func_modifier($4, $6);
  1151. $$ = new CPPInstance(type, ii, 0, @1.file);
  1152. }
  1153. ;
  1154. function_prototype:
  1155. /* Destructors */
  1156. '~' name '('
  1157. {
  1158. push_scope($2->get_scope(current_scope, global_scope));
  1159. }
  1160. function_parameter_list ')' function_post
  1161. {
  1162. pop_scope();
  1163. if ($2->is_scoped()) {
  1164. yyerror("Invalid destructor name: ~" + $2->get_fully_scoped_name(), @2);
  1165. } else {
  1166. CPPIdentifier *ident =
  1167. new CPPIdentifier("~" + $2->get_simple_name(), @2);
  1168. delete $2;
  1169. CPPType *type;
  1170. type = new CPPSimpleType(CPPSimpleType::T_void);
  1171. CPPInstanceIdentifier *ii = new CPPInstanceIdentifier(ident);
  1172. ii->add_func_modifier($5, $7);
  1173. $$ = new CPPInstance(type, ii, 0, @2.file);
  1174. }
  1175. }
  1176. /* This is a special case: a function pointer declaration that looks
  1177. at first a lot like a constructor declaration. This is provided to
  1178. help yacc sort out the differences. It isn't an ideal solution,
  1179. because it doesn't catch a lot of subtle variants on this form--but
  1180. this will get at least the 99% most common uses. */
  1181. | TYPENAME_IDENTIFIER '(' '*' instance_identifier ')' '('
  1182. {
  1183. push_scope($4->get_scope(current_scope, global_scope));
  1184. }
  1185. function_parameter_list ')' function_post maybe_trailing_return_type
  1186. {
  1187. pop_scope();
  1188. CPPType *type = $1->find_type(current_scope, global_scope, false, current_lexer);
  1189. if (type == nullptr) {
  1190. yyerror(string("internal error resolving type ") + $1->get_fully_scoped_name(), @1);
  1191. }
  1192. assert(type != nullptr);
  1193. CPPInstanceIdentifier *ii = $4;
  1194. ii->add_modifier(IIT_pointer);
  1195. ii->add_func_modifier($8, $10);
  1196. $$ = new CPPInstance(type, ii, 0, @1.file);
  1197. }
  1198. | TYPENAME_IDENTIFIER '(' SCOPING '*' instance_identifier ')' '('
  1199. {
  1200. push_scope($5->get_scope(current_scope, global_scope));
  1201. }
  1202. function_parameter_list ')' function_post maybe_trailing_return_type
  1203. {
  1204. pop_scope();
  1205. CPPType *type = $1->find_type(current_scope, global_scope, false, current_lexer);
  1206. if (type == nullptr) {
  1207. yyerror(string("internal error resolving type ") + $1->get_fully_scoped_name(), @1);
  1208. }
  1209. assert(type != nullptr);
  1210. CPPInstanceIdentifier *ii = $5;
  1211. ii->add_scoped_pointer_modifier($3);
  1212. ii->add_func_modifier($9, $11);
  1213. $$ = new CPPInstance(type, ii, 0, @1.file);
  1214. }
  1215. /* Typecast operators */
  1216. | KW_OPERATOR type not_paren_formal_parameter_identifier '('
  1217. {
  1218. if ($1 != nullptr) {
  1219. push_scope($1->get_scope(current_scope, global_scope));
  1220. }
  1221. }
  1222. function_parameter_list ')' function_post
  1223. {
  1224. if ($1 != nullptr) {
  1225. pop_scope();
  1226. }
  1227. // We use formal_parameter_identifier, because that can match a type
  1228. // name with or without an identifier, but especially without, which
  1229. // is what follows the keyword "operator" in a typecast function.
  1230. // As an added bonus, the type of the formal_parameter will be the
  1231. // typecast type, i.e. the return type of the typecast function.
  1232. // We give typecast operators the name "operator typecast <name>",
  1233. // where <name> is a simple name of the type to be typecast. Use
  1234. // the method's return type to determine the full type description.
  1235. string name = "operator typecast " + $2->get_simple_name();
  1236. CPPIdentifier *ident = $1;
  1237. if (ident == nullptr) {
  1238. ident = new CPPIdentifier(name, @2);
  1239. } else {
  1240. ident->add_name(name);
  1241. }
  1242. $$ = CPPInstance::make_typecast_function
  1243. (new CPPInstance($2, $3, 0, @3.file), ident, $6, $8);
  1244. }
  1245. | KW_OPERATOR KW_CONST type not_paren_formal_parameter_identifier '('
  1246. {
  1247. if ($1 != nullptr) {
  1248. push_scope($1->get_scope(current_scope, global_scope));
  1249. }
  1250. }
  1251. function_parameter_list ')' function_post
  1252. {
  1253. if ($1 != nullptr) {
  1254. pop_scope();
  1255. }
  1256. CPPIdentifier *ident = $1;
  1257. if (ident == nullptr) {
  1258. ident = new CPPIdentifier("operator typecast", @4);
  1259. } else {
  1260. ident->add_name("operator typecast");
  1261. }
  1262. $4->add_modifier(IIT_const);
  1263. $$ = CPPInstance::make_typecast_function
  1264. (new CPPInstance($3, $4, 0, @4.file), ident, $7, $9);
  1265. }
  1266. /* Not actually a function prototype, but maybe a template
  1267. instantiation. Just included here (instead of somewhere else) to
  1268. avoid shift/reduce conflicts. */
  1269. | IDENTIFIER
  1270. {
  1271. CPPDeclaration *decl =
  1272. $1->find_symbol(current_scope, global_scope, current_lexer);
  1273. if (decl != nullptr) {
  1274. $$ = decl->as_instance();
  1275. } else {
  1276. $$ = nullptr;
  1277. }
  1278. }
  1279. ;
  1280. function_post:
  1281. empty
  1282. {
  1283. $$ = 0;
  1284. }
  1285. | function_post KW_CONST
  1286. {
  1287. $$ = $1 | (int)CPPFunctionType::F_const_method;
  1288. }
  1289. | function_post KW_VOLATILE
  1290. {
  1291. $$ = $1 | (int)CPPFunctionType::F_volatile_method;
  1292. }
  1293. | function_post KW_NOEXCEPT
  1294. {
  1295. $$ = $1 | (int)CPPFunctionType::F_noexcept;
  1296. }
  1297. /* | function_post KW_NOEXCEPT '(' const_expr ')'
  1298. {
  1299. CPPExpression::Result result = $4->evaluate();
  1300. if (result._type == CPPExpression::RT_error) {
  1301. yywarning("noexcept requires a constant expression", @4);
  1302. } else if (result.as_boolean()) {
  1303. $$ = $1 | (int)CPPFunctionType::F_noexcept;
  1304. }
  1305. }*/
  1306. | function_post KW_FINAL
  1307. {
  1308. $$ = $1 | (int)CPPFunctionType::F_final;
  1309. }
  1310. | function_post KW_OVERRIDE
  1311. {
  1312. $$ = $1 | (int)CPPFunctionType::F_override;
  1313. }
  1314. | function_post '&'
  1315. {
  1316. $$ = $1 | (int)CPPFunctionType::F_lvalue_method;
  1317. }
  1318. | function_post ANDAND
  1319. {
  1320. $$ = $1 | (int)CPPFunctionType::F_rvalue_method;
  1321. }
  1322. | function_post KW_MUTABLE
  1323. {
  1324. // Used for lambdas, currently ignored.
  1325. $$ = $1;
  1326. }
  1327. | function_post KW_CONSTEXPR
  1328. {
  1329. // Used for lambdas in C++17, currently ignored.
  1330. $$ = $1;
  1331. }
  1332. | function_post KW_THROW '(' ')'
  1333. {
  1334. $$ = $1;
  1335. }
  1336. | function_post KW_THROW '(' name ')'
  1337. {
  1338. $$ = $1;
  1339. }
  1340. | function_post KW_THROW '(' name ELLIPSIS ')'
  1341. {
  1342. $$ = $1;
  1343. }
  1344. | function_post ATTR_LEFT attribute_specifiers ATTR_RIGHT
  1345. {
  1346. $$ = $1;
  1347. }
  1348. ;
  1349. function_operator:
  1350. '!'
  1351. {
  1352. $$ = "!";
  1353. }
  1354. | '~'
  1355. {
  1356. $$ = "~";
  1357. }
  1358. | '*'
  1359. {
  1360. $$ = "*";
  1361. }
  1362. | '/'
  1363. {
  1364. $$ = "/";
  1365. }
  1366. | '%'
  1367. {
  1368. $$ = "%";
  1369. }
  1370. | '+'
  1371. {
  1372. $$ = "+";
  1373. }
  1374. | '-'
  1375. {
  1376. $$ = "-";
  1377. }
  1378. | '|'
  1379. {
  1380. $$ = "|";
  1381. }
  1382. | '&'
  1383. {
  1384. $$ = "&";
  1385. }
  1386. | '^'
  1387. {
  1388. $$ = "^";
  1389. }
  1390. | OROR
  1391. {
  1392. $$ = "||";
  1393. }
  1394. | ANDAND
  1395. {
  1396. $$ = "&&";
  1397. }
  1398. | EQCOMPARE
  1399. {
  1400. $$ = "==";
  1401. }
  1402. | NECOMPARE
  1403. {
  1404. $$ = "!=";
  1405. }
  1406. | LECOMPARE
  1407. {
  1408. $$ = "<=";
  1409. }
  1410. | GECOMPARE
  1411. {
  1412. $$ = ">=";
  1413. }
  1414. | '<'
  1415. {
  1416. $$ = "<";
  1417. }
  1418. | '>'
  1419. {
  1420. $$ = ">";
  1421. }
  1422. | LSHIFT
  1423. {
  1424. $$ = "<<";
  1425. }
  1426. | RSHIFT
  1427. {
  1428. $$ = ">>";
  1429. }
  1430. | '='
  1431. {
  1432. $$ = "=";
  1433. }
  1434. | ','
  1435. {
  1436. $$ = ",";
  1437. }
  1438. | PLUSPLUS
  1439. {
  1440. $$ = "++";
  1441. }
  1442. | MINUSMINUS
  1443. {
  1444. $$ = "--";
  1445. }
  1446. | TIMESEQUAL
  1447. {
  1448. $$ = "*=";
  1449. }
  1450. | DIVIDEEQUAL
  1451. {
  1452. $$ = "/=";
  1453. }
  1454. | MODEQUAL
  1455. {
  1456. $$ = "%=";
  1457. }
  1458. | PLUSEQUAL
  1459. {
  1460. $$ = "+=";
  1461. }
  1462. | MINUSEQUAL
  1463. {
  1464. $$ = "-=";
  1465. }
  1466. | OREQUAL
  1467. {
  1468. $$ = "|=";
  1469. }
  1470. | ANDEQUAL
  1471. {
  1472. $$ = "&=";
  1473. }
  1474. | XOREQUAL
  1475. {
  1476. $$ = "^=";
  1477. }
  1478. | LSHIFTEQUAL
  1479. {
  1480. $$ = "<<=";
  1481. }
  1482. | RSHIFTEQUAL
  1483. {
  1484. $$ = ">>=";
  1485. }
  1486. | POINTSAT
  1487. {
  1488. $$ = "->";
  1489. }
  1490. | '[' ']'
  1491. {
  1492. $$ = "[]";
  1493. }
  1494. | '(' ')'
  1495. {
  1496. $$ = "()";
  1497. }
  1498. | KW_NEW
  1499. {
  1500. $$ = "new";
  1501. }
  1502. | KW_DELETE
  1503. {
  1504. $$ = "delete";
  1505. }
  1506. ;
  1507. more_template_declaration:
  1508. type_like_declaration
  1509. | template_declaration
  1510. | friend_declaration
  1511. ;
  1512. template_declaration:
  1513. KW_EXTERN template_declaration
  1514. | KW_TEMPLATE
  1515. {
  1516. push_scope(new CPPTemplateScope(current_scope));
  1517. }
  1518. '<' template_formal_parameters '>' more_template_declaration
  1519. {
  1520. pop_scope();
  1521. }
  1522. | KW_TEMPLATE type_like_declaration
  1523. | KW_TEMPLATE friend_declaration
  1524. ;
  1525. template_formal_parameters:
  1526. empty
  1527. | template_nonempty_formal_parameters
  1528. ;
  1529. template_nonempty_formal_parameters:
  1530. template_formal_parameter
  1531. {
  1532. CPPTemplateScope *ts = current_scope->as_template_scope();
  1533. assert(ts != nullptr);
  1534. ts->add_template_parameter($1);
  1535. }
  1536. | template_nonempty_formal_parameters ',' template_formal_parameter
  1537. {
  1538. CPPTemplateScope *ts = current_scope->as_template_scope();
  1539. assert(ts != nullptr);
  1540. ts->add_template_parameter($3);
  1541. }
  1542. ;
  1543. typename_keyword:
  1544. KW_CLASS
  1545. | KW_TYPENAME
  1546. ;
  1547. template_formal_parameter:
  1548. typename_keyword
  1549. {
  1550. $$ = CPPType::new_type(new CPPClassTemplateParameter(nullptr));
  1551. }
  1552. | typename_keyword name
  1553. {
  1554. $$ = CPPType::new_type(new CPPClassTemplateParameter($2));
  1555. }
  1556. | typename_keyword name '=' full_type
  1557. {
  1558. $$ = CPPType::new_type(new CPPClassTemplateParameter($2, $4));
  1559. }
  1560. | typename_keyword ELLIPSIS
  1561. {
  1562. CPPClassTemplateParameter *ctp = new CPPClassTemplateParameter(nullptr);
  1563. ctp->_packed = true;
  1564. $$ = CPPType::new_type(ctp);
  1565. }
  1566. | typename_keyword ELLIPSIS name
  1567. {
  1568. CPPClassTemplateParameter *ctp = new CPPClassTemplateParameter($3);
  1569. ctp->_packed = true;
  1570. $$ = CPPType::new_type(ctp);
  1571. }
  1572. | template_formal_parameter_type formal_parameter_identifier template_parameter_maybe_initialize
  1573. {
  1574. CPPInstance *inst = new CPPInstance($1, $2, 0, @2.file);
  1575. inst->set_initializer($3);
  1576. $$ = inst;
  1577. }
  1578. | KW_CONST template_formal_parameter_type formal_parameter_identifier template_parameter_maybe_initialize
  1579. {
  1580. $3->add_modifier(IIT_const);
  1581. CPPInstance *inst = new CPPInstance($2, $3, 0, @3.file);
  1582. inst->set_initializer($4);
  1583. $$ = inst;
  1584. }
  1585. | template_formal_parameter_type parameter_pack_identifier
  1586. {
  1587. CPPInstance *inst = new CPPInstance($1, $2, 0, @2.file);
  1588. $$ = inst;
  1589. }
  1590. | KW_CONST template_formal_parameter_type parameter_pack_identifier
  1591. {
  1592. $3->add_modifier(IIT_const);
  1593. CPPInstance *inst = new CPPInstance($2, $3, 0, @3.file);
  1594. $$ = inst;
  1595. }
  1596. ;
  1597. template_formal_parameter_type:
  1598. simple_type
  1599. {
  1600. $$ = CPPType::new_type($1);
  1601. }
  1602. | IDENTIFIER
  1603. {
  1604. yywarning("Not a type: " + $1->get_fully_scoped_name(), @1);
  1605. $$ = CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_unknown));
  1606. }
  1607. | TYPENAME_IDENTIFIER
  1608. {
  1609. $$ = $1->find_type(current_scope, global_scope, false, current_lexer);
  1610. if ($$ == nullptr) {
  1611. yyerror(string("internal error resolving type ") + $1->get_fully_scoped_name(), @1);
  1612. }
  1613. assert($$ != nullptr);
  1614. }
  1615. | TYPEPACK_IDENTIFIER
  1616. {
  1617. $$ = $1->find_type(current_scope, global_scope, false, current_lexer);
  1618. if ($$ == nullptr) {
  1619. yyerror(string("internal error resolving type ") + $1->get_fully_scoped_name(), @1);
  1620. }
  1621. assert($$ != nullptr);
  1622. }
  1623. ;
  1624. instance_identifier:
  1625. name_no_final
  1626. {
  1627. $$ = new CPPInstanceIdentifier($1);
  1628. }
  1629. | KW_OPERATOR function_operator
  1630. {
  1631. // For an operator function. We implement this simply by building a
  1632. // ficticious name for the function; in other respects it's just
  1633. // like a regular function.
  1634. CPPIdentifier *ident = $1;
  1635. if (ident == nullptr) {
  1636. ident = new CPPIdentifier("operator "+$2, @2);
  1637. } else {
  1638. ident->_names.push_back("operator "+$2);
  1639. }
  1640. $$ = new CPPInstanceIdentifier(ident);
  1641. }
  1642. | KW_OPERATOR SIMPLE_STRING IDENTIFIER
  1643. {
  1644. // A C++11 literal operator.
  1645. if (!$2.empty()) {
  1646. yyerror("expected empty string", @2);
  1647. }
  1648. CPPIdentifier *ident = $1;
  1649. if (ident == nullptr) {
  1650. ident = new CPPIdentifier("operator \"\" "+$3->get_simple_name(), @3);
  1651. } else {
  1652. ident->_names.push_back("operator \"\" "+$3->get_simple_name());
  1653. }
  1654. $$ = new CPPInstanceIdentifier(ident);
  1655. }
  1656. | KW_CONST instance_identifier %prec UNARY
  1657. {
  1658. $$ = $2;
  1659. $$->add_modifier(IIT_const);
  1660. }
  1661. | KW_VOLATILE instance_identifier %prec UNARY
  1662. {
  1663. $$ = $2;
  1664. $$->add_modifier(IIT_volatile);
  1665. }
  1666. | '*' instance_identifier %prec UNARY
  1667. {
  1668. $$ = $2;
  1669. $$->add_modifier(IIT_pointer);
  1670. }
  1671. | '&' instance_identifier %prec UNARY
  1672. {
  1673. $$ = $2;
  1674. $$->add_modifier(IIT_reference);
  1675. }
  1676. | ANDAND instance_identifier %prec UNARY
  1677. {
  1678. $$ = $2;
  1679. $$->add_modifier(IIT_rvalue_reference);
  1680. }
  1681. | SCOPING '*' instance_identifier %prec UNARY
  1682. {
  1683. $$ = $3;
  1684. $$->add_scoped_pointer_modifier($1);
  1685. }
  1686. | instance_identifier '[' optional_const_expr ']'
  1687. {
  1688. $$ = $1;
  1689. $$->add_array_modifier($3);
  1690. }
  1691. | '(' instance_identifier ')'
  1692. {
  1693. $$ = $2;
  1694. $$->add_modifier(IIT_paren);
  1695. }
  1696. | instance_identifier '('
  1697. {
  1698. // Create a scope for this function (in case it is a function)
  1699. CPPScope *scope = new CPPScope($1->get_scope(current_scope, global_scope),
  1700. CPPNameComponent(""), V_private);
  1701. // It still needs to be able to pick up any template arguments, if this is
  1702. // a definition for a method template. Add a fake "using" declaration to
  1703. // accomplish this.
  1704. scope->_using.insert(current_scope);
  1705. push_scope(scope);
  1706. }
  1707. formal_parameter_list ')' function_post
  1708. {
  1709. pop_scope();
  1710. $$ = $1;
  1711. if ($4->is_parameter_expr() && $6 == 0) {
  1712. // Oops, this must have been an instance declaration with a
  1713. // parameter list, not a function prototype.
  1714. $$->add_initializer_modifier($4);
  1715. } else {
  1716. // This was (probably) a function prototype.
  1717. $$->add_func_modifier($4, $6);
  1718. }
  1719. }
  1720. ;
  1721. instance_identifier_and_maybe_trailing_return_type:
  1722. instance_identifier maybe_trailing_return_type
  1723. {
  1724. // This is handled a bit awkwardly right now. Ideally it'd be wrapped
  1725. // up in the instance_identifier rule, but then more needs to happen in
  1726. // order to avoid shift/reduce conflicts.
  1727. if ($2 != nullptr) {
  1728. $1->add_trailing_return_type($2);
  1729. }
  1730. $$ = $1;
  1731. }
  1732. | instance_identifier ':' const_expr
  1733. {
  1734. // Bitfield definition.
  1735. $1->_bit_width = $3;
  1736. $$ = $1;
  1737. }
  1738. ;
  1739. maybe_trailing_return_type:
  1740. empty
  1741. {
  1742. $$ = nullptr;
  1743. }
  1744. | POINTSAT predefined_type empty_instance_identifier
  1745. {
  1746. $$ = $3->unroll_type($2);
  1747. }
  1748. | POINTSAT KW_CONST predefined_type empty_instance_identifier
  1749. {
  1750. $4->add_modifier(IIT_const);
  1751. $$ = $4->unroll_type($3);
  1752. }
  1753. ;
  1754. maybe_comma_identifier:
  1755. empty
  1756. {
  1757. $$ = nullptr;
  1758. }
  1759. | ',' IDENTIFIER
  1760. {
  1761. $$ = $2;
  1762. }
  1763. ;
  1764. function_parameter_list:
  1765. empty
  1766. {
  1767. $$ = new CPPParameterList;
  1768. }
  1769. | ELLIPSIS
  1770. {
  1771. $$ = new CPPParameterList;
  1772. $$->_includes_ellipsis = true;
  1773. }
  1774. | function_parameters
  1775. {
  1776. $$ = $1;
  1777. }
  1778. | function_parameters ',' ELLIPSIS
  1779. {
  1780. $$ = $1;
  1781. $$->_includes_ellipsis = true;
  1782. }
  1783. | function_parameters ELLIPSIS
  1784. {
  1785. $$ = $1;
  1786. $$->_includes_ellipsis = true;
  1787. }
  1788. ;
  1789. function_parameters:
  1790. function_parameter
  1791. {
  1792. $$ = new CPPParameterList;
  1793. $$->_parameters.push_back($1);
  1794. }
  1795. | function_parameters ',' function_parameter
  1796. {
  1797. $$ = $1;
  1798. $$->_parameters.push_back($3);
  1799. }
  1800. ;
  1801. formal_parameter_list:
  1802. empty
  1803. {
  1804. $$ = new CPPParameterList;
  1805. }
  1806. | ELLIPSIS
  1807. {
  1808. $$ = new CPPParameterList;
  1809. $$->_includes_ellipsis = true;
  1810. }
  1811. | formal_parameters
  1812. {
  1813. $$ = $1;
  1814. }
  1815. | formal_parameters ',' ELLIPSIS
  1816. {
  1817. $$ = $1;
  1818. $$->_includes_ellipsis = true;
  1819. }
  1820. | formal_parameters ELLIPSIS
  1821. {
  1822. $$ = $1;
  1823. $$->_includes_ellipsis = true;
  1824. }
  1825. ;
  1826. formal_parameters:
  1827. formal_parameter
  1828. {
  1829. $$ = new CPPParameterList;
  1830. $$->_parameters.push_back($1);
  1831. }
  1832. | formal_parameters ',' formal_parameter
  1833. {
  1834. $$ = $1;
  1835. $$->_parameters.push_back($3);
  1836. }
  1837. ;
  1838. template_parameter_maybe_initialize:
  1839. empty
  1840. {
  1841. $$ = nullptr;
  1842. }
  1843. | '=' no_angle_bracket_const_expr
  1844. {
  1845. $$ = $2;
  1846. }
  1847. ;
  1848. maybe_initialize:
  1849. empty
  1850. {
  1851. $$ = nullptr;
  1852. }
  1853. | '=' const_expr
  1854. {
  1855. $$ = $2;
  1856. }
  1857. ;
  1858. maybe_initialize_or_constructor_body:
  1859. ';'
  1860. {
  1861. $$ = nullptr;
  1862. }
  1863. | '{' code '}'
  1864. {
  1865. $$ = nullptr;
  1866. }
  1867. | ':' constructor_inits '{' code '}'
  1868. {
  1869. $$ = nullptr;
  1870. }
  1871. | '=' KW_DEFAULT ';'
  1872. {
  1873. $$ = new CPPExpression(CPPExpression::get_default());
  1874. }
  1875. | '=' KW_DELETE ';'
  1876. {
  1877. $$ = new CPPExpression(CPPExpression::get_delete());
  1878. }
  1879. ;
  1880. maybe_initialize_or_function_body:
  1881. ';'
  1882. {
  1883. $$ = nullptr;
  1884. }
  1885. | '{' code '}'
  1886. {
  1887. $$ = nullptr;
  1888. }
  1889. | '=' const_expr ';'
  1890. {
  1891. $$ = $2;
  1892. }
  1893. | '=' KW_DEFAULT ';'
  1894. {
  1895. $$ = new CPPExpression(CPPExpression::get_default());
  1896. }
  1897. | '=' KW_DELETE ';'
  1898. {
  1899. $$ = new CPPExpression(CPPExpression::get_delete());
  1900. }
  1901. | '=' '{' structure_init '}'
  1902. {
  1903. $$ = nullptr;
  1904. }
  1905. ;
  1906. structure_init:
  1907. empty
  1908. | structure_init_body
  1909. | structure_init_body ','
  1910. ;
  1911. structure_init_body:
  1912. const_expr
  1913. {
  1914. }
  1915. | '{' structure_init '}'
  1916. | structure_init_body ',' const_expr
  1917. | structure_init_body ',' '{' structure_init '}'
  1918. ;
  1919. function_parameter:
  1920. type formal_parameter_identifier maybe_initialize
  1921. {
  1922. $$ = new CPPInstance($1, $2, 0, @2.file);
  1923. $$->set_initializer($3);
  1924. }
  1925. | KW_CONST type formal_parameter_identifier maybe_initialize
  1926. {
  1927. $3->add_modifier(IIT_const);
  1928. $$ = new CPPInstance($2, $3, 0, @3.file);
  1929. $$->set_initializer($4);
  1930. }
  1931. | KW_CONST KW_REGISTER type formal_parameter_identifier maybe_initialize
  1932. {
  1933. $4->add_modifier(IIT_const);
  1934. $$ = new CPPInstance($3, $4, 0, @3.file);
  1935. $$->set_initializer($5);
  1936. }
  1937. | type_pack parameter_pack_identifier maybe_initialize
  1938. {
  1939. $$ = new CPPInstance($1, $2, 0, @2.file);
  1940. $$->set_initializer($3);
  1941. }
  1942. | KW_CONST type_pack parameter_pack_identifier maybe_initialize
  1943. {
  1944. $3->add_modifier(IIT_const);
  1945. $$ = new CPPInstance($2, $3, 0, @3.file);
  1946. $$->set_initializer($4);
  1947. }
  1948. | KW_CONST KW_REGISTER type_pack parameter_pack_identifier maybe_initialize
  1949. {
  1950. $4->add_modifier(IIT_const);
  1951. $$ = new CPPInstance($3, $4, 0, @3.file);
  1952. $$->set_initializer($5);
  1953. }
  1954. | KW_REGISTER function_parameter
  1955. {
  1956. $$ = $2;
  1957. }
  1958. | ATTR_LEFT attribute_specifiers ATTR_RIGHT function_parameter
  1959. {
  1960. $$ = $4;
  1961. }
  1962. ;
  1963. /* A "formal parameter" is like a function parameter, except that it parses
  1964. * instance declarations (that look like functions declaration) as well, and
  1965. * as such accepts constexpr parameters.
  1966. */
  1967. formal_parameter:
  1968. function_parameter
  1969. {
  1970. $$ = $1;
  1971. }
  1972. | formal_const_expr
  1973. {
  1974. CPPType *type =
  1975. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_parameter));
  1976. $$ = new CPPInstance(type, "expr");
  1977. $$->set_initializer($1);
  1978. }
  1979. ;
  1980. not_paren_formal_parameter_identifier:
  1981. empty
  1982. {
  1983. $$ = new CPPInstanceIdentifier(nullptr);
  1984. }
  1985. | name_no_final
  1986. {
  1987. $$ = new CPPInstanceIdentifier($1);
  1988. }
  1989. | KW_CONST not_paren_formal_parameter_identifier %prec UNARY
  1990. {
  1991. $$ = $2;
  1992. $$->add_modifier(IIT_const);
  1993. }
  1994. | KW_VOLATILE not_paren_formal_parameter_identifier %prec UNARY
  1995. {
  1996. $$ = $2;
  1997. $$->add_modifier(IIT_volatile);
  1998. }
  1999. | '*' not_paren_formal_parameter_identifier %prec UNARY
  2000. {
  2001. $$ = $2;
  2002. $$->add_modifier(IIT_pointer);
  2003. }
  2004. | '&' not_paren_formal_parameter_identifier %prec UNARY
  2005. {
  2006. $$ = $2;
  2007. $$->add_modifier(IIT_reference);
  2008. }
  2009. | ANDAND not_paren_formal_parameter_identifier %prec UNARY
  2010. {
  2011. $$ = $2;
  2012. $$->add_modifier(IIT_rvalue_reference);
  2013. }
  2014. | SCOPING '*' not_paren_formal_parameter_identifier %prec UNARY
  2015. {
  2016. $$ = $3;
  2017. $$->add_scoped_pointer_modifier($1);
  2018. }
  2019. | not_paren_formal_parameter_identifier '[' optional_const_expr ']'
  2020. {
  2021. $$ = $1;
  2022. $$->add_array_modifier($3);
  2023. }
  2024. ;
  2025. formal_parameter_identifier:
  2026. empty
  2027. {
  2028. $$ = new CPPInstanceIdentifier(nullptr);
  2029. }
  2030. | name_no_final
  2031. {
  2032. $$ = new CPPInstanceIdentifier($1);
  2033. }
  2034. | KW_CONST formal_parameter_identifier %prec UNARY
  2035. {
  2036. $$ = $2;
  2037. $$->add_modifier(IIT_const);
  2038. }
  2039. | KW_VOLATILE formal_parameter_identifier %prec UNARY
  2040. {
  2041. $$ = $2;
  2042. $$->add_modifier(IIT_volatile);
  2043. }
  2044. | '*' formal_parameter_identifier %prec UNARY
  2045. {
  2046. $$ = $2;
  2047. $$->add_modifier(IIT_pointer);
  2048. }
  2049. | '&' formal_parameter_identifier %prec UNARY
  2050. {
  2051. $$ = $2;
  2052. $$->add_modifier(IIT_reference);
  2053. }
  2054. | ANDAND formal_parameter_identifier %prec UNARY
  2055. {
  2056. $$ = $2;
  2057. $$->add_modifier(IIT_rvalue_reference);
  2058. }
  2059. | SCOPING '*' formal_parameter_identifier %prec UNARY
  2060. {
  2061. $$ = $3;
  2062. $$->add_scoped_pointer_modifier($1);
  2063. }
  2064. | formal_parameter_identifier '[' optional_const_expr ']'
  2065. {
  2066. $$ = $1;
  2067. $$->add_array_modifier($3);
  2068. }
  2069. | '(' formal_parameter_identifier ')' '(' function_parameter_list ')' function_post
  2070. {
  2071. $$ = $2;
  2072. $$->add_modifier(IIT_paren);
  2073. $$->add_func_modifier($5, $7);
  2074. }
  2075. | '(' formal_parameter_identifier ')'
  2076. {
  2077. $$ = $2;
  2078. $$->add_modifier(IIT_paren);
  2079. }
  2080. ;
  2081. parameter_pack_identifier:
  2082. ELLIPSIS
  2083. {
  2084. $$ = new CPPInstanceIdentifier(nullptr);
  2085. $$->_packed = true;
  2086. }
  2087. | ELLIPSIS name
  2088. {
  2089. $$ = new CPPInstanceIdentifier($2);
  2090. $$->_packed = true;
  2091. }
  2092. | KW_CONST parameter_pack_identifier %prec UNARY
  2093. {
  2094. $$ = $2;
  2095. $$->add_modifier(IIT_const);
  2096. }
  2097. | KW_VOLATILE parameter_pack_identifier %prec UNARY
  2098. {
  2099. $$ = $2;
  2100. $$->add_modifier(IIT_volatile);
  2101. }
  2102. | '*' parameter_pack_identifier %prec UNARY
  2103. {
  2104. $$ = $2;
  2105. $$->add_modifier(IIT_pointer);
  2106. }
  2107. | '&' parameter_pack_identifier %prec UNARY
  2108. {
  2109. $$ = $2;
  2110. $$->add_modifier(IIT_reference);
  2111. }
  2112. | ANDAND parameter_pack_identifier %prec UNARY
  2113. {
  2114. $$ = $2;
  2115. $$->add_modifier(IIT_rvalue_reference);
  2116. }
  2117. | SCOPING '*' parameter_pack_identifier %prec UNARY
  2118. {
  2119. $$ = $3;
  2120. $$->add_scoped_pointer_modifier($1);
  2121. }
  2122. | parameter_pack_identifier '[' optional_const_expr ']'
  2123. {
  2124. $$ = $1;
  2125. $$->add_array_modifier($3);
  2126. }
  2127. | '(' parameter_pack_identifier ')' '(' function_parameter_list ')' function_post
  2128. {
  2129. $$ = $2;
  2130. $$->add_modifier(IIT_paren);
  2131. $$->add_func_modifier($5, $7);
  2132. }
  2133. | '(' parameter_pack_identifier ')'
  2134. {
  2135. $$ = $2;
  2136. $$->add_modifier(IIT_paren);
  2137. }
  2138. ;
  2139. not_paren_empty_instance_identifier:
  2140. empty
  2141. {
  2142. $$ = new CPPInstanceIdentifier(nullptr);
  2143. }
  2144. | ELLIPSIS
  2145. {
  2146. $$ = new CPPInstanceIdentifier(nullptr);
  2147. $$->_packed = true;
  2148. }
  2149. | ELLIPSIS name
  2150. {
  2151. $$ = new CPPInstanceIdentifier($2);
  2152. $$->_packed = true;
  2153. }
  2154. | KW_CONST not_paren_empty_instance_identifier %prec UNARY
  2155. {
  2156. $$ = $2;
  2157. $$->add_modifier(IIT_const);
  2158. }
  2159. | KW_VOLATILE not_paren_empty_instance_identifier %prec UNARY
  2160. {
  2161. $$ = $2;
  2162. $$->add_modifier(IIT_volatile);
  2163. }
  2164. | '*' not_paren_empty_instance_identifier %prec UNARY
  2165. {
  2166. $$ = $2;
  2167. $$->add_modifier(IIT_pointer);
  2168. }
  2169. | '&' not_paren_empty_instance_identifier %prec UNARY
  2170. {
  2171. $$ = $2;
  2172. $$->add_modifier(IIT_reference);
  2173. }
  2174. | ANDAND not_paren_empty_instance_identifier %prec UNARY
  2175. {
  2176. $$ = $2;
  2177. $$->add_modifier(IIT_rvalue_reference);
  2178. }
  2179. | SCOPING '*' not_paren_empty_instance_identifier %prec UNARY
  2180. {
  2181. $$ = $3;
  2182. $$->add_scoped_pointer_modifier($1);
  2183. }
  2184. | not_paren_empty_instance_identifier '[' optional_const_expr ']'
  2185. {
  2186. $$ = $1;
  2187. $$->add_array_modifier($3);
  2188. }
  2189. ;
  2190. empty_instance_identifier:
  2191. empty
  2192. {
  2193. $$ = new CPPInstanceIdentifier(nullptr);
  2194. }
  2195. | ELLIPSIS
  2196. {
  2197. $$ = new CPPInstanceIdentifier(nullptr);
  2198. $$->_packed = true;
  2199. }
  2200. | ELLIPSIS name
  2201. {
  2202. $$ = new CPPInstanceIdentifier($2);
  2203. $$->_packed = true;
  2204. }
  2205. | KW_CONST empty_instance_identifier %prec UNARY
  2206. {
  2207. $$ = $2;
  2208. $$->add_modifier(IIT_const);
  2209. }
  2210. | KW_VOLATILE empty_instance_identifier %prec UNARY
  2211. {
  2212. $$ = $2;
  2213. $$->add_modifier(IIT_volatile);
  2214. }
  2215. | '*' not_paren_empty_instance_identifier %prec UNARY
  2216. {
  2217. $$ = $2;
  2218. $$->add_modifier(IIT_pointer);
  2219. }
  2220. | '&' not_paren_empty_instance_identifier %prec UNARY
  2221. {
  2222. $$ = $2;
  2223. $$->add_modifier(IIT_reference);
  2224. }
  2225. | ANDAND not_paren_empty_instance_identifier %prec UNARY
  2226. {
  2227. $$ = $2;
  2228. $$->add_modifier(IIT_rvalue_reference);
  2229. }
  2230. | SCOPING '*' not_paren_empty_instance_identifier %prec UNARY
  2231. {
  2232. $$ = $3;
  2233. $$->add_scoped_pointer_modifier($1);
  2234. }
  2235. | not_paren_empty_instance_identifier '[' optional_const_expr ']'
  2236. {
  2237. $$ = $1;
  2238. $$->add_array_modifier($3);
  2239. }
  2240. | '(' function_parameter_list ')' function_post maybe_trailing_return_type
  2241. {
  2242. $$ = new CPPInstanceIdentifier(nullptr);
  2243. $$->add_modifier(IIT_paren);
  2244. $$->add_func_modifier($2, $4, $5);
  2245. }
  2246. | '(' '*' not_paren_empty_instance_identifier ')' '(' function_parameter_list ')' function_post maybe_trailing_return_type
  2247. {
  2248. $$ = $3;
  2249. $$->add_modifier(IIT_pointer);
  2250. $$->add_modifier(IIT_paren);
  2251. $$->add_func_modifier($6, $8, $9);
  2252. }
  2253. | '(' '&' not_paren_empty_instance_identifier ')' '(' function_parameter_list ')' function_post maybe_trailing_return_type
  2254. {
  2255. $$ = $3;
  2256. $$->add_modifier(IIT_reference);
  2257. $$->add_modifier(IIT_paren);
  2258. $$->add_func_modifier($6, $8, $9);
  2259. }
  2260. | '(' ANDAND not_paren_empty_instance_identifier ')' '(' function_parameter_list ')' function_post maybe_trailing_return_type
  2261. {
  2262. $$ = $3;
  2263. $$->add_modifier(IIT_rvalue_reference);
  2264. $$->add_modifier(IIT_paren);
  2265. $$->add_func_modifier($6, $8, $9);
  2266. }
  2267. ;
  2268. type:
  2269. simple_type
  2270. {
  2271. $$ = CPPType::new_type($1);
  2272. }
  2273. | TYPENAME_IDENTIFIER
  2274. {
  2275. $$ = $1->find_type(current_scope, global_scope, false, current_lexer);
  2276. if ($$ == nullptr) {
  2277. yyerror(string("internal error resolving type ") + $1->get_fully_scoped_name(), @1);
  2278. }
  2279. assert($$ != nullptr);
  2280. }
  2281. | KW_TYPENAME name
  2282. {
  2283. $$ = CPPType::new_type(new CPPTBDType($2));
  2284. }
  2285. | anonymous_struct
  2286. {
  2287. $$ = CPPType::new_type($1);
  2288. }
  2289. | named_struct
  2290. {
  2291. $$ = CPPType::new_type($1);
  2292. }
  2293. | enum
  2294. {
  2295. $$ = CPPType::new_type($1);
  2296. }
  2297. | struct_keyword struct_attributes name
  2298. {
  2299. CPPType *type = $3->find_type(current_scope, global_scope, false, current_lexer);
  2300. if (type != nullptr) {
  2301. $$ = type;
  2302. } else {
  2303. CPPExtensionType *et =
  2304. CPPType::new_type(new CPPExtensionType($1, $3, current_scope, @1.file))
  2305. ->as_extension_type();
  2306. CPPScope *scope = $3->get_scope(current_scope, global_scope);
  2307. if (scope != nullptr) {
  2308. scope->define_extension_type(et);
  2309. }
  2310. $$ = et;
  2311. }
  2312. }
  2313. | enum_keyword name_no_final ':' enum_element_type
  2314. {
  2315. CPPType *type = $2->find_type(current_scope, global_scope, false, current_lexer);
  2316. if (type != nullptr) {
  2317. $$ = type;
  2318. } else {
  2319. CPPExtensionType *et =
  2320. CPPType::new_type(new CPPExtensionType($1, $2, current_scope, @1.file))
  2321. ->as_extension_type();
  2322. CPPScope *scope = $2->get_scope(current_scope, global_scope);
  2323. if (scope != nullptr) {
  2324. scope->define_extension_type(et);
  2325. }
  2326. $$ = et;
  2327. }
  2328. }
  2329. | KW_DECLTYPE '(' const_expr ')'
  2330. {
  2331. $$ = $3->determine_type();
  2332. if ($$ == nullptr) {
  2333. stringstream str;
  2334. str << *$3;
  2335. yyerror("could not determine type of " + str.str(), @3);
  2336. }
  2337. }
  2338. | KW_DECLTYPE '(' KW_AUTO ')'
  2339. {
  2340. $$ = CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_auto));
  2341. }
  2342. | KW_UNDERLYING_TYPE '(' full_type ')'
  2343. {
  2344. CPPEnumType *enum_type = $3->as_enum_type();
  2345. if (enum_type == nullptr) {
  2346. yyerror("an enumeration type is required", @3);
  2347. $$ = $3;
  2348. } else {
  2349. $$ = enum_type->get_underlying_type();
  2350. }
  2351. }
  2352. | KW_AUTO
  2353. {
  2354. $$ = CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_auto));
  2355. }
  2356. ;
  2357. type_pack:
  2358. TYPEPACK_IDENTIFIER
  2359. {
  2360. $$ = $1->find_type(current_scope, global_scope, false, current_lexer);
  2361. if ($$ == nullptr) {
  2362. yyerror(string("internal error resolving type ") + $1->get_fully_scoped_name(), @1);
  2363. }
  2364. assert($$ != nullptr);
  2365. }
  2366. ;
  2367. type_decl:
  2368. simple_type
  2369. {
  2370. $$ = CPPType::new_type($1);
  2371. }
  2372. | TYPENAME_IDENTIFIER
  2373. {
  2374. $$ = $1->find_type(current_scope, global_scope, false, current_lexer);
  2375. if ($$ == nullptr) {
  2376. yyerror(string("internal error resolving type ") + $1->get_fully_scoped_name(), @1);
  2377. }
  2378. assert($$ != nullptr);
  2379. }
  2380. | KW_TYPENAME name
  2381. {
  2382. $$ = CPPType::new_type(new CPPTBDType($2));
  2383. }
  2384. | anonymous_struct
  2385. {
  2386. $$ = CPPType::new_type($1);
  2387. }
  2388. | named_struct
  2389. {
  2390. $$ = new CPPTypeDeclaration(CPPType::new_type($1));
  2391. }
  2392. | enum
  2393. {
  2394. $$ = new CPPTypeDeclaration(CPPType::new_type($1));
  2395. }
  2396. | struct_keyword struct_attributes name
  2397. {
  2398. CPPType *type = $3->find_type(current_scope, global_scope, false, current_lexer);
  2399. if (type != nullptr) {
  2400. $$ = type;
  2401. } else {
  2402. CPPExtensionType *et =
  2403. CPPType::new_type(new CPPExtensionType($1, $3, current_scope, @1.file))
  2404. ->as_extension_type();
  2405. CPPScope *scope = $3->get_scope(current_scope, global_scope);
  2406. if (scope != nullptr) {
  2407. scope->define_extension_type(et);
  2408. }
  2409. $$ = et;
  2410. }
  2411. }
  2412. | enum_keyword name_no_final ':' enum_element_type
  2413. {
  2414. CPPType *type = $2->find_type(current_scope, global_scope, false, current_lexer);
  2415. if (type != nullptr) {
  2416. $$ = type;
  2417. } else {
  2418. CPPExtensionType *et =
  2419. CPPType::new_type(new CPPExtensionType($1, $2, current_scope, @1.file))
  2420. ->as_extension_type();
  2421. CPPScope *scope = $2->get_scope(current_scope, global_scope);
  2422. if (scope != nullptr) {
  2423. scope->define_extension_type(et);
  2424. }
  2425. $$ = et;
  2426. }
  2427. }
  2428. | enum_keyword name
  2429. {
  2430. yywarning(string("C++ does not permit forward declaration of untyped enum ") + $2->get_fully_scoped_name(), @1);
  2431. CPPType *type = $2->find_type(current_scope, global_scope, false, current_lexer);
  2432. if (type != nullptr) {
  2433. $$ = type;
  2434. } else {
  2435. CPPExtensionType *et =
  2436. CPPType::new_type(new CPPExtensionType($1, $2, current_scope, @1.file))
  2437. ->as_extension_type();
  2438. CPPScope *scope = $2->get_scope(current_scope, global_scope);
  2439. if (scope != nullptr) {
  2440. scope->define_extension_type(et);
  2441. }
  2442. $$ = et;
  2443. }
  2444. }
  2445. | KW_DECLTYPE '(' const_expr ')'
  2446. {
  2447. $$ = $3->determine_type();
  2448. if ($$ == nullptr) {
  2449. stringstream str;
  2450. str << *$3;
  2451. yyerror("could not determine type of " + str.str(), @3);
  2452. }
  2453. }
  2454. | KW_DECLTYPE '(' KW_AUTO ')'
  2455. {
  2456. $$ = CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_auto));
  2457. }
  2458. | KW_UNDERLYING_TYPE '(' full_type ')'
  2459. {
  2460. CPPEnumType *enum_type = $3->as_enum_type();
  2461. if (enum_type == nullptr) {
  2462. yyerror("an enumeration type is required", @3);
  2463. $$ = $3;
  2464. } else {
  2465. $$ = enum_type->get_underlying_type();
  2466. }
  2467. }
  2468. | KW_AUTO
  2469. {
  2470. $$ = CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_auto));
  2471. }
  2472. ;
  2473. predefined_type:
  2474. simple_type
  2475. {
  2476. $$ = CPPType::new_type($1);
  2477. }
  2478. | TYPENAME_IDENTIFIER
  2479. {
  2480. $$ = $1->find_type(current_scope, global_scope, false, current_lexer);
  2481. if ($$ == nullptr) {
  2482. yyerror(string("internal error resolving type ") + $1->get_fully_scoped_name(), @1);
  2483. }
  2484. assert($$ != nullptr);
  2485. }
  2486. | KW_TYPENAME name
  2487. {
  2488. $$ = CPPType::new_type(new CPPTBDType($2));
  2489. }
  2490. | struct_keyword struct_attributes name
  2491. {
  2492. CPPType *type = $3->find_type(current_scope, global_scope, false, current_lexer);
  2493. if (type != nullptr) {
  2494. $$ = type;
  2495. } else {
  2496. CPPExtensionType *et =
  2497. CPPType::new_type(new CPPExtensionType($1, $3, current_scope, @1.file))
  2498. ->as_extension_type();
  2499. CPPScope *scope = $3->get_scope(current_scope, global_scope);
  2500. if (scope != nullptr) {
  2501. scope->define_extension_type(et);
  2502. }
  2503. $$ = et;
  2504. }
  2505. }
  2506. | enum_keyword name
  2507. {
  2508. CPPType *type = $2->find_type(current_scope, global_scope, false, current_lexer);
  2509. if (type != nullptr) {
  2510. $$ = type;
  2511. } else {
  2512. CPPExtensionType *et =
  2513. CPPType::new_type(new CPPExtensionType($1, $2, current_scope, @1.file))
  2514. ->as_extension_type();
  2515. CPPScope *scope = $2->get_scope(current_scope, global_scope);
  2516. if (scope != nullptr) {
  2517. scope->define_extension_type(et);
  2518. }
  2519. $$ = et;
  2520. }
  2521. }
  2522. | KW_DECLTYPE '(' const_expr ')'
  2523. {
  2524. $$ = $3->determine_type();
  2525. if ($$ == nullptr) {
  2526. stringstream str;
  2527. str << *$3;
  2528. yyerror("could not determine type of " + str.str(), @3);
  2529. }
  2530. }
  2531. | KW_UNDERLYING_TYPE '(' full_type ')'
  2532. {
  2533. CPPEnumType *enum_type = $3->as_enum_type();
  2534. if (enum_type == nullptr) {
  2535. yyerror("an enumeration type is required", @3);
  2536. $$ = $3;
  2537. } else {
  2538. $$ = enum_type->get_underlying_type();
  2539. }
  2540. }
  2541. | KW_AUTO
  2542. {
  2543. $$ = CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_auto));
  2544. }
  2545. ;
  2546. var_type_decl:
  2547. type_decl
  2548. {
  2549. $$ = $1;
  2550. }
  2551. | IDENTIFIER
  2552. {
  2553. yyerror(string("unknown type '") + $1->get_fully_scoped_name() + "'", @1);
  2554. $$ = CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_unknown));
  2555. }
  2556. full_type:
  2557. type empty_instance_identifier
  2558. {
  2559. $$ = $2->unroll_type($1);
  2560. }
  2561. | KW_CONST type empty_instance_identifier
  2562. {
  2563. $3->add_modifier(IIT_const);
  2564. $$ = $3->unroll_type($2);
  2565. }
  2566. | type_pack empty_instance_identifier
  2567. {
  2568. $$ = $2->unroll_type($1);
  2569. }
  2570. | KW_CONST type_pack empty_instance_identifier
  2571. {
  2572. $3->add_modifier(IIT_const);
  2573. $$ = $3->unroll_type($2);
  2574. }
  2575. ;
  2576. struct_attributes:
  2577. empty
  2578. | struct_attributes ATTR_LEFT attribute_specifiers ATTR_RIGHT
  2579. | struct_attributes KW_ALIGNAS '(' const_expr ')'
  2580. | struct_attributes KW_ALIGNAS '(' type_decl ')'
  2581. ;
  2582. anonymous_struct:
  2583. struct_keyword struct_attributes '{'
  2584. {
  2585. CPPVisibility starting_vis =
  2586. ($1 == CPPExtensionType::T_class) ? V_private : V_public;
  2587. CPPScope *new_scope = new CPPScope(current_scope, CPPNameComponent("anon"),
  2588. starting_vis);
  2589. CPPStructType *st = new CPPStructType($1, nullptr, current_scope,
  2590. new_scope, @1.file);
  2591. new_scope->set_struct_type(st);
  2592. push_scope(new_scope);
  2593. push_struct(st);
  2594. }
  2595. cpp '}'
  2596. {
  2597. $$ = current_struct;
  2598. current_struct->_incomplete = false;
  2599. pop_struct();
  2600. pop_scope();
  2601. }
  2602. ;
  2603. named_struct:
  2604. struct_keyword struct_attributes name_no_final
  2605. {
  2606. CPPVisibility starting_vis =
  2607. ($1 == CPPExtensionType::T_class) ? V_private : V_public;
  2608. CPPScope *scope = $3->get_scope(current_scope, global_scope, current_lexer);
  2609. if (scope == nullptr) {
  2610. scope = current_scope;
  2611. }
  2612. CPPScope *new_scope = new CPPScope(scope, $3->_names.back(),
  2613. starting_vis);
  2614. CPPStructType *st = new CPPStructType($1, $3, current_scope,
  2615. new_scope, @1.file);
  2616. new_scope->set_struct_type(st);
  2617. current_scope->define_extension_type(st);
  2618. push_scope(new_scope);
  2619. push_struct(st);
  2620. }
  2621. maybe_final maybe_class_derivation '{' cpp '}'
  2622. {
  2623. $$ = current_struct;
  2624. current_struct->_incomplete = false;
  2625. pop_struct();
  2626. pop_scope();
  2627. }
  2628. ;
  2629. maybe_final:
  2630. empty
  2631. | KW_FINAL
  2632. {
  2633. current_struct->_final = true;
  2634. }
  2635. ;
  2636. maybe_class_derivation:
  2637. empty
  2638. | class_derivation
  2639. ;
  2640. class_derivation:
  2641. ':' base_specification
  2642. | class_derivation ',' base_specification
  2643. ;
  2644. base_specification:
  2645. class_derivation_name
  2646. {
  2647. current_struct->append_derivation($1, V_unknown, false);
  2648. }
  2649. | KW_PUBLIC class_derivation_name
  2650. {
  2651. current_struct->append_derivation($2, V_public, false);
  2652. }
  2653. | KW_PROTECTED class_derivation_name
  2654. {
  2655. current_struct->append_derivation($2, V_protected, false);
  2656. }
  2657. | KW_PRIVATE class_derivation_name
  2658. {
  2659. current_struct->append_derivation($2, V_private, false);
  2660. }
  2661. | KW_VIRTUAL KW_PUBLIC class_derivation_name
  2662. {
  2663. current_struct->append_derivation($3, V_public, true);
  2664. }
  2665. | KW_VIRTUAL KW_PROTECTED class_derivation_name
  2666. {
  2667. current_struct->append_derivation($3, V_protected, true);
  2668. }
  2669. | KW_VIRTUAL KW_PRIVATE class_derivation_name
  2670. {
  2671. current_struct->append_derivation($3, V_private, true);
  2672. }
  2673. | KW_PUBLIC KW_VIRTUAL class_derivation_name
  2674. {
  2675. current_struct->append_derivation($3, V_public, true);
  2676. }
  2677. | KW_PROTECTED KW_VIRTUAL class_derivation_name
  2678. {
  2679. current_struct->append_derivation($3, V_protected, true);
  2680. }
  2681. | KW_PRIVATE KW_VIRTUAL class_derivation_name
  2682. {
  2683. current_struct->append_derivation($3, V_private, true);
  2684. }
  2685. ;
  2686. enum:
  2687. enum_decl '{' enum_body '}'
  2688. {
  2689. $$ = current_enum;
  2690. current_enum = nullptr;
  2691. }
  2692. ;
  2693. enum_decl:
  2694. enum_keyword ':' enum_element_type
  2695. {
  2696. current_enum = new CPPEnumType($1, nullptr, $3, current_scope, nullptr, @1.file);
  2697. }
  2698. | enum_keyword
  2699. {
  2700. current_enum = new CPPEnumType($1, nullptr, current_scope, nullptr, @1.file);
  2701. }
  2702. | enum_keyword name_no_final ':' enum_element_type
  2703. {
  2704. CPPScope *new_scope = new CPPScope(current_scope, $2->_names.back(), V_public);
  2705. current_enum = new CPPEnumType($1, $2, $4, current_scope, new_scope, @1.file);
  2706. }
  2707. | enum_keyword name_no_final
  2708. {
  2709. CPPScope *new_scope = new CPPScope(current_scope, $2->_names.back(), V_public);
  2710. current_enum = new CPPEnumType($1, $2, current_scope, new_scope, @1.file);
  2711. }
  2712. ;
  2713. enum_element_type:
  2714. simple_int_type
  2715. {
  2716. $$ = CPPType::new_type($1);
  2717. }
  2718. | TYPENAME_IDENTIFIER
  2719. {
  2720. $$ = $1->find_type(current_scope, global_scope, false, current_lexer);
  2721. }
  2722. ;
  2723. enum_body_trailing_comma:
  2724. empty
  2725. | enum_body_trailing_comma name ','
  2726. {
  2727. assert(current_enum != nullptr);
  2728. current_enum->add_element($2->get_simple_name(), nullptr, current_lexer, @2);
  2729. }
  2730. | enum_body_trailing_comma name '=' const_expr ','
  2731. {
  2732. assert(current_enum != nullptr);
  2733. current_enum->add_element($2->get_simple_name(), $4, current_lexer, @2);
  2734. };
  2735. enum_body:
  2736. enum_body_trailing_comma
  2737. | enum_body_trailing_comma name
  2738. {
  2739. assert(current_enum != nullptr);
  2740. current_enum->add_element($2->get_simple_name(), nullptr, current_lexer, @2);
  2741. }
  2742. | enum_body_trailing_comma name '=' const_expr
  2743. {
  2744. assert(current_enum != nullptr);
  2745. current_enum->add_element($2->get_simple_name(), $4, current_lexer, @2);
  2746. }
  2747. ;
  2748. enum_keyword:
  2749. KW_ENUM
  2750. {
  2751. $$ = CPPExtensionType::T_enum;
  2752. }
  2753. | KW_ENUM KW_CLASS
  2754. {
  2755. $$ = CPPExtensionType::T_enum_class;
  2756. }
  2757. | KW_ENUM KW_STRUCT
  2758. {
  2759. $$ = CPPExtensionType::T_enum_struct;
  2760. }
  2761. ;
  2762. struct_keyword:
  2763. KW_CLASS
  2764. {
  2765. $$ = CPPExtensionType::T_class;
  2766. }
  2767. | KW_STRUCT
  2768. {
  2769. $$ = CPPExtensionType::T_struct;
  2770. }
  2771. | KW_UNION
  2772. {
  2773. $$ = CPPExtensionType::T_union;
  2774. }
  2775. ;
  2776. namespace_declaration:
  2777. KW_NAMESPACE name '{'
  2778. {
  2779. CPPScope *scope = $2->find_scope(current_scope, global_scope, current_lexer);
  2780. if (scope == nullptr) {
  2781. // This must be a new namespace declaration.
  2782. CPPScope *parent_scope =
  2783. $2->get_scope(current_scope, global_scope, current_lexer);
  2784. if (parent_scope == nullptr) {
  2785. parent_scope = current_scope;
  2786. }
  2787. scope = new CPPScope(parent_scope, $2->_names.back(), V_public);
  2788. }
  2789. CPPNamespace *nspace = new CPPNamespace($2, scope, @1.file);
  2790. current_scope->add_declaration(nspace, global_scope, current_lexer, @1);
  2791. current_scope->define_namespace(nspace);
  2792. push_scope(scope);
  2793. }
  2794. cpp '}'
  2795. {
  2796. pop_scope();
  2797. }
  2798. | KW_INLINE KW_NAMESPACE name '{'
  2799. {
  2800. CPPScope *scope = $3->find_scope(current_scope, global_scope, current_lexer);
  2801. if (scope == nullptr) {
  2802. // This must be a new namespace declaration.
  2803. CPPScope *parent_scope =
  2804. $3->get_scope(current_scope, global_scope, current_lexer);
  2805. if (parent_scope == nullptr) {
  2806. parent_scope = current_scope;
  2807. }
  2808. scope = new CPPScope(parent_scope, $3->_names.back(), V_public);
  2809. }
  2810. CPPNamespace *nspace = new CPPNamespace($3, scope, @2.file);
  2811. nspace->_is_inline = true;
  2812. current_scope->add_declaration(nspace, global_scope, current_lexer, @2);
  2813. current_scope->define_namespace(nspace);
  2814. push_scope(scope);
  2815. }
  2816. cpp '}'
  2817. {
  2818. pop_scope();
  2819. }
  2820. | KW_NAMESPACE '{' cpp '}'
  2821. | KW_INLINE KW_NAMESPACE '{' cpp '}'
  2822. ;
  2823. using_declaration:
  2824. KW_USING name ';'
  2825. {
  2826. CPPUsing *using_decl = new CPPUsing($2, false, @1.file);
  2827. current_scope->add_declaration(using_decl, global_scope, current_lexer, @1);
  2828. current_scope->add_using(using_decl, global_scope, current_lexer);
  2829. }
  2830. | KW_USING name '=' full_type ';'
  2831. {
  2832. // This is really just an alternative way to declare a typedef.
  2833. CPPTypedefType *typedef_type = new CPPTypedefType($4, $2, current_scope);
  2834. typedef_type->_using = true;
  2835. current_scope->add_declaration(CPPType::new_type(typedef_type), global_scope, current_lexer, @1);
  2836. }
  2837. | KW_USING KW_NAMESPACE name ';'
  2838. {
  2839. CPPUsing *using_decl = new CPPUsing($3, true, @1.file);
  2840. current_scope->add_declaration(using_decl, global_scope, current_lexer, @1);
  2841. current_scope->add_using(using_decl, global_scope, current_lexer);
  2842. }
  2843. ;
  2844. simple_type:
  2845. simple_int_type
  2846. | simple_float_type
  2847. | simple_void_type
  2848. ;
  2849. simple_int_type:
  2850. KW_BOOL
  2851. {
  2852. $$ = new CPPSimpleType(CPPSimpleType::T_bool);
  2853. }
  2854. | KW_CHAR
  2855. {
  2856. $$ = new CPPSimpleType(CPPSimpleType::T_char);
  2857. }
  2858. | KW_WCHAR_T
  2859. {
  2860. $$ = new CPPSimpleType(CPPSimpleType::T_wchar_t);
  2861. }
  2862. | KW_CHAR16_T
  2863. {
  2864. $$ = new CPPSimpleType(CPPSimpleType::T_char16_t);
  2865. }
  2866. | KW_CHAR32_T
  2867. {
  2868. $$ = new CPPSimpleType(CPPSimpleType::T_char32_t);
  2869. }
  2870. | KW_SHORT
  2871. {
  2872. $$ = new CPPSimpleType(CPPSimpleType::T_int,
  2873. CPPSimpleType::F_short);
  2874. }
  2875. | KW_LONG
  2876. {
  2877. $$ = new CPPSimpleType(CPPSimpleType::T_int,
  2878. CPPSimpleType::F_long);
  2879. }
  2880. | KW_UNSIGNED
  2881. {
  2882. $$ = new CPPSimpleType(CPPSimpleType::T_int,
  2883. CPPSimpleType::F_unsigned);
  2884. }
  2885. | KW_SIGNED
  2886. {
  2887. $$ = new CPPSimpleType(CPPSimpleType::T_int,
  2888. CPPSimpleType::F_signed);
  2889. }
  2890. | KW_INT
  2891. {
  2892. $$ = new CPPSimpleType(CPPSimpleType::T_int);
  2893. }
  2894. | KW_SHORT simple_int_type
  2895. {
  2896. $$ = $2;
  2897. $$->_flags |= CPPSimpleType::F_short;
  2898. }
  2899. | KW_LONG simple_int_type
  2900. {
  2901. $$ = $2;
  2902. if ($$->_flags & CPPSimpleType::F_long) {
  2903. $$->_flags |= CPPSimpleType::F_longlong;
  2904. } else {
  2905. $$->_flags |= CPPSimpleType::F_long;
  2906. }
  2907. }
  2908. | KW_UNSIGNED simple_int_type
  2909. {
  2910. $$ = $2;
  2911. $$->_flags |= CPPSimpleType::F_unsigned;
  2912. }
  2913. | KW_SIGNED simple_int_type
  2914. {
  2915. $$ = $2;
  2916. $$->_flags |= CPPSimpleType::F_signed;
  2917. }
  2918. ;
  2919. simple_float_type:
  2920. KW_FLOAT
  2921. {
  2922. $$ = new CPPSimpleType(CPPSimpleType::T_float);
  2923. }
  2924. | KW_DOUBLE
  2925. {
  2926. $$ = new CPPSimpleType(CPPSimpleType::T_double);
  2927. }
  2928. | KW_LONG KW_DOUBLE
  2929. {
  2930. $$ = new CPPSimpleType(CPPSimpleType::T_double,
  2931. CPPSimpleType::F_long);
  2932. }
  2933. ;
  2934. simple_void_type:
  2935. KW_VOID
  2936. {
  2937. $$ = new CPPSimpleType(CPPSimpleType::T_void);
  2938. }
  2939. ;
  2940. /* We don't care what the code is. We just want to be sure we match
  2941. up opening and closing braces properly. For anything else, we'll
  2942. accept just token salad. */
  2943. code:
  2944. {
  2945. current_lexer->_resolve_identifiers = false;
  2946. }
  2947. code_block
  2948. {
  2949. current_lexer->_resolve_identifiers = true;
  2950. }
  2951. ;
  2952. code_block:
  2953. empty
  2954. | code_block element
  2955. ;
  2956. element:
  2957. REAL
  2958. | INTEGER
  2959. | SIMPLE_STRING
  2960. | STRING_LITERAL
  2961. | CUSTOM_LITERAL
  2962. | CHAR_TOK
  2963. | IDENTIFIER
  2964. | TYPENAME_IDENTIFIER
  2965. | TYPEPACK_IDENTIFIER
  2966. | SCOPING
  2967. | SIMPLE_IDENTIFIER
  2968. | ELLIPSIS | OROR | ANDAND
  2969. | EQCOMPARE | NECOMPARE | LECOMPARE | GECOMPARE
  2970. | LSHIFT | RSHIFT | POINTSAT_STAR | DOT_STAR | POINTSAT
  2971. | SCOPE | PLUSPLUS | MINUSMINUS
  2972. | TIMESEQUAL | DIVIDEEQUAL | MODEQUAL | PLUSEQUAL | MINUSEQUAL
  2973. | OREQUAL | ANDEQUAL | XOREQUAL | LSHIFTEQUAL | RSHIFTEQUAL
  2974. | ATTR_LEFT | ATTR_RIGHT
  2975. | KW_ALIGNAS | KW_ALIGNOF | KW_AUTO | KW_BOOL | KW_CATCH
  2976. | KW_CHAR | KW_CHAR16_T | KW_CHAR32_T | KW_CLASS | KW_CONST
  2977. | KW_CONSTEXPR | KW_CONST_CAST | KW_DECLTYPE | KW_DEFAULT
  2978. | KW_DELETE | KW_DOUBLE | KW_DYNAMIC_CAST | KW_ELSE | KW_ENUM
  2979. | KW_EXTERN | KW_EXPLICIT | KW_FALSE | KW_FINAL | KW_FLOAT
  2980. | KW_FRIEND | KW_FOR | KW_GOTO | KW_IF | KW_INLINE | KW_INT
  2981. | KW_LONG | KW_MUTABLE | KW_NAMESPACE | KW_NEW | KW_NULLPTR
  2982. | KW_OPERATOR | KW_OVERRIDE | KW_PRIVATE | KW_PROTECTED
  2983. | KW_PUBLIC | KW_PUBLISHED | KW_REGISTER | KW_REINTERPRET_CAST
  2984. | KW_RETURN | KW_SHORT | KW_SIGNED | KW_SIZEOF | KW_STATIC
  2985. | KW_STATIC_ASSERT | KW_STATIC_CAST | KW_STRUCT | KW_TEMPLATE
  2986. | KW_THREAD_LOCAL | KW_THROW | KW_TRUE | KW_TRY | KW_TYPEDEF
  2987. | KW_TYPEID | KW_TYPENAME | KW_UNDERLYING_TYPE | KW_UNION
  2988. | KW_UNSIGNED | KW_USING | KW_VIRTUAL | KW_VOID | KW_VOLATILE
  2989. | KW_WCHAR_T | KW_WHILE
  2990. {
  2991. }
  2992. | '+' | '-' | '*' | '/' | '&' | '|' | '^' | '!' | '~' | '=' | '%'
  2993. | '<' | '>' | '(' | ')' | '.' | ',' | ';' | ':' | '[' | ']'
  2994. | '?' | '{' code_block '}'
  2995. ;
  2996. optional_const_expr:
  2997. empty
  2998. {
  2999. $$ = nullptr;
  3000. }
  3001. | const_expr
  3002. {
  3003. $$ = $1;
  3004. }
  3005. ;
  3006. optional_const_expr_comma:
  3007. empty
  3008. {
  3009. $$ = nullptr;
  3010. }
  3011. | const_expr_comma
  3012. {
  3013. $$ = $1;
  3014. }
  3015. ;
  3016. const_expr_comma:
  3017. const_expr
  3018. {
  3019. $$ = $1;
  3020. }
  3021. | const_expr_comma ',' const_expr
  3022. {
  3023. $$ = new CPPExpression(',', $1, $3);
  3024. }
  3025. ;
  3026. no_angle_bracket_const_expr:
  3027. const_operand
  3028. {
  3029. $$ = $1;
  3030. }
  3031. | '(' full_type ')' no_angle_bracket_const_expr %prec UNARY
  3032. {
  3033. $$ = new CPPExpression(CPPExpression::typecast_op($2, $4));
  3034. }
  3035. | KW_STATIC_CAST '<' full_type '>' '(' const_expr_comma ')'
  3036. {
  3037. $$ = new CPPExpression(CPPExpression::typecast_op($3, $6, CPPExpression::T_static_cast));
  3038. }
  3039. | KW_DYNAMIC_CAST '<' full_type '>' '(' const_expr_comma ')'
  3040. {
  3041. $$ = new CPPExpression(CPPExpression::typecast_op($3, $6, CPPExpression::T_dynamic_cast));
  3042. }
  3043. | KW_CONST_CAST '<' full_type '>' '(' const_expr_comma ')'
  3044. {
  3045. $$ = new CPPExpression(CPPExpression::typecast_op($3, $6, CPPExpression::T_const_cast));
  3046. }
  3047. | KW_REINTERPRET_CAST '<' full_type '>' '(' const_expr_comma ')'
  3048. {
  3049. $$ = new CPPExpression(CPPExpression::typecast_op($3, $6, CPPExpression::T_reinterpret_cast));
  3050. }
  3051. | KW_SIZEOF '(' full_type ')' %prec UNARY
  3052. {
  3053. $$ = new CPPExpression(CPPExpression::sizeof_func($3));
  3054. }
  3055. | KW_SIZEOF no_angle_bracket_const_expr %prec UNARY
  3056. {
  3057. $$ = new CPPExpression(CPPExpression::sizeof_func($2));
  3058. }
  3059. | KW_SIZEOF ELLIPSIS '(' name ')' %prec UNARY
  3060. {
  3061. $$ = new CPPExpression(CPPExpression::sizeof_ellipsis_func($4));
  3062. }
  3063. | KW_ALIGNOF '(' full_type ')' %prec UNARY
  3064. {
  3065. $$ = new CPPExpression(CPPExpression::alignof_func($3));
  3066. }
  3067. | '!' no_angle_bracket_const_expr %prec UNARY
  3068. {
  3069. $$ = new CPPExpression(UNARY_NOT, $2);
  3070. }
  3071. | '~' no_angle_bracket_const_expr %prec UNARY
  3072. {
  3073. $$ = new CPPExpression(UNARY_NEGATE, $2);
  3074. }
  3075. | '-' no_angle_bracket_const_expr %prec UNARY
  3076. {
  3077. $$ = new CPPExpression(UNARY_MINUS, $2);
  3078. }
  3079. | '+' no_angle_bracket_const_expr %prec UNARY
  3080. {
  3081. $$ = new CPPExpression(UNARY_PLUS, $2);
  3082. }
  3083. | '*' no_angle_bracket_const_expr %prec UNARY
  3084. {
  3085. $$ = new CPPExpression(UNARY_STAR, $2);
  3086. }
  3087. | '&' no_angle_bracket_const_expr %prec UNARY
  3088. {
  3089. $$ = new CPPExpression(UNARY_REF, $2);
  3090. }
  3091. | no_angle_bracket_const_expr '*' no_angle_bracket_const_expr
  3092. {
  3093. $$ = new CPPExpression('*', $1, $3);
  3094. }
  3095. | no_angle_bracket_const_expr '/' no_angle_bracket_const_expr
  3096. {
  3097. $$ = new CPPExpression('/', $1, $3);
  3098. }
  3099. | no_angle_bracket_const_expr '%' no_angle_bracket_const_expr
  3100. {
  3101. $$ = new CPPExpression('%', $1, $3);
  3102. }
  3103. | no_angle_bracket_const_expr '+' no_angle_bracket_const_expr
  3104. {
  3105. $$ = new CPPExpression('+', $1, $3);
  3106. }
  3107. | no_angle_bracket_const_expr '-' no_angle_bracket_const_expr
  3108. {
  3109. $$ = new CPPExpression('-', $1, $3);
  3110. }
  3111. | no_angle_bracket_const_expr '|' no_angle_bracket_const_expr
  3112. {
  3113. $$ = new CPPExpression('|', $1, $3);
  3114. }
  3115. | no_angle_bracket_const_expr '^' no_angle_bracket_const_expr
  3116. {
  3117. $$ = new CPPExpression('^', $1, $3);
  3118. }
  3119. | no_angle_bracket_const_expr '&' no_angle_bracket_const_expr
  3120. {
  3121. $$ = new CPPExpression('&', $1, $3);
  3122. }
  3123. | no_angle_bracket_const_expr OROR no_angle_bracket_const_expr
  3124. {
  3125. $$ = new CPPExpression(OROR, $1, $3);
  3126. }
  3127. | no_angle_bracket_const_expr ANDAND no_angle_bracket_const_expr
  3128. {
  3129. $$ = new CPPExpression(ANDAND, $1, $3);
  3130. }
  3131. | no_angle_bracket_const_expr EQCOMPARE no_angle_bracket_const_expr
  3132. {
  3133. $$ = new CPPExpression(EQCOMPARE, $1, $3);
  3134. }
  3135. | no_angle_bracket_const_expr NECOMPARE no_angle_bracket_const_expr
  3136. {
  3137. $$ = new CPPExpression(NECOMPARE, $1, $3);
  3138. }
  3139. | no_angle_bracket_const_expr LECOMPARE no_angle_bracket_const_expr
  3140. {
  3141. $$ = new CPPExpression(LECOMPARE, $1, $3);
  3142. }
  3143. | no_angle_bracket_const_expr GECOMPARE no_angle_bracket_const_expr
  3144. {
  3145. $$ = new CPPExpression(GECOMPARE, $1, $3);
  3146. }
  3147. | no_angle_bracket_const_expr LSHIFT no_angle_bracket_const_expr
  3148. {
  3149. $$ = new CPPExpression(LSHIFT, $1, $3);
  3150. }
  3151. | no_angle_bracket_const_expr RSHIFT no_angle_bracket_const_expr
  3152. {
  3153. $$ = new CPPExpression(RSHIFT, $1, $3);
  3154. }
  3155. | no_angle_bracket_const_expr '?' no_angle_bracket_const_expr ':' no_angle_bracket_const_expr
  3156. {
  3157. $$ = new CPPExpression('?', $1, $3, $5);
  3158. }
  3159. | no_angle_bracket_const_expr '[' const_expr ']'
  3160. {
  3161. $$ = new CPPExpression('[', $1, $3);
  3162. }
  3163. | no_angle_bracket_const_expr '(' const_expr_comma ')'
  3164. {
  3165. $$ = new CPPExpression('f', $1, $3);
  3166. }
  3167. | no_angle_bracket_const_expr '(' ')'
  3168. {
  3169. $$ = new CPPExpression('f', $1);
  3170. }
  3171. | no_angle_bracket_const_expr '.' name
  3172. {
  3173. $$ = new CPPExpression('.', $1, new CPPExpression($3, current_scope, global_scope, current_lexer));
  3174. }
  3175. | no_angle_bracket_const_expr POINTSAT no_angle_bracket_const_expr
  3176. {
  3177. $$ = new CPPExpression(POINTSAT, $1, $3);
  3178. }
  3179. | '(' const_expr_comma ')'
  3180. {
  3181. $$ = $2;
  3182. }
  3183. ;
  3184. const_expr:
  3185. const_operand
  3186. {
  3187. $$ = $1;
  3188. }
  3189. | '(' full_type ')' const_expr %prec UNARY
  3190. {
  3191. $$ = new CPPExpression(CPPExpression::typecast_op($2, $4));
  3192. }
  3193. | KW_STATIC_CAST '<' full_type '>' '(' const_expr_comma ')'
  3194. {
  3195. $$ = new CPPExpression(CPPExpression::typecast_op($3, $6, CPPExpression::T_static_cast));
  3196. }
  3197. | KW_DYNAMIC_CAST '<' full_type '>' '(' const_expr_comma ')'
  3198. {
  3199. $$ = new CPPExpression(CPPExpression::typecast_op($3, $6, CPPExpression::T_dynamic_cast));
  3200. }
  3201. | KW_CONST_CAST '<' full_type '>' '(' const_expr_comma ')'
  3202. {
  3203. $$ = new CPPExpression(CPPExpression::typecast_op($3, $6, CPPExpression::T_const_cast));
  3204. }
  3205. | KW_REINTERPRET_CAST '<' full_type '>' '(' const_expr_comma ')'
  3206. {
  3207. $$ = new CPPExpression(CPPExpression::typecast_op($3, $6, CPPExpression::T_reinterpret_cast));
  3208. }
  3209. | TYPENAME_IDENTIFIER '(' optional_const_expr_comma ')'
  3210. {
  3211. // A constructor call.
  3212. CPPType *type = $1->find_type(current_scope, global_scope, false, current_lexer);
  3213. if (type == nullptr) {
  3214. yyerror(string("internal error resolving type ") + $1->get_fully_scoped_name(), @1);
  3215. }
  3216. assert(type != nullptr);
  3217. $$ = new CPPExpression(CPPExpression::construct_op(type, $3));
  3218. }
  3219. | TYPENAME_IDENTIFIER '{' optional_const_expr_comma '}'
  3220. {
  3221. // Aggregate initialization.
  3222. CPPType *type = $1->find_type(current_scope, global_scope, false, current_lexer);
  3223. if (type == nullptr) {
  3224. yyerror(string("internal error resolving type ") + $1->get_fully_scoped_name(), @1);
  3225. }
  3226. assert(type != nullptr);
  3227. $$ = new CPPExpression(CPPExpression::aggregate_init_op(type, $3));
  3228. }
  3229. | KW_INT '(' optional_const_expr_comma ')'
  3230. {
  3231. CPPType *type =
  3232. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_int));
  3233. $$ = new CPPExpression(CPPExpression::construct_op(type, $3));
  3234. }
  3235. | KW_CHAR '(' optional_const_expr_comma ')'
  3236. {
  3237. CPPType *type =
  3238. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_char));
  3239. $$ = new CPPExpression(CPPExpression::construct_op(type, $3));
  3240. }
  3241. | KW_WCHAR_T '(' optional_const_expr_comma ')'
  3242. {
  3243. CPPType *type =
  3244. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_wchar_t));
  3245. $$ = new CPPExpression(CPPExpression::construct_op(type, $3));
  3246. }
  3247. | KW_CHAR16_T '(' optional_const_expr_comma ')'
  3248. {
  3249. CPPType *type =
  3250. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_char16_t));
  3251. $$ = new CPPExpression(CPPExpression::construct_op(type, $3));
  3252. }
  3253. | KW_CHAR32_T '(' optional_const_expr_comma ')'
  3254. {
  3255. CPPType *type =
  3256. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_char32_t));
  3257. $$ = new CPPExpression(CPPExpression::construct_op(type, $3));
  3258. }
  3259. | KW_BOOL '(' optional_const_expr_comma ')'
  3260. {
  3261. CPPType *type =
  3262. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_bool));
  3263. $$ = new CPPExpression(CPPExpression::construct_op(type, $3));
  3264. }
  3265. | KW_SHORT '(' optional_const_expr_comma ')'
  3266. {
  3267. CPPType *type =
  3268. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_int,
  3269. CPPSimpleType::F_short));
  3270. $$ = new CPPExpression(CPPExpression::construct_op(type, $3));
  3271. }
  3272. | KW_LONG '(' optional_const_expr_comma ')'
  3273. {
  3274. CPPType *type =
  3275. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_int,
  3276. CPPSimpleType::F_long));
  3277. $$ = new CPPExpression(CPPExpression::construct_op(type, $3));
  3278. }
  3279. | KW_UNSIGNED '(' optional_const_expr_comma ')'
  3280. {
  3281. CPPType *type =
  3282. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_int,
  3283. CPPSimpleType::F_unsigned));
  3284. $$ = new CPPExpression(CPPExpression::construct_op(type, $3));
  3285. }
  3286. | KW_SIGNED '(' optional_const_expr_comma ')'
  3287. {
  3288. CPPType *type =
  3289. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_int,
  3290. CPPSimpleType::F_signed));
  3291. $$ = new CPPExpression(CPPExpression::construct_op(type, $3));
  3292. }
  3293. | KW_FLOAT '(' optional_const_expr_comma ')'
  3294. {
  3295. CPPType *type =
  3296. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_float));
  3297. $$ = new CPPExpression(CPPExpression::construct_op(type, $3));
  3298. }
  3299. | KW_DOUBLE '(' optional_const_expr_comma ')'
  3300. {
  3301. CPPType *type =
  3302. CPPType::new_type(new CPPSimpleType(CPPSimpleType::T_double));
  3303. $$ = new CPPExpression(CPPExpression::construct_op(type, $3));
  3304. }
  3305. | KW_SIZEOF '(' full_type ')' %prec UNARY
  3306. {
  3307. $$ = new CPPExpression(CPPExpression::sizeof_func($3));
  3308. }
  3309. | KW_SIZEOF const_expr %prec UNARY
  3310. {
  3311. $$ = new CPPExpression(CPPExpression::sizeof_func($2));
  3312. }
  3313. | KW_SIZEOF ELLIPSIS '(' name ')' %prec UNARY
  3314. {
  3315. $$ = new CPPExpression(CPPExpression::sizeof_ellipsis_func($4));
  3316. }
  3317. | KW_ALIGNOF '(' full_type ')' %prec UNARY
  3318. {
  3319. $$ = new CPPExpression(CPPExpression::alignof_func($3));
  3320. }
  3321. | KW_NEW predefined_type %prec UNARY
  3322. {
  3323. $$ = new CPPExpression(CPPExpression::new_op($2));
  3324. }
  3325. | KW_NEW predefined_type '(' optional_const_expr_comma ')' %prec UNARY
  3326. {
  3327. $$ = new CPPExpression(CPPExpression::new_op($2, $4));
  3328. }
  3329. | KW_TYPEID '(' full_type ')'
  3330. {
  3331. CPPIdentifier ident("");
  3332. ident.add_name("std");
  3333. ident.add_name("type_info");
  3334. CPPType *std_type_info = ident.find_type(current_scope, global_scope, false, current_lexer);
  3335. if (!std_type_info) {
  3336. yywarning("cannot use typeid before including <typeinfo>", @1);
  3337. }
  3338. $$ = new CPPExpression(CPPExpression::typeid_op($3, std_type_info));
  3339. }
  3340. | KW_TYPEID '(' const_expr ')'
  3341. {
  3342. CPPIdentifier ident("");
  3343. ident.add_name("std");
  3344. ident.add_name("type_info");
  3345. CPPType *std_type_info = ident.find_type(current_scope, global_scope, false, current_lexer);
  3346. if (!std_type_info) {
  3347. yywarning("cannot use typeid before including <typeinfo>", @1);
  3348. }
  3349. $$ = new CPPExpression(CPPExpression::typeid_op($3, std_type_info));
  3350. }
  3351. | '!' const_expr %prec UNARY
  3352. {
  3353. $$ = new CPPExpression(UNARY_NOT, $2);
  3354. }
  3355. | '~' const_expr %prec UNARY
  3356. {
  3357. $$ = new CPPExpression(UNARY_NEGATE, $2);
  3358. }
  3359. | '-' const_expr %prec UNARY
  3360. {
  3361. $$ = new CPPExpression(UNARY_MINUS, $2);
  3362. }
  3363. | '+' const_expr %prec UNARY
  3364. {
  3365. $$ = new CPPExpression(UNARY_PLUS, $2);
  3366. }
  3367. | '*' const_expr %prec UNARY
  3368. {
  3369. $$ = new CPPExpression(UNARY_STAR, $2);
  3370. }
  3371. | '&' const_expr %prec UNARY
  3372. {
  3373. $$ = new CPPExpression(UNARY_REF, $2);
  3374. }
  3375. | const_expr '*' const_expr
  3376. {
  3377. $$ = new CPPExpression('*', $1, $3);
  3378. }
  3379. | const_expr '/' const_expr
  3380. {
  3381. $$ = new CPPExpression('/', $1, $3);
  3382. }
  3383. | const_expr '%' const_expr
  3384. {
  3385. $$ = new CPPExpression('%', $1, $3);
  3386. }
  3387. | const_expr '+' const_expr
  3388. {
  3389. $$ = new CPPExpression('+', $1, $3);
  3390. }
  3391. | const_expr '-' const_expr
  3392. {
  3393. $$ = new CPPExpression('-', $1, $3);
  3394. }
  3395. | const_expr '|' const_expr
  3396. {
  3397. $$ = new CPPExpression('|', $1, $3);
  3398. }
  3399. | const_expr '^' const_expr
  3400. {
  3401. $$ = new CPPExpression('^', $1, $3);
  3402. }
  3403. | const_expr '&' const_expr
  3404. {
  3405. $$ = new CPPExpression('&', $1, $3);
  3406. }
  3407. | const_expr OROR const_expr
  3408. {
  3409. $$ = new CPPExpression(OROR, $1, $3);
  3410. }
  3411. | const_expr ANDAND const_expr
  3412. {
  3413. $$ = new CPPExpression(ANDAND, $1, $3);
  3414. }
  3415. | const_expr EQCOMPARE const_expr
  3416. {
  3417. $$ = new CPPExpression(EQCOMPARE, $1, $3);
  3418. }
  3419. | const_expr NECOMPARE const_expr
  3420. {
  3421. $$ = new CPPExpression(NECOMPARE, $1, $3);
  3422. }
  3423. | const_expr LECOMPARE const_expr
  3424. {
  3425. $$ = new CPPExpression(LECOMPARE, $1, $3);
  3426. }
  3427. | const_expr GECOMPARE const_expr
  3428. {
  3429. $$ = new CPPExpression(GECOMPARE, $1, $3);
  3430. }
  3431. | const_expr '<' const_expr
  3432. {
  3433. $$ = new CPPExpression('<', $1, $3);
  3434. }
  3435. | const_expr '>' const_expr
  3436. {
  3437. $$ = new CPPExpression('>', $1, $3);
  3438. }
  3439. | const_expr LSHIFT const_expr
  3440. {
  3441. $$ = new CPPExpression(LSHIFT, $1, $3);
  3442. }
  3443. | const_expr RSHIFT const_expr
  3444. {
  3445. $$ = new CPPExpression(RSHIFT, $1, $3);
  3446. }
  3447. | const_expr '?' const_expr ':' const_expr
  3448. {
  3449. $$ = new CPPExpression('?', $1, $3, $5);
  3450. }
  3451. | const_expr '[' const_expr ']'
  3452. {
  3453. $$ = new CPPExpression('[', $1, $3);
  3454. }
  3455. | const_expr '(' const_expr_comma ')'
  3456. {
  3457. $$ = new CPPExpression('f', $1, $3);
  3458. }
  3459. | const_expr '(' ')'
  3460. {
  3461. $$ = new CPPExpression('f', $1);
  3462. }
  3463. | const_expr '.' name
  3464. {
  3465. $$ = new CPPExpression('.', $1, new CPPExpression($3, current_scope, global_scope, current_lexer));
  3466. }
  3467. | const_expr POINTSAT const_expr
  3468. {
  3469. $$ = new CPPExpression(POINTSAT, $1, $3);
  3470. }
  3471. | '(' const_expr_comma ')'
  3472. {
  3473. $$ = $2;
  3474. }
  3475. ;
  3476. const_operand:
  3477. INTEGER
  3478. {
  3479. $$ = new CPPExpression($1);
  3480. }
  3481. | KW_TRUE
  3482. {
  3483. $$ = new CPPExpression(true);
  3484. }
  3485. | KW_FALSE
  3486. {
  3487. $$ = new CPPExpression(false);
  3488. }
  3489. | CHAR_TOK
  3490. {
  3491. $$ = new CPPExpression($1);
  3492. }
  3493. | REAL
  3494. {
  3495. $$ = new CPPExpression($1);
  3496. }
  3497. | string_literal
  3498. {
  3499. $$ = $1;
  3500. }
  3501. | CUSTOM_LITERAL
  3502. {
  3503. $$ = $1;
  3504. }
  3505. | IDENTIFIER
  3506. {
  3507. $$ = new CPPExpression($1, current_scope, global_scope, current_lexer);
  3508. }
  3509. | KW_FINAL
  3510. {
  3511. // A variable named "final". C++11 explicitly permits this.
  3512. CPPIdentifier *ident = new CPPIdentifier("final", @1);
  3513. $$ = new CPPExpression(ident, current_scope, global_scope, current_lexer);
  3514. }
  3515. | KW_OVERRIDE
  3516. {
  3517. // A variable named "override". C++11 explicitly permits this.
  3518. CPPIdentifier *ident = new CPPIdentifier("override", @1);
  3519. $$ = new CPPExpression(ident, current_scope, global_scope, current_lexer);
  3520. }
  3521. | KW_NULLPTR
  3522. {
  3523. $$ = new CPPExpression(CPPExpression::get_nullptr());
  3524. }
  3525. | '[' capture_list ']' function_post maybe_trailing_return_type '{' code '}'
  3526. {
  3527. $2->_flags = $4;
  3528. $2->_return_type = $5;
  3529. $$ = new CPPExpression(CPPExpression::lambda($2));
  3530. }
  3531. | '[' capture_list ']' '(' function_parameter_list ')' function_post maybe_trailing_return_type '{' code '}'
  3532. {
  3533. $2->_parameters = $5;
  3534. $2->_flags = $7;
  3535. $2->_return_type = $8;
  3536. $$ = new CPPExpression(CPPExpression::lambda($2));
  3537. }
  3538. | KW_HAS_VIRTUAL_DESTRUCTOR '(' full_type ')'
  3539. {
  3540. $$ = new CPPExpression(CPPExpression::type_trait(KW_HAS_VIRTUAL_DESTRUCTOR, $3));
  3541. }
  3542. | KW_IS_ABSTRACT '(' full_type ')'
  3543. {
  3544. $$ = new CPPExpression(CPPExpression::type_trait(KW_IS_ABSTRACT, $3));
  3545. }
  3546. | KW_IS_BASE_OF '(' full_type ',' full_type ')'
  3547. {
  3548. $$ = new CPPExpression(CPPExpression::type_trait(KW_IS_CLASS, $3, $5));
  3549. }
  3550. | KW_IS_CLASS '(' full_type ')'
  3551. {
  3552. $$ = new CPPExpression(CPPExpression::type_trait(KW_IS_CLASS, $3));
  3553. }
  3554. | KW_IS_CONSTRUCTIBLE '(' full_type ')'
  3555. {
  3556. $$ = new CPPExpression(CPPExpression::type_trait(KW_IS_CONSTRUCTIBLE, $3));
  3557. }
  3558. | KW_IS_CONSTRUCTIBLE '(' full_type ',' full_type ')'
  3559. {
  3560. $$ = new CPPExpression(CPPExpression::type_trait(KW_IS_CONSTRUCTIBLE, $3, $5));
  3561. }
  3562. | KW_IS_CONVERTIBLE_TO '(' full_type ',' full_type ')'
  3563. {
  3564. $$ = new CPPExpression(CPPExpression::type_trait(KW_IS_CONVERTIBLE_TO, $3, $5));
  3565. }
  3566. | KW_IS_DESTRUCTIBLE '(' full_type ')'
  3567. {
  3568. $$ = new CPPExpression(CPPExpression::type_trait(KW_IS_DESTRUCTIBLE, $3));
  3569. }
  3570. | KW_IS_EMPTY '(' full_type ')'
  3571. {
  3572. $$ = new CPPExpression(CPPExpression::type_trait(KW_IS_EMPTY, $3));
  3573. }
  3574. | KW_IS_ENUM '(' full_type ')'
  3575. {
  3576. $$ = new CPPExpression(CPPExpression::type_trait(KW_IS_ENUM, $3));
  3577. }
  3578. | KW_IS_FINAL '(' full_type ')'
  3579. {
  3580. $$ = new CPPExpression(CPPExpression::type_trait(KW_IS_FINAL, $3));
  3581. }
  3582. | KW_IS_FUNDAMENTAL '(' full_type ')'
  3583. {
  3584. $$ = new CPPExpression(CPPExpression::type_trait(KW_IS_FUNDAMENTAL, $3));
  3585. }
  3586. | KW_IS_POD '(' full_type ')'
  3587. {
  3588. $$ = new CPPExpression(CPPExpression::type_trait(KW_IS_POD, $3));
  3589. }
  3590. | KW_IS_POLYMORPHIC '(' full_type ')'
  3591. {
  3592. $$ = new CPPExpression(CPPExpression::type_trait(KW_IS_POLYMORPHIC, $3));
  3593. }
  3594. | KW_IS_STANDARD_LAYOUT '(' full_type ')'
  3595. {
  3596. $$ = new CPPExpression(CPPExpression::type_trait(KW_IS_STANDARD_LAYOUT, $3));
  3597. }
  3598. | KW_IS_TRIVIAL '(' full_type ')'
  3599. {
  3600. $$ = new CPPExpression(CPPExpression::type_trait(KW_IS_TRIVIAL, $3));
  3601. }
  3602. | KW_IS_UNION '(' full_type ')'
  3603. {
  3604. $$ = new CPPExpression(CPPExpression::type_trait(KW_IS_UNION, $3));
  3605. }
  3606. ;
  3607. /* This is used for a const_expr as a "formal parameter", which really
  3608. means an instance declaration using a parameter list (which looks a
  3609. lot like a function prototype). It differs from const_expr mainly
  3610. in that it forbids some expressions unless they are parenthesized,
  3611. to avoid shift/reduce conflicts with the actual formal parameter
  3612. definition. */
  3613. formal_const_expr:
  3614. formal_const_operand
  3615. {
  3616. $$ = $1;
  3617. }
  3618. | '(' full_type ')' const_expr %prec UNARY
  3619. {
  3620. $$ = new CPPExpression(CPPExpression::typecast_op($2, $4));
  3621. }
  3622. | KW_STATIC_CAST '<' full_type '>' '(' const_expr_comma ')'
  3623. {
  3624. $$ = new CPPExpression(CPPExpression::typecast_op($3, $6, CPPExpression::T_static_cast));
  3625. }
  3626. | KW_DYNAMIC_CAST '<' full_type '>' '(' const_expr_comma ')'
  3627. {
  3628. $$ = new CPPExpression(CPPExpression::typecast_op($3, $6, CPPExpression::T_dynamic_cast));
  3629. }
  3630. | KW_CONST_CAST '<' full_type '>' '(' const_expr_comma ')'
  3631. {
  3632. $$ = new CPPExpression(CPPExpression::typecast_op($3, $6, CPPExpression::T_const_cast));
  3633. }
  3634. | KW_REINTERPRET_CAST '<' full_type '>' '(' const_expr_comma ')'
  3635. {
  3636. $$ = new CPPExpression(CPPExpression::typecast_op($3, $6, CPPExpression::T_reinterpret_cast));
  3637. }
  3638. | KW_SIZEOF '(' full_type ')' %prec UNARY
  3639. {
  3640. $$ = new CPPExpression(CPPExpression::sizeof_func($3));
  3641. }
  3642. | KW_SIZEOF formal_const_expr %prec UNARY
  3643. {
  3644. $$ = new CPPExpression(CPPExpression::sizeof_func($2));
  3645. }
  3646. | KW_SIZEOF ELLIPSIS '(' name ')' %prec UNARY
  3647. {
  3648. $$ = new CPPExpression(CPPExpression::sizeof_ellipsis_func($4));
  3649. }
  3650. | KW_ALIGNOF '(' full_type ')' %prec UNARY
  3651. {
  3652. $$ = new CPPExpression(CPPExpression::alignof_func($3));
  3653. }
  3654. | KW_NEW predefined_type %prec UNARY
  3655. {
  3656. $$ = new CPPExpression(CPPExpression::new_op($2));
  3657. }
  3658. | KW_NEW predefined_type '(' optional_const_expr_comma ')' %prec UNARY
  3659. {
  3660. $$ = new CPPExpression(CPPExpression::new_op($2, $4));
  3661. }
  3662. | KW_TYPEID '(' full_type ')'
  3663. {
  3664. CPPIdentifier ident("");
  3665. ident.add_name("std");
  3666. ident.add_name("type_info");
  3667. CPPType *std_type_info = ident.find_type(current_scope, global_scope, false, current_lexer);
  3668. if (!std_type_info) {
  3669. yywarning("cannot use typeid before including <typeinfo>", @1);
  3670. }
  3671. $$ = new CPPExpression(CPPExpression::typeid_op($3, std_type_info));
  3672. }
  3673. | KW_TYPEID '(' const_expr ')'
  3674. {
  3675. CPPIdentifier ident("");
  3676. ident.add_name("std");
  3677. ident.add_name("type_info");
  3678. CPPType *std_type_info = ident.find_type(current_scope, global_scope, false, current_lexer);
  3679. if (!std_type_info) {
  3680. yywarning("cannot use typeid before including <typeinfo>", @1);
  3681. }
  3682. $$ = new CPPExpression(CPPExpression::typeid_op($3, std_type_info));
  3683. }
  3684. | '!' const_expr %prec UNARY
  3685. {
  3686. $$ = new CPPExpression(UNARY_NOT, $2);
  3687. }
  3688. | '~' const_expr %prec UNARY
  3689. {
  3690. $$ = new CPPExpression(UNARY_NEGATE, $2);
  3691. }
  3692. | '-' const_expr %prec UNARY
  3693. {
  3694. $$ = new CPPExpression(UNARY_MINUS, $2);
  3695. }
  3696. | '+' const_expr %prec UNARY
  3697. {
  3698. $$ = new CPPExpression(UNARY_PLUS, $2);
  3699. }
  3700. | '&' const_expr %prec UNARY
  3701. {
  3702. $$ = new CPPExpression(UNARY_REF, $2);
  3703. }
  3704. | formal_const_expr '*' const_expr
  3705. {
  3706. $$ = new CPPExpression('*', $1, $3);
  3707. }
  3708. | formal_const_expr '/' const_expr
  3709. {
  3710. $$ = new CPPExpression('/', $1, $3);
  3711. }
  3712. | formal_const_expr '%' const_expr
  3713. {
  3714. $$ = new CPPExpression('%', $1, $3);
  3715. }
  3716. | formal_const_expr '+' const_expr
  3717. {
  3718. $$ = new CPPExpression('+', $1, $3);
  3719. }
  3720. | formal_const_expr '-' const_expr
  3721. {
  3722. $$ = new CPPExpression('-', $1, $3);
  3723. }
  3724. | formal_const_expr '|' const_expr
  3725. {
  3726. $$ = new CPPExpression('|', $1, $3);
  3727. }
  3728. | formal_const_expr '^' const_expr
  3729. {
  3730. $$ = new CPPExpression('^', $1, $3);
  3731. }
  3732. | formal_const_expr '&' const_expr
  3733. {
  3734. $$ = new CPPExpression('&', $1, $3);
  3735. }
  3736. | formal_const_expr OROR const_expr
  3737. {
  3738. $$ = new CPPExpression(OROR, $1, $3);
  3739. }
  3740. | formal_const_expr ANDAND const_expr
  3741. {
  3742. $$ = new CPPExpression(ANDAND, $1, $3);
  3743. }
  3744. | formal_const_expr EQCOMPARE const_expr
  3745. {
  3746. $$ = new CPPExpression(EQCOMPARE, $1, $3);
  3747. }
  3748. | formal_const_expr NECOMPARE const_expr
  3749. {
  3750. $$ = new CPPExpression(NECOMPARE, $1, $3);
  3751. }
  3752. | formal_const_expr LECOMPARE const_expr
  3753. {
  3754. $$ = new CPPExpression(LECOMPARE, $1, $3);
  3755. }
  3756. | formal_const_expr GECOMPARE const_expr
  3757. {
  3758. $$ = new CPPExpression(GECOMPARE, $1, $3);
  3759. }
  3760. | formal_const_expr '<' const_expr
  3761. {
  3762. $$ = new CPPExpression('<', $1, $3);
  3763. }
  3764. | formal_const_expr '>' const_expr
  3765. {
  3766. $$ = new CPPExpression('>', $1, $3);
  3767. }
  3768. | formal_const_expr LSHIFT const_expr
  3769. {
  3770. $$ = new CPPExpression(LSHIFT, $1, $3);
  3771. }
  3772. | formal_const_expr RSHIFT const_expr
  3773. {
  3774. $$ = new CPPExpression(RSHIFT, $1, $3);
  3775. }
  3776. | formal_const_expr '?' const_expr ':' const_expr
  3777. {
  3778. $$ = new CPPExpression('?', $1, $3, $5);
  3779. }
  3780. | formal_const_expr '[' const_expr ']'
  3781. {
  3782. $$ = new CPPExpression('[', $1, $3);
  3783. }
  3784. | formal_const_expr '(' const_expr_comma ')'
  3785. {
  3786. $$ = new CPPExpression('f', $1, $3);
  3787. }
  3788. | formal_const_expr '(' ')'
  3789. {
  3790. $$ = new CPPExpression('f', $1);
  3791. }
  3792. | formal_const_expr '.' name
  3793. {
  3794. $$ = new CPPExpression('.', $1, new CPPExpression($3, current_scope, global_scope, current_lexer));
  3795. }
  3796. | formal_const_expr POINTSAT const_expr
  3797. {
  3798. $$ = new CPPExpression(POINTSAT, $1, $3);
  3799. }
  3800. | '(' const_expr_comma ')'
  3801. {
  3802. $$ = $2;
  3803. }
  3804. ;
  3805. formal_const_operand:
  3806. INTEGER
  3807. {
  3808. $$ = new CPPExpression($1);
  3809. }
  3810. | KW_TRUE
  3811. {
  3812. $$ = new CPPExpression(true);
  3813. }
  3814. | KW_FALSE
  3815. {
  3816. $$ = new CPPExpression(false);
  3817. }
  3818. | CHAR_TOK
  3819. {
  3820. $$ = new CPPExpression($1);
  3821. }
  3822. | REAL
  3823. {
  3824. $$ = new CPPExpression($1);
  3825. }
  3826. | string_literal
  3827. {
  3828. $$ = $1;
  3829. }
  3830. | CUSTOM_LITERAL
  3831. {
  3832. $$ = $1;
  3833. }
  3834. | IDENTIFIER
  3835. {
  3836. $$ = new CPPExpression($1, current_scope, global_scope, current_lexer);
  3837. }
  3838. | KW_FINAL
  3839. {
  3840. // A variable named "final". C++11 explicitly permits this.
  3841. CPPIdentifier *ident = new CPPIdentifier("final", @1);
  3842. $$ = new CPPExpression(ident, current_scope, global_scope, current_lexer);
  3843. }
  3844. | KW_OVERRIDE
  3845. {
  3846. // A variable named "override". C++11 explicitly permits this.
  3847. CPPIdentifier *ident = new CPPIdentifier("override", @1);
  3848. $$ = new CPPExpression(ident, current_scope, global_scope, current_lexer);
  3849. }
  3850. | KW_NULLPTR
  3851. {
  3852. $$ = new CPPExpression(CPPExpression::get_nullptr());
  3853. }
  3854. ;
  3855. /* The contents of the [] list preceding a lambda expression. */
  3856. capture_list:
  3857. empty
  3858. {
  3859. $$ = new CPPClosureType();
  3860. }
  3861. | '='
  3862. {
  3863. $$ = new CPPClosureType(CPPClosureType::CT_by_value);
  3864. }
  3865. | '&'
  3866. {
  3867. $$ = new CPPClosureType(CPPClosureType::CT_by_reference);
  3868. }
  3869. | capture maybe_initialize
  3870. {
  3871. $$ = new CPPClosureType();
  3872. $1->_initializer = $2;
  3873. $$->_captures.push_back(*$1);
  3874. delete $1;
  3875. }
  3876. | capture_list ',' capture maybe_initialize
  3877. {
  3878. $$ = $1;
  3879. $3->_initializer = $4;
  3880. $$->_captures.push_back(*$3);
  3881. delete $3;
  3882. }
  3883. ;
  3884. capture:
  3885. '&' name
  3886. {
  3887. $$ = new CPPClosureType::Capture;
  3888. $$->_name = $2->get_simple_name();
  3889. $$->_type = CPPClosureType::CT_by_reference;
  3890. }
  3891. | '&' name ELLIPSIS
  3892. {
  3893. $$ = new CPPClosureType::Capture;
  3894. $$->_name = $2->get_simple_name();
  3895. $$->_type = CPPClosureType::CT_by_reference;
  3896. }
  3897. | name
  3898. {
  3899. $$ = new CPPClosureType::Capture;
  3900. $$->_name = $1->get_simple_name();
  3901. if ($$->_name == "this") {
  3902. $$->_type = CPPClosureType::CT_by_reference;
  3903. } else {
  3904. $$->_type = CPPClosureType::CT_by_value;
  3905. }
  3906. }
  3907. | '*' name
  3908. {
  3909. $$ = new CPPClosureType::Capture;
  3910. $$->_name = $2->get_simple_name();
  3911. $$->_type = CPPClosureType::CT_by_value;
  3912. if ($$->_name != "this") {
  3913. yywarning("only capture name 'this' may be preceded by an asterisk", @2);
  3914. }
  3915. }
  3916. ;
  3917. class_derivation_name:
  3918. name
  3919. {
  3920. CPPType *type = $1->find_type(current_scope, global_scope, true);
  3921. if (type == nullptr) {
  3922. type = CPPType::new_type(new CPPTBDType($1));
  3923. }
  3924. $$ = type;
  3925. }
  3926. | KW_TYPENAME name
  3927. {
  3928. $$ = CPPType::new_type(new CPPTBDType($2));
  3929. }
  3930. | name ELLIPSIS
  3931. {
  3932. CPPClassTemplateParameter *ctp = new CPPClassTemplateParameter($1);
  3933. ctp->_packed = true;
  3934. $$ = CPPType::new_type(ctp);
  3935. }
  3936. ;
  3937. /*
  3938. typedefname:
  3939. TYPENAME_IDENTIFIER
  3940. {
  3941. CPPType *type = $1->find_type(current_scope, global_scope, false, current_lexer);
  3942. if (type == NULL) {
  3943. yyerror(string("internal error resolving type ") + $1->get_fully_scoped_name(), @1);
  3944. }
  3945. assert(type != NULL);
  3946. $$ = type;
  3947. }
  3948. | KW_TYPENAME name
  3949. {
  3950. $$ = CPPType::new_type(new CPPTBDType($2));
  3951. }
  3952. ;
  3953. */
  3954. /* Note that we should also accept "final" and "override" as valid names,
  3955. * according to C++11. */
  3956. name:
  3957. IDENTIFIER
  3958. {
  3959. $$ = $1;
  3960. }
  3961. | TYPENAME_IDENTIFIER
  3962. {
  3963. $$ = $1;
  3964. }
  3965. | TYPEPACK_IDENTIFIER
  3966. {
  3967. $$ = $1;
  3968. }
  3969. | KW_FINAL
  3970. {
  3971. $$ = new CPPIdentifier("final", @1);
  3972. }
  3973. | KW_OVERRIDE
  3974. {
  3975. $$ = new CPPIdentifier("override", @1);
  3976. }
  3977. | KW_SIGNED
  3978. {
  3979. // This is not a keyword in Python, so it is useful to be able to use this
  3980. // in MAKE_PROPERTY definitions, etc.
  3981. $$ = new CPPIdentifier("signed", @1);
  3982. }
  3983. | KW_FLOAT
  3984. {
  3985. $$ = new CPPIdentifier("float", @1);
  3986. }
  3987. | KW_PUBLIC
  3988. {
  3989. $$ = new CPPIdentifier("public", @1);
  3990. }
  3991. | KW_PRIVATE
  3992. {
  3993. $$ = new CPPIdentifier("private", @1);
  3994. }
  3995. | KW_STATIC
  3996. {
  3997. $$ = new CPPIdentifier("static", @1);
  3998. }
  3999. | KW_DEFAULT
  4000. {
  4001. $$ = new CPPIdentifier("default", @1);
  4002. }
  4003. ;
  4004. /* A variant on name that's used for structs, where we disallow final
  4005. * to disambiguate the case of struct A final {};
  4006. */
  4007. name_no_final:
  4008. IDENTIFIER
  4009. {
  4010. $$ = $1;
  4011. }
  4012. | TYPENAME_IDENTIFIER
  4013. {
  4014. $$ = $1;
  4015. }
  4016. | TYPEPACK_IDENTIFIER
  4017. {
  4018. $$ = $1;
  4019. }
  4020. | KW_OVERRIDE
  4021. {
  4022. $$ = new CPPIdentifier("override", @1);
  4023. }
  4024. ;
  4025. string_literal:
  4026. SIMPLE_STRING
  4027. {
  4028. $$ = new CPPExpression($1);
  4029. }
  4030. | STRING_LITERAL
  4031. {
  4032. $$ = $1;
  4033. }
  4034. | string_literal SIMPLE_STRING
  4035. {
  4036. // The right string takes on the literal type of the left.
  4037. $$ = $1;
  4038. $$->_str += $2;
  4039. }
  4040. | string_literal STRING_LITERAL
  4041. {
  4042. // We have to check that the two literal types match up.
  4043. $$ = $1;
  4044. if ($2->_type != CPPExpression::T_string && $2->_type != $1->_type) {
  4045. yywarning("cannot concatenate two string literals of different types", @$);
  4046. }
  4047. $$->_str += $2->_str;
  4048. }
  4049. ;
  4050. empty:
  4051. ;