parser.y 117 KB

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