parser.y 118 KB

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