parser.y 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384
  1. %{
  2. /*
  3. * IDL Compiler
  4. *
  5. * Copyright 2002 Ove Kaaven
  6. * Copyright 2006-2008 Robert Shearman
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  21. */
  22. #include "config.h"
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <stdarg.h>
  26. #include <assert.h>
  27. #include <ctype.h>
  28. #include <string.h>
  29. #include "widl.h"
  30. #include "utils.h"
  31. #include "parser.h"
  32. #include "header.h"
  33. #include "typelib.h"
  34. #include "typegen.h"
  35. #include "expr.h"
  36. #include "typetree.h"
  37. struct _import_t
  38. {
  39. char *name;
  40. int import_performed;
  41. };
  42. static str_list_t *append_str(str_list_t *list, char *str);
  43. static attr_list_t *append_attr_list(attr_list_t *new_list, attr_list_t *old_list);
  44. static decl_spec_t *make_decl_spec(type_t *type, decl_spec_t *left, decl_spec_t *right,
  45. enum storage_class stgclass, enum type_qualifier qual, enum function_specifier func_specifier);
  46. static attr_t *make_attr(enum attr_type type);
  47. static attr_t *make_attrv(enum attr_type type, unsigned int val);
  48. static attr_t *make_custom_attr(UUID *id, expr_t *pval);
  49. static expr_list_t *append_expr(expr_list_t *list, expr_t *expr);
  50. static var_t *declare_var(attr_list_t *attrs, decl_spec_t *decl_spec, declarator_t *decl, int top);
  51. static var_list_t *set_var_types(attr_list_t *attrs, decl_spec_t *decl_spec, declarator_list_t *decls);
  52. static var_list_t *append_var_list(var_list_t *list, var_list_t *vars);
  53. static declarator_list_t *append_declarator(declarator_list_t *list, declarator_t *p);
  54. static declarator_t *make_declarator(var_t *var);
  55. static type_t *make_safearray(type_t *type);
  56. static typelib_t *make_library(const char *name, const attr_list_t *attrs);
  57. static void append_array(declarator_t *decl, expr_t *expr);
  58. static void append_chain_type(declarator_t *decl, type_t *type, enum type_qualifier qual);
  59. static void append_chain_callconv(type_t *chain, char *callconv);
  60. static warning_list_t *append_warning(warning_list_t *, int);
  61. static type_t *reg_typedefs(decl_spec_t *decl_spec, var_list_t *names, attr_list_t *attrs);
  62. static type_t *find_type_or_error(struct namespace *parent, const char *name);
  63. static struct namespace *find_namespace_or_error(struct namespace *namespace, const char *name);
  64. static var_t *reg_const(var_t *var);
  65. static void push_namespace(const char *name);
  66. static void pop_namespace(const char *name);
  67. static void push_parameters_namespace(const char *name);
  68. static void pop_parameters_namespace(const char *name);
  69. static statement_list_t *append_parameterized_type_stmts(statement_list_t *stmts);
  70. static void check_arg_attrs(const var_t *arg);
  71. static void check_statements(const statement_list_t *stmts, int is_inside_library);
  72. static void check_all_user_types(const statement_list_t *stmts);
  73. static attr_list_t *check_function_attrs(const char *name, attr_list_t *attrs);
  74. static attr_list_t *check_typedef_attrs(attr_list_t *attrs);
  75. static attr_list_t *check_enum_attrs(attr_list_t *attrs);
  76. static attr_list_t *check_enum_member_attrs(attr_list_t *attrs);
  77. static attr_list_t *check_struct_attrs(attr_list_t *attrs);
  78. static attr_list_t *check_union_attrs(attr_list_t *attrs);
  79. static attr_list_t *check_field_attrs(const char *name, attr_list_t *attrs);
  80. static attr_list_t *check_library_attrs(const char *name, attr_list_t *attrs);
  81. const char *get_attr_display_name(enum attr_type type);
  82. static void add_explicit_handle_if_necessary(const type_t *iface, var_t *func);
  83. static void check_async_uuid(type_t *iface);
  84. static statement_t *make_statement(enum statement_type type);
  85. static statement_t *make_statement_type_decl(type_t *type);
  86. static statement_t *make_statement_reference(type_t *type);
  87. static statement_t *make_statement_declaration(var_t *var);
  88. static statement_t *make_statement_library(typelib_t *typelib);
  89. static statement_t *make_statement_pragma(const char *str);
  90. static statement_t *make_statement_cppquote(const char *str);
  91. static statement_t *make_statement_importlib(const char *str);
  92. static statement_t *make_statement_module(type_t *type);
  93. static statement_t *make_statement_typedef(var_list_t *names, int declonly);
  94. static statement_t *make_statement_import(const char *str);
  95. static statement_t *make_statement_parameterized_type(type_t *type, typeref_list_t *params);
  96. static statement_t *make_statement_delegate(type_t *ret, var_list_t *args);
  97. static statement_list_t *append_statement(statement_list_t *list, statement_t *stmt);
  98. static statement_list_t *append_statements(statement_list_t *, statement_list_t *);
  99. static attr_list_t *append_attribs(attr_list_t *, attr_list_t *);
  100. static struct namespace global_namespace = {
  101. NULL, NULL, LIST_INIT(global_namespace.entry), LIST_INIT(global_namespace.children)
  102. };
  103. static struct namespace *current_namespace = &global_namespace;
  104. static struct namespace *parameters_namespace = NULL;
  105. static statement_list_t *parameterized_type_stmts = NULL;
  106. static typelib_t *current_typelib;
  107. %}
  108. %union {
  109. attr_t *attr;
  110. attr_list_t *attr_list;
  111. str_list_t *str_list;
  112. expr_t *expr;
  113. expr_list_t *expr_list;
  114. type_t *type;
  115. var_t *var;
  116. var_list_t *var_list;
  117. declarator_t *declarator;
  118. declarator_list_t *declarator_list;
  119. statement_t *statement;
  120. statement_list_t *stmt_list;
  121. warning_t *warning;
  122. warning_list_t *warning_list;
  123. typeref_t *typeref;
  124. typeref_list_t *typeref_list;
  125. char *str;
  126. UUID *uuid;
  127. unsigned int num;
  128. double dbl;
  129. typelib_t *typelib;
  130. struct _import_t *import;
  131. struct _decl_spec_t *declspec;
  132. enum storage_class stgclass;
  133. enum type_qualifier type_qualifier;
  134. enum function_specifier function_specifier;
  135. struct namespace *namespace;
  136. }
  137. %token <str> aIDENTIFIER aPRAGMA
  138. %token <str> aKNOWNTYPE
  139. %token <num> aNUM aHEXNUM
  140. %token <dbl> aDOUBLE
  141. %token <str> aSTRING aWSTRING aSQSTRING
  142. %token <uuid> aUUID
  143. %token aEOF aACF
  144. %token SHL SHR
  145. %token MEMBERPTR
  146. %token EQUALITY INEQUALITY
  147. %token GREATEREQUAL LESSEQUAL
  148. %token LOGICALOR LOGICALAND
  149. %token ELLIPSIS
  150. %token tACTIVATABLE
  151. %token tAGGREGATABLE
  152. %token tAGILE
  153. %token tALLNODES tALLOCATE tANNOTATION
  154. %token tAPICONTRACT
  155. %token tAPPOBJECT tASYNC tASYNCUUID
  156. %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
  157. %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
  158. %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
  159. %token tCONTEXTHANDLESERIALIZE
  160. %token tCONTRACT
  161. %token tCONTRACTVERSION
  162. %token tCONTROL tCPPQUOTE
  163. %token tCUSTOM
  164. %token tDECLARE
  165. %token tDECODE tDEFAULT tDEFAULTBIND
  166. %token tDELEGATE
  167. %token tDEFAULTCOLLELEM
  168. %token tDEFAULTVALUE
  169. %token tDEFAULTVTABLE
  170. %token tDISABLECONSISTENCYCHECK tDISPLAYBIND
  171. %token tDISPINTERFACE
  172. %token tDLLNAME tDONTFREE tDOUBLE tDUAL
  173. %token tENABLEALLOCATE tENCODE tENDPOINT
  174. %token tENTRY tENUM tERRORSTATUST
  175. %token tEVENTADD tEVENTREMOVE
  176. %token tEXCLUSIVETO
  177. %token tEXPLICITHANDLE tEXTERN
  178. %token tFALSE
  179. %token tFASTCALL tFAULTSTATUS
  180. %token tFLAGS
  181. %token tFLOAT tFORCEALLOCATE
  182. %token tHANDLE
  183. %token tHANDLET
  184. %token tHELPCONTEXT tHELPFILE
  185. %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
  186. %token tHIDDEN
  187. %token tHYPER tID tIDEMPOTENT
  188. %token tIGNORE tIIDIS
  189. %token tIMMEDIATEBIND
  190. %token tIMPLICITHANDLE
  191. %token tIMPORT tIMPORTLIB
  192. %token tIN tIN_LINE tINLINE
  193. %token tINPUTSYNC
  194. %token tINT tINT32 tINT3264 tINT64
  195. %token tINTERFACE
  196. %token tLCID
  197. %token tLENGTHIS tLIBRARY
  198. %token tLICENSED tLOCAL
  199. %token tLONG
  200. %token tMARSHALINGBEHAVIOR
  201. %token tMAYBE tMESSAGE
  202. %token tMETHODS
  203. %token tMODULE
  204. %token tMTA
  205. %token tNAMESPACE
  206. %token tNOCODE tNONBROWSABLE
  207. %token tNONCREATABLE
  208. %token tNONE
  209. %token tNONEXTENSIBLE
  210. %token tNOTIFY tNOTIFYFLAG
  211. %token tNULL
  212. %token tOBJECT tODL tOLEAUTOMATION
  213. %token tOPTIMIZE tOPTIONAL
  214. %token tOUT
  215. %token tPARTIALIGNORE tPASCAL
  216. %token tPOINTERDEFAULT
  217. %token tPRAGMA_WARNING
  218. %token tPROGID tPROPERTIES
  219. %token tPROPGET tPROPPUT tPROPPUTREF
  220. %token tPROXY tPTR
  221. %token tPUBLIC
  222. %token tRANGE
  223. %token tREADONLY tREF
  224. %token tREGISTER tREPRESENTAS
  225. %token tREQUESTEDIT
  226. %token tREQUIRES
  227. %token tRESTRICTED
  228. %token tRETVAL
  229. %token tRUNTIMECLASS
  230. %token tSAFEARRAY
  231. %token tSHORT
  232. %token tSIGNED tSINGLENODE
  233. %token tSIZEIS tSIZEOF
  234. %token tSMALL
  235. %token tSOURCE
  236. %token tSTANDARD
  237. %token tSTATIC
  238. %token tSTDCALL
  239. %token tSTRICTCONTEXTHANDLE
  240. %token tSTRING tSTRUCT
  241. %token tSWITCH tSWITCHIS tSWITCHTYPE
  242. %token tTHREADING tTRANSMITAS
  243. %token tTRUE
  244. %token tTYPEDEF
  245. %token tUIDEFAULT tUNION
  246. %token tUNIQUE
  247. %token tUNSIGNED
  248. %token tUSESGETLASTERROR tUSERMARSHAL tUUID
  249. %token tV1ENUM
  250. %token tVARARG
  251. %token tVERSION tVIPROGID
  252. %token tVOID
  253. %token tWCHAR tWIREMARSHAL
  254. %token tAPARTMENT tNEUTRAL tSINGLE tFREE tBOTH
  255. %type <attr> attribute acf_attribute
  256. %type <attr_list> m_attributes attributes attrib_list
  257. %type <attr_list> acf_attributes acf_attribute_list
  258. %type <attr_list> dispattributes
  259. %type <str_list> str_list
  260. %type <expr> m_expr expr expr_const expr_int_const array m_bitfield
  261. %type <expr_list> m_exprs /* exprs expr_list */ expr_list_int_const
  262. %type <expr> contract_req
  263. %type <expr> static_attr
  264. %type <type> delegatedef
  265. %type <stgclass> storage_cls_spec
  266. %type <type_qualifier> type_qualifier m_type_qual_list
  267. %type <function_specifier> function_specifier
  268. %type <declspec> decl_spec unqualified_decl_spec decl_spec_no_type m_decl_spec_no_type
  269. %type <type> inherit interface interfacedef
  270. %type <type> interfaceref
  271. %type <type> dispinterfaceref
  272. %type <type> dispinterface dispinterfacedef
  273. %type <type> module moduledef
  274. %type <str> namespacedef
  275. %type <type> base_type int_std
  276. %type <type> enumdef structdef uniondef typedecl
  277. %type <type> type unqualified_type qualified_type
  278. %type <type> type_parameter
  279. %type <typeref_list> type_parameters
  280. %type <type> parameterized_type
  281. %type <type> parameterized_type_arg
  282. %type <typeref_list> parameterized_type_args
  283. %type <typeref> class_interface
  284. %type <typeref_list> class_interfaces
  285. %type <typeref_list> requires required_types
  286. %type <var> arg ne_union_field union_field s_field case enum enum_member declaration
  287. %type <var> funcdef
  288. %type <var_list> m_args arg_list args dispint_meths
  289. %type <var_list> fields ne_union_fields cases enums enum_list dispint_props field
  290. %type <var> m_ident ident
  291. %type <declarator> declarator direct_declarator init_declarator struct_declarator
  292. %type <declarator> m_any_declarator any_declarator any_declarator_no_direct any_direct_declarator
  293. %type <declarator> m_abstract_declarator abstract_declarator abstract_declarator_no_direct abstract_direct_declarator
  294. %type <declarator_list> declarator_list struct_declarator_list
  295. %type <type> coclass coclassdef
  296. %type <type> runtimeclass runtimeclass_def
  297. %type <type> apicontract apicontract_def
  298. %type <num> contract_ver
  299. %type <num> pointer_type threading_type marshaling_behavior version
  300. %type <str> libraryhdr callconv cppquote importlib import
  301. %type <str> typename m_typename
  302. %type <uuid> uuid_string
  303. %type <import> import_start
  304. %type <typelib> library_start librarydef
  305. %type <statement> statement typedef pragma_warning
  306. %type <stmt_list> gbl_statements imp_statements int_statements
  307. %type <stmt_list> decl_block decl_statements
  308. %type <stmt_list> imp_decl_block imp_decl_statements
  309. %type <warning_list> warnings
  310. %type <num> allocate_option_list allocate_option
  311. %type <namespace> namespace_pfx
  312. %left ','
  313. %right '?' ':'
  314. %left LOGICALOR
  315. %left LOGICALAND
  316. %left '|'
  317. %left '^'
  318. %left '&'
  319. %left EQUALITY INEQUALITY
  320. %left '<' '>' LESSEQUAL GREATEREQUAL
  321. %left SHL SHR
  322. %left '-' '+'
  323. %left '*' '/' '%'
  324. %right '!' '~' CAST PPTR POS NEG ADDRESSOF tSIZEOF
  325. %left '.' MEMBERPTR '[' ']'
  326. %define parse.error verbose
  327. %%
  328. input: gbl_statements m_acf { $1 = append_parameterized_type_stmts($1);
  329. check_statements($1, FALSE);
  330. check_all_user_types($1);
  331. write_header($1);
  332. write_id_data($1);
  333. write_proxies($1);
  334. write_client($1);
  335. write_server($1);
  336. write_regscript($1);
  337. write_typelib_regscript($1);
  338. write_dlldata($1);
  339. write_local_stubs($1);
  340. }
  341. ;
  342. m_acf: /* empty */ | aACF acf_statements
  343. decl_statements: { $$ = NULL; }
  344. | decl_statements tINTERFACE qualified_type '<' parameterized_type_args '>' ';'
  345. { parameterized_type_stmts = append_statement(parameterized_type_stmts, make_statement_parameterized_type($3, $5));
  346. $$ = append_statement($1, make_statement_reference(type_parameterized_type_specialize_declare($3, $5)));
  347. }
  348. ;
  349. decl_block: tDECLARE '{' decl_statements '}' { $$ = $3; }
  350. imp_decl_statements: { $$ = NULL; }
  351. | imp_decl_statements tINTERFACE qualified_type '<' parameterized_type_args '>' ';'
  352. { $$ = append_statement($1, make_statement_reference(type_parameterized_type_specialize_declare($3, $5))); }
  353. ;
  354. imp_decl_block: tDECLARE '{' imp_decl_statements '}' { $$ = $3; }
  355. gbl_statements: { $$ = NULL; }
  356. | gbl_statements namespacedef '{' { push_namespace($2); } gbl_statements '}'
  357. { pop_namespace($2); $$ = append_statements($1, $5); }
  358. | gbl_statements interface ';' { $$ = append_statement($1, make_statement_reference($2)); }
  359. | gbl_statements dispinterface ';' { $$ = append_statement($1, make_statement_reference($2)); }
  360. | gbl_statements interfacedef { $$ = append_statement($1, make_statement_type_decl($2)); }
  361. | gbl_statements delegatedef { $$ = append_statement($1, make_statement_type_decl($2)); }
  362. | gbl_statements coclass ';' { $$ = $1;
  363. reg_type($2, $2->name, current_namespace, 0);
  364. }
  365. | gbl_statements coclassdef { $$ = append_statement($1, make_statement_type_decl($2));
  366. reg_type($2, $2->name, current_namespace, 0);
  367. }
  368. | gbl_statements apicontract ';' { $$ = $1; reg_type($2, $2->name, current_namespace, 0); }
  369. | gbl_statements apicontract_def { $$ = append_statement($1, make_statement_type_decl($2));
  370. reg_type($2, $2->name, current_namespace, 0); }
  371. | gbl_statements runtimeclass ';' { $$ = $1; reg_type($2, $2->name, current_namespace, 0); }
  372. | gbl_statements runtimeclass_def { $$ = append_statement($1, make_statement_type_decl($2));
  373. reg_type($2, $2->name, current_namespace, 0); }
  374. | gbl_statements moduledef { $$ = append_statement($1, make_statement_module($2)); }
  375. | gbl_statements librarydef { $$ = append_statement($1, make_statement_library($2)); }
  376. | gbl_statements statement { $$ = append_statement($1, $2); }
  377. | gbl_statements decl_block { $$ = append_statements($1, $2); }
  378. ;
  379. imp_statements: { $$ = NULL; }
  380. | imp_statements interface ';' { $$ = append_statement($1, make_statement_reference($2)); }
  381. | imp_statements dispinterface ';' { $$ = append_statement($1, make_statement_reference($2)); }
  382. | imp_statements namespacedef '{' { push_namespace($2); } imp_statements '}'
  383. { pop_namespace($2); $$ = append_statements($1, $5); }
  384. | imp_statements interfacedef { $$ = append_statement($1, make_statement_type_decl($2)); }
  385. | imp_statements delegatedef { $$ = append_statement($1, make_statement_type_decl($2)); }
  386. | imp_statements coclass ';' { $$ = $1; reg_type($2, $2->name, current_namespace, 0); }
  387. | imp_statements coclassdef { $$ = append_statement($1, make_statement_type_decl($2));
  388. reg_type($2, $2->name, current_namespace, 0);
  389. }
  390. | imp_statements apicontract ';' { $$ = $1; reg_type($2, $2->name, current_namespace, 0); }
  391. | imp_statements apicontract_def { $$ = append_statement($1, make_statement_type_decl($2));
  392. reg_type($2, $2->name, current_namespace, 0); }
  393. | imp_statements runtimeclass ';' { $$ = $1; reg_type($2, $2->name, current_namespace, 0); }
  394. | imp_statements runtimeclass_def { $$ = append_statement($1, make_statement_type_decl($2));
  395. reg_type($2, $2->name, current_namespace, 0); }
  396. | imp_statements moduledef { $$ = append_statement($1, make_statement_module($2)); }
  397. | imp_statements statement { $$ = append_statement($1, $2); }
  398. | imp_statements importlib { $$ = append_statement($1, make_statement_importlib($2)); }
  399. | imp_statements librarydef { $$ = append_statement($1, make_statement_library($2)); }
  400. | imp_statements imp_decl_block { $$ = append_statements($1, $2); }
  401. ;
  402. int_statements: { $$ = NULL; }
  403. | int_statements statement { $$ = append_statement($1, $2); }
  404. ;
  405. semicolon_opt:
  406. | ';'
  407. ;
  408. statement:
  409. cppquote { $$ = make_statement_cppquote($1); }
  410. | typedecl ';' { $$ = make_statement_type_decl($1); }
  411. | declaration ';' { $$ = make_statement_declaration($1); }
  412. | import { $$ = make_statement_import($1); }
  413. | typedef ';' { $$ = $1; }
  414. | aPRAGMA { $$ = make_statement_pragma($1); }
  415. | pragma_warning { $$ = NULL; }
  416. ;
  417. pragma_warning: tPRAGMA_WARNING '(' aIDENTIFIER ':' warnings ')'
  418. {
  419. int result;
  420. $$ = NULL;
  421. result = do_warning($3, $5);
  422. if(!result)
  423. error_loc("expected \"disable\", \"enable\" or \"default\"\n");
  424. }
  425. | tPRAGMA_WARNING '(' tDEFAULT ':' warnings ')'
  426. {
  427. $$ = NULL;
  428. do_warning("default", $5);
  429. }
  430. ;
  431. warnings:
  432. aNUM { $$ = append_warning(NULL, $1); }
  433. | warnings aNUM { $$ = append_warning($1, $2); }
  434. ;
  435. typedecl:
  436. enumdef
  437. | tENUM aIDENTIFIER { $$ = type_new_enum($2, current_namespace, FALSE, NULL); }
  438. | structdef
  439. | tSTRUCT aIDENTIFIER { $$ = type_new_struct($2, current_namespace, FALSE, NULL); }
  440. | uniondef
  441. | tUNION aIDENTIFIER { $$ = type_new_nonencapsulated_union($2, FALSE, NULL); }
  442. | attributes enumdef { $$ = $2; $$->attrs = check_enum_attrs($1); }
  443. | attributes structdef { $$ = $2; $$->attrs = check_struct_attrs($1); }
  444. | attributes uniondef { $$ = $2; $$->attrs = check_union_attrs($1); }
  445. ;
  446. cppquote: tCPPQUOTE '(' aSTRING ')' { $$ = $3; }
  447. ;
  448. import_start: tIMPORT aSTRING ';' { assert(yychar == YYEMPTY);
  449. $$ = xmalloc(sizeof(struct _import_t));
  450. $$->name = $2;
  451. $$->import_performed = do_import($2);
  452. if (!$$->import_performed) yychar = aEOF;
  453. }
  454. ;
  455. import: import_start imp_statements aEOF { $$ = $1->name;
  456. if ($1->import_performed) pop_import();
  457. free($1);
  458. }
  459. ;
  460. importlib: tIMPORTLIB '(' aSTRING ')'
  461. semicolon_opt { $$ = $3; if(!parse_only) add_importlib($3, current_typelib); }
  462. ;
  463. libraryhdr: tLIBRARY typename { $$ = $2; }
  464. ;
  465. library_start: attributes libraryhdr '{' { $$ = make_library($2, check_library_attrs($2, $1));
  466. if (!parse_only && do_typelib) current_typelib = $$;
  467. }
  468. ;
  469. librarydef: library_start imp_statements '}'
  470. semicolon_opt { $$ = $1; $$->stmts = $2; }
  471. ;
  472. m_args: { $$ = NULL; }
  473. | args
  474. ;
  475. arg_list: arg { check_arg_attrs($1); $$ = append_var( NULL, $1 ); }
  476. | arg_list ',' arg { check_arg_attrs($3); $$ = append_var( $1, $3 ); }
  477. ;
  478. args: arg_list
  479. | arg_list ',' ELLIPSIS { $$ = append_var( $1, make_var(strdup("...")) ); }
  480. ;
  481. /* split into two rules to get bison to resolve a tVOID conflict */
  482. arg: attributes decl_spec m_any_declarator { if ($2->stgclass != STG_NONE && $2->stgclass != STG_REGISTER)
  483. error_loc("invalid storage class for function parameter\n");
  484. $$ = declare_var($1, $2, $3, TRUE);
  485. free($2); free($3);
  486. }
  487. | decl_spec m_any_declarator { if ($1->stgclass != STG_NONE && $1->stgclass != STG_REGISTER)
  488. error_loc("invalid storage class for function parameter\n");
  489. $$ = declare_var(NULL, $1, $2, TRUE);
  490. free($1); free($2);
  491. }
  492. ;
  493. array: '[' expr ']' { $$ = $2;
  494. if (!$$->is_const || $$->cval <= 0)
  495. error_loc("array dimension is not a positive integer constant\n");
  496. }
  497. | '[' '*' ']' { $$ = make_expr(EXPR_VOID); }
  498. | '[' ']' { $$ = make_expr(EXPR_VOID); }
  499. ;
  500. m_attributes: { $$ = NULL; }
  501. | attributes
  502. ;
  503. attributes:
  504. '[' attrib_list ']' { $$ = $2; }
  505. ;
  506. attrib_list: attribute { $$ = append_attr( NULL, $1 ); }
  507. | attrib_list ',' attribute { $$ = append_attr( $1, $3 ); }
  508. | attrib_list ']' '[' attribute { $$ = append_attr( $1, $4 ); }
  509. ;
  510. str_list: aSTRING { $$ = append_str( NULL, $1 ); }
  511. | str_list ',' aSTRING { $$ = append_str( $1, $3 ); }
  512. ;
  513. marshaling_behavior:
  514. tAGILE { $$ = MARSHALING_AGILE; }
  515. | tNONE { $$ = MARSHALING_NONE; }
  516. | tSTANDARD { $$ = MARSHALING_STANDARD; }
  517. ;
  518. contract_ver:
  519. aNUM { $$ = MAKEVERSION(0, $1); }
  520. | aNUM '.' aNUM { $$ = MAKEVERSION($3, $1); }
  521. ;
  522. contract_req: decl_spec ',' contract_ver { if ($1->type->type_type != TYPE_APICONTRACT)
  523. error_loc("type %s is not an apicontract\n", $1->type->name);
  524. $$ = make_exprl(EXPR_NUM, $3);
  525. $$ = make_exprt(EXPR_GTREQL, declare_var(NULL, $1, make_declarator(NULL), 0), $$);
  526. }
  527. static_attr: decl_spec ',' contract_req { if ($1->type->type_type != TYPE_INTERFACE)
  528. error_loc("type %s is not an interface\n", $1->type->name);
  529. $$ = make_exprt(EXPR_MEMBER, declare_var(NULL, $1, make_declarator(NULL), 0), $3);
  530. }
  531. attribute: { $$ = NULL; }
  532. | tACTIVATABLE '(' contract_req ')' { $$ = make_attrp(ATTR_ACTIVATABLE, $3); }
  533. | tAGGREGATABLE { $$ = make_attr(ATTR_AGGREGATABLE); }
  534. | tANNOTATION '(' aSTRING ')' { $$ = make_attrp(ATTR_ANNOTATION, $3); }
  535. | tAPPOBJECT { $$ = make_attr(ATTR_APPOBJECT); }
  536. | tASYNC { $$ = make_attr(ATTR_ASYNC); }
  537. | tAUTOHANDLE { $$ = make_attr(ATTR_AUTO_HANDLE); }
  538. | tBINDABLE { $$ = make_attr(ATTR_BINDABLE); }
  539. | tBROADCAST { $$ = make_attr(ATTR_BROADCAST); }
  540. | tCALLAS '(' ident ')' { $$ = make_attrp(ATTR_CALLAS, $3); }
  541. | tCASE '(' expr_list_int_const ')' { $$ = make_attrp(ATTR_CASE, $3); }
  542. | tCODE { $$ = make_attr(ATTR_CODE); }
  543. | tCOMMSTATUS { $$ = make_attr(ATTR_COMMSTATUS); }
  544. | tCONTEXTHANDLE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); }
  545. | tCONTEXTHANDLENOSERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
  546. | tCONTEXTHANDLESERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
  547. | tCONTRACT '(' contract_req ')' { $$ = make_attrp(ATTR_CONTRACT, $3); }
  548. | tCONTRACTVERSION '(' contract_ver ')' { $$ = make_attrv(ATTR_CONTRACTVERSION, $3); }
  549. | tCONTROL { $$ = make_attr(ATTR_CONTROL); }
  550. | tCUSTOM '(' uuid_string ',' expr_const ')' { $$ = make_custom_attr($3, $5); }
  551. | tDECODE { $$ = make_attr(ATTR_DECODE); }
  552. | tDEFAULT { $$ = make_attr(ATTR_DEFAULT); }
  553. | tDEFAULTBIND { $$ = make_attr(ATTR_DEFAULTBIND); }
  554. | tDEFAULTCOLLELEM { $$ = make_attr(ATTR_DEFAULTCOLLELEM); }
  555. | tDEFAULTVALUE '(' expr_const ')' { $$ = make_attrp(ATTR_DEFAULTVALUE, $3); }
  556. | tDEFAULTVTABLE { $$ = make_attr(ATTR_DEFAULTVTABLE); }
  557. | tDISABLECONSISTENCYCHECK { $$ = make_attr(ATTR_DISABLECONSISTENCYCHECK); }
  558. | tDISPLAYBIND { $$ = make_attr(ATTR_DISPLAYBIND); }
  559. | tDLLNAME '(' aSTRING ')' { $$ = make_attrp(ATTR_DLLNAME, $3); }
  560. | tDUAL { $$ = make_attr(ATTR_DUAL); }
  561. | tENABLEALLOCATE { $$ = make_attr(ATTR_ENABLEALLOCATE); }
  562. | tENCODE { $$ = make_attr(ATTR_ENCODE); }
  563. | tENDPOINT '(' str_list ')' { $$ = make_attrp(ATTR_ENDPOINT, $3); }
  564. | tENTRY '(' expr_const ')' { $$ = make_attrp(ATTR_ENTRY, $3); }
  565. | tEVENTADD { $$ = make_attr(ATTR_EVENTADD); }
  566. | tEVENTREMOVE { $$ = make_attr(ATTR_EVENTREMOVE); }
  567. | tEXCLUSIVETO '(' decl_spec ')' { if ($3->type->type_type != TYPE_RUNTIMECLASS)
  568. error_loc("type %s is not a runtimeclass\n", $3->type->name);
  569. $$ = make_attrp(ATTR_EXCLUSIVETO, $3->type); }
  570. | tEXPLICITHANDLE { $$ = make_attr(ATTR_EXPLICIT_HANDLE); }
  571. | tFAULTSTATUS { $$ = make_attr(ATTR_FAULTSTATUS); }
  572. | tFLAGS { $$ = make_attr(ATTR_FLAGS); }
  573. | tFORCEALLOCATE { $$ = make_attr(ATTR_FORCEALLOCATE); }
  574. | tHANDLE { $$ = make_attr(ATTR_HANDLE); }
  575. | tHELPCONTEXT '(' expr_int_const ')' { $$ = make_attrp(ATTR_HELPCONTEXT, $3); }
  576. | tHELPFILE '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPFILE, $3); }
  577. | tHELPSTRING '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRING, $3); }
  578. | tHELPSTRINGCONTEXT '(' expr_int_const ')' { $$ = make_attrp(ATTR_HELPSTRINGCONTEXT, $3); }
  579. | tHELPSTRINGDLL '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRINGDLL, $3); }
  580. | tHIDDEN { $$ = make_attr(ATTR_HIDDEN); }
  581. | tID '(' expr_int_const ')' { $$ = make_attrp(ATTR_ID, $3); }
  582. | tIDEMPOTENT { $$ = make_attr(ATTR_IDEMPOTENT); }
  583. | tIGNORE { $$ = make_attr(ATTR_IGNORE); }
  584. | tIIDIS '(' expr ')' { $$ = make_attrp(ATTR_IIDIS, $3); }
  585. | tIMMEDIATEBIND { $$ = make_attr(ATTR_IMMEDIATEBIND); }
  586. | tIMPLICITHANDLE '(' arg ')' { $$ = make_attrp(ATTR_IMPLICIT_HANDLE, $3); }
  587. | tIN { $$ = make_attr(ATTR_IN); }
  588. | tINPUTSYNC { $$ = make_attr(ATTR_INPUTSYNC); }
  589. | tLENGTHIS '(' m_exprs ')' { $$ = make_attrp(ATTR_LENGTHIS, $3); }
  590. | tLCID '(' expr_int_const ')' { $$ = make_attrp(ATTR_LIBLCID, $3); }
  591. | tLCID { $$ = make_attr(ATTR_PARAMLCID); }
  592. | tLICENSED { $$ = make_attr(ATTR_LICENSED); }
  593. | tLOCAL { $$ = make_attr(ATTR_LOCAL); }
  594. | tMARSHALINGBEHAVIOR '(' marshaling_behavior ')'
  595. { $$ = make_attrv(ATTR_MARSHALING_BEHAVIOR, $3); }
  596. | tMAYBE { $$ = make_attr(ATTR_MAYBE); }
  597. | tMESSAGE { $$ = make_attr(ATTR_MESSAGE); }
  598. | tNOCODE { $$ = make_attr(ATTR_NOCODE); }
  599. | tNONBROWSABLE { $$ = make_attr(ATTR_NONBROWSABLE); }
  600. | tNONCREATABLE { $$ = make_attr(ATTR_NONCREATABLE); }
  601. | tNONEXTENSIBLE { $$ = make_attr(ATTR_NONEXTENSIBLE); }
  602. | tNOTIFY { $$ = make_attr(ATTR_NOTIFY); }
  603. | tNOTIFYFLAG { $$ = make_attr(ATTR_NOTIFYFLAG); }
  604. | tOBJECT { $$ = make_attr(ATTR_OBJECT); }
  605. | tODL { $$ = make_attr(ATTR_ODL); }
  606. | tOLEAUTOMATION { $$ = make_attr(ATTR_OLEAUTOMATION); }
  607. | tOPTIMIZE '(' aSTRING ')' { $$ = make_attrp(ATTR_OPTIMIZE, $3); }
  608. | tOPTIONAL { $$ = make_attr(ATTR_OPTIONAL); }
  609. | tOUT { $$ = make_attr(ATTR_OUT); }
  610. | tPARTIALIGNORE { $$ = make_attr(ATTR_PARTIALIGNORE); }
  611. | tPOINTERDEFAULT '(' pointer_type ')' { $$ = make_attrv(ATTR_POINTERDEFAULT, $3); }
  612. | tPROGID '(' aSTRING ')' { $$ = make_attrp(ATTR_PROGID, $3); }
  613. | tPROPGET { $$ = make_attr(ATTR_PROPGET); }
  614. | tPROPPUT { $$ = make_attr(ATTR_PROPPUT); }
  615. | tPROPPUTREF { $$ = make_attr(ATTR_PROPPUTREF); }
  616. | tPROXY { $$ = make_attr(ATTR_PROXY); }
  617. | tPUBLIC { $$ = make_attr(ATTR_PUBLIC); }
  618. | tRANGE '(' expr_int_const ',' expr_int_const ')'
  619. { expr_list_t *list = append_expr( NULL, $3 );
  620. list = append_expr( list, $5 );
  621. $$ = make_attrp(ATTR_RANGE, list); }
  622. | tREADONLY { $$ = make_attr(ATTR_READONLY); }
  623. | tREPRESENTAS '(' type ')' { $$ = make_attrp(ATTR_REPRESENTAS, $3); }
  624. | tREQUESTEDIT { $$ = make_attr(ATTR_REQUESTEDIT); }
  625. | tRESTRICTED { $$ = make_attr(ATTR_RESTRICTED); }
  626. | tRETVAL { $$ = make_attr(ATTR_RETVAL); }
  627. | tSIZEIS '(' m_exprs ')' { $$ = make_attrp(ATTR_SIZEIS, $3); }
  628. | tSOURCE { $$ = make_attr(ATTR_SOURCE); }
  629. | tSTATIC '(' static_attr ')' { $$ = make_attrp(ATTR_STATIC, $3); }
  630. | tSTRICTCONTEXTHANDLE { $$ = make_attr(ATTR_STRICTCONTEXTHANDLE); }
  631. | tSTRING { $$ = make_attr(ATTR_STRING); }
  632. | tSWITCHIS '(' expr ')' { $$ = make_attrp(ATTR_SWITCHIS, $3); }
  633. | tSWITCHTYPE '(' type ')' { $$ = make_attrp(ATTR_SWITCHTYPE, $3); }
  634. | tTRANSMITAS '(' type ')' { $$ = make_attrp(ATTR_TRANSMITAS, $3); }
  635. | tTHREADING '(' threading_type ')' { $$ = make_attrv(ATTR_THREADING, $3); }
  636. | tUIDEFAULT { $$ = make_attr(ATTR_UIDEFAULT); }
  637. | tUSESGETLASTERROR { $$ = make_attr(ATTR_USESGETLASTERROR); }
  638. | tUSERMARSHAL '(' type ')' { $$ = make_attrp(ATTR_USERMARSHAL, $3); }
  639. | tUUID '(' uuid_string ')' { $$ = make_attrp(ATTR_UUID, $3); }
  640. | tASYNCUUID '(' uuid_string ')' { $$ = make_attrp(ATTR_ASYNCUUID, $3); }
  641. | tV1ENUM { $$ = make_attr(ATTR_V1ENUM); }
  642. | tVARARG { $$ = make_attr(ATTR_VARARG); }
  643. | tVERSION '(' version ')' { $$ = make_attrv(ATTR_VERSION, $3); }
  644. | tVIPROGID '(' aSTRING ')' { $$ = make_attrp(ATTR_VIPROGID, $3); }
  645. | tWIREMARSHAL '(' type ')' { $$ = make_attrp(ATTR_WIREMARSHAL, $3); }
  646. | pointer_type { $$ = make_attrv(ATTR_POINTERTYPE, $1); }
  647. ;
  648. uuid_string:
  649. aUUID
  650. | aSTRING { if (!is_valid_uuid($1))
  651. error_loc("invalid UUID: %s\n", $1);
  652. $$ = parse_uuid($1); }
  653. ;
  654. callconv: tCDECL { $$ = xstrdup("__cdecl"); }
  655. | tFASTCALL { $$ = xstrdup("__fastcall"); }
  656. | tPASCAL { $$ = xstrdup("__pascal"); }
  657. | tSTDCALL { $$ = xstrdup("__stdcall"); }
  658. ;
  659. cases: { $$ = NULL; }
  660. | cases case { $$ = append_var( $1, $2 ); }
  661. ;
  662. case: tCASE expr_int_const ':' union_field { attr_t *a = make_attrp(ATTR_CASE, append_expr( NULL, $2 ));
  663. $$ = $4; if (!$$) $$ = make_var(NULL);
  664. $$->attrs = append_attr( $$->attrs, a );
  665. }
  666. | tDEFAULT ':' union_field { attr_t *a = make_attr(ATTR_DEFAULT);
  667. $$ = $3; if (!$$) $$ = make_var(NULL);
  668. $$->attrs = append_attr( $$->attrs, a );
  669. }
  670. ;
  671. enums: { $$ = NULL; }
  672. | enum_list ',' { $$ = $1; }
  673. | enum_list
  674. ;
  675. enum_list: enum { if (!$1->eval)
  676. $1->eval = make_exprl(EXPR_NUM, 0 /* default for first enum entry */);
  677. $$ = append_var( NULL, $1 );
  678. }
  679. | enum_list ',' enum { if (!$3->eval)
  680. {
  681. var_t *last = LIST_ENTRY( list_tail($$), var_t, entry );
  682. enum expr_type type = EXPR_NUM;
  683. if (last->eval->type == EXPR_HEXNUM) type = EXPR_HEXNUM;
  684. if (last->eval->cval + 1 < 0) type = EXPR_HEXNUM;
  685. $3->eval = make_exprl(type, last->eval->cval + 1);
  686. }
  687. $$ = append_var( $1, $3 );
  688. }
  689. ;
  690. enum_member: m_attributes ident { $$ = $2;
  691. $$->attrs = check_enum_member_attrs($1);
  692. }
  693. ;
  694. enum: enum_member '=' expr_int_const { $$ = reg_const($1);
  695. $$->eval = $3;
  696. $$->declspec.type = type_new_int(TYPE_BASIC_INT, 0);
  697. }
  698. | enum_member { $$ = reg_const($1);
  699. $$->declspec.type = type_new_int(TYPE_BASIC_INT, 0);
  700. }
  701. ;
  702. enumdef: tENUM m_typename '{' enums '}' { $$ = type_new_enum($2, current_namespace, TRUE, $4); }
  703. ;
  704. m_exprs: m_expr { $$ = append_expr( NULL, $1 ); }
  705. | m_exprs ',' m_expr { $$ = append_expr( $1, $3 ); }
  706. ;
  707. m_expr: { $$ = make_expr(EXPR_VOID); }
  708. | expr
  709. ;
  710. expr: aNUM { $$ = make_exprl(EXPR_NUM, $1); }
  711. | aHEXNUM { $$ = make_exprl(EXPR_HEXNUM, $1); }
  712. | aDOUBLE { $$ = make_exprd(EXPR_DOUBLE, $1); }
  713. | tFALSE { $$ = make_exprl(EXPR_TRUEFALSE, 0); }
  714. | tNULL { $$ = make_exprl(EXPR_NUM, 0); }
  715. | tTRUE { $$ = make_exprl(EXPR_TRUEFALSE, 1); }
  716. | aSTRING { $$ = make_exprs(EXPR_STRLIT, $1); }
  717. | aWSTRING { $$ = make_exprs(EXPR_WSTRLIT, $1); }
  718. | aSQSTRING { $$ = make_exprs(EXPR_CHARCONST, $1); }
  719. | aIDENTIFIER { $$ = make_exprs(EXPR_IDENTIFIER, $1); }
  720. | expr '?' expr ':' expr { $$ = make_expr3(EXPR_COND, $1, $3, $5); }
  721. | expr LOGICALOR expr { $$ = make_expr2(EXPR_LOGOR, $1, $3); }
  722. | expr LOGICALAND expr { $$ = make_expr2(EXPR_LOGAND, $1, $3); }
  723. | expr '|' expr { $$ = make_expr2(EXPR_OR , $1, $3); }
  724. | expr '^' expr { $$ = make_expr2(EXPR_XOR, $1, $3); }
  725. | expr '&' expr { $$ = make_expr2(EXPR_AND, $1, $3); }
  726. | expr EQUALITY expr { $$ = make_expr2(EXPR_EQUALITY, $1, $3); }
  727. | expr INEQUALITY expr { $$ = make_expr2(EXPR_INEQUALITY, $1, $3); }
  728. | expr '>' expr { $$ = make_expr2(EXPR_GTR, $1, $3); }
  729. | expr '<' expr { $$ = make_expr2(EXPR_LESS, $1, $3); }
  730. | expr GREATEREQUAL expr { $$ = make_expr2(EXPR_GTREQL, $1, $3); }
  731. | expr LESSEQUAL expr { $$ = make_expr2(EXPR_LESSEQL, $1, $3); }
  732. | expr SHL expr { $$ = make_expr2(EXPR_SHL, $1, $3); }
  733. | expr SHR expr { $$ = make_expr2(EXPR_SHR, $1, $3); }
  734. | expr '+' expr { $$ = make_expr2(EXPR_ADD, $1, $3); }
  735. | expr '-' expr { $$ = make_expr2(EXPR_SUB, $1, $3); }
  736. | expr '%' expr { $$ = make_expr2(EXPR_MOD, $1, $3); }
  737. | expr '*' expr { $$ = make_expr2(EXPR_MUL, $1, $3); }
  738. | expr '/' expr { $$ = make_expr2(EXPR_DIV, $1, $3); }
  739. | '!' expr { $$ = make_expr1(EXPR_LOGNOT, $2); }
  740. | '~' expr { $$ = make_expr1(EXPR_NOT, $2); }
  741. | '+' expr %prec POS { $$ = make_expr1(EXPR_POS, $2); }
  742. | '-' expr %prec NEG { $$ = make_expr1(EXPR_NEG, $2); }
  743. | '&' expr %prec ADDRESSOF { $$ = make_expr1(EXPR_ADDRESSOF, $2); }
  744. | '*' expr %prec PPTR { $$ = make_expr1(EXPR_PPTR, $2); }
  745. | expr MEMBERPTR aIDENTIFIER { $$ = make_expr2(EXPR_MEMBER, make_expr1(EXPR_PPTR, $1), make_exprs(EXPR_IDENTIFIER, $3)); }
  746. | expr '.' aIDENTIFIER { $$ = make_expr2(EXPR_MEMBER, $1, make_exprs(EXPR_IDENTIFIER, $3)); }
  747. | '(' unqualified_decl_spec m_abstract_declarator ')' expr %prec CAST
  748. { $$ = make_exprt(EXPR_CAST, declare_var(NULL, $2, $3, 0), $5); free($2); free($3); }
  749. | tSIZEOF '(' unqualified_decl_spec m_abstract_declarator ')'
  750. { $$ = make_exprt(EXPR_SIZEOF, declare_var(NULL, $3, $4, 0), NULL); free($3); free($4); }
  751. | expr '[' expr ']' { $$ = make_expr2(EXPR_ARRAY, $1, $3); }
  752. | '(' expr ')' { $$ = $2; }
  753. ;
  754. expr_list_int_const: expr_int_const { $$ = append_expr( NULL, $1 ); }
  755. | expr_list_int_const ',' expr_int_const { $$ = append_expr( $1, $3 ); }
  756. ;
  757. expr_int_const: expr { $$ = $1;
  758. if (!$$->is_const)
  759. error_loc("expression is not an integer constant\n");
  760. }
  761. ;
  762. expr_const: expr { $$ = $1;
  763. if (!$$->is_const && $$->type != EXPR_STRLIT && $$->type != EXPR_WSTRLIT)
  764. error_loc("expression is not constant\n");
  765. }
  766. ;
  767. fields: { $$ = NULL; }
  768. | fields field { $$ = append_var_list($1, $2); }
  769. ;
  770. field: m_attributes decl_spec struct_declarator_list ';'
  771. { const char *first = LIST_ENTRY(list_head($3), declarator_t, entry)->var->name;
  772. check_field_attrs(first, $1);
  773. $$ = set_var_types($1, $2, $3);
  774. }
  775. | m_attributes uniondef ';' { var_t *v = make_var(NULL);
  776. v->declspec.type = $2; v->attrs = $1;
  777. $$ = append_var(NULL, v);
  778. }
  779. ;
  780. ne_union_field:
  781. s_field ';' { $$ = $1; }
  782. | attributes ';' { $$ = make_var(NULL); $$->attrs = $1; }
  783. ;
  784. ne_union_fields: { $$ = NULL; }
  785. | ne_union_fields ne_union_field { $$ = append_var( $1, $2 ); }
  786. ;
  787. union_field:
  788. s_field ';' { $$ = $1; }
  789. | ';' { $$ = NULL; }
  790. ;
  791. s_field: m_attributes decl_spec declarator { $$ = declare_var(check_field_attrs($3->var->name, $1),
  792. $2, $3, FALSE);
  793. free($3);
  794. }
  795. | m_attributes structdef { var_t *v = make_var(NULL);
  796. v->declspec.type = $2; v->attrs = $1;
  797. $$ = v;
  798. }
  799. ;
  800. funcdef: declaration { $$ = $1;
  801. if (type_get_type($$->declspec.type) != TYPE_FUNCTION)
  802. error_loc("only methods may be declared inside the methods section of a dispinterface\n");
  803. check_function_attrs($$->name, $$->attrs);
  804. }
  805. ;
  806. declaration:
  807. attributes decl_spec init_declarator
  808. { $$ = declare_var($1, $2, $3, FALSE);
  809. free($3);
  810. }
  811. | decl_spec init_declarator { $$ = declare_var(NULL, $1, $2, FALSE);
  812. free($2);
  813. }
  814. ;
  815. m_ident: { $$ = NULL; }
  816. | ident
  817. ;
  818. m_typename: { $$ = NULL; }
  819. | typename
  820. ;
  821. typename: aIDENTIFIER
  822. | aKNOWNTYPE
  823. ;
  824. ident: typename { $$ = make_var($1); }
  825. ;
  826. base_type: tBYTE { $$ = find_type_or_error(NULL, $<str>1); }
  827. | tWCHAR { $$ = find_type_or_error(NULL, $<str>1); }
  828. | int_std
  829. | tSIGNED int_std { $$ = type_new_int(type_basic_get_type($2), -1); }
  830. | tUNSIGNED int_std { $$ = type_new_int(type_basic_get_type($2), 1); }
  831. | tUNSIGNED { $$ = type_new_int(TYPE_BASIC_INT, 1); }
  832. | tFLOAT { $$ = find_type_or_error(NULL, $<str>1); }
  833. | tDOUBLE { $$ = find_type_or_error(NULL, $<str>1); }
  834. | tBOOLEAN { $$ = find_type_or_error(NULL, $<str>1); }
  835. | tERRORSTATUST { $$ = find_type_or_error(NULL, $<str>1); }
  836. | tHANDLET { $$ = find_type_or_error(NULL, $<str>1); }
  837. ;
  838. m_int:
  839. | tINT
  840. ;
  841. int_std: tINT { $$ = type_new_int(TYPE_BASIC_INT, 0); }
  842. | tSHORT m_int { $$ = type_new_int(TYPE_BASIC_INT16, 0); }
  843. | tSMALL { $$ = type_new_int(TYPE_BASIC_INT8, 0); }
  844. | tLONG m_int { $$ = type_new_int(TYPE_BASIC_LONG, 0); }
  845. | tHYPER m_int { $$ = type_new_int(TYPE_BASIC_HYPER, 0); }
  846. | tINT64 { $$ = type_new_int(TYPE_BASIC_INT64, 0); }
  847. | tCHAR { $$ = type_new_int(TYPE_BASIC_CHAR, 0); }
  848. | tINT32 { $$ = type_new_int(TYPE_BASIC_INT32, 0); }
  849. | tINT3264 { $$ = type_new_int(TYPE_BASIC_INT3264, 0); }
  850. ;
  851. namespace_pfx:
  852. aIDENTIFIER '.' { $$ = find_namespace_or_error(&global_namespace, $1); }
  853. | namespace_pfx aIDENTIFIER '.' { $$ = find_namespace_or_error($1, $2); }
  854. ;
  855. qualified_type:
  856. typename { $$ = find_type_or_error(current_namespace, $1); }
  857. | namespace_pfx typename { $$ = find_type_or_error($1, $2); }
  858. ;
  859. parameterized_type: qualified_type '<' parameterized_type_args '>'
  860. { $$ = find_parameterized_type($1, $3); }
  861. ;
  862. parameterized_type_arg:
  863. base_type { $$ = $1; }
  864. | qualified_type { $$ = $1; }
  865. | qualified_type '*' { $$ = type_new_pointer($1); }
  866. | parameterized_type { $$ = $1; }
  867. | parameterized_type '*' { $$ = type_new_pointer($1); }
  868. ;
  869. parameterized_type_args:
  870. parameterized_type_arg { $$ = append_typeref(NULL, make_typeref($1)); }
  871. | parameterized_type_args ',' parameterized_type_arg
  872. { $$ = append_typeref($1, make_typeref($3)); }
  873. ;
  874. coclass: tCOCLASS typename { $$ = type_coclass_declare($2); }
  875. ;
  876. coclassdef: attributes coclass '{' class_interfaces '}' semicolon_opt
  877. { $$ = type_coclass_define($2, $1, $4); }
  878. ;
  879. runtimeclass: tRUNTIMECLASS typename { $$ = type_runtimeclass_declare($2, current_namespace); }
  880. ;
  881. runtimeclass_def: attributes runtimeclass '{' class_interfaces '}' semicolon_opt
  882. { $$ = type_runtimeclass_define($2, $1, $4); }
  883. ;
  884. apicontract: tAPICONTRACT typename { $$ = type_apicontract_declare($2, current_namespace); }
  885. ;
  886. apicontract_def: attributes apicontract '{' '}' semicolon_opt
  887. { $$ = type_apicontract_define($2, $1); }
  888. ;
  889. namespacedef: tNAMESPACE aIDENTIFIER { $$ = $2; }
  890. ;
  891. class_interfaces: { $$ = NULL; }
  892. | class_interfaces class_interface { $$ = append_typeref( $1, $2 ); }
  893. ;
  894. class_interface:
  895. m_attributes interfaceref ';' { $$ = make_typeref($2); $$->attrs = $1; }
  896. | m_attributes dispinterfaceref ';' { $$ = make_typeref($2); $$->attrs = $1; }
  897. ;
  898. dispinterface: tDISPINTERFACE typename { $$ = type_dispinterface_declare($2); }
  899. ;
  900. dispattributes: attributes { $$ = append_attr($1, make_attr(ATTR_DISPINTERFACE)); }
  901. ;
  902. dispint_props: tPROPERTIES ':' { $$ = NULL; }
  903. | dispint_props s_field ';' { $$ = append_var( $1, $2 ); }
  904. ;
  905. dispint_meths: tMETHODS ':' { $$ = NULL; }
  906. | dispint_meths funcdef ';' { $$ = append_var( $1, $2 ); }
  907. ;
  908. dispinterfacedef:
  909. dispattributes dispinterface '{' dispint_props dispint_meths '}'
  910. { $$ = type_dispinterface_define($2, $1, $4, $5); }
  911. | dispattributes dispinterface '{' interface ';' '}'
  912. { $$ = type_dispinterface_define_from_iface($2, $1, $4); }
  913. ;
  914. inherit: { $$ = NULL; }
  915. | ':' qualified_type { $$ = $2; }
  916. | ':' parameterized_type { $$ = $2; }
  917. ;
  918. type_parameter: typename { $$ = get_type(TYPE_PARAMETER, $1, parameters_namespace, 0); }
  919. ;
  920. type_parameters:
  921. type_parameter { $$ = append_typeref(NULL, make_typeref($1)); }
  922. | type_parameters ',' type_parameter { $$ = append_typeref($1, make_typeref($3)); }
  923. ;
  924. interface:
  925. tINTERFACE typename { $$ = type_interface_declare($2, current_namespace); }
  926. | tINTERFACE typename '<' { push_parameters_namespace($2); } type_parameters { pop_parameters_namespace($2); } '>'
  927. { $$ = type_parameterized_interface_declare($2, current_namespace, $5); }
  928. ;
  929. delegatedef: m_attributes tDELEGATE type ident '(' m_args ')' semicolon_opt
  930. { $$ = type_delegate_declare($4->name, current_namespace);
  931. $$ = type_delegate_define($$, $1, append_statement(NULL, make_statement_delegate($3, $6)));
  932. }
  933. | m_attributes tDELEGATE type ident
  934. '<' { push_parameters_namespace($4->name); } type_parameters '>'
  935. '(' m_args ')' { pop_parameters_namespace($4->name); } semicolon_opt
  936. { $$ = type_parameterized_delegate_declare($4->name, current_namespace, $7);
  937. $$ = type_parameterized_delegate_define($$, $1, append_statement(NULL, make_statement_delegate($3, $10)));
  938. }
  939. ;
  940. required_types:
  941. qualified_type { $$ = append_typeref(NULL, make_typeref($1)); }
  942. | parameterized_type { $$ = append_typeref(NULL, make_typeref($1)); }
  943. | required_types ',' qualified_type { $$ = append_typeref($1, make_typeref($3)); }
  944. | required_types ',' parameterized_type { $$ = append_typeref($1, make_typeref($3)); }
  945. requires: { $$ = NULL; }
  946. | tREQUIRES required_types { $$ = $2; }
  947. ;
  948. interfacedef: attributes interface { if ($2->type_type == TYPE_PARAMETERIZED_TYPE) push_parameters_namespace($2->name); }
  949. inherit requires '{' int_statements '}' semicolon_opt
  950. { if ($2->type_type == TYPE_PARAMETERIZED_TYPE)
  951. {
  952. $$ = type_parameterized_interface_define($2, $1, $4, $7, $5);
  953. pop_parameters_namespace($2->name);
  954. }
  955. else
  956. {
  957. $$ = type_interface_define($2, $1, $4, $7, $5);
  958. check_async_uuid($$);
  959. }
  960. }
  961. | dispinterfacedef semicolon_opt { $$ = $1; }
  962. ;
  963. interfaceref:
  964. tINTERFACE typename { $$ = get_type(TYPE_INTERFACE, $2, current_namespace, 0); }
  965. | tINTERFACE namespace_pfx typename { $$ = get_type(TYPE_INTERFACE, $3, $2, 0); }
  966. ;
  967. dispinterfaceref:
  968. tDISPINTERFACE typename { $$ = get_type(TYPE_INTERFACE, $2, current_namespace, 0); }
  969. ;
  970. module: tMODULE typename { $$ = type_module_declare($2); }
  971. ;
  972. moduledef: attributes module '{' int_statements '}' semicolon_opt
  973. { $$ = type_module_define($2, $1, $4); }
  974. ;
  975. storage_cls_spec:
  976. tEXTERN { $$ = STG_EXTERN; }
  977. | tSTATIC { $$ = STG_STATIC; }
  978. | tREGISTER { $$ = STG_REGISTER; }
  979. ;
  980. function_specifier:
  981. tINLINE { $$ = FUNCTION_SPECIFIER_INLINE; }
  982. ;
  983. type_qualifier:
  984. tCONST { $$ = TYPE_QUALIFIER_CONST; }
  985. ;
  986. m_type_qual_list: { $$ = 0; }
  987. | m_type_qual_list type_qualifier { $$ = $1 | $2; }
  988. ;
  989. decl_spec: type m_decl_spec_no_type { $$ = make_decl_spec($1, $2, NULL, STG_NONE, 0, 0); }
  990. | decl_spec_no_type type m_decl_spec_no_type
  991. { $$ = make_decl_spec($2, $1, $3, STG_NONE, 0, 0); }
  992. ;
  993. unqualified_decl_spec: unqualified_type m_decl_spec_no_type
  994. { $$ = make_decl_spec($1, $2, NULL, STG_NONE, 0, 0); }
  995. | decl_spec_no_type unqualified_type m_decl_spec_no_type
  996. { $$ = make_decl_spec($2, $1, $3, STG_NONE, 0, 0); }
  997. ;
  998. m_decl_spec_no_type: { $$ = NULL; }
  999. | decl_spec_no_type
  1000. ;
  1001. decl_spec_no_type:
  1002. type_qualifier m_decl_spec_no_type { $$ = make_decl_spec(NULL, $2, NULL, STG_NONE, $1, 0); }
  1003. | function_specifier m_decl_spec_no_type { $$ = make_decl_spec(NULL, $2, NULL, STG_NONE, 0, $1); }
  1004. | storage_cls_spec m_decl_spec_no_type { $$ = make_decl_spec(NULL, $2, NULL, $1, 0, 0); }
  1005. ;
  1006. declarator:
  1007. '*' m_type_qual_list declarator %prec PPTR
  1008. { $$ = $3; append_chain_type($$, type_new_pointer(NULL), $2); }
  1009. | callconv declarator { $$ = $2; append_chain_callconv($$->type, $1); }
  1010. | direct_declarator
  1011. ;
  1012. direct_declarator:
  1013. ident { $$ = make_declarator($1); }
  1014. | '(' declarator ')' { $$ = $2; }
  1015. | direct_declarator array { $$ = $1; append_array($$, $2); }
  1016. | direct_declarator '(' m_args ')' { $$ = $1; append_chain_type($$, type_new_function($3), 0); }
  1017. ;
  1018. /* abstract declarator */
  1019. abstract_declarator:
  1020. '*' m_type_qual_list m_abstract_declarator %prec PPTR
  1021. { $$ = $3; append_chain_type($$, type_new_pointer(NULL), $2); }
  1022. | callconv m_abstract_declarator { $$ = $2; append_chain_callconv($$->type, $1); }
  1023. | abstract_direct_declarator
  1024. ;
  1025. /* abstract declarator without accepting direct declarator */
  1026. abstract_declarator_no_direct:
  1027. '*' m_type_qual_list m_any_declarator %prec PPTR
  1028. { $$ = $3; append_chain_type($$, type_new_pointer(NULL), $2); }
  1029. | callconv m_any_declarator { $$ = $2; append_chain_callconv($$->type, $1); }
  1030. ;
  1031. /* abstract declarator or empty */
  1032. m_abstract_declarator: { $$ = make_declarator(NULL); }
  1033. | abstract_declarator
  1034. ;
  1035. /* abstract direct declarator */
  1036. abstract_direct_declarator:
  1037. '(' abstract_declarator_no_direct ')' { $$ = $2; }
  1038. | abstract_direct_declarator array { $$ = $1; append_array($$, $2); }
  1039. | array { $$ = make_declarator(NULL); append_array($$, $1); }
  1040. | '(' m_args ')'
  1041. { $$ = make_declarator(NULL);
  1042. append_chain_type($$, type_new_function($2), 0);
  1043. }
  1044. | abstract_direct_declarator '(' m_args ')'
  1045. { $$ = $1;
  1046. append_chain_type($$, type_new_function($3), 0);
  1047. }
  1048. ;
  1049. /* abstract or non-abstract declarator */
  1050. any_declarator:
  1051. '*' m_type_qual_list m_any_declarator %prec PPTR
  1052. { $$ = $3; append_chain_type($$, type_new_pointer(NULL), $2); }
  1053. | callconv m_any_declarator { $$ = $2; append_chain_callconv($$->type, $1); }
  1054. | any_direct_declarator
  1055. ;
  1056. /* abstract or non-abstract declarator without accepting direct declarator */
  1057. any_declarator_no_direct:
  1058. '*' m_type_qual_list m_any_declarator %prec PPTR
  1059. { $$ = $3; append_chain_type($$, type_new_pointer(NULL), $2); }
  1060. | callconv m_any_declarator { $$ = $2; append_chain_callconv($$->type, $1); }
  1061. ;
  1062. /* abstract or non-abstract declarator or empty */
  1063. m_any_declarator: { $$ = make_declarator(NULL); }
  1064. | any_declarator
  1065. ;
  1066. /* abstract or non-abstract direct declarator. note: direct declarators
  1067. * aren't accepted inside brackets to avoid ambiguity with the rule for
  1068. * function arguments */
  1069. any_direct_declarator:
  1070. ident { $$ = make_declarator($1); }
  1071. | '(' any_declarator_no_direct ')' { $$ = $2; }
  1072. | any_direct_declarator array { $$ = $1; append_array($$, $2); }
  1073. | array { $$ = make_declarator(NULL); append_array($$, $1); }
  1074. | '(' m_args ')'
  1075. { $$ = make_declarator(NULL);
  1076. append_chain_type($$, type_new_function($2), 0);
  1077. }
  1078. | any_direct_declarator '(' m_args ')'
  1079. { $$ = $1;
  1080. append_chain_type($$, type_new_function($3), 0);
  1081. }
  1082. ;
  1083. declarator_list:
  1084. declarator { $$ = append_declarator( NULL, $1 ); }
  1085. | declarator_list ',' declarator { $$ = append_declarator( $1, $3 ); }
  1086. ;
  1087. m_bitfield: { $$ = NULL; }
  1088. | ':' expr_const { $$ = $2; }
  1089. ;
  1090. struct_declarator: any_declarator m_bitfield { $$ = $1; $$->bits = $2;
  1091. if (!$$->bits && !$$->var->name)
  1092. error_loc("unnamed fields are not allowed\n");
  1093. }
  1094. ;
  1095. struct_declarator_list:
  1096. struct_declarator { $$ = append_declarator( NULL, $1 ); }
  1097. | struct_declarator_list ',' struct_declarator
  1098. { $$ = append_declarator( $1, $3 ); }
  1099. ;
  1100. init_declarator:
  1101. declarator { $$ = $1; }
  1102. | declarator '=' expr_const { $$ = $1; $1->var->eval = $3; }
  1103. ;
  1104. threading_type:
  1105. tAPARTMENT { $$ = THREADING_APARTMENT; }
  1106. | tNEUTRAL { $$ = THREADING_NEUTRAL; }
  1107. | tSINGLE { $$ = THREADING_SINGLE; }
  1108. | tFREE { $$ = THREADING_FREE; }
  1109. | tBOTH { $$ = THREADING_BOTH; }
  1110. | tMTA { $$ = THREADING_FREE; }
  1111. ;
  1112. pointer_type:
  1113. tREF { $$ = FC_RP; }
  1114. | tUNIQUE { $$ = FC_UP; }
  1115. | tPTR { $$ = FC_FP; }
  1116. ;
  1117. structdef: tSTRUCT m_typename '{' fields '}' { $$ = type_new_struct($2, current_namespace, TRUE, $4); }
  1118. ;
  1119. unqualified_type:
  1120. tVOID { $$ = type_new_void(); }
  1121. | base_type { $$ = $1; }
  1122. | enumdef { $$ = $1; }
  1123. | tENUM aIDENTIFIER { $$ = type_new_enum($2, current_namespace, FALSE, NULL); }
  1124. | structdef { $$ = $1; }
  1125. | tSTRUCT aIDENTIFIER { $$ = type_new_struct($2, current_namespace, FALSE, NULL); }
  1126. | uniondef { $$ = $1; }
  1127. | tUNION aIDENTIFIER { $$ = type_new_nonencapsulated_union($2, FALSE, NULL); }
  1128. | tSAFEARRAY '(' type ')' { $$ = make_safearray($3); }
  1129. | aKNOWNTYPE { $$ = find_type_or_error(current_namespace, $1); }
  1130. ;
  1131. type:
  1132. unqualified_type
  1133. | namespace_pfx typename { $$ = find_type_or_error($1, $2); }
  1134. | parameterized_type { $$ = $1; }
  1135. ;
  1136. typedef: m_attributes tTYPEDEF m_attributes decl_spec declarator_list
  1137. { $1 = append_attribs($1, $3);
  1138. reg_typedefs($4, $5, check_typedef_attrs($1));
  1139. $$ = make_statement_typedef($5, !$4->type->defined);
  1140. }
  1141. ;
  1142. uniondef: tUNION m_typename '{' ne_union_fields '}'
  1143. { $$ = type_new_nonencapsulated_union($2, TRUE, $4); }
  1144. | tUNION m_typename
  1145. tSWITCH '(' s_field ')'
  1146. m_ident '{' cases '}' { $$ = type_new_encapsulated_union($2, $5, $7, $9); }
  1147. ;
  1148. version:
  1149. aNUM { $$ = MAKEVERSION($1, 0); }
  1150. | aNUM '.' aNUM { $$ = MAKEVERSION($1, $3); }
  1151. | aHEXNUM { $$ = $1; }
  1152. ;
  1153. acf_statements
  1154. : /* empty */
  1155. | acf_interface acf_statements
  1156. ;
  1157. acf_int_statements
  1158. : /* empty */
  1159. | acf_int_statement acf_int_statements
  1160. ;
  1161. acf_int_statement
  1162. : tTYPEDEF acf_attributes aKNOWNTYPE ';'
  1163. { type_t *type = find_type_or_error(current_namespace, $3);
  1164. type->attrs = append_attr_list(type->attrs, $2);
  1165. }
  1166. ;
  1167. acf_interface
  1168. : acf_attributes tINTERFACE aKNOWNTYPE '{' acf_int_statements '}'
  1169. { type_t *iface = find_type_or_error(current_namespace, $3);
  1170. if (type_get_type(iface) != TYPE_INTERFACE)
  1171. error_loc("%s is not an interface\n", iface->name);
  1172. iface->attrs = append_attr_list(iface->attrs, $1);
  1173. }
  1174. ;
  1175. acf_attributes
  1176. : /* empty */ { $$ = NULL; };
  1177. | '[' acf_attribute_list ']' { $$ = $2; };
  1178. ;
  1179. acf_attribute_list
  1180. : acf_attribute { $$ = append_attr(NULL, $1); }
  1181. | acf_attribute_list ',' acf_attribute { $$ = append_attr($1, $3); }
  1182. ;
  1183. acf_attribute
  1184. : tALLOCATE '(' allocate_option_list ')'
  1185. { $$ = make_attrv(ATTR_ALLOCATE, $3); }
  1186. | tENCODE { $$ = make_attr(ATTR_ENCODE); }
  1187. | tDECODE { $$ = make_attr(ATTR_DECODE); }
  1188. | tEXPLICITHANDLE { $$ = make_attr(ATTR_EXPLICIT_HANDLE); }
  1189. ;
  1190. allocate_option_list
  1191. : allocate_option { $$ = $1; }
  1192. | allocate_option_list ',' allocate_option
  1193. { $$ = $1 | $3; }
  1194. ;
  1195. allocate_option
  1196. : tDONTFREE { $$ = FC_DONT_FREE; }
  1197. | tFREE { $$ = 0; }
  1198. | tALLNODES { $$ = FC_ALLOCATE_ALL_NODES; }
  1199. | tSINGLENODE { $$ = 0; }
  1200. ;
  1201. %%
  1202. static void decl_builtin_basic(const char *name, enum type_basic_type type)
  1203. {
  1204. type_t *t = type_new_basic(type);
  1205. reg_type(t, name, NULL, 0);
  1206. }
  1207. static void decl_builtin_alias(const char *name, type_t *t)
  1208. {
  1209. const decl_spec_t ds = {.type = t};
  1210. reg_type(type_new_alias(&ds, name), name, NULL, 0);
  1211. }
  1212. void init_types(void)
  1213. {
  1214. decl_builtin_basic("byte", TYPE_BASIC_BYTE);
  1215. decl_builtin_basic("wchar_t", TYPE_BASIC_WCHAR);
  1216. decl_builtin_basic("float", TYPE_BASIC_FLOAT);
  1217. decl_builtin_basic("double", TYPE_BASIC_DOUBLE);
  1218. decl_builtin_basic("error_status_t", TYPE_BASIC_ERROR_STATUS_T);
  1219. decl_builtin_basic("handle_t", TYPE_BASIC_HANDLE);
  1220. decl_builtin_alias("boolean", type_new_basic(TYPE_BASIC_CHAR));
  1221. }
  1222. static str_list_t *append_str(str_list_t *list, char *str)
  1223. {
  1224. struct str_list_entry_t *entry;
  1225. if (!str) return list;
  1226. if (!list)
  1227. {
  1228. list = xmalloc( sizeof(*list) );
  1229. list_init( list );
  1230. }
  1231. entry = xmalloc( sizeof(*entry) );
  1232. entry->str = str;
  1233. list_add_tail( list, &entry->entry );
  1234. return list;
  1235. }
  1236. static attr_list_t *move_attr(attr_list_t *dst, attr_list_t *src, enum attr_type type)
  1237. {
  1238. attr_t *attr;
  1239. if (!src) return dst;
  1240. LIST_FOR_EACH_ENTRY(attr, src, attr_t, entry)
  1241. if (attr->type == type)
  1242. {
  1243. list_remove(&attr->entry);
  1244. return append_attr(dst, attr);
  1245. }
  1246. return dst;
  1247. }
  1248. static attr_list_t *append_attr_list(attr_list_t *new_list, attr_list_t *old_list)
  1249. {
  1250. struct list *entry;
  1251. if (!old_list) return new_list;
  1252. while ((entry = list_head(old_list)))
  1253. {
  1254. attr_t *attr = LIST_ENTRY(entry, attr_t, entry);
  1255. list_remove(entry);
  1256. new_list = append_attr(new_list, attr);
  1257. }
  1258. return new_list;
  1259. }
  1260. typedef int (*map_attrs_filter_t)(attr_list_t*,const attr_t*);
  1261. static attr_list_t *map_attrs(const attr_list_t *list, map_attrs_filter_t filter)
  1262. {
  1263. attr_list_t *new_list;
  1264. const attr_t *attr;
  1265. attr_t *new_attr;
  1266. if (!list) return NULL;
  1267. new_list = xmalloc( sizeof(*list) );
  1268. list_init( new_list );
  1269. LIST_FOR_EACH_ENTRY(attr, list, const attr_t, entry)
  1270. {
  1271. if (filter && !filter(new_list, attr)) continue;
  1272. new_attr = xmalloc(sizeof(*new_attr));
  1273. *new_attr = *attr;
  1274. list_add_tail(new_list, &new_attr->entry);
  1275. }
  1276. return new_list;
  1277. }
  1278. static decl_spec_t *make_decl_spec(type_t *type, decl_spec_t *left, decl_spec_t *right,
  1279. enum storage_class stgclass, enum type_qualifier qual, enum function_specifier func_specifier)
  1280. {
  1281. decl_spec_t *declspec = left ? left : right;
  1282. if (!declspec)
  1283. {
  1284. declspec = xmalloc(sizeof(*declspec));
  1285. declspec->type = NULL;
  1286. declspec->stgclass = STG_NONE;
  1287. declspec->qualifier = 0;
  1288. declspec->func_specifier = 0;
  1289. }
  1290. declspec->type = type;
  1291. if (left && declspec != left)
  1292. {
  1293. if (declspec->stgclass == STG_NONE)
  1294. declspec->stgclass = left->stgclass;
  1295. else if (left->stgclass != STG_NONE)
  1296. error_loc("only one storage class can be specified\n");
  1297. declspec->qualifier |= left->qualifier;
  1298. declspec->func_specifier |= left->func_specifier;
  1299. assert(!left->type);
  1300. free(left);
  1301. }
  1302. if (right && declspec != right)
  1303. {
  1304. if (declspec->stgclass == STG_NONE)
  1305. declspec->stgclass = right->stgclass;
  1306. else if (right->stgclass != STG_NONE)
  1307. error_loc("only one storage class can be specified\n");
  1308. declspec->qualifier |= right->qualifier;
  1309. declspec->func_specifier |= right->func_specifier;
  1310. assert(!right->type);
  1311. free(right);
  1312. }
  1313. if (declspec->stgclass == STG_NONE)
  1314. declspec->stgclass = stgclass;
  1315. else if (stgclass != STG_NONE)
  1316. error_loc("only one storage class can be specified\n");
  1317. declspec->qualifier |= qual;
  1318. declspec->func_specifier |= func_specifier;
  1319. return declspec;
  1320. }
  1321. static attr_t *make_attr(enum attr_type type)
  1322. {
  1323. attr_t *a = xmalloc(sizeof(attr_t));
  1324. a->type = type;
  1325. a->u.ival = 0;
  1326. return a;
  1327. }
  1328. static attr_t *make_attrv(enum attr_type type, unsigned int val)
  1329. {
  1330. attr_t *a = xmalloc(sizeof(attr_t));
  1331. a->type = type;
  1332. a->u.ival = val;
  1333. return a;
  1334. }
  1335. attr_t *make_attrp(enum attr_type type, void *val)
  1336. {
  1337. attr_t *a = xmalloc(sizeof(attr_t));
  1338. a->type = type;
  1339. a->u.pval = val;
  1340. return a;
  1341. }
  1342. static attr_t *make_custom_attr(UUID *id, expr_t *pval)
  1343. {
  1344. attr_t *a = xmalloc(sizeof(attr_t));
  1345. attr_custdata_t *cstdata = xmalloc(sizeof(attr_custdata_t));
  1346. a->type = ATTR_CUSTOM;
  1347. cstdata->id = *id;
  1348. cstdata->pval = pval;
  1349. a->u.pval = cstdata;
  1350. return a;
  1351. }
  1352. static expr_list_t *append_expr(expr_list_t *list, expr_t *expr)
  1353. {
  1354. if (!expr) return list;
  1355. if (!list)
  1356. {
  1357. list = xmalloc( sizeof(*list) );
  1358. list_init( list );
  1359. }
  1360. list_add_tail( list, &expr->entry );
  1361. return list;
  1362. }
  1363. static void append_array(declarator_t *decl, expr_t *expr)
  1364. {
  1365. type_t *array;
  1366. if (!expr)
  1367. return;
  1368. /* An array is always a reference pointer unless explicitly marked otherwise
  1369. * (regardless of what the default pointer attribute is). */
  1370. array = type_new_array(NULL, NULL, FALSE, expr->is_const ? expr->cval : 0,
  1371. expr->is_const ? NULL : expr, NULL);
  1372. append_chain_type(decl, array, 0);
  1373. }
  1374. static struct list type_pool = LIST_INIT(type_pool);
  1375. typedef struct
  1376. {
  1377. type_t data;
  1378. struct list link;
  1379. } type_pool_node_t;
  1380. type_t *alloc_type(void)
  1381. {
  1382. type_pool_node_t *node = xmalloc(sizeof *node);
  1383. list_add_tail(&type_pool, &node->link);
  1384. return &node->data;
  1385. }
  1386. void set_all_tfswrite(int val)
  1387. {
  1388. type_pool_node_t *node;
  1389. LIST_FOR_EACH_ENTRY(node, &type_pool, type_pool_node_t, link)
  1390. node->data.tfswrite = val;
  1391. }
  1392. void clear_all_offsets(void)
  1393. {
  1394. type_pool_node_t *node;
  1395. LIST_FOR_EACH_ENTRY(node, &type_pool, type_pool_node_t, link)
  1396. node->data.typestring_offset = node->data.ptrdesc = 0;
  1397. }
  1398. static void type_function_add_head_arg(type_t *type, var_t *arg)
  1399. {
  1400. if (!type->details.function->args)
  1401. {
  1402. type->details.function->args = xmalloc( sizeof(*type->details.function->args) );
  1403. list_init( type->details.function->args );
  1404. }
  1405. list_add_head( type->details.function->args, &arg->entry );
  1406. }
  1407. static int is_allowed_range_type(const type_t *type)
  1408. {
  1409. switch (type_get_type(type))
  1410. {
  1411. case TYPE_ENUM:
  1412. return TRUE;
  1413. case TYPE_BASIC:
  1414. switch (type_basic_get_type(type))
  1415. {
  1416. case TYPE_BASIC_INT8:
  1417. case TYPE_BASIC_INT16:
  1418. case TYPE_BASIC_INT32:
  1419. case TYPE_BASIC_INT64:
  1420. case TYPE_BASIC_INT:
  1421. case TYPE_BASIC_INT3264:
  1422. case TYPE_BASIC_LONG:
  1423. case TYPE_BASIC_BYTE:
  1424. case TYPE_BASIC_CHAR:
  1425. case TYPE_BASIC_WCHAR:
  1426. case TYPE_BASIC_HYPER:
  1427. return TRUE;
  1428. case TYPE_BASIC_FLOAT:
  1429. case TYPE_BASIC_DOUBLE:
  1430. case TYPE_BASIC_ERROR_STATUS_T:
  1431. case TYPE_BASIC_HANDLE:
  1432. return FALSE;
  1433. }
  1434. return FALSE;
  1435. default:
  1436. return FALSE;
  1437. }
  1438. }
  1439. static type_t *get_chain_ref(type_t *type)
  1440. {
  1441. if (is_ptr(type))
  1442. return type_pointer_get_ref_type(type);
  1443. else if (is_array(type))
  1444. return type_array_get_element_type(type);
  1445. else if (is_func(type))
  1446. return type_function_get_rettype(type);
  1447. return NULL;
  1448. }
  1449. static type_t *get_chain_end(type_t *type)
  1450. {
  1451. type_t *inner;
  1452. while ((inner = get_chain_ref(type)))
  1453. type = inner;
  1454. return type;
  1455. }
  1456. static void append_chain_type(declarator_t *decl, type_t *type, enum type_qualifier qual)
  1457. {
  1458. type_t *chain_type;
  1459. if (!decl->type)
  1460. {
  1461. decl->type = type;
  1462. decl->qualifier = qual;
  1463. return;
  1464. }
  1465. chain_type = get_chain_end(decl->type);
  1466. if (is_ptr(chain_type))
  1467. {
  1468. chain_type->details.pointer.ref.type = type;
  1469. chain_type->details.pointer.ref.qualifier = qual;
  1470. }
  1471. else if (is_array(chain_type))
  1472. {
  1473. chain_type->details.array.elem.type = type;
  1474. chain_type->details.array.elem.qualifier = qual;
  1475. }
  1476. else if (is_func(chain_type))
  1477. {
  1478. chain_type->details.function->retval->declspec.type = type;
  1479. chain_type->details.function->retval->declspec.qualifier = qual;
  1480. }
  1481. else
  1482. assert(0);
  1483. if (!is_func(chain_type))
  1484. type->attrs = move_attr(type->attrs, chain_type->attrs, ATTR_CALLCONV);
  1485. }
  1486. static void append_chain_callconv(type_t *chain, char *callconv)
  1487. {
  1488. type_t *chain_end;
  1489. if (chain && (chain_end = get_chain_end(chain)))
  1490. chain_end->attrs = append_attr(chain_end->attrs, make_attrp(ATTR_CALLCONV, callconv));
  1491. else
  1492. error_loc("calling convention applied to non-function type\n");
  1493. }
  1494. static warning_list_t *append_warning(warning_list_t *list, int num)
  1495. {
  1496. warning_t *entry;
  1497. if(!list)
  1498. {
  1499. list = xmalloc( sizeof(*list) );
  1500. list_init( list );
  1501. }
  1502. entry = xmalloc( sizeof(*entry) );
  1503. entry->num = num;
  1504. list_add_tail( list, &entry->entry );
  1505. return list;
  1506. }
  1507. static var_t *declare_var(attr_list_t *attrs, decl_spec_t *decl_spec, declarator_t *decl,
  1508. int top)
  1509. {
  1510. var_t *v = decl->var;
  1511. expr_list_t *sizes = get_attrp(attrs, ATTR_SIZEIS);
  1512. expr_list_t *lengs = get_attrp(attrs, ATTR_LENGTHIS);
  1513. expr_t *dim;
  1514. type_t **ptype;
  1515. type_t *type = decl_spec->type;
  1516. if (decl_spec->func_specifier & FUNCTION_SPECIFIER_INLINE)
  1517. {
  1518. if (!decl || !is_func(decl->type))
  1519. error_loc("inline attribute applied to non-function type\n");
  1520. }
  1521. /* add type onto the end of the pointers in pident->type */
  1522. append_chain_type(decl, type, decl_spec->qualifier);
  1523. v->declspec = *decl_spec;
  1524. v->declspec.type = decl->type;
  1525. v->declspec.qualifier = decl->qualifier;
  1526. v->attrs = attrs;
  1527. v->declonly = !type->defined;
  1528. if (is_attr(type->attrs, ATTR_CALLCONV) && !is_func(type))
  1529. error_loc("calling convention applied to non-function type\n");
  1530. /* check for pointer attribute being applied to non-pointer, non-array
  1531. * type */
  1532. if (!is_array(v->declspec.type))
  1533. {
  1534. int ptr_attr = get_attrv(v->attrs, ATTR_POINTERTYPE);
  1535. const type_t *ptr = NULL;
  1536. for (ptr = v->declspec.type; ptr && !ptr_attr; )
  1537. {
  1538. ptr_attr = get_attrv(ptr->attrs, ATTR_POINTERTYPE);
  1539. if (!ptr_attr && type_is_alias(ptr))
  1540. ptr = type_alias_get_aliasee_type(ptr);
  1541. else
  1542. break;
  1543. }
  1544. if (is_ptr(ptr))
  1545. {
  1546. if (ptr_attr && ptr_attr != FC_UP &&
  1547. type_get_type(type_pointer_get_ref_type(ptr)) == TYPE_INTERFACE)
  1548. warning_loc_info(&v->loc_info,
  1549. "%s: pointer attribute applied to interface "
  1550. "pointer type has no effect\n", v->name);
  1551. if (!ptr_attr && top)
  1552. {
  1553. /* FIXME: this is a horrible hack to cope with the issue that we
  1554. * store an offset to the typeformat string in the type object, but
  1555. * two typeformat strings may be written depending on whether the
  1556. * pointer is a toplevel parameter or not */
  1557. v->declspec.type = duptype(v->declspec.type, 1);
  1558. }
  1559. }
  1560. else if (ptr_attr)
  1561. error_loc("%s: pointer attribute applied to non-pointer type\n", v->name);
  1562. }
  1563. if (is_attr(v->attrs, ATTR_STRING))
  1564. {
  1565. type_t *t = type;
  1566. if (!is_ptr(v->declspec.type) && !is_array(v->declspec.type))
  1567. error_loc("'%s': [string] attribute applied to non-pointer, non-array type\n",
  1568. v->name);
  1569. for (;;)
  1570. {
  1571. if (is_ptr(t))
  1572. t = type_pointer_get_ref_type(t);
  1573. else if (is_array(t))
  1574. t = type_array_get_element_type(t);
  1575. else
  1576. break;
  1577. }
  1578. if (type_get_type(t) != TYPE_BASIC &&
  1579. (get_basic_fc(t) != FC_CHAR &&
  1580. get_basic_fc(t) != FC_BYTE &&
  1581. get_basic_fc(t) != FC_WCHAR))
  1582. {
  1583. error_loc("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
  1584. v->name);
  1585. }
  1586. }
  1587. if (is_attr(v->attrs, ATTR_V1ENUM))
  1588. {
  1589. if (type_get_type_detect_alias(v->declspec.type) != TYPE_ENUM)
  1590. error_loc("'%s': [v1_enum] attribute applied to non-enum type\n", v->name);
  1591. }
  1592. if (is_attr(v->attrs, ATTR_RANGE) && !is_allowed_range_type(v->declspec.type))
  1593. error_loc("'%s': [range] attribute applied to non-integer type\n",
  1594. v->name);
  1595. ptype = &v->declspec.type;
  1596. if (sizes) LIST_FOR_EACH_ENTRY(dim, sizes, expr_t, entry)
  1597. {
  1598. if (dim->type != EXPR_VOID)
  1599. {
  1600. if (is_array(*ptype))
  1601. {
  1602. if (!type_array_get_conformance(*ptype) ||
  1603. type_array_get_conformance(*ptype)->type != EXPR_VOID)
  1604. error_loc("%s: cannot specify size_is for an already sized array\n", v->name);
  1605. else
  1606. *ptype = type_new_array((*ptype)->name,
  1607. type_array_get_element(*ptype), FALSE,
  1608. 0, dim, NULL);
  1609. }
  1610. else if (is_ptr(*ptype))
  1611. *ptype = type_new_array((*ptype)->name, type_pointer_get_ref(*ptype), TRUE,
  1612. 0, dim, NULL);
  1613. else
  1614. error_loc("%s: size_is attribute applied to illegal type\n", v->name);
  1615. }
  1616. if (is_ptr(*ptype))
  1617. ptype = &(*ptype)->details.pointer.ref.type;
  1618. else if (is_array(*ptype))
  1619. ptype = &(*ptype)->details.array.elem.type;
  1620. else
  1621. error_loc("%s: too many expressions in size_is attribute\n", v->name);
  1622. }
  1623. ptype = &v->declspec.type;
  1624. if (lengs) LIST_FOR_EACH_ENTRY(dim, lengs, expr_t, entry)
  1625. {
  1626. if (dim->type != EXPR_VOID)
  1627. {
  1628. if (is_array(*ptype))
  1629. {
  1630. *ptype = type_new_array((*ptype)->name,
  1631. type_array_get_element(*ptype),
  1632. type_array_is_decl_as_ptr(*ptype),
  1633. type_array_get_dim(*ptype),
  1634. type_array_get_conformance(*ptype), dim);
  1635. }
  1636. else
  1637. error_loc("%s: length_is attribute applied to illegal type\n", v->name);
  1638. }
  1639. if (is_ptr(*ptype))
  1640. ptype = &(*ptype)->details.pointer.ref.type;
  1641. else if (is_array(*ptype))
  1642. ptype = &(*ptype)->details.array.elem.type;
  1643. else
  1644. error_loc("%s: too many expressions in length_is attribute\n", v->name);
  1645. }
  1646. if (decl->bits)
  1647. v->declspec.type = type_new_bitfield(v->declspec.type, decl->bits);
  1648. return v;
  1649. }
  1650. static var_list_t *set_var_types(attr_list_t *attrs, decl_spec_t *decl_spec, declarator_list_t *decls)
  1651. {
  1652. declarator_t *decl, *next;
  1653. var_list_t *var_list = NULL;
  1654. LIST_FOR_EACH_ENTRY_SAFE( decl, next, decls, declarator_t, entry )
  1655. {
  1656. var_t *var = declare_var(attrs, decl_spec, decl, 0);
  1657. var_list = append_var(var_list, var);
  1658. free(decl);
  1659. }
  1660. free(decl_spec);
  1661. return var_list;
  1662. }
  1663. typeref_list_t *append_typeref(typeref_list_t *list, typeref_t *ref)
  1664. {
  1665. if (!ref) return list;
  1666. if (!list)
  1667. {
  1668. list = xmalloc( sizeof(*list) );
  1669. list_init( list );
  1670. }
  1671. list_add_tail( list, &ref->entry );
  1672. return list;
  1673. }
  1674. typeref_t *make_typeref(type_t *type)
  1675. {
  1676. typeref_t *ref = xmalloc(sizeof(typeref_t));
  1677. ref->type = type;
  1678. ref->attrs = NULL;
  1679. return ref;
  1680. }
  1681. var_list_t *append_var(var_list_t *list, var_t *var)
  1682. {
  1683. if (!var) return list;
  1684. if (!list)
  1685. {
  1686. list = xmalloc( sizeof(*list) );
  1687. list_init( list );
  1688. }
  1689. list_add_tail( list, &var->entry );
  1690. return list;
  1691. }
  1692. static var_list_t *append_var_list(var_list_t *list, var_list_t *vars)
  1693. {
  1694. if (!vars) return list;
  1695. if (!list)
  1696. {
  1697. list = xmalloc( sizeof(*list) );
  1698. list_init( list );
  1699. }
  1700. list_move_tail( list, vars );
  1701. return list;
  1702. }
  1703. var_t *make_var(char *name)
  1704. {
  1705. var_t *v = xmalloc(sizeof(var_t));
  1706. v->name = name;
  1707. init_declspec(&v->declspec, NULL);
  1708. v->attrs = NULL;
  1709. v->eval = NULL;
  1710. init_loc_info(&v->loc_info);
  1711. v->declonly = FALSE;
  1712. return v;
  1713. }
  1714. static var_t *copy_var(var_t *src, char *name, map_attrs_filter_t attr_filter)
  1715. {
  1716. var_t *v = xmalloc(sizeof(var_t));
  1717. v->name = name;
  1718. v->declspec = src->declspec;
  1719. v->attrs = map_attrs(src->attrs, attr_filter);
  1720. v->eval = src->eval;
  1721. v->loc_info = src->loc_info;
  1722. return v;
  1723. }
  1724. static declarator_list_t *append_declarator(declarator_list_t *list, declarator_t *d)
  1725. {
  1726. if (!d) return list;
  1727. if (!list) {
  1728. list = xmalloc(sizeof(*list));
  1729. list_init(list);
  1730. }
  1731. list_add_tail(list, &d->entry);
  1732. return list;
  1733. }
  1734. static declarator_t *make_declarator(var_t *var)
  1735. {
  1736. declarator_t *d = xmalloc(sizeof(*d));
  1737. d->var = var ? var : make_var(NULL);
  1738. d->type = NULL;
  1739. d->qualifier = 0;
  1740. d->bits = NULL;
  1741. return d;
  1742. }
  1743. static type_t *make_safearray(type_t *type)
  1744. {
  1745. decl_spec_t ds = {.type = type};
  1746. ds.type = type_new_alias(&ds, "SAFEARRAY");
  1747. return type_new_array(NULL, &ds, TRUE, 0, NULL, NULL);
  1748. }
  1749. static typelib_t *make_library(const char *name, const attr_list_t *attrs)
  1750. {
  1751. typelib_t *typelib = xmalloc(sizeof(*typelib));
  1752. memset(typelib, 0, sizeof(*typelib));
  1753. typelib->name = xstrdup(name);
  1754. typelib->attrs = attrs;
  1755. list_init( &typelib->importlibs );
  1756. return typelib;
  1757. }
  1758. static int hash_ident(const char *name)
  1759. {
  1760. const char *p = name;
  1761. int sum = 0;
  1762. /* a simple sum hash is probably good enough */
  1763. while (*p) {
  1764. sum += *p;
  1765. p++;
  1766. }
  1767. return sum & (HASHMAX-1);
  1768. }
  1769. /***** type repository *****/
  1770. static struct namespace *find_sub_namespace(struct namespace *namespace, const char *name)
  1771. {
  1772. struct namespace *cur;
  1773. LIST_FOR_EACH_ENTRY(cur, &namespace->children, struct namespace, entry) {
  1774. if(!strcmp(cur->name, name))
  1775. return cur;
  1776. }
  1777. return NULL;
  1778. }
  1779. static void push_namespace(const char *name)
  1780. {
  1781. struct namespace *namespace;
  1782. namespace = find_sub_namespace(current_namespace, name);
  1783. if(!namespace) {
  1784. namespace = xmalloc(sizeof(*namespace));
  1785. namespace->name = xstrdup(name);
  1786. namespace->parent = current_namespace;
  1787. list_add_tail(&current_namespace->children, &namespace->entry);
  1788. list_init(&namespace->children);
  1789. memset(namespace->type_hash, 0, sizeof(namespace->type_hash));
  1790. }
  1791. current_namespace = namespace;
  1792. }
  1793. static void pop_namespace(const char *name)
  1794. {
  1795. assert(!strcmp(current_namespace->name, name) && current_namespace->parent);
  1796. current_namespace = current_namespace->parent;
  1797. }
  1798. static void push_parameters_namespace(const char *name)
  1799. {
  1800. struct namespace *namespace;
  1801. if (!(namespace = find_sub_namespace(current_namespace, name)))
  1802. {
  1803. namespace = xmalloc(sizeof(*namespace));
  1804. namespace->name = xstrdup(name);
  1805. namespace->parent = current_namespace;
  1806. list_add_tail(&current_namespace->children, &namespace->entry);
  1807. list_init(&namespace->children);
  1808. memset(namespace->type_hash, 0, sizeof(namespace->type_hash));
  1809. }
  1810. parameters_namespace = namespace;
  1811. }
  1812. static void pop_parameters_namespace(const char *name)
  1813. {
  1814. assert(!strcmp(parameters_namespace->name, name) && parameters_namespace->parent);
  1815. parameters_namespace = NULL;
  1816. }
  1817. struct rtype {
  1818. const char *name;
  1819. type_t *type;
  1820. int t;
  1821. struct rtype *next;
  1822. };
  1823. type_t *reg_type(type_t *type, const char *name, struct namespace *namespace, int t)
  1824. {
  1825. struct rtype *nt;
  1826. int hash;
  1827. if (!name) {
  1828. error_loc("registering named type without name\n");
  1829. return type;
  1830. }
  1831. if (!namespace)
  1832. namespace = &global_namespace;
  1833. hash = hash_ident(name);
  1834. nt = xmalloc(sizeof(struct rtype));
  1835. nt->name = name;
  1836. if (is_global_namespace(namespace))
  1837. {
  1838. type->c_name = name;
  1839. type->qualified_name = name;
  1840. }
  1841. else
  1842. {
  1843. type->c_name = format_namespace(namespace, "__x_", "_C", name, use_abi_namespace ? "ABI" : NULL);
  1844. type->qualified_name = format_namespace(namespace, "", "::", name, use_abi_namespace ? "ABI" : NULL);
  1845. }
  1846. nt->type = type;
  1847. nt->t = t;
  1848. nt->next = namespace->type_hash[hash];
  1849. namespace->type_hash[hash] = nt;
  1850. return type;
  1851. }
  1852. static type_t *reg_typedefs(decl_spec_t *decl_spec, declarator_list_t *decls, attr_list_t *attrs)
  1853. {
  1854. declarator_t *decl;
  1855. type_t *type = decl_spec->type;
  1856. if (is_attr(attrs, ATTR_UUID) && !is_attr(attrs, ATTR_PUBLIC))
  1857. attrs = append_attr( attrs, make_attr(ATTR_PUBLIC) );
  1858. /* We must generate names for tagless enum, struct or union.
  1859. Typedef-ing a tagless enum, struct or union means we want the typedef
  1860. to be included in a library hence the public attribute. */
  1861. if (type_get_type_detect_alias(type) == TYPE_ENUM ||
  1862. type_get_type_detect_alias(type) == TYPE_STRUCT ||
  1863. type_get_type_detect_alias(type) == TYPE_UNION ||
  1864. type_get_type_detect_alias(type) == TYPE_ENCAPSULATED_UNION)
  1865. {
  1866. if (!type->name)
  1867. {
  1868. type->name = gen_name();
  1869. if (!is_attr(attrs, ATTR_PUBLIC))
  1870. attrs = append_attr(attrs, make_attr(ATTR_PUBLIC));
  1871. }
  1872. /* replace existing attributes when generating a typelib */
  1873. if (do_typelib)
  1874. type->attrs = attrs;
  1875. }
  1876. LIST_FOR_EACH_ENTRY( decl, decls, declarator_t, entry )
  1877. {
  1878. if (decl->var->name) {
  1879. type_t *cur;
  1880. var_t *name;
  1881. cur = find_type(decl->var->name, current_namespace, 0);
  1882. /*
  1883. * MIDL allows shadowing types that are declared in imported files.
  1884. * We don't throw an error in this case and instead add a new type
  1885. * (which is earlier on the list in hash table, so it will be used
  1886. * instead of shadowed type).
  1887. *
  1888. * FIXME: We may consider string separated type tables for each input
  1889. * for cleaner solution.
  1890. */
  1891. if (cur && input_name == cur->loc_info.input_name)
  1892. error_loc("%s: redefinition error; original definition was at %s:%d\n",
  1893. cur->name, cur->loc_info.input_name,
  1894. cur->loc_info.line_number);
  1895. name = declare_var(attrs, decl_spec, decl, 0);
  1896. cur = type_new_alias(&name->declspec, name->name);
  1897. cur->attrs = attrs;
  1898. reg_type(cur, cur->name, current_namespace, 0);
  1899. }
  1900. }
  1901. return type;
  1902. }
  1903. type_t *find_type(const char *name, struct namespace *namespace, int t)
  1904. {
  1905. struct rtype *cur;
  1906. if(namespace && namespace != &global_namespace) {
  1907. for(cur = namespace->type_hash[hash_ident(name)]; cur; cur = cur->next) {
  1908. if(cur->t == t && !strcmp(cur->name, name))
  1909. return cur->type;
  1910. }
  1911. }
  1912. for(cur = global_namespace.type_hash[hash_ident(name)]; cur; cur = cur->next) {
  1913. if(cur->t == t && !strcmp(cur->name, name))
  1914. return cur->type;
  1915. }
  1916. return NULL;
  1917. }
  1918. static type_t *find_type_or_error(struct namespace *namespace, const char *name)
  1919. {
  1920. type_t *type;
  1921. if (!(type = find_type(name, namespace, 0)) &&
  1922. !(type = find_type(name, parameters_namespace, 0)))
  1923. {
  1924. error_loc("type '%s' not found in %s namespace\n", name, namespace && namespace->name ? namespace->name : "global");
  1925. return NULL;
  1926. }
  1927. return type;
  1928. }
  1929. static struct namespace *find_namespace_or_error(struct namespace *parent, const char *name)
  1930. {
  1931. struct namespace *namespace = NULL;
  1932. if (!winrt_mode)
  1933. error_loc("namespaces are only supported in winrt mode.\n");
  1934. else if (!(namespace = find_sub_namespace(parent, name)))
  1935. error_loc("namespace '%s' not found in '%s'\n", name, parent->name);
  1936. return namespace;
  1937. }
  1938. int is_type(const char *name)
  1939. {
  1940. return find_type(name, current_namespace, 0) != NULL ||
  1941. find_type(name, parameters_namespace, 0);
  1942. }
  1943. type_t *get_type(enum type_type type, char *name, struct namespace *namespace, int t)
  1944. {
  1945. type_t *tp;
  1946. if (!namespace)
  1947. namespace = &global_namespace;
  1948. if (name) {
  1949. tp = find_type(name, namespace, t);
  1950. if (tp) {
  1951. free(name);
  1952. return tp;
  1953. }
  1954. }
  1955. tp = make_type(type);
  1956. tp->name = name;
  1957. tp->namespace = namespace;
  1958. if (!name) return tp;
  1959. return reg_type(tp, name, namespace, t);
  1960. }
  1961. /***** constant repository *****/
  1962. struct rconst {
  1963. char *name;
  1964. var_t *var;
  1965. struct rconst *next;
  1966. };
  1967. struct rconst *const_hash[HASHMAX];
  1968. static var_t *reg_const(var_t *var)
  1969. {
  1970. struct rconst *nc;
  1971. int hash;
  1972. if (!var->name) {
  1973. error_loc("registering constant without name\n");
  1974. return var;
  1975. }
  1976. hash = hash_ident(var->name);
  1977. nc = xmalloc(sizeof(struct rconst));
  1978. nc->name = var->name;
  1979. nc->var = var;
  1980. nc->next = const_hash[hash];
  1981. const_hash[hash] = nc;
  1982. return var;
  1983. }
  1984. var_t *find_const(const char *name, int f)
  1985. {
  1986. struct rconst *cur = const_hash[hash_ident(name)];
  1987. while (cur && strcmp(cur->name, name))
  1988. cur = cur->next;
  1989. if (!cur) {
  1990. if (f) error_loc("constant '%s' not found\n", name);
  1991. return NULL;
  1992. }
  1993. return cur->var;
  1994. }
  1995. char *gen_name(void)
  1996. {
  1997. static unsigned long n = 0;
  1998. static const char *file_id;
  1999. if (! file_id)
  2000. {
  2001. char *dst = dup_basename(input_idl_name, ".idl");
  2002. file_id = dst;
  2003. for (; *dst; ++dst)
  2004. if (! isalnum((unsigned char) *dst))
  2005. *dst = '_';
  2006. }
  2007. return strmake("__WIDL_%s_generated_name_%08lX", file_id, n++);
  2008. }
  2009. struct allowed_attr
  2010. {
  2011. unsigned int dce_compatible : 1;
  2012. unsigned int acf : 1;
  2013. unsigned int multiple : 1;
  2014. unsigned int on_interface : 1;
  2015. unsigned int on_function : 1;
  2016. unsigned int on_arg : 1;
  2017. unsigned int on_type : 1;
  2018. unsigned int on_enum : 1;
  2019. unsigned int on_enum_member : 1;
  2020. unsigned int on_struct : 2;
  2021. unsigned int on_union : 1;
  2022. unsigned int on_field : 1;
  2023. unsigned int on_library : 1;
  2024. unsigned int on_dispinterface : 1;
  2025. unsigned int on_module : 1;
  2026. unsigned int on_coclass : 1;
  2027. unsigned int on_apicontract : 1;
  2028. unsigned int on_runtimeclass : 1;
  2029. const char *display_name;
  2030. };
  2031. struct allowed_attr allowed_attr[] =
  2032. {
  2033. /* attr { D ACF M I Fn ARG T En Enm St Un Fi L DI M C AC R <display name> } */
  2034. /* ATTR_ACTIVATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "activatable" },
  2035. /* ATTR_AGGREGATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "aggregatable" },
  2036. /* ATTR_ALLOCATE */ { 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "allocate" },
  2037. /* ATTR_ANNOTATION */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "annotation" },
  2038. /* ATTR_APPOBJECT */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "appobject" },
  2039. /* ATTR_ASYNC */ { 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "async" },
  2040. /* ATTR_ASYNCUUID */ { 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, "async_uuid" },
  2041. /* ATTR_AUTO_HANDLE */ { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "auto_handle" },
  2042. /* ATTR_BINDABLE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "bindable" },
  2043. /* ATTR_BROADCAST */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "broadcast" },
  2044. /* ATTR_CALLAS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "call_as" },
  2045. /* ATTR_CALLCONV */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL },
  2046. /* ATTR_CASE */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "case" },
  2047. /* ATTR_CODE */ { 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "code" },
  2048. /* ATTR_COMMSTATUS */ { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "comm_status" },
  2049. /* ATTR_CONTEXTHANDLE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "context_handle" },
  2050. /* ATTR_CONTRACT */ { 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, "contract" },
  2051. /* ATTR_CONTRACTVERSION */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, "contractversion" },
  2052. /* ATTR_CONTROL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, "control" },
  2053. /* ATTR_CUSTOM */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, "custom" },
  2054. /* ATTR_DECODE */ { 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "decode" },
  2055. /* ATTR_DEFAULT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "default" },
  2056. /* ATTR_DEFAULTBIND */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultbind" },
  2057. /* ATTR_DEFAULTCOLLELEM */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultcollelem" },
  2058. /* ATTR_DEFAULTVALUE */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultvalue" },
  2059. /* ATTR_DEFAULTVTABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "defaultvtable" },
  2060. /* ATTR_DISABLECONSISTENCYCHECK */{ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "disable_consistency_check" },
  2061. /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, NULL },
  2062. /* ATTR_DISPLAYBIND */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "displaybind" },
  2063. /* ATTR_DLLNAME */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "dllname" },
  2064. /* ATTR_DUAL */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "dual" },
  2065. /* ATTR_ENABLEALLOCATE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "enable_allocate" },
  2066. /* ATTR_ENCODE */ { 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "encode" },
  2067. /* ATTR_ENDPOINT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "endpoint" },
  2068. /* ATTR_ENTRY */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "entry" },
  2069. /* ATTR_EVENTADD */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "eventadd" },
  2070. /* ATTR_EVENTREMOVE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "eventremove" },
  2071. /* ATTR_EXCLUSIVETO */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "exclusive_to" },
  2072. /* ATTR_EXPLICIT_HANDLE */ { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "explicit_handle" },
  2073. /* ATTR_FAULTSTATUS */ { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "fault_status" },
  2074. /* ATTR_FLAGS */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "flags" },
  2075. /* ATTR_FORCEALLOCATE */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "force_allocate" },
  2076. /* ATTR_HANDLE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "handle" },
  2077. /* ATTR_HELPCONTEXT */ { 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, "helpcontext" },
  2078. /* ATTR_HELPFILE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "helpfile" },
  2079. /* ATTR_HELPSTRING */ { 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, "helpstring" },
  2080. /* ATTR_HELPSTRINGCONTEXT */ { 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, "helpstringcontext" },
  2081. /* ATTR_HELPSTRINGDLL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "helpstringdll" },
  2082. /* ATTR_HIDDEN */ { 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, "hidden" },
  2083. /* ATTR_ID */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, "id" },
  2084. /* ATTR_IDEMPOTENT */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "idempotent" },
  2085. /* ATTR_IGNORE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "ignore" },
  2086. /* ATTR_IIDIS */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "iid_is" },
  2087. /* ATTR_IMMEDIATEBIND */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "immediatebind" },
  2088. /* ATTR_IMPLICIT_HANDLE */ { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "implicit_handle" },
  2089. /* ATTR_IN */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "in" },
  2090. /* ATTR_INPUTSYNC */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inputsync" },
  2091. /* ATTR_LENGTHIS */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "length_is" },
  2092. /* ATTR_LIBLCID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "lcid" },
  2093. /* ATTR_LICENSED */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "licensed" },
  2094. /* ATTR_LOCAL */ { 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "local" },
  2095. /* ATTR_MARSHALING_BEHAVIOR */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "marshaling_behavior" },
  2096. /* ATTR_MAYBE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "maybe" },
  2097. /* ATTR_MESSAGE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "message" },
  2098. /* ATTR_NOCODE */ { 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nocode" },
  2099. /* ATTR_NONBROWSABLE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonbrowsable" },
  2100. /* ATTR_NONCREATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "noncreatable" },
  2101. /* ATTR_NONEXTENSIBLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonextensible" },
  2102. /* ATTR_NOTIFY */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "notify" },
  2103. /* ATTR_NOTIFYFLAG */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "notify_flag" },
  2104. /* ATTR_OBJECT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "object" },
  2105. /* ATTR_ODL */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "odl" },
  2106. /* ATTR_OLEAUTOMATION */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "oleautomation" },
  2107. /* ATTR_OPTIMIZE */ { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "optimize" },
  2108. /* ATTR_OPTIONAL */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "optional" },
  2109. /* ATTR_OUT */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "out" },
  2110. /* ATTR_PARAMLCID */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "lcid" },
  2111. /* ATTR_PARTIALIGNORE */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "partial_ignore" },
  2112. /* ATTR_POINTERDEFAULT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "pointer_default" },
  2113. /* ATTR_POINTERTYPE */ { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "ref, unique or ptr" },
  2114. /* ATTR_PROGID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "progid" },
  2115. /* ATTR_PROPGET */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propget" },
  2116. /* ATTR_PROPPUT */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propput" },
  2117. /* ATTR_PROPPUTREF */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propputref" },
  2118. /* ATTR_PROXY */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "proxy" },
  2119. /* ATTR_PUBLIC */ { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "public" },
  2120. /* ATTR_RANGE */ { 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "range" },
  2121. /* ATTR_READONLY */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "readonly" },
  2122. /* ATTR_REPRESENTAS */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "represent_as" },
  2123. /* ATTR_REQUESTEDIT */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "requestedit" },
  2124. /* ATTR_RESTRICTED */ { 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, "restricted" },
  2125. /* ATTR_RETVAL */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "retval" },
  2126. /* ATTR_SIZEIS */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "size_is" },
  2127. /* ATTR_SOURCE */ { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "source" },
  2128. /* ATTR_STATIC */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "static" },
  2129. /* ATTR_STRICTCONTEXTHANDLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "strict_context_handle" },
  2130. /* ATTR_STRING */ { 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "string" },
  2131. /* ATTR_SWITCHIS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "switch_is" },
  2132. /* ATTR_SWITCHTYPE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "switch_type" },
  2133. /* ATTR_THREADING */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, "threading" },
  2134. /* ATTR_TRANSMITAS */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "transmit_as" },
  2135. /* ATTR_UIDEFAULT */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "uidefault" },
  2136. /* ATTR_USESGETLASTERROR */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "usesgetlasterror" },
  2137. /* ATTR_USERMARSHAL */ { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "user_marshal" },
  2138. /* ATTR_UUID */ { 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, "uuid" },
  2139. /* ATTR_V1ENUM */ { 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "v1_enum" },
  2140. /* ATTR_VARARG */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "vararg" },
  2141. /* ATTR_VERSION */ { 1, 0, 0, 1, 0, 0, 1, 1, 0, 2, 0, 0, 1, 0, 0, 1, 0, 1, "version" },
  2142. /* ATTR_VIPROGID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "vi_progid" },
  2143. /* ATTR_WIREMARSHAL */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "wire_marshal" },
  2144. };
  2145. attr_list_t *append_attr(attr_list_t *list, attr_t *attr)
  2146. {
  2147. attr_t *attr_existing;
  2148. if (!attr) return list;
  2149. if (!list)
  2150. {
  2151. list = xmalloc( sizeof(*list) );
  2152. list_init( list );
  2153. }
  2154. if (!allowed_attr[attr->type].multiple)
  2155. {
  2156. LIST_FOR_EACH_ENTRY(attr_existing, list, attr_t, entry)
  2157. if (attr_existing->type == attr->type)
  2158. {
  2159. parser_warning("duplicate attribute %s\n", get_attr_display_name(attr->type));
  2160. /* use the last attribute, like MIDL does */
  2161. list_remove(&attr_existing->entry);
  2162. break;
  2163. }
  2164. }
  2165. list_add_tail( list, &attr->entry );
  2166. return list;
  2167. }
  2168. const char *get_attr_display_name(enum attr_type type)
  2169. {
  2170. return allowed_attr[type].display_name;
  2171. }
  2172. attr_list_t *check_interface_attrs(const char *name, attr_list_t *attrs)
  2173. {
  2174. const attr_t *attr;
  2175. if (!attrs) return attrs;
  2176. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  2177. {
  2178. if (!allowed_attr[attr->type].on_interface)
  2179. error_loc("inapplicable attribute %s for interface %s\n",
  2180. allowed_attr[attr->type].display_name, name);
  2181. if (attr->type == ATTR_IMPLICIT_HANDLE)
  2182. {
  2183. const var_t *var = attr->u.pval;
  2184. if (type_get_type( var->declspec.type) == TYPE_BASIC &&
  2185. type_basic_get_type( var->declspec.type ) == TYPE_BASIC_HANDLE)
  2186. continue;
  2187. if (is_aliaschain_attr( var->declspec.type, ATTR_HANDLE ))
  2188. continue;
  2189. error_loc("attribute %s requires a handle type in interface %s\n",
  2190. allowed_attr[attr->type].display_name, name);
  2191. }
  2192. }
  2193. return attrs;
  2194. }
  2195. static attr_list_t *check_function_attrs(const char *name, attr_list_t *attrs)
  2196. {
  2197. const attr_t *attr;
  2198. if (!attrs) return attrs;
  2199. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  2200. {
  2201. if (!allowed_attr[attr->type].on_function)
  2202. error_loc("inapplicable attribute %s for function %s\n",
  2203. allowed_attr[attr->type].display_name, name);
  2204. }
  2205. return attrs;
  2206. }
  2207. static void check_arg_attrs(const var_t *arg)
  2208. {
  2209. const attr_t *attr;
  2210. if (arg->attrs)
  2211. {
  2212. LIST_FOR_EACH_ENTRY(attr, arg->attrs, const attr_t, entry)
  2213. {
  2214. if (!allowed_attr[attr->type].on_arg)
  2215. error_loc("inapplicable attribute %s for argument %s\n",
  2216. allowed_attr[attr->type].display_name, arg->name);
  2217. }
  2218. }
  2219. }
  2220. static attr_list_t *check_typedef_attrs(attr_list_t *attrs)
  2221. {
  2222. const attr_t *attr;
  2223. if (!attrs) return attrs;
  2224. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  2225. {
  2226. if (!allowed_attr[attr->type].on_type)
  2227. error_loc("inapplicable attribute %s for typedef\n",
  2228. allowed_attr[attr->type].display_name);
  2229. }
  2230. return attrs;
  2231. }
  2232. static attr_list_t *check_enum_attrs(attr_list_t *attrs)
  2233. {
  2234. const attr_t *attr;
  2235. if (!attrs) return attrs;
  2236. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  2237. {
  2238. if (!allowed_attr[attr->type].on_enum)
  2239. error_loc("inapplicable attribute %s for enum\n",
  2240. allowed_attr[attr->type].display_name);
  2241. }
  2242. return attrs;
  2243. }
  2244. static attr_list_t *check_enum_member_attrs(attr_list_t *attrs)
  2245. {
  2246. const attr_t *attr;
  2247. if (!attrs) return attrs;
  2248. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  2249. {
  2250. if (!allowed_attr[attr->type].on_enum_member)
  2251. error_loc("inapplicable attribute %s for enum member\n",
  2252. allowed_attr[attr->type].display_name);
  2253. }
  2254. return attrs;
  2255. }
  2256. static attr_list_t *check_struct_attrs(attr_list_t *attrs)
  2257. {
  2258. int mask = winrt_mode ? 3 : 1;
  2259. const attr_t *attr;
  2260. if (!attrs) return attrs;
  2261. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  2262. {
  2263. if (!(allowed_attr[attr->type].on_struct & mask))
  2264. error_loc("inapplicable attribute %s for struct\n",
  2265. allowed_attr[attr->type].display_name);
  2266. }
  2267. return attrs;
  2268. }
  2269. static attr_list_t *check_union_attrs(attr_list_t *attrs)
  2270. {
  2271. const attr_t *attr;
  2272. if (!attrs) return attrs;
  2273. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  2274. {
  2275. if (!allowed_attr[attr->type].on_union)
  2276. error_loc("inapplicable attribute %s for union\n",
  2277. allowed_attr[attr->type].display_name);
  2278. }
  2279. return attrs;
  2280. }
  2281. static attr_list_t *check_field_attrs(const char *name, attr_list_t *attrs)
  2282. {
  2283. const attr_t *attr;
  2284. if (!attrs) return attrs;
  2285. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  2286. {
  2287. if (!allowed_attr[attr->type].on_field)
  2288. error_loc("inapplicable attribute %s for field %s\n",
  2289. allowed_attr[attr->type].display_name, name);
  2290. }
  2291. return attrs;
  2292. }
  2293. static attr_list_t *check_library_attrs(const char *name, attr_list_t *attrs)
  2294. {
  2295. const attr_t *attr;
  2296. if (!attrs) return attrs;
  2297. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  2298. {
  2299. if (!allowed_attr[attr->type].on_library)
  2300. error_loc("inapplicable attribute %s for library %s\n",
  2301. allowed_attr[attr->type].display_name, name);
  2302. }
  2303. return attrs;
  2304. }
  2305. attr_list_t *check_dispiface_attrs(const char *name, attr_list_t *attrs)
  2306. {
  2307. const attr_t *attr;
  2308. if (!attrs) return attrs;
  2309. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  2310. {
  2311. if (!allowed_attr[attr->type].on_dispinterface)
  2312. error_loc("inapplicable attribute %s for dispinterface %s\n",
  2313. allowed_attr[attr->type].display_name, name);
  2314. }
  2315. return attrs;
  2316. }
  2317. attr_list_t *check_module_attrs(const char *name, attr_list_t *attrs)
  2318. {
  2319. const attr_t *attr;
  2320. if (!attrs) return attrs;
  2321. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  2322. {
  2323. if (!allowed_attr[attr->type].on_module)
  2324. error_loc("inapplicable attribute %s for module %s\n",
  2325. allowed_attr[attr->type].display_name, name);
  2326. }
  2327. return attrs;
  2328. }
  2329. attr_list_t *check_coclass_attrs(const char *name, attr_list_t *attrs)
  2330. {
  2331. const attr_t *attr;
  2332. if (!attrs) return attrs;
  2333. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  2334. {
  2335. if (!allowed_attr[attr->type].on_coclass)
  2336. error_loc("inapplicable attribute %s for coclass %s\n",
  2337. allowed_attr[attr->type].display_name, name);
  2338. }
  2339. return attrs;
  2340. }
  2341. attr_list_t *check_runtimeclass_attrs(const char *name, attr_list_t *attrs)
  2342. {
  2343. const attr_t *attr;
  2344. if (!attrs) return attrs;
  2345. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  2346. if (!allowed_attr[attr->type].on_runtimeclass)
  2347. error_loc("inapplicable attribute %s for runtimeclass %s\n",
  2348. allowed_attr[attr->type].display_name, name);
  2349. return attrs;
  2350. }
  2351. attr_list_t *check_apicontract_attrs(const char *name, attr_list_t *attrs)
  2352. {
  2353. const attr_t *attr;
  2354. if (!attrs) return attrs;
  2355. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  2356. if (!allowed_attr[attr->type].on_apicontract)
  2357. error_loc("inapplicable attribute %s for apicontract %s\n",
  2358. allowed_attr[attr->type].display_name, name);
  2359. return attrs;
  2360. }
  2361. static int is_allowed_conf_type(const type_t *type)
  2362. {
  2363. switch (type_get_type(type))
  2364. {
  2365. case TYPE_ENUM:
  2366. return TRUE;
  2367. case TYPE_BASIC:
  2368. switch (type_basic_get_type(type))
  2369. {
  2370. case TYPE_BASIC_INT8:
  2371. case TYPE_BASIC_INT16:
  2372. case TYPE_BASIC_INT32:
  2373. case TYPE_BASIC_INT64:
  2374. case TYPE_BASIC_INT:
  2375. case TYPE_BASIC_LONG:
  2376. case TYPE_BASIC_CHAR:
  2377. case TYPE_BASIC_HYPER:
  2378. case TYPE_BASIC_BYTE:
  2379. case TYPE_BASIC_WCHAR:
  2380. return TRUE;
  2381. default:
  2382. return FALSE;
  2383. }
  2384. case TYPE_ALIAS:
  2385. /* shouldn't get here because of type_get_type call above */
  2386. assert(0);
  2387. /* fall through */
  2388. case TYPE_STRUCT:
  2389. case TYPE_UNION:
  2390. case TYPE_ENCAPSULATED_UNION:
  2391. case TYPE_ARRAY:
  2392. case TYPE_POINTER:
  2393. case TYPE_VOID:
  2394. case TYPE_MODULE:
  2395. case TYPE_COCLASS:
  2396. case TYPE_FUNCTION:
  2397. case TYPE_INTERFACE:
  2398. case TYPE_BITFIELD:
  2399. case TYPE_RUNTIMECLASS:
  2400. case TYPE_DELEGATE:
  2401. return FALSE;
  2402. case TYPE_APICONTRACT:
  2403. case TYPE_PARAMETERIZED_TYPE:
  2404. case TYPE_PARAMETER:
  2405. /* not supposed to be here */
  2406. assert(0);
  2407. break;
  2408. }
  2409. return FALSE;
  2410. }
  2411. static int is_ptr_guid_type(const type_t *type)
  2412. {
  2413. /* first, make sure it is a pointer to something */
  2414. if (!is_ptr(type)) return FALSE;
  2415. /* second, make sure it is a pointer to something of size sizeof(GUID),
  2416. * i.e. 16 bytes */
  2417. return (type_memsize(type_pointer_get_ref_type(type)) == 16);
  2418. }
  2419. static void check_conformance_expr_list(const char *attr_name, const var_t *arg, const type_t *container_type, expr_list_t *expr_list)
  2420. {
  2421. expr_t *dim;
  2422. struct expr_loc expr_loc;
  2423. expr_loc.v = arg;
  2424. expr_loc.attr = attr_name;
  2425. if (expr_list) LIST_FOR_EACH_ENTRY(dim, expr_list, expr_t, entry)
  2426. {
  2427. if (dim->type != EXPR_VOID)
  2428. {
  2429. const type_t *expr_type = expr_resolve_type(&expr_loc, container_type, dim);
  2430. if (!is_allowed_conf_type(expr_type))
  2431. error_loc_info(&arg->loc_info, "expression must resolve to integral type <= 32bits for attribute %s\n",
  2432. attr_name);
  2433. }
  2434. }
  2435. }
  2436. static void check_remoting_fields(const var_t *var, type_t *type);
  2437. /* checks that properties common to fields and arguments are consistent */
  2438. static void check_field_common(const type_t *container_type,
  2439. const char *container_name, const var_t *arg)
  2440. {
  2441. type_t *type = arg->declspec.type;
  2442. int more_to_do;
  2443. const char *container_type_name;
  2444. const char *var_type;
  2445. switch (type_get_type(container_type))
  2446. {
  2447. case TYPE_STRUCT:
  2448. container_type_name = "struct";
  2449. var_type = "field";
  2450. break;
  2451. case TYPE_UNION:
  2452. container_type_name = "union";
  2453. var_type = "arm";
  2454. break;
  2455. case TYPE_ENCAPSULATED_UNION:
  2456. container_type_name = "encapsulated union";
  2457. var_type = "arm";
  2458. break;
  2459. case TYPE_FUNCTION:
  2460. container_type_name = "function";
  2461. var_type = "parameter";
  2462. break;
  2463. default:
  2464. /* should be no other container types */
  2465. assert(0);
  2466. return;
  2467. }
  2468. if (is_attr(arg->attrs, ATTR_LENGTHIS) &&
  2469. (is_attr(arg->attrs, ATTR_STRING) || is_aliaschain_attr(arg->declspec.type, ATTR_STRING)))
  2470. error_loc_info(&arg->loc_info,
  2471. "string and length_is specified for argument %s are mutually exclusive attributes\n",
  2472. arg->name);
  2473. if (is_attr(arg->attrs, ATTR_SIZEIS))
  2474. {
  2475. expr_list_t *size_is_exprs = get_attrp(arg->attrs, ATTR_SIZEIS);
  2476. check_conformance_expr_list("size_is", arg, container_type, size_is_exprs);
  2477. }
  2478. if (is_attr(arg->attrs, ATTR_LENGTHIS))
  2479. {
  2480. expr_list_t *length_is_exprs = get_attrp(arg->attrs, ATTR_LENGTHIS);
  2481. check_conformance_expr_list("length_is", arg, container_type, length_is_exprs);
  2482. }
  2483. if (is_attr(arg->attrs, ATTR_IIDIS))
  2484. {
  2485. struct expr_loc expr_loc;
  2486. expr_t *expr = get_attrp(arg->attrs, ATTR_IIDIS);
  2487. if (expr->type != EXPR_VOID)
  2488. {
  2489. const type_t *expr_type;
  2490. expr_loc.v = arg;
  2491. expr_loc.attr = "iid_is";
  2492. expr_type = expr_resolve_type(&expr_loc, container_type, expr);
  2493. if (!expr_type || !is_ptr_guid_type(expr_type))
  2494. error_loc_info(&arg->loc_info, "expression must resolve to pointer to GUID type for attribute iid_is\n");
  2495. }
  2496. }
  2497. if (is_attr(arg->attrs, ATTR_SWITCHIS))
  2498. {
  2499. struct expr_loc expr_loc;
  2500. expr_t *expr = get_attrp(arg->attrs, ATTR_SWITCHIS);
  2501. if (expr->type != EXPR_VOID)
  2502. {
  2503. const type_t *expr_type;
  2504. expr_loc.v = arg;
  2505. expr_loc.attr = "switch_is";
  2506. expr_type = expr_resolve_type(&expr_loc, container_type, expr);
  2507. if (!expr_type || !is_allowed_conf_type(expr_type))
  2508. error_loc_info(&arg->loc_info, "expression must resolve to integral type <= 32bits for attribute %s\n",
  2509. expr_loc.attr);
  2510. }
  2511. }
  2512. do
  2513. {
  2514. more_to_do = FALSE;
  2515. switch (typegen_detect_type(type, arg->attrs, TDT_IGNORE_STRINGS))
  2516. {
  2517. case TGT_STRUCT:
  2518. case TGT_UNION:
  2519. check_remoting_fields(arg, type);
  2520. break;
  2521. case TGT_INVALID:
  2522. {
  2523. const char *reason = "is invalid";
  2524. switch (type_get_type(type))
  2525. {
  2526. case TYPE_VOID:
  2527. reason = "cannot derive from void *";
  2528. break;
  2529. case TYPE_FUNCTION:
  2530. reason = "cannot be a function pointer";
  2531. break;
  2532. case TYPE_BITFIELD:
  2533. reason = "cannot be a bit-field";
  2534. break;
  2535. case TYPE_COCLASS:
  2536. reason = "cannot be a class";
  2537. break;
  2538. case TYPE_INTERFACE:
  2539. reason = "cannot be a non-pointer to an interface";
  2540. break;
  2541. case TYPE_MODULE:
  2542. reason = "cannot be a module";
  2543. break;
  2544. default:
  2545. break;
  2546. }
  2547. error_loc_info(&arg->loc_info, "%s \'%s\' of %s \'%s\' %s\n",
  2548. var_type, arg->name, container_type_name, container_name, reason);
  2549. break;
  2550. }
  2551. case TGT_CTXT_HANDLE:
  2552. case TGT_CTXT_HANDLE_POINTER:
  2553. if (type_get_type(container_type) != TYPE_FUNCTION)
  2554. error_loc_info(&arg->loc_info,
  2555. "%s \'%s\' of %s \'%s\' cannot be a context handle\n",
  2556. var_type, arg->name, container_type_name,
  2557. container_name);
  2558. break;
  2559. case TGT_STRING:
  2560. {
  2561. const type_t *t = type;
  2562. while (is_ptr(t))
  2563. t = type_pointer_get_ref_type(t);
  2564. if (is_aliaschain_attr(t, ATTR_RANGE))
  2565. warning_loc_info(&arg->loc_info, "%s: range not verified for a string of ranged types\n", arg->name);
  2566. break;
  2567. }
  2568. case TGT_POINTER:
  2569. type = type_pointer_get_ref_type(type);
  2570. more_to_do = TRUE;
  2571. break;
  2572. case TGT_ARRAY:
  2573. type = type_array_get_element_type(type);
  2574. more_to_do = TRUE;
  2575. break;
  2576. case TGT_ENUM:
  2577. type = type_get_real_type(type);
  2578. if (!type_is_complete(type))
  2579. {
  2580. error_loc_info(&arg->loc_info, "undefined type declaration \"enum %s\"\n", type->name);
  2581. }
  2582. case TGT_USER_TYPE:
  2583. case TGT_IFACE_POINTER:
  2584. case TGT_BASIC:
  2585. case TGT_RANGE:
  2586. /* nothing to do */
  2587. break;
  2588. }
  2589. } while (more_to_do);
  2590. }
  2591. static void check_remoting_fields(const var_t *var, type_t *type)
  2592. {
  2593. const var_t *field;
  2594. const var_list_t *fields = NULL;
  2595. type = type_get_real_type(type);
  2596. if (type->checked)
  2597. return;
  2598. type->checked = TRUE;
  2599. if (type_get_type(type) == TYPE_STRUCT)
  2600. {
  2601. if (type_is_complete(type))
  2602. fields = type_struct_get_fields(type);
  2603. else
  2604. error_loc_info(&var->loc_info, "undefined type declaration \"struct %s\"\n", type->name);
  2605. }
  2606. else if (type_get_type(type) == TYPE_UNION || type_get_type(type) == TYPE_ENCAPSULATED_UNION)
  2607. {
  2608. if (type_is_complete(type))
  2609. fields = type_union_get_cases(type);
  2610. else
  2611. error_loc_info(&var->loc_info, "undefined type declaration \"union %s\"\n", type->name);
  2612. }
  2613. if (fields) LIST_FOR_EACH_ENTRY( field, fields, const var_t, entry )
  2614. if (field->declspec.type) check_field_common(type, type->name, field);
  2615. }
  2616. /* checks that arguments for a function make sense for marshalling and unmarshalling */
  2617. static void check_remoting_args(const var_t *func)
  2618. {
  2619. const char *funcname = func->name;
  2620. const var_t *arg;
  2621. if (!type_function_get_args(func->declspec.type))
  2622. return;
  2623. LIST_FOR_EACH_ENTRY( arg, type_function_get_args(func->declspec.type), const var_t, entry )
  2624. {
  2625. const type_t *type = arg->declspec.type;
  2626. /* check that [out] parameters have enough pointer levels */
  2627. if (is_attr(arg->attrs, ATTR_OUT))
  2628. {
  2629. switch (typegen_detect_type(type, arg->attrs, TDT_ALL_TYPES))
  2630. {
  2631. case TGT_BASIC:
  2632. case TGT_ENUM:
  2633. case TGT_RANGE:
  2634. case TGT_STRUCT:
  2635. case TGT_UNION:
  2636. case TGT_CTXT_HANDLE:
  2637. case TGT_USER_TYPE:
  2638. error_loc_info(&arg->loc_info, "out parameter \'%s\' of function \'%s\' is not a pointer\n", arg->name, funcname);
  2639. break;
  2640. case TGT_IFACE_POINTER:
  2641. error_loc_info(&arg->loc_info, "out interface pointer \'%s\' of function \'%s\' is not a double pointer\n", arg->name, funcname);
  2642. break;
  2643. case TGT_STRING:
  2644. if (is_array(type))
  2645. {
  2646. /* needs conformance or fixed dimension */
  2647. if (type_array_has_conformance(type) &&
  2648. type_array_get_conformance(type)->type != EXPR_VOID) break;
  2649. if (!type_array_has_conformance(type) && type_array_get_dim(type)) break;
  2650. }
  2651. if (is_attr( arg->attrs, ATTR_IN )) break;
  2652. error_loc_info(&arg->loc_info, "out parameter \'%s\' of function \'%s\' cannot be an unsized string\n", arg->name, funcname);
  2653. break;
  2654. case TGT_INVALID:
  2655. /* already error'd before we get here */
  2656. case TGT_CTXT_HANDLE_POINTER:
  2657. case TGT_POINTER:
  2658. case TGT_ARRAY:
  2659. /* OK */
  2660. break;
  2661. }
  2662. }
  2663. check_field_common(func->declspec.type, funcname, arg);
  2664. }
  2665. if (type_get_type(type_function_get_rettype(func->declspec.type)) != TYPE_VOID)
  2666. {
  2667. var_t var;
  2668. var = *func;
  2669. var.declspec.type = type_function_get_rettype(func->declspec.type);
  2670. var.name = xstrdup("return value");
  2671. check_field_common(func->declspec.type, funcname, &var);
  2672. free(var.name);
  2673. }
  2674. }
  2675. static void add_explicit_handle_if_necessary(const type_t *iface, var_t *func)
  2676. {
  2677. unsigned char explicit_fc, implicit_fc;
  2678. /* check for a defined binding handle */
  2679. if (!get_func_handle_var( iface, func, &explicit_fc, &implicit_fc ) || !explicit_fc)
  2680. {
  2681. /* no explicit handle specified so add
  2682. * "[in] handle_t IDL_handle" as the first parameter to the
  2683. * function */
  2684. var_t *idl_handle = make_var(xstrdup("IDL_handle"));
  2685. idl_handle->attrs = append_attr(NULL, make_attr(ATTR_IN));
  2686. idl_handle->declspec.type = find_type_or_error(NULL, "handle_t");
  2687. type_function_add_head_arg(func->declspec.type, idl_handle);
  2688. }
  2689. }
  2690. static void check_functions(const type_t *iface, int is_inside_library)
  2691. {
  2692. const statement_t *stmt;
  2693. /* check for duplicates */
  2694. if (is_attr(iface->attrs, ATTR_DISPINTERFACE))
  2695. {
  2696. var_list_t *methods = type_dispiface_get_methods(iface);
  2697. var_t *func, *func_iter;
  2698. if (methods) LIST_FOR_EACH_ENTRY( func, methods, var_t, entry )
  2699. {
  2700. LIST_FOR_EACH_ENTRY( func_iter, methods, var_t, entry )
  2701. {
  2702. if (func == func_iter) break;
  2703. if (strcmp(func->name, func_iter->name)) continue;
  2704. if (is_attr(func->attrs, ATTR_EVENTADD) != is_attr(func_iter->attrs, ATTR_EVENTADD)) continue;
  2705. if (is_attr(func->attrs, ATTR_EVENTREMOVE) != is_attr(func_iter->attrs, ATTR_EVENTREMOVE)) continue;
  2706. if (is_attr(func->attrs, ATTR_PROPGET) != is_attr(func_iter->attrs, ATTR_PROPGET)) continue;
  2707. if (is_attr(func->attrs, ATTR_PROPPUT) != is_attr(func_iter->attrs, ATTR_PROPPUT)) continue;
  2708. if (is_attr(func->attrs, ATTR_PROPPUTREF) != is_attr(func_iter->attrs, ATTR_PROPPUTREF)) continue;
  2709. error_loc_info(&func->loc_info, "duplicated function \'%s\'\n", func->name);
  2710. }
  2711. }
  2712. }
  2713. if (is_attr(iface->attrs, ATTR_EXPLICIT_HANDLE))
  2714. {
  2715. STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
  2716. {
  2717. var_t *func = stmt->u.var;
  2718. add_explicit_handle_if_necessary(iface, func);
  2719. }
  2720. }
  2721. if (!is_inside_library && !is_attr(iface->attrs, ATTR_LOCAL))
  2722. {
  2723. STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
  2724. {
  2725. const var_t *func = stmt->u.var;
  2726. if (!is_attr(func->attrs, ATTR_LOCAL))
  2727. check_remoting_args(func);
  2728. }
  2729. }
  2730. }
  2731. static int async_iface_attrs(attr_list_t *attrs, const attr_t *attr)
  2732. {
  2733. switch(attr->type)
  2734. {
  2735. case ATTR_UUID:
  2736. return 0;
  2737. case ATTR_ASYNCUUID:
  2738. append_attr(attrs, make_attrp(ATTR_UUID, attr->u.pval));
  2739. return 0;
  2740. default:
  2741. return 1;
  2742. }
  2743. }
  2744. static int arg_in_attrs(attr_list_t *attrs, const attr_t *attr)
  2745. {
  2746. return attr->type != ATTR_OUT && attr->type != ATTR_RETVAL;
  2747. }
  2748. static int arg_out_attrs(attr_list_t *attrs, const attr_t *attr)
  2749. {
  2750. return attr->type != ATTR_IN;
  2751. }
  2752. static void check_async_uuid(type_t *iface)
  2753. {
  2754. statement_list_t *stmts = NULL;
  2755. statement_t *stmt;
  2756. type_t *async_iface;
  2757. type_t *inherit;
  2758. if (!is_attr(iface->attrs, ATTR_ASYNCUUID)) return;
  2759. inherit = type_iface_get_inherit(iface);
  2760. if (inherit && strcmp(inherit->name, "IUnknown"))
  2761. inherit = type_iface_get_async_iface(inherit);
  2762. if (!inherit)
  2763. error_loc("async_uuid applied to an interface with incompatible parent\n");
  2764. async_iface = type_interface_declare(strmake("Async%s", iface->name), iface->namespace);
  2765. STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
  2766. {
  2767. var_t *begin_func, *finish_func, *func = stmt->u.var, *arg;
  2768. var_list_t *begin_args = NULL, *finish_args = NULL, *args;
  2769. if (is_attr(func->attrs, ATTR_CALLAS)) continue;
  2770. args = type_function_get_args(func->declspec.type);
  2771. if (args) LIST_FOR_EACH_ENTRY(arg, args, var_t, entry)
  2772. {
  2773. if (is_attr(arg->attrs, ATTR_IN) || !is_attr(arg->attrs, ATTR_OUT))
  2774. begin_args = append_var(begin_args, copy_var(arg, strdup(arg->name), arg_in_attrs));
  2775. if (is_attr(arg->attrs, ATTR_OUT))
  2776. finish_args = append_var(finish_args, copy_var(arg, strdup(arg->name), arg_out_attrs));
  2777. }
  2778. begin_func = copy_var(func, strmake("Begin_%s", func->name), NULL);
  2779. begin_func->declspec.type = type_new_function(begin_args);
  2780. begin_func->declspec.type->attrs = func->attrs;
  2781. begin_func->declspec.type->details.function->retval = func->declspec.type->details.function->retval;
  2782. stmts = append_statement(stmts, make_statement_declaration(begin_func));
  2783. finish_func = copy_var(func, strmake("Finish_%s", func->name), NULL);
  2784. finish_func->declspec.type = type_new_function(finish_args);
  2785. finish_func->declspec.type->attrs = func->attrs;
  2786. finish_func->declspec.type->details.function->retval = func->declspec.type->details.function->retval;
  2787. stmts = append_statement(stmts, make_statement_declaration(finish_func));
  2788. }
  2789. type_interface_define(async_iface, map_attrs(iface->attrs, async_iface_attrs), inherit, stmts, NULL);
  2790. iface->details.iface->async_iface = async_iface->details.iface->async_iface = async_iface;
  2791. }
  2792. static statement_list_t *append_parameterized_type_stmts(statement_list_t *stmts)
  2793. {
  2794. statement_t *stmt, *next;
  2795. if (stmts && parameterized_type_stmts) LIST_FOR_EACH_ENTRY_SAFE(stmt, next, parameterized_type_stmts, statement_t, entry)
  2796. {
  2797. switch(stmt->type)
  2798. {
  2799. case STMT_TYPE:
  2800. stmt->u.type = type_parameterized_type_specialize_define(stmt->u.type);
  2801. stmt->declonly = FALSE;
  2802. list_remove(&stmt->entry);
  2803. stmts = append_statement(stmts, stmt);
  2804. break;
  2805. default:
  2806. assert(0); /* should not be there */
  2807. break;
  2808. }
  2809. }
  2810. return stmts;
  2811. }
  2812. static void check_statements(const statement_list_t *stmts, int is_inside_library)
  2813. {
  2814. const statement_t *stmt;
  2815. if (stmts) LIST_FOR_EACH_ENTRY(stmt, stmts, const statement_t, entry)
  2816. {
  2817. switch(stmt->type) {
  2818. case STMT_LIBRARY:
  2819. check_statements(stmt->u.lib->stmts, TRUE);
  2820. break;
  2821. case STMT_TYPE:
  2822. switch(type_get_type(stmt->u.type)) {
  2823. case TYPE_INTERFACE:
  2824. check_functions(stmt->u.type, is_inside_library);
  2825. break;
  2826. case TYPE_COCLASS:
  2827. if(winrt_mode)
  2828. error_loc("coclass is not allowed in Windows Runtime mode\n");
  2829. break;
  2830. default:
  2831. break;
  2832. }
  2833. break;
  2834. default:
  2835. break;
  2836. }
  2837. }
  2838. }
  2839. static void check_all_user_types(const statement_list_t *stmts)
  2840. {
  2841. const statement_t *stmt;
  2842. const var_t *v;
  2843. if (stmts) LIST_FOR_EACH_ENTRY(stmt, stmts, const statement_t, entry)
  2844. {
  2845. if (stmt->type == STMT_LIBRARY)
  2846. check_all_user_types(stmt->u.lib->stmts);
  2847. else if (stmt->type == STMT_TYPE && type_get_type(stmt->u.type) == TYPE_INTERFACE &&
  2848. !is_local(stmt->u.type->attrs))
  2849. {
  2850. const statement_t *stmt_func;
  2851. STATEMENTS_FOR_EACH_FUNC(stmt_func, type_iface_get_stmts(stmt->u.type)) {
  2852. const var_t *func = stmt_func->u.var;
  2853. if (type_function_get_args(func->declspec.type))
  2854. LIST_FOR_EACH_ENTRY( v, type_function_get_args(func->declspec.type), const var_t, entry )
  2855. check_for_additional_prototype_types(v->declspec.type);
  2856. check_for_additional_prototype_types(type_function_get_rettype(func->declspec.type));
  2857. }
  2858. }
  2859. }
  2860. }
  2861. int is_valid_uuid(const char *s)
  2862. {
  2863. int i;
  2864. for (i = 0; i < 36; ++i)
  2865. if (i == 8 || i == 13 || i == 18 || i == 23)
  2866. {
  2867. if (s[i] != '-')
  2868. return FALSE;
  2869. }
  2870. else
  2871. if (!isxdigit(s[i]))
  2872. return FALSE;
  2873. return s[i] == '\0';
  2874. }
  2875. static statement_t *make_statement(enum statement_type type)
  2876. {
  2877. statement_t *stmt = xmalloc(sizeof(*stmt));
  2878. stmt->type = type;
  2879. return stmt;
  2880. }
  2881. static statement_t *make_statement_type_decl(type_t *type)
  2882. {
  2883. statement_t *stmt = make_statement(STMT_TYPE);
  2884. stmt->u.type = type;
  2885. stmt->declonly = !type->defined;
  2886. return stmt;
  2887. }
  2888. static statement_t *make_statement_reference(type_t *type)
  2889. {
  2890. statement_t *stmt = make_statement(STMT_TYPEREF);
  2891. stmt->u.type = type;
  2892. return stmt;
  2893. }
  2894. static statement_t *make_statement_declaration(var_t *var)
  2895. {
  2896. statement_t *stmt = make_statement(STMT_DECLARATION);
  2897. stmt->u.var = var;
  2898. if (var->declspec.stgclass == STG_EXTERN && var->eval)
  2899. warning("'%s' initialised and declared extern\n", var->name);
  2900. if (is_const_decl(var))
  2901. {
  2902. if (var->eval)
  2903. reg_const(var);
  2904. }
  2905. else if (type_get_type(var->declspec.type) == TYPE_FUNCTION)
  2906. check_function_attrs(var->name, var->attrs);
  2907. else if (var->declspec.stgclass == STG_NONE || var->declspec.stgclass == STG_REGISTER)
  2908. error_loc("instantiation of data is illegal\n");
  2909. return stmt;
  2910. }
  2911. static statement_t *make_statement_library(typelib_t *typelib)
  2912. {
  2913. statement_t *stmt = make_statement(STMT_LIBRARY);
  2914. stmt->u.lib = typelib;
  2915. return stmt;
  2916. }
  2917. static statement_t *make_statement_pragma(const char *str)
  2918. {
  2919. statement_t *stmt = make_statement(STMT_PRAGMA);
  2920. stmt->u.str = str;
  2921. return stmt;
  2922. }
  2923. static statement_t *make_statement_cppquote(const char *str)
  2924. {
  2925. statement_t *stmt = make_statement(STMT_CPPQUOTE);
  2926. stmt->u.str = str;
  2927. return stmt;
  2928. }
  2929. static statement_t *make_statement_importlib(const char *str)
  2930. {
  2931. statement_t *stmt = make_statement(STMT_IMPORTLIB);
  2932. stmt->u.str = str;
  2933. return stmt;
  2934. }
  2935. static statement_t *make_statement_import(const char *str)
  2936. {
  2937. statement_t *stmt = make_statement(STMT_IMPORT);
  2938. stmt->u.str = str;
  2939. return stmt;
  2940. }
  2941. static statement_t *make_statement_module(type_t *type)
  2942. {
  2943. statement_t *stmt = make_statement(STMT_MODULE);
  2944. stmt->u.type = type;
  2945. return stmt;
  2946. }
  2947. static statement_t *make_statement_typedef(declarator_list_t *decls, int declonly)
  2948. {
  2949. declarator_t *decl, *next;
  2950. statement_t *stmt;
  2951. if (!decls) return NULL;
  2952. stmt = make_statement(STMT_TYPEDEF);
  2953. stmt->u.type_list = NULL;
  2954. stmt->declonly = declonly;
  2955. LIST_FOR_EACH_ENTRY_SAFE( decl, next, decls, declarator_t, entry )
  2956. {
  2957. var_t *var = decl->var;
  2958. type_t *type = find_type_or_error(current_namespace, var->name);
  2959. stmt->u.type_list = append_typeref(stmt->u.type_list, make_typeref(type));
  2960. free(decl);
  2961. free(var);
  2962. }
  2963. return stmt;
  2964. }
  2965. static statement_t *make_statement_parameterized_type(type_t *type, typeref_list_t *params)
  2966. {
  2967. statement_t *stmt = make_statement(STMT_TYPE);
  2968. stmt->u.type = type_parameterized_type_specialize_partial(type, params);
  2969. return stmt;
  2970. }
  2971. static statement_t *make_statement_delegate(type_t *ret, var_list_t *args)
  2972. {
  2973. declarator_t *decl = make_declarator(make_var(xstrdup("Invoke")));
  2974. decl_spec_t *spec = make_decl_spec(ret, NULL, NULL, STG_NONE, 0, 0);
  2975. append_chain_type(decl, type_new_function(args), 0);
  2976. return make_statement_declaration(declare_var(NULL, spec, decl, FALSE));
  2977. }
  2978. static statement_list_t *append_statements(statement_list_t *l1, statement_list_t *l2)
  2979. {
  2980. if (!l2) return l1;
  2981. if (!l1 || l1 == l2) return l2;
  2982. list_move_tail (l1, l2);
  2983. return l1;
  2984. }
  2985. static attr_list_t *append_attribs(attr_list_t *l1, attr_list_t *l2)
  2986. {
  2987. if (!l2) return l1;
  2988. if (!l1 || l1 == l2) return l2;
  2989. list_move_tail (l1, l2);
  2990. return l1;
  2991. }
  2992. static statement_list_t *append_statement(statement_list_t *list, statement_t *stmt)
  2993. {
  2994. if (!stmt) return list;
  2995. if (!list)
  2996. {
  2997. list = xmalloc( sizeof(*list) );
  2998. list_init( list );
  2999. }
  3000. list_add_tail( list, &stmt->entry );
  3001. return list;
  3002. }
  3003. void init_loc_info(loc_info_t *i)
  3004. {
  3005. i->input_name = input_name ? input_name : "stdin";
  3006. i->line_number = line_number;
  3007. i->near_text = parser_text;
  3008. }
  3009. type_t *find_parameterized_type(type_t *type, typeref_list_t *params)
  3010. {
  3011. char *name = format_parameterized_type_name(type, params);
  3012. if (parameters_namespace)
  3013. {
  3014. assert(type->type_type == TYPE_PARAMETERIZED_TYPE);
  3015. type = type_parameterized_type_specialize_partial(type, params);
  3016. }
  3017. else if ((type = find_type(name, type->namespace, 0)))
  3018. assert(type->type_type != TYPE_PARAMETERIZED_TYPE);
  3019. else
  3020. error_loc("parameterized type '%s' not declared\n", name);
  3021. free(name);
  3022. return type;
  3023. }