PageRenderTime 113ms CodeModel.GetById 39ms RepoModel.GetById 0ms app.codeStats 0ms

/tools/widl/parser.y

https://github.com/diosmosis/wine
Happy | 2819 lines | 2534 code | 285 blank | 0 comment | 0 complexity | 681f50f3c736b42d1b264fd1a1d31d79 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-2.0
  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. #if defined(YYBYACC)
  38. /* Berkeley yacc (byacc) doesn't seem to know about these */
  39. /* Some *BSD supplied versions do define these though */
  40. # ifndef YYEMPTY
  41. # define YYEMPTY (-1) /* Empty lookahead value of yychar */
  42. # endif
  43. # ifndef YYLEX
  44. # define YYLEX yylex()
  45. # endif
  46. #elif defined(YYBISON)
  47. /* Bison was used for original development */
  48. /* #define YYEMPTY -2 */
  49. /* #define YYLEX yylex() */
  50. #else
  51. /* No yacc we know yet */
  52. # if !defined(YYEMPTY) || !defined(YYLEX)
  53. # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
  54. # elif defined(__GNUC__) /* gcc defines the #warning directive */
  55. # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
  56. /* #else we just take a chance that it works... */
  57. # endif
  58. #endif
  59. #define YYERROR_VERBOSE
  60. static unsigned char pointer_default = RPC_FC_UP;
  61. typedef struct list typelist_t;
  62. struct typenode {
  63. type_t *type;
  64. struct list entry;
  65. };
  66. struct _import_t
  67. {
  68. char *name;
  69. int import_performed;
  70. };
  71. typedef struct _decl_spec_t
  72. {
  73. type_t *type;
  74. attr_list_t *attrs;
  75. enum storage_class stgclass;
  76. } decl_spec_t;
  77. typelist_t incomplete_types = LIST_INIT(incomplete_types);
  78. static void fix_incomplete(void);
  79. static void fix_incomplete_types(type_t *complete_type);
  80. static str_list_t *append_str(str_list_t *list, char *str);
  81. static attr_list_t *append_attr(attr_list_t *list, attr_t *attr);
  82. static attr_list_t *append_attr_list(attr_list_t *new_list, attr_list_t *old_list);
  83. static decl_spec_t *make_decl_spec(type_t *type, decl_spec_t *left, decl_spec_t *right, attr_t *attr, enum storage_class stgclass);
  84. static attr_t *make_attr(enum attr_type type);
  85. static attr_t *make_attrv(enum attr_type type, unsigned int val);
  86. static attr_t *make_attrp(enum attr_type type, void *val);
  87. static expr_list_t *append_expr(expr_list_t *list, expr_t *expr);
  88. static array_dims_t *append_array(array_dims_t *list, expr_t *expr);
  89. static var_t *declare_var(attr_list_t *attrs, decl_spec_t *decl_spec, const declarator_t *decl, int top);
  90. static var_list_t *set_var_types(attr_list_t *attrs, decl_spec_t *decl_spec, declarator_list_t *decls);
  91. static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface);
  92. static ifref_t *make_ifref(type_t *iface);
  93. static var_list_t *append_var_list(var_list_t *list, var_list_t *vars);
  94. static declarator_list_t *append_declarator(declarator_list_t *list, declarator_t *p);
  95. static declarator_t *make_declarator(var_t *var);
  96. static type_t *make_safearray(type_t *type);
  97. static typelib_t *make_library(const char *name, const attr_list_t *attrs);
  98. static type_t *append_ptrchain_type(type_t *ptrchain, type_t *type);
  99. static type_t *reg_typedefs(decl_spec_t *decl_spec, var_list_t *names, attr_list_t *attrs);
  100. static type_t *find_type_or_error(const char *name, int t);
  101. static type_t *find_type_or_error2(char *name, int t);
  102. static var_t *reg_const(var_t *var);
  103. static char *gen_name(void);
  104. static void check_arg_attrs(const var_t *arg);
  105. static void check_statements(const statement_list_t *stmts, int is_inside_library);
  106. static void check_all_user_types(const statement_list_t *stmts);
  107. static attr_list_t *check_iface_attrs(const char *name, attr_list_t *attrs);
  108. static attr_list_t *check_function_attrs(const char *name, attr_list_t *attrs);
  109. static attr_list_t *check_typedef_attrs(attr_list_t *attrs);
  110. static attr_list_t *check_enum_attrs(attr_list_t *attrs);
  111. static attr_list_t *check_struct_attrs(attr_list_t *attrs);
  112. static attr_list_t *check_union_attrs(attr_list_t *attrs);
  113. static attr_list_t *check_field_attrs(const char *name, attr_list_t *attrs);
  114. static attr_list_t *check_library_attrs(const char *name, attr_list_t *attrs);
  115. static attr_list_t *check_dispiface_attrs(const char *name, attr_list_t *attrs);
  116. static attr_list_t *check_module_attrs(const char *name, attr_list_t *attrs);
  117. static attr_list_t *check_coclass_attrs(const char *name, attr_list_t *attrs);
  118. const char *get_attr_display_name(enum attr_type type);
  119. static void add_explicit_handle_if_necessary(var_t *func);
  120. static void check_def(const type_t *t);
  121. static statement_t *make_statement(enum statement_type type);
  122. static statement_t *make_statement_type_decl(type_t *type);
  123. static statement_t *make_statement_reference(type_t *type);
  124. static statement_t *make_statement_declaration(var_t *var);
  125. static statement_t *make_statement_library(typelib_t *typelib);
  126. static statement_t *make_statement_cppquote(const char *str);
  127. static statement_t *make_statement_importlib(const char *str);
  128. static statement_t *make_statement_module(type_t *type);
  129. static statement_t *make_statement_typedef(var_list_t *names);
  130. static statement_t *make_statement_import(const char *str);
  131. static statement_t *make_statement_typedef(var_list_t *names);
  132. static statement_list_t *append_statement(statement_list_t *list, statement_t *stmt);
  133. %}
  134. %union {
  135. attr_t *attr;
  136. attr_list_t *attr_list;
  137. str_list_t *str_list;
  138. expr_t *expr;
  139. expr_list_t *expr_list;
  140. array_dims_t *array_dims;
  141. type_t *type;
  142. var_t *var;
  143. var_list_t *var_list;
  144. declarator_t *declarator;
  145. declarator_list_t *declarator_list;
  146. statement_t *statement;
  147. statement_list_t *stmt_list;
  148. ifref_t *ifref;
  149. ifref_list_t *ifref_list;
  150. char *str;
  151. UUID *uuid;
  152. unsigned int num;
  153. double dbl;
  154. interface_info_t ifinfo;
  155. typelib_t *typelib;
  156. struct _import_t *import;
  157. struct _decl_spec_t *declspec;
  158. enum storage_class stgclass;
  159. }
  160. %token <str> aIDENTIFIER
  161. %token <str> aKNOWNTYPE
  162. %token <num> aNUM aHEXNUM
  163. %token <dbl> aDOUBLE
  164. %token <str> aSTRING aWSTRING aSQSTRING
  165. %token <uuid> aUUID
  166. %token aEOF
  167. %token SHL SHR
  168. %token MEMBERPTR
  169. %token EQUALITY INEQUALITY
  170. %token GREATEREQUAL LESSEQUAL
  171. %token LOGICALOR LOGICALAND
  172. %token ELLIPSIS
  173. %token tAGGREGATABLE tALLOCATE tANNOTATION tAPPOBJECT tASYNC tASYNCUUID
  174. %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
  175. %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
  176. %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
  177. %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
  178. %token tDECODE tDEFAULT tDEFAULTBIND
  179. %token tDEFAULTCOLLELEM
  180. %token tDEFAULTVALUE
  181. %token tDEFAULTVTABLE
  182. %token tDISABLECONSISTENCYCHECK tDISPLAYBIND
  183. %token tDISPINTERFACE
  184. %token tDLLNAME tDOUBLE tDUAL
  185. %token tENABLEALLOCATE tENCODE tENDPOINT
  186. %token tENTRY tENUM tERRORSTATUST
  187. %token tEXPLICITHANDLE tEXTERN
  188. %token tFALSE
  189. %token tFASTCALL tFAULTSTATUS
  190. %token tFLOAT tFORCEALLOCATE
  191. %token tHANDLE
  192. %token tHANDLET
  193. %token tHELPCONTEXT tHELPFILE
  194. %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
  195. %token tHIDDEN
  196. %token tHYPER tID tIDEMPOTENT
  197. %token tIGNORE tIIDIS
  198. %token tIMMEDIATEBIND
  199. %token tIMPLICITHANDLE
  200. %token tIMPORT tIMPORTLIB
  201. %token tIN tIN_LINE tINLINE
  202. %token tINPUTSYNC
  203. %token tINT tINT3264 tINT64
  204. %token tINTERFACE
  205. %token tLCID
  206. %token tLENGTHIS tLIBRARY
  207. %token tLICENSED tLOCAL
  208. %token tLONG
  209. %token tMAYBE tMESSAGE
  210. %token tMETHODS
  211. %token tMODULE
  212. %token tNOCODE tNONBROWSABLE
  213. %token tNONCREATABLE
  214. %token tNONEXTENSIBLE
  215. %token tNOTIFY tNOTIFYFLAG
  216. %token tNULL
  217. %token tOBJECT tODL tOLEAUTOMATION
  218. %token tOPTIMIZE tOPTIONAL
  219. %token tOUT
  220. %token tPARTIALIGNORE tPASCAL
  221. %token tPOINTERDEFAULT
  222. %token tPROGID tPROPERTIES
  223. %token tPROPGET tPROPPUT tPROPPUTREF
  224. %token tPROXY tPTR
  225. %token tPUBLIC
  226. %token tRANGE
  227. %token tREADONLY tREF
  228. %token tREGISTER tREPRESENTAS
  229. %token tREQUESTEDIT
  230. %token tRESTRICTED
  231. %token tRETVAL
  232. %token tSAFEARRAY
  233. %token tSHORT
  234. %token tSIGNED
  235. %token tSIZEIS tSIZEOF
  236. %token tSMALL
  237. %token tSOURCE
  238. %token tSTATIC
  239. %token tSTDCALL
  240. %token tSTRICTCONTEXTHANDLE
  241. %token tSTRING tSTRUCT
  242. %token tSWITCH tSWITCHIS tSWITCHTYPE
  243. %token tTHREADING tTRANSMITAS
  244. %token tTRUE
  245. %token tTYPEDEF
  246. %token tUIDEFAULT tUNION
  247. %token tUNIQUE
  248. %token tUNSIGNED
  249. %token tUSESGETLASTERROR tUSERMARSHAL tUUID
  250. %token tV1ENUM
  251. %token tVARARG
  252. %token tVERSION tVIPROGID
  253. %token tVOID
  254. %token tWCHAR tWIREMARSHAL
  255. %token tAPARTMENT tNEUTRAL tSINGLE tFREE tBOTH
  256. %type <attr> attribute type_qualifier function_specifier
  257. %type <attr_list> m_attributes attributes attrib_list m_type_qual_list
  258. %type <str_list> str_list
  259. %type <expr> m_expr expr expr_const expr_int_const array m_bitfield
  260. %type <expr_list> m_exprs /* exprs expr_list */ expr_list_int_const
  261. %type <ifinfo> interfacehdr
  262. %type <stgclass> storage_cls_spec
  263. %type <declspec> decl_spec decl_spec_no_type m_decl_spec_no_type
  264. %type <type> inherit interface interfacedef interfacedec
  265. %type <type> dispinterface dispinterfacehdr dispinterfacedef
  266. %type <type> module modulehdr moduledef
  267. %type <type> base_type int_std
  268. %type <type> enumdef structdef uniondef typedecl
  269. %type <type> type
  270. %type <ifref> coclass_int
  271. %type <ifref_list> coclass_ints
  272. %type <var> arg ne_union_field union_field s_field case enum declaration
  273. %type <var> funcdef
  274. %type <var_list> m_args arg_list args dispint_meths
  275. %type <var_list> fields ne_union_fields cases enums enum_list dispint_props field
  276. %type <var> m_ident ident
  277. %type <declarator> declarator direct_declarator init_declarator struct_declarator
  278. %type <declarator> m_any_declarator any_declarator any_declarator_no_direct any_direct_declarator
  279. %type <declarator> m_abstract_declarator abstract_declarator abstract_declarator_no_direct abstract_direct_declarator
  280. %type <declarator_list> declarator_list struct_declarator_list
  281. %type <type> coclass coclasshdr coclassdef
  282. %type <num> pointer_type threading_type version
  283. %type <str> libraryhdr callconv cppquote importlib import t_ident
  284. %type <uuid> uuid_string
  285. %type <import> import_start
  286. %type <typelib> library_start librarydef
  287. %type <statement> statement typedef
  288. %type <stmt_list> gbl_statements imp_statements int_statements
  289. %left ','
  290. %right '?' ':'
  291. %left LOGICALOR
  292. %left LOGICALAND
  293. %left '|'
  294. %left '^'
  295. %left '&'
  296. %left EQUALITY INEQUALITY
  297. %left '<' '>' LESSEQUAL GREATEREQUAL
  298. %left SHL SHR
  299. %left '-' '+'
  300. %left '*' '/' '%'
  301. %right '!' '~' CAST PPTR POS NEG ADDRESSOF tSIZEOF
  302. %left '.' MEMBERPTR '[' ']'
  303. %%
  304. input: gbl_statements { fix_incomplete();
  305. check_statements($1, FALSE);
  306. check_all_user_types($1);
  307. write_header($1);
  308. write_id_data($1);
  309. write_proxies($1);
  310. write_client($1);
  311. write_server($1);
  312. write_regscript($1);
  313. write_dlldata($1);
  314. write_local_stubs($1);
  315. }
  316. ;
  317. gbl_statements: { $$ = NULL; }
  318. | gbl_statements interfacedec { $$ = append_statement($1, make_statement_reference($2)); }
  319. | gbl_statements interfacedef { $$ = append_statement($1, make_statement_type_decl($2)); }
  320. | gbl_statements coclass ';' { $$ = $1;
  321. reg_type($2, $2->name, 0);
  322. }
  323. | gbl_statements coclassdef { $$ = append_statement($1, make_statement_type_decl($2));
  324. reg_type($2, $2->name, 0);
  325. }
  326. | gbl_statements moduledef { $$ = append_statement($1, make_statement_module($2)); }
  327. | gbl_statements librarydef { $$ = append_statement($1, make_statement_library($2)); }
  328. | gbl_statements statement { $$ = append_statement($1, $2); }
  329. ;
  330. imp_statements: { $$ = NULL; }
  331. | imp_statements interfacedec { $$ = append_statement($1, make_statement_reference($2)); }
  332. | imp_statements interfacedef { $$ = append_statement($1, make_statement_type_decl($2)); }
  333. | imp_statements coclass ';' { $$ = $1; reg_type($2, $2->name, 0); }
  334. | imp_statements coclassdef { $$ = append_statement($1, make_statement_type_decl($2));
  335. reg_type($2, $2->name, 0);
  336. }
  337. | imp_statements moduledef { $$ = append_statement($1, make_statement_module($2)); }
  338. | imp_statements statement { $$ = append_statement($1, $2); }
  339. | imp_statements importlib { $$ = append_statement($1, make_statement_importlib($2)); }
  340. | imp_statements librarydef { $$ = append_statement($1, make_statement_library($2)); }
  341. ;
  342. int_statements: { $$ = NULL; }
  343. | int_statements statement { $$ = append_statement($1, $2); }
  344. ;
  345. semicolon_opt:
  346. | ';'
  347. ;
  348. statement:
  349. cppquote { $$ = make_statement_cppquote($1); }
  350. | typedecl ';' { $$ = make_statement_type_decl($1); }
  351. | declaration ';' { $$ = make_statement_declaration($1); }
  352. | import { $$ = make_statement_import($1); }
  353. | typedef ';' { $$ = $1; }
  354. ;
  355. typedecl:
  356. enumdef
  357. | tENUM aIDENTIFIER { $$ = type_new_enum($2, FALSE, NULL); }
  358. | structdef
  359. | tSTRUCT aIDENTIFIER { $$ = type_new_struct($2, FALSE, NULL); }
  360. | uniondef
  361. | tUNION aIDENTIFIER { $$ = type_new_nonencapsulated_union($2, FALSE, NULL); }
  362. | attributes enumdef { $$ = $2; $$->attrs = check_enum_attrs($1); }
  363. | attributes structdef { $$ = $2; $$->attrs = check_struct_attrs($1); }
  364. | attributes uniondef { $$ = $2; $$->attrs = check_union_attrs($1); }
  365. ;
  366. cppquote: tCPPQUOTE '(' aSTRING ')' { $$ = $3; }
  367. ;
  368. import_start: tIMPORT aSTRING ';' { assert(yychar == YYEMPTY);
  369. $$ = xmalloc(sizeof(struct _import_t));
  370. $$->name = $2;
  371. $$->import_performed = do_import($2);
  372. if (!$$->import_performed) yychar = aEOF;
  373. }
  374. ;
  375. import: import_start imp_statements aEOF { $$ = $1->name;
  376. if ($1->import_performed) pop_import();
  377. free($1);
  378. }
  379. ;
  380. importlib: tIMPORTLIB '(' aSTRING ')'
  381. semicolon_opt { $$ = $3; if(!parse_only) add_importlib($3); }
  382. ;
  383. libraryhdr: tLIBRARY aIDENTIFIER { $$ = $2; }
  384. ;
  385. library_start: attributes libraryhdr '{' { $$ = make_library($2, check_library_attrs($2, $1));
  386. if (!parse_only) start_typelib($$);
  387. }
  388. ;
  389. librarydef: library_start imp_statements '}'
  390. semicolon_opt { $$ = $1;
  391. $$->stmts = $2;
  392. if (!parse_only) end_typelib();
  393. }
  394. ;
  395. m_args: { $$ = NULL; }
  396. | args
  397. ;
  398. arg_list: arg { check_arg_attrs($1); $$ = append_var( NULL, $1 ); }
  399. | arg_list ',' arg { check_arg_attrs($3); $$ = append_var( $1, $3 ); }
  400. ;
  401. args: arg_list
  402. | arg_list ',' ELLIPSIS { $$ = append_var( $1, make_var(strdup("...")) ); }
  403. ;
  404. /* split into two rules to get bison to resolve a tVOID conflict */
  405. arg: attributes decl_spec m_any_declarator { if ($2->stgclass != STG_NONE && $2->stgclass != STG_REGISTER)
  406. error_loc("invalid storage class for function parameter\n");
  407. $$ = declare_var($1, $2, $3, TRUE);
  408. free($2); free($3);
  409. }
  410. | decl_spec m_any_declarator { if ($1->stgclass != STG_NONE && $1->stgclass != STG_REGISTER)
  411. error_loc("invalid storage class for function parameter\n");
  412. $$ = declare_var(NULL, $1, $2, TRUE);
  413. free($1); free($2);
  414. }
  415. ;
  416. array: '[' m_expr ']' { $$ = $2; }
  417. | '[' '*' ']' { $$ = make_expr(EXPR_VOID); }
  418. ;
  419. m_attributes: { $$ = NULL; }
  420. | attributes
  421. ;
  422. attributes:
  423. '[' attrib_list ']' { $$ = $2; }
  424. ;
  425. attrib_list: attribute { $$ = append_attr( NULL, $1 ); }
  426. | attrib_list ',' attribute { $$ = append_attr( $1, $3 ); }
  427. | attrib_list ']' '[' attribute { $$ = append_attr( $1, $4 ); }
  428. ;
  429. str_list: aSTRING { $$ = append_str( NULL, $1 ); }
  430. | str_list ',' aSTRING { $$ = append_str( $1, $3 ); }
  431. ;
  432. attribute: { $$ = NULL; }
  433. | tAGGREGATABLE { $$ = make_attr(ATTR_AGGREGATABLE); }
  434. | tANNOTATION '(' aSTRING ')' { $$ = make_attrp(ATTR_ANNOTATION, $3); }
  435. | tAPPOBJECT { $$ = make_attr(ATTR_APPOBJECT); }
  436. | tASYNC { $$ = make_attr(ATTR_ASYNC); }
  437. | tAUTOHANDLE { $$ = make_attr(ATTR_AUTO_HANDLE); }
  438. | tBINDABLE { $$ = make_attr(ATTR_BINDABLE); }
  439. | tBROADCAST { $$ = make_attr(ATTR_BROADCAST); }
  440. | tCALLAS '(' ident ')' { $$ = make_attrp(ATTR_CALLAS, $3); }
  441. | tCASE '(' expr_list_int_const ')' { $$ = make_attrp(ATTR_CASE, $3); }
  442. | tCODE { $$ = make_attr(ATTR_CODE); }
  443. | tCOMMSTATUS { $$ = make_attr(ATTR_COMMSTATUS); }
  444. | tCONTEXTHANDLE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); }
  445. | tCONTEXTHANDLENOSERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
  446. | tCONTEXTHANDLESERIALIZE { $$ = make_attrv(ATTR_CONTEXTHANDLE, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
  447. | tCONTROL { $$ = make_attr(ATTR_CONTROL); }
  448. | tDECODE { $$ = make_attr(ATTR_DECODE); }
  449. | tDEFAULT { $$ = make_attr(ATTR_DEFAULT); }
  450. | tDEFAULTBIND { $$ = make_attr(ATTR_DEFAULTBIND); }
  451. | tDEFAULTCOLLELEM { $$ = make_attr(ATTR_DEFAULTCOLLELEM); }
  452. | tDEFAULTVALUE '(' expr_const ')' { $$ = make_attrp(ATTR_DEFAULTVALUE, $3); }
  453. | tDEFAULTVTABLE { $$ = make_attr(ATTR_DEFAULTVTABLE); }
  454. | tDISABLECONSISTENCYCHECK { $$ = make_attr(ATTR_DISABLECONSISTENCYCHECK); }
  455. | tDISPLAYBIND { $$ = make_attr(ATTR_DISPLAYBIND); }
  456. | tDLLNAME '(' aSTRING ')' { $$ = make_attrp(ATTR_DLLNAME, $3); }
  457. | tDUAL { $$ = make_attr(ATTR_DUAL); }
  458. | tENABLEALLOCATE { $$ = make_attr(ATTR_ENABLEALLOCATE); }
  459. | tENCODE { $$ = make_attr(ATTR_ENCODE); }
  460. | tENDPOINT '(' str_list ')' { $$ = make_attrp(ATTR_ENDPOINT, $3); }
  461. | tENTRY '(' expr_const ')' { $$ = make_attrp(ATTR_ENTRY, $3); }
  462. | tEXPLICITHANDLE { $$ = make_attr(ATTR_EXPLICIT_HANDLE); }
  463. | tFAULTSTATUS { $$ = make_attr(ATTR_FAULTSTATUS); }
  464. | tFORCEALLOCATE { $$ = make_attr(ATTR_FORCEALLOCATE); }
  465. | tHANDLE { $$ = make_attr(ATTR_HANDLE); }
  466. | tHELPCONTEXT '(' expr_int_const ')' { $$ = make_attrp(ATTR_HELPCONTEXT, $3); }
  467. | tHELPFILE '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPFILE, $3); }
  468. | tHELPSTRING '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRING, $3); }
  469. | tHELPSTRINGCONTEXT '(' expr_int_const ')' { $$ = make_attrp(ATTR_HELPSTRINGCONTEXT, $3); }
  470. | tHELPSTRINGDLL '(' aSTRING ')' { $$ = make_attrp(ATTR_HELPSTRINGDLL, $3); }
  471. | tHIDDEN { $$ = make_attr(ATTR_HIDDEN); }
  472. | tID '(' expr_int_const ')' { $$ = make_attrp(ATTR_ID, $3); }
  473. | tIDEMPOTENT { $$ = make_attr(ATTR_IDEMPOTENT); }
  474. | tIGNORE { $$ = make_attr(ATTR_IGNORE); }
  475. | tIIDIS '(' expr ')' { $$ = make_attrp(ATTR_IIDIS, $3); }
  476. | tIMMEDIATEBIND { $$ = make_attr(ATTR_IMMEDIATEBIND); }
  477. | tIMPLICITHANDLE '(' tHANDLET aIDENTIFIER ')' { $$ = make_attrp(ATTR_IMPLICIT_HANDLE, $4); }
  478. | tIN { $$ = make_attr(ATTR_IN); }
  479. | tINPUTSYNC { $$ = make_attr(ATTR_INPUTSYNC); }
  480. | tLENGTHIS '(' m_exprs ')' { $$ = make_attrp(ATTR_LENGTHIS, $3); }
  481. | tLCID '(' expr_int_const ')' { $$ = make_attrp(ATTR_LIBLCID, $3); }
  482. | tLCID { $$ = make_attr(ATTR_PARAMLCID); }
  483. | tLICENSED { $$ = make_attr(ATTR_LICENSED); }
  484. | tLOCAL { $$ = make_attr(ATTR_LOCAL); }
  485. | tMAYBE { $$ = make_attr(ATTR_MAYBE); }
  486. | tMESSAGE { $$ = make_attr(ATTR_MESSAGE); }
  487. | tNOCODE { $$ = make_attr(ATTR_NOCODE); }
  488. | tNONBROWSABLE { $$ = make_attr(ATTR_NONBROWSABLE); }
  489. | tNONCREATABLE { $$ = make_attr(ATTR_NONCREATABLE); }
  490. | tNONEXTENSIBLE { $$ = make_attr(ATTR_NONEXTENSIBLE); }
  491. | tNOTIFY { $$ = make_attr(ATTR_NOTIFY); }
  492. | tNOTIFYFLAG { $$ = make_attr(ATTR_NOTIFYFLAG); }
  493. | tOBJECT { $$ = make_attr(ATTR_OBJECT); }
  494. | tODL { $$ = make_attr(ATTR_ODL); }
  495. | tOLEAUTOMATION { $$ = make_attr(ATTR_OLEAUTOMATION); }
  496. | tOPTIMIZE '(' aSTRING ')' { $$ = make_attrp(ATTR_OPTIMIZE, $3); }
  497. | tOPTIONAL { $$ = make_attr(ATTR_OPTIONAL); }
  498. | tOUT { $$ = make_attr(ATTR_OUT); }
  499. | tPARTIALIGNORE { $$ = make_attr(ATTR_PARTIALIGNORE); }
  500. | tPOINTERDEFAULT '(' pointer_type ')' { $$ = make_attrv(ATTR_POINTERDEFAULT, $3); }
  501. | tPROGID '(' aSTRING ')' { $$ = make_attrp(ATTR_PROGID, $3); }
  502. | tPROPGET { $$ = make_attr(ATTR_PROPGET); }
  503. | tPROPPUT { $$ = make_attr(ATTR_PROPPUT); }
  504. | tPROPPUTREF { $$ = make_attr(ATTR_PROPPUTREF); }
  505. | tPROXY { $$ = make_attr(ATTR_PROXY); }
  506. | tPUBLIC { $$ = make_attr(ATTR_PUBLIC); }
  507. | tRANGE '(' expr_int_const ',' expr_int_const ')'
  508. { expr_list_t *list = append_expr( NULL, $3 );
  509. list = append_expr( list, $5 );
  510. $$ = make_attrp(ATTR_RANGE, list); }
  511. | tREADONLY { $$ = make_attr(ATTR_READONLY); }
  512. | tREPRESENTAS '(' type ')' { $$ = make_attrp(ATTR_REPRESENTAS, $3); }
  513. | tREQUESTEDIT { $$ = make_attr(ATTR_REQUESTEDIT); }
  514. | tRESTRICTED { $$ = make_attr(ATTR_RESTRICTED); }
  515. | tRETVAL { $$ = make_attr(ATTR_RETVAL); }
  516. | tSIZEIS '(' m_exprs ')' { $$ = make_attrp(ATTR_SIZEIS, $3); }
  517. | tSOURCE { $$ = make_attr(ATTR_SOURCE); }
  518. | tSTRICTCONTEXTHANDLE { $$ = make_attr(ATTR_STRICTCONTEXTHANDLE); }
  519. | tSTRING { $$ = make_attr(ATTR_STRING); }
  520. | tSWITCHIS '(' expr ')' { $$ = make_attrp(ATTR_SWITCHIS, $3); }
  521. | tSWITCHTYPE '(' type ')' { $$ = make_attrp(ATTR_SWITCHTYPE, $3); }
  522. | tTRANSMITAS '(' type ')' { $$ = make_attrp(ATTR_TRANSMITAS, $3); }
  523. | tTHREADING '(' threading_type ')' { $$ = make_attrv(ATTR_THREADING, $3); }
  524. | tUIDEFAULT { $$ = make_attr(ATTR_UIDEFAULT); }
  525. | tUSESGETLASTERROR { $$ = make_attr(ATTR_USESGETLASTERROR); }
  526. | tUSERMARSHAL '(' type ')' { $$ = make_attrp(ATTR_USERMARSHAL, $3); }
  527. | tUUID '(' uuid_string ')' { $$ = make_attrp(ATTR_UUID, $3); }
  528. | tV1ENUM { $$ = make_attr(ATTR_V1ENUM); }
  529. | tVARARG { $$ = make_attr(ATTR_VARARG); }
  530. | tVERSION '(' version ')' { $$ = make_attrv(ATTR_VERSION, $3); }
  531. | tVIPROGID '(' aSTRING ')' { $$ = make_attrp(ATTR_VIPROGID, $3); }
  532. | tWIREMARSHAL '(' type ')' { $$ = make_attrp(ATTR_WIREMARSHAL, $3); }
  533. | pointer_type { $$ = make_attrv(ATTR_POINTERTYPE, $1); }
  534. ;
  535. uuid_string:
  536. aUUID
  537. | aSTRING { if (!is_valid_uuid($1))
  538. error_loc("invalid UUID: %s\n", $1);
  539. $$ = parse_uuid($1); }
  540. ;
  541. callconv: tCDECL { $$ = $<str>1; }
  542. | tFASTCALL { $$ = $<str>1; }
  543. | tPASCAL { $$ = $<str>1; }
  544. | tSTDCALL { $$ = $<str>1; }
  545. ;
  546. cases: { $$ = NULL; }
  547. | cases case { $$ = append_var( $1, $2 ); }
  548. ;
  549. case: tCASE expr_int_const ':' union_field { attr_t *a = make_attrp(ATTR_CASE, append_expr( NULL, $2 ));
  550. $$ = $4; if (!$$) $$ = make_var(NULL);
  551. $$->attrs = append_attr( $$->attrs, a );
  552. }
  553. | tDEFAULT ':' union_field { attr_t *a = make_attr(ATTR_DEFAULT);
  554. $$ = $3; if (!$$) $$ = make_var(NULL);
  555. $$->attrs = append_attr( $$->attrs, a );
  556. }
  557. ;
  558. enums: { $$ = NULL; }
  559. | enum_list ',' { $$ = $1; }
  560. | enum_list
  561. ;
  562. enum_list: enum { if (!$1->eval)
  563. $1->eval = make_exprl(EXPR_NUM, 0 /* default for first enum entry */);
  564. $$ = append_var( NULL, $1 );
  565. }
  566. | enum_list ',' enum { if (!$3->eval)
  567. {
  568. var_t *last = LIST_ENTRY( list_tail($$), var_t, entry );
  569. $3->eval = make_exprl(EXPR_NUM, last->eval->cval + 1);
  570. }
  571. $$ = append_var( $1, $3 );
  572. }
  573. ;
  574. enum: ident '=' expr_int_const { $$ = reg_const($1);
  575. $$->eval = $3;
  576. $$->type = type_new_int(TYPE_BASIC_INT, 0);
  577. }
  578. | ident { $$ = reg_const($1);
  579. $$->type = type_new_int(TYPE_BASIC_INT, 0);
  580. }
  581. ;
  582. enumdef: tENUM t_ident '{' enums '}' { $$ = type_new_enum($2, TRUE, $4); }
  583. ;
  584. m_exprs: m_expr { $$ = append_expr( NULL, $1 ); }
  585. | m_exprs ',' m_expr { $$ = append_expr( $1, $3 ); }
  586. ;
  587. /*
  588. exprs: { $$ = make_expr(EXPR_VOID); }
  589. | expr_list
  590. ;
  591. expr_list: expr
  592. | expr_list ',' expr { LINK($3, $1); $$ = $3; }
  593. ;
  594. */
  595. m_expr: { $$ = make_expr(EXPR_VOID); }
  596. | expr
  597. ;
  598. expr: aNUM { $$ = make_exprl(EXPR_NUM, $1); }
  599. | aHEXNUM { $$ = make_exprl(EXPR_HEXNUM, $1); }
  600. | aDOUBLE { $$ = make_exprd(EXPR_DOUBLE, $1); }
  601. | tFALSE { $$ = make_exprl(EXPR_TRUEFALSE, 0); }
  602. | tNULL { $$ = make_exprl(EXPR_NUM, 0); }
  603. | tTRUE { $$ = make_exprl(EXPR_TRUEFALSE, 1); }
  604. | aSTRING { $$ = make_exprs(EXPR_STRLIT, $1); }
  605. | aWSTRING { $$ = make_exprs(EXPR_WSTRLIT, $1); }
  606. | aSQSTRING { $$ = make_exprs(EXPR_CHARCONST, $1); }
  607. | aIDENTIFIER { $$ = make_exprs(EXPR_IDENTIFIER, $1); }
  608. | expr '?' expr ':' expr { $$ = make_expr3(EXPR_COND, $1, $3, $5); }
  609. | expr LOGICALOR expr { $$ = make_expr2(EXPR_LOGOR, $1, $3); }
  610. | expr LOGICALAND expr { $$ = make_expr2(EXPR_LOGAND, $1, $3); }
  611. | expr '|' expr { $$ = make_expr2(EXPR_OR , $1, $3); }
  612. | expr '^' expr { $$ = make_expr2(EXPR_XOR, $1, $3); }
  613. | expr '&' expr { $$ = make_expr2(EXPR_AND, $1, $3); }
  614. | expr EQUALITY expr { $$ = make_expr2(EXPR_EQUALITY, $1, $3); }
  615. | expr INEQUALITY expr { $$ = make_expr2(EXPR_INEQUALITY, $1, $3); }
  616. | expr '>' expr { $$ = make_expr2(EXPR_GTR, $1, $3); }
  617. | expr '<' expr { $$ = make_expr2(EXPR_LESS, $1, $3); }
  618. | expr GREATEREQUAL expr { $$ = make_expr2(EXPR_GTREQL, $1, $3); }
  619. | expr LESSEQUAL expr { $$ = make_expr2(EXPR_LESSEQL, $1, $3); }
  620. | expr SHL expr { $$ = make_expr2(EXPR_SHL, $1, $3); }
  621. | expr SHR expr { $$ = make_expr2(EXPR_SHR, $1, $3); }
  622. | expr '+' expr { $$ = make_expr2(EXPR_ADD, $1, $3); }
  623. | expr '-' expr { $$ = make_expr2(EXPR_SUB, $1, $3); }
  624. | expr '%' expr { $$ = make_expr2(EXPR_MOD, $1, $3); }
  625. | expr '*' expr { $$ = make_expr2(EXPR_MUL, $1, $3); }
  626. | expr '/' expr { $$ = make_expr2(EXPR_DIV, $1, $3); }
  627. | '!' expr { $$ = make_expr1(EXPR_LOGNOT, $2); }
  628. | '~' expr { $$ = make_expr1(EXPR_NOT, $2); }
  629. | '+' expr %prec POS { $$ = make_expr1(EXPR_POS, $2); }
  630. | '-' expr %prec NEG { $$ = make_expr1(EXPR_NEG, $2); }
  631. | '&' expr %prec ADDRESSOF { $$ = make_expr1(EXPR_ADDRESSOF, $2); }
  632. | '*' expr %prec PPTR { $$ = make_expr1(EXPR_PPTR, $2); }
  633. | expr MEMBERPTR aIDENTIFIER { $$ = make_expr2(EXPR_MEMBER, make_expr1(EXPR_PPTR, $1), make_exprs(EXPR_IDENTIFIER, $3)); }
  634. | expr '.' aIDENTIFIER { $$ = make_expr2(EXPR_MEMBER, $1, make_exprs(EXPR_IDENTIFIER, $3)); }
  635. | '(' decl_spec m_abstract_declarator ')' expr %prec CAST
  636. { $$ = make_exprt(EXPR_CAST, declare_var(NULL, $2, $3, 0), $5); free($2); free($3); }
  637. | tSIZEOF '(' decl_spec m_abstract_declarator ')'
  638. { $$ = make_exprt(EXPR_SIZEOF, declare_var(NULL, $3, $4, 0), NULL); free($3); free($4); }
  639. | expr '[' expr ']' { $$ = make_expr2(EXPR_ARRAY, $1, $3); }
  640. | '(' expr ')' { $$ = $2; }
  641. ;
  642. expr_list_int_const: expr_int_const { $$ = append_expr( NULL, $1 ); }
  643. | expr_list_int_const ',' expr_int_const { $$ = append_expr( $1, $3 ); }
  644. ;
  645. expr_int_const: expr { $$ = $1;
  646. if (!$$->is_const)
  647. error_loc("expression is not an integer constant\n");
  648. }
  649. ;
  650. expr_const: expr { $$ = $1;
  651. if (!$$->is_const && $$->type != EXPR_STRLIT && $$->type != EXPR_WSTRLIT)
  652. error_loc("expression is not constant\n");
  653. }
  654. ;
  655. fields: { $$ = NULL; }
  656. | fields field { $$ = append_var_list($1, $2); }
  657. ;
  658. field: m_attributes decl_spec struct_declarator_list ';'
  659. { const char *first = LIST_ENTRY(list_head($3), declarator_t, entry)->var->name;
  660. check_field_attrs(first, $1);
  661. $$ = set_var_types($1, $2, $3);
  662. }
  663. | m_attributes uniondef ';' { var_t *v = make_var(NULL);
  664. v->type = $2; v->attrs = $1;
  665. $$ = append_var(NULL, v);
  666. }
  667. ;
  668. ne_union_field:
  669. s_field ';' { $$ = $1; }
  670. | attributes ';' { $$ = make_var(NULL); $$->attrs = $1; }
  671. ;
  672. ne_union_fields: { $$ = NULL; }
  673. | ne_union_fields ne_union_field { $$ = append_var( $1, $2 ); }
  674. ;
  675. union_field:
  676. s_field ';' { $$ = $1; }
  677. | ';' { $$ = NULL; }
  678. ;
  679. s_field: m_attributes decl_spec declarator { $$ = declare_var(check_field_attrs($3->var->name, $1),
  680. $2, $3, FALSE);
  681. free($3);
  682. }
  683. ;
  684. funcdef: declaration { $$ = $1;
  685. if (type_get_type($$->type) != TYPE_FUNCTION)
  686. error_loc("only methods may be declared inside the methods section of a dispinterface\n");
  687. check_function_attrs($$->name, $$->attrs);
  688. }
  689. ;
  690. declaration:
  691. attributes decl_spec init_declarator
  692. { $$ = declare_var($1, $2, $3, FALSE);
  693. free($3);
  694. }
  695. | decl_spec init_declarator { $$ = declare_var(NULL, $1, $2, FALSE);
  696. free($2);
  697. }
  698. ;
  699. m_ident: { $$ = NULL; }
  700. | ident
  701. ;
  702. t_ident: { $$ = NULL; }
  703. | aIDENTIFIER { $$ = $1; }
  704. | aKNOWNTYPE { $$ = $1; }
  705. ;
  706. ident: aIDENTIFIER { $$ = make_var($1); }
  707. /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
  708. | aKNOWNTYPE { $$ = make_var($<str>1); }
  709. ;
  710. base_type: tBYTE { $$ = find_type_or_error($<str>1, 0); }
  711. | tWCHAR { $$ = find_type_or_error($<str>1, 0); }
  712. | int_std
  713. | tSIGNED int_std { $$ = type_new_int(type_basic_get_type($2), -1); }
  714. | tUNSIGNED int_std { $$ = type_new_int(type_basic_get_type($2), 1); }
  715. | tUNSIGNED { $$ = type_new_int(TYPE_BASIC_INT, 1); }
  716. | tFLOAT { $$ = find_type_or_error($<str>1, 0); }
  717. | tDOUBLE { $$ = find_type_or_error($<str>1, 0); }
  718. | tBOOLEAN { $$ = find_type_or_error($<str>1, 0); }
  719. | tERRORSTATUST { $$ = find_type_or_error($<str>1, 0); }
  720. | tHANDLET { $$ = find_type_or_error($<str>1, 0); }
  721. ;
  722. m_int:
  723. | tINT
  724. ;
  725. int_std: tINT { $$ = type_new_int(TYPE_BASIC_INT, 0); }
  726. | tSHORT m_int { $$ = type_new_int(TYPE_BASIC_INT16, 0); }
  727. | tSMALL { $$ = type_new_int(TYPE_BASIC_INT8, 0); }
  728. | tLONG m_int { $$ = type_new_int(TYPE_BASIC_INT32, 0); }
  729. | tHYPER m_int { $$ = type_new_int(TYPE_BASIC_HYPER, 0); }
  730. | tINT64 { $$ = type_new_int(TYPE_BASIC_INT64, 0); }
  731. | tCHAR { $$ = type_new_int(TYPE_BASIC_CHAR, 0); }
  732. | tINT3264 { $$ = type_new_int(TYPE_BASIC_INT3264, 0); }
  733. ;
  734. coclass: tCOCLASS aIDENTIFIER { $$ = type_new_coclass($2); }
  735. | tCOCLASS aKNOWNTYPE { $$ = find_type($2, 0);
  736. if (type_get_type_detect_alias($$) != TYPE_COCLASS)
  737. error_loc("%s was not declared a coclass at %s:%d\n",
  738. $2, $$->loc_info.input_name,
  739. $$->loc_info.line_number);
  740. }
  741. ;
  742. coclasshdr: attributes coclass { $$ = $2;
  743. check_def($$);
  744. $$->attrs = check_coclass_attrs($2->name, $1);
  745. }
  746. ;
  747. coclassdef: coclasshdr '{' coclass_ints '}' semicolon_opt
  748. { $$ = type_coclass_define($1, $3); }
  749. ;
  750. coclass_ints: { $$ = NULL; }
  751. | coclass_ints coclass_int { $$ = append_ifref( $1, $2 ); }
  752. ;
  753. coclass_int:
  754. m_attributes interfacedec { $$ = make_ifref($2); $$->attrs = $1; }
  755. ;
  756. dispinterface: tDISPINTERFACE aIDENTIFIER { $$ = get_type(TYPE_INTERFACE, $2, 0); }
  757. | tDISPINTERFACE aKNOWNTYPE { $$ = get_type(TYPE_INTERFACE, $2, 0); }
  758. ;
  759. dispinterfacehdr: attributes dispinterface { attr_t *attrs;
  760. $$ = $2;
  761. check_def($$);
  762. attrs = make_attr(ATTR_DISPINTERFACE);
  763. $$->attrs = append_attr( check_dispiface_attrs($2->name, $1), attrs );
  764. $$->defined = TRUE;
  765. }
  766. ;
  767. dispint_props: tPROPERTIES ':' { $$ = NULL; }
  768. | dispint_props s_field ';' { $$ = append_var( $1, $2 ); }
  769. ;
  770. dispint_meths: tMETHODS ':' { $$ = NULL; }
  771. | dispint_meths funcdef ';' { $$ = append_var( $1, $2 ); }
  772. ;
  773. dispinterfacedef: dispinterfacehdr '{'
  774. dispint_props
  775. dispint_meths
  776. '}' { $$ = $1;
  777. type_dispinterface_define($$, $3, $4);
  778. }
  779. | dispinterfacehdr
  780. '{' interface ';' '}' { $$ = $1;
  781. type_dispinterface_define_from_iface($$, $3);
  782. }
  783. ;
  784. inherit: { $$ = NULL; }
  785. | ':' aKNOWNTYPE { $$ = find_type_or_error2($2, 0); }
  786. ;
  787. interface: tINTERFACE aIDENTIFIER { $$ = get_type(TYPE_INTERFACE, $2, 0); }
  788. | tINTERFACE aKNOWNTYPE { $$ = get_type(TYPE_INTERFACE, $2, 0); }
  789. ;
  790. interfacehdr: attributes interface { $$.interface = $2;
  791. $$.old_pointer_default = pointer_default;
  792. if (is_attr($1, ATTR_POINTERDEFAULT))
  793. pointer_default = get_attrv($1, ATTR_POINTERDEFAULT);
  794. check_def($2);
  795. $2->attrs = check_iface_attrs($2->name, $1);
  796. $2->defined = TRUE;
  797. }
  798. ;
  799. interfacedef: interfacehdr inherit
  800. '{' int_statements '}' semicolon_opt { $$ = $1.interface;
  801. type_interface_define($$, $2, $4);
  802. pointer_default = $1.old_pointer_default;
  803. }
  804. /* MIDL is able to import the definition of a base class from inside the
  805. * definition of a derived class, I'll try to support it with this rule */
  806. | interfacehdr ':' aIDENTIFIER
  807. '{' import int_statements '}'
  808. semicolon_opt { $$ = $1.interface;
  809. type_interface_define($$, find_type_or_error2($3, 0), $6);
  810. pointer_default = $1.old_pointer_default;
  811. }
  812. | dispinterfacedef semicolon_opt { $$ = $1; }
  813. ;
  814. interfacedec:
  815. interface ';' { $$ = $1; }
  816. | dispinterface ';' { $$ = $1; }
  817. ;
  818. module: tMODULE aIDENTIFIER { $$ = type_new_module($2); }
  819. | tMODULE aKNOWNTYPE { $$ = type_new_module($2); }
  820. ;
  821. modulehdr: attributes module { $$ = $2;
  822. $$->attrs = check_module_attrs($2->name, $1);
  823. }
  824. ;
  825. moduledef: modulehdr '{' int_statements '}'
  826. semicolon_opt { $$ = $1;
  827. type_module_define($$, $3);
  828. }
  829. ;
  830. storage_cls_spec:
  831. tEXTERN { $$ = STG_EXTERN; }
  832. | tSTATIC { $$ = STG_STATIC; }
  833. | tREGISTER { $$ = STG_REGISTER; }
  834. ;
  835. function_specifier:
  836. tINLINE { $$ = make_attr(ATTR_INLINE); }
  837. ;
  838. type_qualifier:
  839. tCONST { $$ = make_attr(ATTR_CONST); }
  840. ;
  841. m_type_qual_list: { $$ = NULL; }
  842. | m_type_qual_list type_qualifier { $$ = append_attr($1, $2); }
  843. ;
  844. decl_spec: type m_decl_spec_no_type { $$ = make_decl_spec($1, $2, NULL, NULL, STG_NONE); }
  845. | decl_spec_no_type type m_decl_spec_no_type
  846. { $$ = make_decl_spec($2, $1, $3, NULL, STG_NONE); }
  847. ;
  848. m_decl_spec_no_type: { $$ = NULL; }
  849. | decl_spec_no_type
  850. ;
  851. decl_spec_no_type:
  852. type_qualifier m_decl_spec_no_type { $$ = make_decl_spec(NULL, $2, NULL, $1, STG_NONE); }
  853. | function_specifier m_decl_spec_no_type { $$ = make_decl_spec(NULL, $2, NULL, $1, STG_NONE); }
  854. | storage_cls_spec m_decl_spec_no_type { $$ = make_decl_spec(NULL, $2, NULL, NULL, $1); }
  855. ;
  856. declarator:
  857. '*' m_type_qual_list declarator %prec PPTR
  858. { $$ = $3; $$->type = append_ptrchain_type($$->type, type_new_pointer(pointer_default, NULL, $2)); }
  859. | callconv declarator { $$ = $2; if ($$->func_type) $$->func_type->attrs = append_attr($$->func_type->attrs, make_attrp(ATTR_CALLCONV, $1));
  860. else if ($$->type) $$->type->attrs = append_attr($$->type->attrs, make_attrp(ATTR_CALLCONV, $1)); }
  861. | direct_declarator
  862. ;
  863. direct_declarator:
  864. ident { $$ = make_declarator($1); }
  865. | '(' declarator ')' { $$ = $2; }
  866. | direct_declarator array { $$ = $1; $$->array = append_array($$->array, $2); }
  867. | direct_declarator '(' m_args ')' { $$ = $1;
  868. $$->func_type = append_ptrchain_type($$->type, type_new_function($3));
  869. $$->type = NULL;
  870. }
  871. ;
  872. /* abstract declarator */
  873. abstract_declarator:
  874. '*' m_type_qual_list m_abstract_declarator %prec PPTR
  875. { $$ = $3; $$->type = append_ptrchain_type($$->type, type_new_pointer(pointer_default, NULL, $2)); }
  876. | callconv m_abstract_declarator { $$ = $2; if ($$->func_type) $$->func_type->attrs = append_attr($$->func_type->attrs, make_attrp(ATTR_CALLCONV, $1));
  877. else if ($$->type) $$->type->attrs = append_attr($$->type->attrs, make_attrp(ATTR_CALLCONV, $1)); }
  878. | abstract_direct_declarator
  879. ;
  880. /* abstract declarator without accepting direct declarator */
  881. abstract_declarator_no_direct:
  882. '*' m_type_qual_list m_any_declarator %prec PPTR
  883. { $$ = $3; $$->type = append_ptrchain_type($$->type, type_new_pointer(pointer_default, NULL, $2)); }
  884. | callconv m_any_declarator { $$ = $2; if ($$->func_type) $$->func_type->attrs = append_attr($$->func_type->attrs, make_attrp(ATTR_CALLCONV, $1));
  885. else if ($$->type) $$->type->attrs = append_attr($$->type->attrs, make_attrp(ATTR_CALLCONV, $1)); }
  886. ;
  887. /* abstract declarator or empty */
  888. m_abstract_declarator: { $$ = make_declarator(NULL); }
  889. | abstract_declarator
  890. ;
  891. /* abstract direct declarator */
  892. abstract_direct_declarator:
  893. '(' abstract_declarator_no_direct ')' { $$ = $2; }
  894. | abstract_direct_declarator array { $$ = $1; $$->array = append_array($$->array, $2); }
  895. | array { $$ = make_declarator(NULL); $$->array = append_array($$->array, $1); }
  896. | '(' m_args ')'
  897. { $$ = make_declarator(NULL);
  898. $$->func_type = append_ptrchain_type($$->type, type_new_function($2));
  899. $$->type = NULL;
  900. }
  901. | abstract_direct_declarator '(' m_args ')'
  902. { $$ = $1;
  903. $$->func_type = append_ptrchain_type($$->type, type_new_function($3));
  904. $$->type = NULL;
  905. }
  906. ;
  907. /* abstract or non-abstract declarator */
  908. any_declarator:
  909. '*' m_type_qual_list m_any_declarator %prec PPTR
  910. { $$ = $3; $$->type = append_ptrchain_type($$->type, type_new_pointer(pointer_default, NULL, $2)); }
  911. | callconv m_any_declarator { $$ = $2; $$->type->attrs = append_attr($$->type->attrs, make_attrp(ATTR_CALLCONV, $1)); }
  912. | any_direct_declarator
  913. ;
  914. /* abstract or non-abstract declarator without accepting direct declarator */
  915. any_declarator_no_direct:
  916. '*' m_type_qual_list m_any_declarator %prec PPTR
  917. { $$ = $3; $$->type = append_ptrchain_type($$->type, type_new_pointer(pointer_default, NULL, $2)); }
  918. | callconv m_any_declarator { $$ = $2; $$->type->attrs = append_attr($$->type->attrs, make_attrp(ATTR_CALLCONV, $1)); }
  919. ;
  920. /* abstract or non-abstract declarator or empty */
  921. m_any_declarator: { $$ = make_declarator(NULL); }
  922. | any_declarator
  923. ;
  924. /* abstract or non-abstract direct declarator. note: direct declarators
  925. * aren't accepted inside brackets to avoid ambiguity with the rule for
  926. * function arguments */
  927. any_direct_declarator:
  928. ident { $$ = make_declarator($1); }
  929. | '(' any_declarator_no_direct ')' { $$ = $2; }
  930. | any_direct_declarator array { $$ = $1; $$->array = append_array($$->array, $2); }
  931. | array { $$ = make_declarator(NULL); $$->array = append_array($$->array, $1); }
  932. | '(' m_args ')'
  933. { $$ = make_declarator(NULL);
  934. $$->func_type = append_ptrchain_type($$->type, type_new_function($2));
  935. $$->type = NULL;
  936. }
  937. | any_direct_declarator '(' m_args ')'
  938. { $$ = $1;
  939. $$->func_type = append_ptrchain_type($$->type, type_new_function($3));
  940. $$->type = NULL;
  941. }
  942. ;
  943. declarator_list:
  944. declarator { $$ = append_declarator( NULL, $1 ); }
  945. | declarator_list ',' declarator { $$ = append_declarator( $1, $3 ); }
  946. ;
  947. m_bitfield: { $$ = NULL; }
  948. | ':' expr_const { $$ = $2; }
  949. ;
  950. struct_declarator: any_declarator m_bitfield { $$ = $1; $$->bits = $2;
  951. if (!$$->bits && !$$->var->name)
  952. error_loc("unnamed fields are not allowed\n");
  953. }
  954. ;
  955. struct_declarator_list:
  956. struct_declarator { $$ = append_declarator( NULL, $1 ); }
  957. | struct_declarator_list ',' struct_declarator
  958. { $$ = append_declarator( $1, $3 ); }
  959. ;
  960. init_declarator:
  961. declarator { $$ = $1; }
  962. | declarator '=' expr_const { $$ = $1; $1->var->eval = $3; }
  963. ;
  964. threading_type:
  965. tAPARTMENT { $$ = THREADING_APARTMENT; }
  966. | tNEUTRAL { $$ = THREADING_NEUTRAL; }
  967. | tSINGLE { $$ = THREADING_SINGLE; }
  968. | tFREE { $$ = THREADING_FREE; }
  969. | tBOTH { $$ = THREADING_BOTH; }
  970. ;
  971. pointer_type:
  972. tREF { $$ = RPC_FC_RP; }
  973. | tUNIQUE { $$ = RPC_FC_UP; }
  974. | tPTR { $$ = RPC_FC_FP; }
  975. ;
  976. structdef: tSTRUCT t_ident '{' fields '}' { $$ = type_new_struct($2, TRUE, $4); }
  977. ;
  978. type: tVOID { $$ = type_new_void(); }
  979. | aKNOWNTYPE { $$ = find_type_or_error($1, 0); }
  980. | base_type { $$ = $1; }
  981. | enumdef { $$ = $1; }
  982. | tENUM aIDENTIFIER { $$ = type_new_enum($2, FALSE, NULL); }
  983. | structdef { $$ = $1; }
  984. | tSTRUCT aIDENTIFIER { $$ = type_new_struct($2, FALSE, NULL); }
  985. | uniondef { $$ = $1; }
  986. | tUNION aIDENTIFIER { $$ = type_new_nonencapsulated_union($2, FALSE, NULL); }
  987. | tSAFEARRAY '(' type ')' { $$ = make_safearray($3); }
  988. ;
  989. typedef: tTYPEDEF m_attributes decl_spec declarator_list
  990. { reg_typedefs($3, $4, check_typedef_attrs($2));
  991. $$ = make_statement_typedef($4);
  992. }
  993. ;
  994. uniondef: tUNION t_ident '{' ne_union_fields '}'
  995. { $$ = type_new_nonencapsulated_union($2, TRUE, $4); }
  996. | tUNION t_ident
  997. tSWITCH '(' s_field ')'
  998. m_ident '{' cases '}' { $$ = type_new_encapsulated_union($2, $5, $7, $9); }
  999. ;
  1000. version:
  1001. aNUM { $$ = MAKEVERSION($1, 0); }
  1002. | aNUM '.' aNUM { $$ = MAKEVERSION($1, $3); }
  1003. ;
  1004. %%
  1005. static void decl_builtin_basic(const char *name, enum type_basic_type type)
  1006. {
  1007. type_t *t = type_new_basic(type);
  1008. reg_type(t, name, 0);
  1009. }
  1010. static void decl_builtin_alias(const char *name, type_t *t)
  1011. {
  1012. reg_type(type_new_alias(t, name), name, 0);
  1013. }
  1014. void init_types(void)
  1015. {
  1016. decl_builtin_basic("byte", TYPE_BASIC_BYTE);
  1017. decl_builtin_basic("wchar_t", TYPE_BASIC_WCHAR);
  1018. decl_builtin_basic("float", TYPE_BASIC_FLOAT);
  1019. decl_builtin_basic("double", TYPE_BASIC_DOUBLE);
  1020. decl_builtin_basic("error_status_t", TYPE_BASIC_ERROR_STATUS_T);
  1021. decl_builtin_basic("handle_t", TYPE_BASIC_HANDLE);
  1022. decl_builtin_alias("boolean", type_new_basic(TYPE_BASIC_BYTE));
  1023. }
  1024. static str_list_t *append_str(str_list_t *list, char *str)
  1025. {
  1026. struct str_list_entry_t *entry;
  1027. if (!str) return list;
  1028. if (!list)
  1029. {
  1030. list = xmalloc( sizeof(*list) );
  1031. list_init( list );
  1032. }
  1033. entry = xmalloc( sizeof(*entry) );
  1034. entry->str = str;
  1035. list_add_tail( list, &entry->entry );
  1036. return list;
  1037. }
  1038. static attr_list_t *append_attr(attr_list_t *list, attr_t *attr)
  1039. {
  1040. attr_t *attr_existing;
  1041. if (!attr) return list;
  1042. if (!list)
  1043. {
  1044. list = xmalloc( sizeof(*list) );
  1045. list_init( list );
  1046. }
  1047. LIST_FOR_EACH_ENTRY(attr_existing, list, attr_t, entry)
  1048. if (attr_existing->type == attr->type)
  1049. {
  1050. parser_warning("duplicate attribute %s\n", get_attr_display_name(attr->type));
  1051. /* use the last attribute, like MIDL does */
  1052. list_remove(&attr_existing->entry);
  1053. break;
  1054. }
  1055. list_add_tail( list, &attr->entry );
  1056. return list;
  1057. }
  1058. static attr_list_t *move_attr(attr_list_t *dst, attr_list_t *src, enum attr_type type)
  1059. {
  1060. attr_t *attr;
  1061. if (!src) return dst;
  1062. LIST_FOR_EACH_ENTRY(attr, src, attr_t, entry)
  1063. if (attr->type == type)
  1064. {
  1065. list_remove(&attr->entry);
  1066. return append_attr(dst, attr);
  1067. }
  1068. return dst;
  1069. }
  1070. static attr_list_t *append_attr_list(attr_list_t *new_list, attr_list_t *old_list)
  1071. {
  1072. struct list *entry;
  1073. if (!old_list) return new_list;
  1074. while ((entry = list_head(old_list)))
  1075. {
  1076. attr_t *attr = LIST_ENTRY(entry, attr_t, entry);
  1077. list_remove(entry);
  1078. new_list = append_attr(new_list, attr);
  1079. }
  1080. return new_list;
  1081. }
  1082. static attr_list_t *dupattrs(const attr_list_t *list)
  1083. {
  1084. attr_list_t *new_list;
  1085. const attr_t *attr;
  1086. if (!list) return NULL;
  1087. new_list = xmalloc( sizeof(*list) );
  1088. list_init( new_list );
  1089. LIST_FOR_EACH_ENTRY(attr, list, const attr_t, entry)
  1090. {
  1091. attr_t *new_attr = xmalloc(sizeof(*new_attr));
  1092. *new_attr = *attr;
  1093. list_add_tail(new_list, &new_attr->entry);
  1094. }
  1095. return new_list;
  1096. }
  1097. static decl_spec_t *make_decl_spec(type_t *type, decl_spec_t *left, decl_spec_t *right, attr_t *attr, enum storage_class stgclass)
  1098. {
  1099. decl_spec_t *declspec = left ? left : right;
  1100. if (!declspec)
  1101. {
  1102. declspec = xmalloc(sizeof(*declspec));
  1103. declspec->type = NULL;
  1104. declspec->attrs = NULL;
  1105. declspec->stgclass = STG_NONE;
  1106. }
  1107. declspec->type = type;
  1108. if (left && declspec != left)
  1109. {
  1110. declspec->attrs = append_attr_list(declspec->attrs, left->attrs);
  1111. if (declspec->stgclass == STG_NONE)
  1112. declspec->stgclass = left->stgclass;
  1113. else if (left->stgclass != STG_NONE)
  1114. error_loc("only one storage class can be specified\n");
  1115. assert(!left->type);
  1116. free(left);
  1117. }
  1118. if (right && declspec != right)
  1119. {
  1120. declspec->attrs = append_attr_list(declspec->attrs, right->attrs);
  1121. if (declspec->stgclass == STG_NONE)
  1122. declspec->stgclass = right->stgclass;
  1123. else if (right->stgclass != STG_NONE)
  1124. error_loc("only one storage class can be specified\n");
  1125. assert(!right->type);
  1126. free(right);
  1127. }
  1128. declspec->attrs = append_attr(declspec->attrs, attr);
  1129. if (declspec->stgclass == STG_NONE)
  1130. declspec->stgclass = stgclass;
  1131. else if (stgclass != STG_NONE)
  1132. error_loc("only one storage class can be specified\n");
  1133. /* apply attributes to type */
  1134. if (type && declspec->attrs)
  1135. {
  1136. attr_list_t *attrs;
  1137. declspec->type = duptype(type, 1);
  1138. attrs = dupattrs(type->attrs);
  1139. declspec->type->attrs = append_attr_list(attrs, declspec->attrs);
  1140. declspec->attrs = NULL;
  1141. }
  1142. return declspec;
  1143. }
  1144. static attr_t *make_attr(enum attr_type type)
  1145. {
  1146. attr_t *a = xmalloc(sizeof(attr_t));
  1147. a->type = type;
  1148. a->u.ival = 0;
  1149. return a;
  1150. }
  1151. static attr_t *make_attrv(enum attr_type type, unsigned int val)
  1152. {
  1153. attr_t *a = xmalloc(sizeof(attr_t));
  1154. a->type = type;
  1155. a->u.ival = val;
  1156. return a;
  1157. }
  1158. static attr_t *make_attrp(enum attr_type type, void *val)
  1159. {
  1160. attr_t *a = xmalloc(sizeof(attr_t));
  1161. a->type = type;
  1162. a->u.pval = val;
  1163. return a;
  1164. }
  1165. static expr_list_t *append_expr(expr_list_t *list, expr_t *expr)
  1166. {
  1167. if (!expr) return list;
  1168. if (!list)
  1169. {
  1170. list = xmalloc( sizeof(*list) );
  1171. list_init( list );
  1172. }
  1173. list_add_tail( list, &expr->entry );
  1174. return list;
  1175. }
  1176. static array_dims_t *append_array(array_dims_t *list, expr_t *expr)
  1177. {
  1178. if (!expr) return list;
  1179. if (!list)
  1180. {
  1181. list = xmalloc( sizeof(*list) );
  1182. list_init( list );
  1183. }
  1184. list_add_tail( list, &expr->entry );
  1185. return list;
  1186. }
  1187. static struct list type_pool = LIST_INIT(type_pool);
  1188. typedef struct
  1189. {
  1190. type_t data;
  1191. struct list link;
  1192. } type_pool_node_t;
  1193. type_t *alloc_type(void)
  1194. {
  1195. type_pool_node_t *node = xmalloc(sizeof *node);
  1196. list_add_tail(&type_pool, &node->link);
  1197. return &node->data;
  1198. }
  1199. void set_all_tfswrite(int val)
  1200. {
  1201. type_pool_node_t *node;
  1202. LIST_FOR_EACH_ENTRY(node, &type_pool, type_pool_node_t, link)
  1203. node->data.tfswrite = val;
  1204. }
  1205. void clear_all_offsets(void)
  1206. {
  1207. type_pool_node_t *node;
  1208. LIST_FOR_EACH_ENTRY(node, &type_pool, type_pool_node_t, link)
  1209. node->data.typestring_offset = node->data.ptrdesc = 0;
  1210. }
  1211. static void type_function_add_head_arg(type_t *type, var_t *arg)
  1212. {
  1213. if (!type->details.function->args)
  1214. {
  1215. type->details.function->args = xmalloc( sizeof(*type->details.function->args) );
  1216. list_init( type->details.function->args );
  1217. }
  1218. list_add_head( type->details.function->args, &arg->entry );
  1219. }
  1220. static int is_allowed_range_type(const type_t *type)
  1221. {
  1222. switch (type_get_type(type))
  1223. {
  1224. case TYPE_ENUM:
  1225. return TRUE;
  1226. case TYPE_BASIC:
  1227. switch (type_basic_get_type(type))
  1228. {
  1229. case TYPE_BASIC_INT8:
  1230. case TYPE_BASIC_INT16:
  1231. case TYPE_BASIC_INT32:
  1232. case TYPE_BASIC_INT64:
  1233. case TYPE_BASIC_INT:
  1234. case TYPE_BASIC_INT3264:
  1235. case TYPE_BASIC_BYTE:
  1236. case TYPE_BASIC_CHAR:
  1237. case TYPE_BASIC_WCHAR:
  1238. case TYPE_BASIC_HYPER:
  1239. return TRUE;
  1240. case TYPE_BASIC_FLOAT:
  1241. case TYPE_BASIC_DOUBLE:
  1242. case TYPE_BASIC_ERROR_STATUS_T:
  1243. case TYPE_BASIC_HANDLE:
  1244. return FALSE;
  1245. }
  1246. return FALSE;
  1247. default:
  1248. return FALSE;
  1249. }
  1250. }
  1251. static type_t *append_ptrchain_type(type_t *ptrchain, type_t *type)
  1252. {
  1253. type_t *ptrchain_type;
  1254. if (!ptrchain)
  1255. return type;
  1256. for (ptrchain_type = ptrchain; type_pointer_get_ref(ptrchain_type); ptrchain_type = type_pointer_get_ref(ptrchain_type))
  1257. ;
  1258. assert(ptrchain_type->type_type == TYPE_POINTER);
  1259. ptrchain_type->details.pointer.ref = type;
  1260. return ptrchain;
  1261. }
  1262. static var_t *declare_var(attr_list_t *attrs, decl_spec_t *decl_spec, const declarator_t *decl,
  1263. int top)
  1264. {
  1265. var_t *v = decl->var;
  1266. expr_list_t *sizes = get_attrp(attrs, ATTR_SIZEIS);
  1267. expr_list_t *lengs = get_attrp(attrs, ATTR_LENGTHIS);
  1268. int sizeless;
  1269. expr_t *dim;
  1270. type_t **ptype;
  1271. array_dims_t *arr = decl ? decl->array : NULL;
  1272. type_t *func_type = decl ? decl->func_type : NULL;
  1273. type_t *type = decl_spec->type;
  1274. if (is_attr(type->attrs, ATTR_INLINE))
  1275. {
  1276. if (!func_type)
  1277. error_loc("inline attribute applied to non-function type\n");
  1278. else
  1279. {
  1280. type_t *t;
  1281. /* move inline attribute from return type node to function node */
  1282. for (t = func_type; is_ptr(t); t = type_pointer_get_ref(t))
  1283. ;
  1284. t->attrs = move_attr(t->attrs, type->attrs, ATTR_INLINE);
  1285. }
  1286. }
  1287. /* add type onto the end of the pointers in pident->type */
  1288. v->type = append_ptrchain_type(decl ? decl->type : NULL, type);
  1289. v->stgclass = decl_spec->stgclass;
  1290. v->attrs = attrs;
  1291. /* check for pointer attribute being applied to non-pointer, non-array
  1292. * type */
  1293. if (!arr)
  1294. {
  1295. int ptr_attr = get_attrv(v->attrs, ATTR_POINTERTYPE);
  1296. const type_t *ptr = NULL;
  1297. /* pointer attributes on the left side of the type belong to the function
  1298. * pointer, if one is being declared */
  1299. type_t **pt = func_type ? &func_type : &v->type;
  1300. for (ptr = *pt; ptr && !ptr_attr; )
  1301. {
  1302. ptr_attr = get_attrv(ptr->attrs, ATTR_POINTERTYPE);
  1303. if (!ptr_attr && type_is_alias(ptr))
  1304. ptr = type_alias_get_aliasee(ptr);
  1305. else
  1306. break;
  1307. }
  1308. if (is_ptr(ptr))
  1309. {
  1310. if (ptr_attr && ptr_attr != RPC_FC_UP &&
  1311. type_get_type(type_pointer_get_ref(ptr)) == TYPE_INTERFACE)
  1312. warning_loc_info(&v->loc_info,
  1313. "%s: pointer attribute applied to interface "
  1314. "pointer type has no effect\n", v->name);
  1315. if (!ptr_attr && top && (*pt)->details.pointer.def_fc != RPC_FC_RP)
  1316. {
  1317. /* FIXME: this is a horrible hack to cope with the issue that we
  1318. * store an offset to the typeformat string in the type object, but
  1319. * two typeformat strings may be written depending on whether the
  1320. * pointer is a toplevel parameter or not */
  1321. *pt = duptype(*pt, 1);
  1322. }
  1323. }
  1324. else if (ptr_attr)
  1325. error_loc("%s: pointer attribute applied to non-pointer type\n", v->name);
  1326. }
  1327. if (is_attr(v->attrs, ATTR_STRING))
  1328. {
  1329. type_t *t = type;
  1330. if (!is_ptr(v->type) && !arr)
  1331. error_loc("'%s': [string] attribute applied to non-pointer, non-array type\n",
  1332. v->name);
  1333. while (is_ptr(t))
  1334. t = type_pointer_get_ref(t);
  1335. if (type_get_type(t) != TYPE_BASIC &&
  1336. (get_basic_fc(t) != RPC_FC_CHAR &&
  1337. get_basic_fc(t) != RPC_FC_BYTE &&
  1338. get_basic_fc(t) != RPC_FC_WCHAR))
  1339. {
  1340. error_loc("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
  1341. v->name);
  1342. }
  1343. }
  1344. if (is_attr(v->attrs, ATTR_V1ENUM))
  1345. {
  1346. if (type_get_type_detect_alias(v->type) != TYPE_ENUM)
  1347. error_loc("'%s': [v1_enum] attribute applied to non-enum type\n", v->name);
  1348. }
  1349. if (is_attr(v->attrs, ATTR_RANGE) && !is_allowed_range_type(v->type))
  1350. error_loc("'%s': [range] attribute applied to non-integer type\n",
  1351. v->name);
  1352. ptype = &v->type;
  1353. sizeless = FALSE;
  1354. if (arr) LIST_FOR_EACH_ENTRY_REV(dim, arr, expr_t, entry)
  1355. {
  1356. if (sizeless)
  1357. error_loc("%s: only the first array dimension can be unspecified\n", v->name);
  1358. if (dim->is_const)
  1359. {
  1360. if (dim->cval <= 0)
  1361. error_loc("%s: array dimension must be positive\n", v->name);
  1362. /* FIXME: should use a type_memsize that allows us to pass in a pointer size */
  1363. if (0)
  1364. {
  1365. unsigned int size = type_memsize(v->type);
  1366. if (0xffffffffu / size < dim->cval)
  1367. error_loc("%s: total array size is too large\n", v->name);
  1368. }
  1369. }
  1370. else
  1371. sizeless = TRUE;
  1372. *ptype = type_new_array(NULL, *ptype, FALSE,
  1373. dim->is_const ? dim->cval : 0,
  1374. dim->is_const ? NULL : dim, NULL,
  1375. pointer_default);
  1376. }
  1377. ptype = &v->type;
  1378. if (sizes) LIST_FOR_EACH_ENTRY(dim, sizes, expr_t, entry)
  1379. {
  1380. if (dim->type != EXPR_VOID)
  1381. {
  1382. if (is_array(*ptype))
  1383. {
  1384. if (!type_array_get_conformance(*ptype) ||
  1385. type_array_get_conformance(*ptype)->type != EXPR_VOID)
  1386. error_loc("%s: cannot specify size_is for an already sized array\n", v->name);
  1387. else
  1388. *ptype = type_new_array((*ptype)->name,
  1389. type_array_get_element(*ptype), FALSE,
  1390. 0, dim, NULL, 0);
  1391. }
  1392. else if (is_ptr(*ptype))
  1393. *ptype = type_new_array((*ptype)->name, type_pointer_get_ref(*ptype), TRUE,
  1394. 0, dim, NULL, pointer_default);
  1395. else
  1396. error_loc("%s: size_is attribute applied to illegal type\n", v->name);
  1397. }
  1398. if (is_ptr(*ptype))
  1399. ptype = &(*ptype)->details.pointer.ref;
  1400. else if (is_array(*ptype))
  1401. ptype = &(*ptype)->details.array.elem;
  1402. else
  1403. error_loc("%s: too many expressions in size_is attribute\n", v->name);
  1404. }
  1405. ptype = &v->type;
  1406. if (lengs) LIST_FOR_EACH_ENTRY(dim, lengs, expr_t, entry)
  1407. {
  1408. if (dim->type != EXPR_VOID)
  1409. {
  1410. if (is_array(*ptype))
  1411. {
  1412. *ptype = type_new_array((*ptype)->name,
  1413. type_array_get_element(*ptype),
  1414. type_array_is_decl_as_ptr(*ptype),
  1415. type_array_get_dim(*ptype),
  1416. type_array_get_conformance(*ptype),
  1417. dim, type_array_get_ptr_default_fc(*ptype));
  1418. }
  1419. else
  1420. error_loc("%s: length_is attribute applied to illegal type\n", v->name);
  1421. }
  1422. if (is_ptr(*ptype))
  1423. ptype = &(*ptype)->details.pointer.ref;
  1424. else if (is_array(*ptype))
  1425. ptype = &(*ptype)->details.array.elem;
  1426. else
  1427. error_loc("%s: too many expressions in length_is attribute\n", v->name);
  1428. }
  1429. /* v->type is currently pointing to the type on the left-side of the
  1430. * declaration, so we need to fix this up so that it is the return type of the
  1431. * function and make v->type point to the function side of the declaration */
  1432. if (func_type)
  1433. {
  1434. type_t *ft, *t;
  1435. type_t *return_type = v->type;
  1436. v->type = func_type;
  1437. for (ft = v->type; is_ptr(ft); ft = type_pointer_get_ref(ft))
  1438. ;
  1439. assert(type_get_type_detect_alias(ft) == TYPE_FUNCTION);
  1440. ft->details.function->rettype = return_type;
  1441. /* move calling convention attribute, if present, from pointer nodes to
  1442. * function node */
  1443. for (t = v->type; is_ptr(t); t = type_pointer_get_ref(t))
  1444. ft->attrs = move_attr(ft->attrs, t->attrs, ATTR_CALLCONV);
  1445. }
  1446. else
  1447. {
  1448. type_t *t;
  1449. for (t = v->type; is_ptr(t); t = type_pointer_get_ref(t))
  1450. if (is_attr(t->attrs, ATTR_CALLCONV))
  1451. error_loc("calling convention applied to non-function-pointer type\n");
  1452. }
  1453. if (decl->bits)
  1454. v->type = type_new_bitfield(v->type, decl->bits);
  1455. return v;
  1456. }
  1457. static var_list_t *set_var_types(attr_list_t *attrs, decl_spec_t *decl_spec, declarator_list_t *decls)
  1458. {
  1459. declarator_t *decl, *next;
  1460. var_list_t *var_list = NULL;
  1461. LIST_FOR_EACH_ENTRY_SAFE( decl, next, decls, declarator_t, entry )
  1462. {
  1463. var_t *var = declare_var(attrs, decl_spec, decl, 0);
  1464. var_list = append_var(var_list, var);
  1465. free(decl);
  1466. }
  1467. free(decl_spec);
  1468. return var_list;
  1469. }
  1470. static ifref_list_t *append_ifref(ifref_list_t *list, ifref_t *iface)
  1471. {
  1472. if (!iface) return list;
  1473. if (!list)
  1474. {
  1475. list = xmalloc( sizeof(*list) );
  1476. list_init( list );
  1477. }
  1478. list_add_tail( list, &iface->entry );
  1479. return list;
  1480. }
  1481. static ifref_t *make_ifref(type_t *iface)
  1482. {
  1483. ifref_t *l = xmalloc(sizeof(ifref_t));
  1484. l->iface = iface;
  1485. l->attrs = NULL;
  1486. return l;
  1487. }
  1488. var_list_t *append_var(var_list_t *list, var_t *var)
  1489. {
  1490. if (!var) return list;
  1491. if (!list)
  1492. {
  1493. list = xmalloc( sizeof(*list) );
  1494. list_init( list );
  1495. }
  1496. list_add_tail( list, &var->entry );
  1497. return list;
  1498. }
  1499. static var_list_t *append_var_list(var_list_t *list, var_list_t *vars)
  1500. {
  1501. if (!vars) return list;
  1502. if (!list)
  1503. {
  1504. list = xmalloc( sizeof(*list) );
  1505. list_init( list );
  1506. }
  1507. list_move_tail( list, vars );
  1508. return list;
  1509. }
  1510. var_t *make_var(char *name)
  1511. {
  1512. var_t *v = xmalloc(sizeof(var_t));
  1513. v->name = name;
  1514. v->type = NULL;
  1515. v->attrs = NULL;
  1516. v->eval = NULL;
  1517. v->stgclass = STG_NONE;
  1518. init_loc_info(&v->loc_info);
  1519. return v;
  1520. }
  1521. static declarator_list_t *append_declarator(declarator_list_t *list, declarator_t *d)
  1522. {
  1523. if (!d) return list;
  1524. if (!list) {
  1525. list = xmalloc(sizeof(*list));
  1526. list_init(list);
  1527. }
  1528. list_add_tail(list, &d->entry);
  1529. return list;
  1530. }
  1531. static declarator_t *make_declarator(var_t *var)
  1532. {
  1533. declarator_t *d = xmalloc(sizeof(*d));
  1534. d->var = var ? var : make_var(NULL);
  1535. d->type = NULL;
  1536. d->func_type = NULL;
  1537. d->array = NULL;
  1538. d->bits = NULL;
  1539. return d;
  1540. }
  1541. static type_t *make_safearray(type_t *type)
  1542. {
  1543. return type_new_array(NULL, type_new_alias(type, "SAFEARRAY"), TRUE, 0,
  1544. NULL, NULL, RPC_FC_RP);
  1545. }
  1546. static typelib_t *make_library(const char *name, const attr_list_t *attrs)
  1547. {
  1548. typelib_t *typelib = xmalloc(sizeof(*typelib));
  1549. typelib->name = xstrdup(name);
  1550. typelib->filename = NULL;
  1551. typelib->attrs = attrs;
  1552. list_init( &typelib->importlibs );
  1553. return typelib;
  1554. }
  1555. #define HASHMAX 64
  1556. static int hash_ident(const char *name)
  1557. {
  1558. const char *p = name;
  1559. int sum = 0;
  1560. /* a simple sum hash is probably good enough */
  1561. while (*p) {
  1562. sum += *p;
  1563. p++;
  1564. }
  1565. return sum & (HASHMAX-1);
  1566. }
  1567. /***** type repository *****/
  1568. struct rtype {
  1569. const char *name;
  1570. type_t *type;
  1571. int t;
  1572. struct rtype *next;
  1573. };
  1574. struct rtype *type_hash[HASHMAX];
  1575. type_t *reg_type(type_t *type, const char *name, int t)
  1576. {
  1577. struct rtype *nt;
  1578. int hash;
  1579. if (!name) {
  1580. error_loc("registering named type without name\n");
  1581. return type;
  1582. }
  1583. hash = hash_ident(name);
  1584. nt = xmalloc(sizeof(struct rtype));
  1585. nt->name = name;
  1586. nt->type = type;
  1587. nt->t = t;
  1588. nt->next = type_hash[hash];
  1589. type_hash[hash] = nt;
  1590. if ((t == tsSTRUCT || t == tsUNION))
  1591. fix_incomplete_types(type);
  1592. return type;
  1593. }
  1594. static int is_incomplete(const type_t *t)
  1595. {
  1596. return !t->defined &&
  1597. (type_get_type_detect_alias(t) == TYPE_STRUCT ||
  1598. type_get_type_detect_alias(t) == TYPE_UNION ||
  1599. type_get_type_detect_alias(t) == TYPE_ENCAPSULATED_UNION);
  1600. }
  1601. void add_incomplete(type_t *t)
  1602. {
  1603. struct typenode *tn = xmalloc(sizeof *tn);
  1604. tn->type = t;
  1605. list_add_tail(&incomplete_types, &tn->entry);
  1606. }
  1607. static void fix_type(type_t *t)
  1608. {
  1609. if (type_is_alias(t) && is_incomplete(t)) {
  1610. type_t *ot = type_alias_get_aliasee(t);
  1611. fix_type(ot);
  1612. if (type_get_type_detect_alias(ot) == TYPE_STRUCT ||
  1613. type_get_type_detect_alias(ot) == TYPE_UNION ||
  1614. type_get_type_detect_alias(ot) == TYPE_ENCAPSULATED_UNION)
  1615. t->details.structure = ot->details.structure;
  1616. t->defined = ot->defined;
  1617. }
  1618. }
  1619. static void fix_incomplete(void)
  1620. {
  1621. struct typenode *tn, *next;
  1622. LIST_FOR_EACH_ENTRY_SAFE(tn, next, &incomplete_types, struct typenode, entry) {
  1623. fix_type(tn->type);
  1624. list_remove(&tn->entry);
  1625. free(tn);
  1626. }
  1627. }
  1628. static void fix_incomplete_types(type_t *complete_type)
  1629. {
  1630. struct typenode *tn, *next;
  1631. LIST_FOR_EACH_ENTRY_SAFE(tn, next, &incomplete_types, struct typenode, entry)
  1632. {
  1633. if (type_is_equal(complete_type, tn->type))
  1634. {
  1635. tn->type->details.structure = complete_type->details.structure;
  1636. list_remove(&tn->entry);
  1637. free(tn);
  1638. }
  1639. }
  1640. }
  1641. static type_t *reg_typedefs(decl_spec_t *decl_spec, declarator_list_t *decls, attr_list_t *attrs)
  1642. {
  1643. const declarator_t *decl;
  1644. type_t *type = decl_spec->type;
  1645. /* We must generate names for tagless enum, struct or union.
  1646. Typedef-ing a tagless enum, struct or union means we want the typedef
  1647. to be included in a library hence the public attribute. */
  1648. if ((type_get_type_detect_alias(type) == TYPE_ENUM ||
  1649. type_get_type_detect_alias(type) == TYPE_STRUCT ||
  1650. type_get_type_detect_alias(type) == TYPE_UNION ||
  1651. type_get_type_detect_alias(type) == TYPE_ENCAPSULATED_UNION) &&
  1652. !type->name && !parse_only)
  1653. {
  1654. if (! is_attr(attrs, ATTR_PUBLIC))
  1655. attrs = append_attr( attrs, make_attr(ATTR_PUBLIC) );
  1656. type->name = gen_name();
  1657. }
  1658. else if (is_attr(attrs, ATTR_UUID) && !is_attr(attrs, ATTR_PUBLIC))
  1659. attrs = append_attr( attrs, make_attr(ATTR_PUBLIC) );
  1660. LIST_FOR_EACH_ENTRY( decl, decls, const declarator_t, entry )
  1661. {
  1662. if (decl->var->name) {
  1663. type_t *cur;
  1664. var_t *name;
  1665. cur = find_type(decl->var->name, 0);
  1666. if (cur)
  1667. error_loc("%s: redefinition error; original definition was at %s:%d\n",
  1668. cur->name, cur->loc_info.input_name,
  1669. cur->loc_info.line_number);
  1670. name = declare_var(attrs, decl_spec, decl, 0);
  1671. cur = type_new_alias(name->type, name->name);
  1672. cur->attrs = attrs;
  1673. if (is_incomplete(cur))
  1674. add_incomplete(cur);
  1675. reg_type(cur, cur->name, 0);
  1676. }
  1677. }
  1678. return type;
  1679. }
  1680. type_t *find_type(const char *name, int t)
  1681. {
  1682. struct rtype *cur = type_hash[hash_ident(name)];
  1683. while (cur && (cur->t != t || strcmp(cur->name, name)))
  1684. cur = cur->next;
  1685. return cur ? cur->type : NULL;
  1686. }
  1687. static type_t *find_type_or_error(const char *name, int t)
  1688. {
  1689. type_t *type = find_type(name, t);
  1690. if (!type) {
  1691. error_loc("type '%s' not found\n", name);
  1692. return NULL;
  1693. }
  1694. return type;
  1695. }
  1696. static type_t *find_type_or_error2(char *name, int t)
  1697. {
  1698. type_t *tp = find_type_or_error(name, t);
  1699. free(name);
  1700. return tp;
  1701. }
  1702. int is_type(const char *name)
  1703. {
  1704. return find_type(name, 0) != NULL;
  1705. }
  1706. type_t *get_type(enum type_type type, char *name, int t)
  1707. {
  1708. type_t *tp;
  1709. if (name) {
  1710. tp = find_type(name, t);
  1711. if (tp) {
  1712. free(name);
  1713. return tp;
  1714. }
  1715. }
  1716. tp = make_type(type);
  1717. tp->name = name;
  1718. if (!name) return tp;
  1719. return reg_type(tp, name, t);
  1720. }
  1721. /***** constant repository *****/
  1722. struct rconst {
  1723. char *name;
  1724. var_t *var;
  1725. struct rconst *next;
  1726. };
  1727. struct rconst *const_hash[HASHMAX];
  1728. static var_t *reg_const(var_t *var)
  1729. {
  1730. struct rconst *nc;
  1731. int hash;
  1732. if (!var->name) {
  1733. error_loc("registering constant without name\n");
  1734. return var;
  1735. }
  1736. hash = hash_ident(var->name);
  1737. nc = xmalloc(sizeof(struct rconst));
  1738. nc->name = var->name;
  1739. nc->var = var;
  1740. nc->next = const_hash[hash];
  1741. const_hash[hash] = nc;
  1742. return var;
  1743. }
  1744. var_t *find_const(const char *name, int f)
  1745. {
  1746. struct rconst *cur = const_hash[hash_ident(name)];
  1747. while (cur && strcmp(cur->name, name))
  1748. cur = cur->next;
  1749. if (!cur) {
  1750. if (f) error_loc("constant '%s' not found\n", name);
  1751. return NULL;
  1752. }
  1753. return cur->var;
  1754. }
  1755. static char *gen_name(void)
  1756. {
  1757. static const char format[] = "__WIDL_%s_generated_name_%08lX";
  1758. static unsigned long n = 0;
  1759. static const char *file_id;
  1760. static size_t size;
  1761. char *name;
  1762. if (! file_id)
  1763. {
  1764. char *dst = dup_basename(input_name, ".idl");
  1765. file_id = dst;
  1766. for (; *dst; ++dst)
  1767. if (! isalnum((unsigned char) *dst))
  1768. *dst = '_';
  1769. size = sizeof format - 7 + strlen(file_id) + 8;
  1770. }
  1771. name = xmalloc(size);
  1772. sprintf(name, format, file_id, n++);
  1773. return name;
  1774. }
  1775. struct allowed_attr
  1776. {
  1777. unsigned int dce_compatible : 1;
  1778. unsigned int acf : 1;
  1779. unsigned int on_interface : 1;
  1780. unsigned int on_function : 1;
  1781. unsigned int on_arg : 1;
  1782. unsigned int on_type : 1;
  1783. unsigned int on_enum : 1;
  1784. unsigned int on_struct : 1;
  1785. unsigned int on_union : 1;
  1786. unsigned int on_field : 1;
  1787. unsigned int on_library : 1;
  1788. unsigned int on_dispinterface : 1;
  1789. unsigned int on_module : 1;
  1790. unsigned int on_coclass : 1;
  1791. const char *display_name;
  1792. };
  1793. struct allowed_attr allowed_attr[] =
  1794. {
  1795. /* attr { D ACF I Fn ARG T En St Un Fi L DI M C <display name> } */
  1796. /* ATTR_AGGREGATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "aggregatable" },
  1797. /* ATTR_ANNOTATION */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "annotation" },
  1798. /* ATTR_APPOBJECT */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "appobject" },
  1799. /* ATTR_ASYNC */ { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "async" },
  1800. /* ATTR_AUTO_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "auto_handle" },
  1801. /* ATTR_BINDABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "bindable" },
  1802. /* ATTR_BROADCAST */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "broadcast" },
  1803. /* ATTR_CALLAS */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "call_as" },
  1804. /* ATTR_CALLCONV */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL },
  1805. /* ATTR_CASE */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "case" },
  1806. /* ATTR_CODE */ { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "code" },
  1807. /* ATTR_COMMSTATUS */ { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "comm_status" },
  1808. /* ATTR_CONST */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "const" },
  1809. /* ATTR_CONTEXTHANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "context_handle" },
  1810. /* ATTR_CONTROL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, "control" },
  1811. /* ATTR_DECODE */ { 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "decode" },
  1812. /* ATTR_DEFAULT */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, "default" },
  1813. /* ATTR_DEFAULTBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultbind" },
  1814. /* ATTR_DEFAULTCOLLELEM */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultcollelem" },
  1815. /* ATTR_DEFAULTVALUE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultvalue" },
  1816. /* ATTR_DEFAULTVTABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "defaultvtable" },
  1817. /* ATTR_DISABLECONSISTENCYCHECK */{ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "disable_consistency_check" },
  1818. /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL },
  1819. /* ATTR_DISPLAYBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "displaybind" },
  1820. /* ATTR_DLLNAME */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, "dllname" },
  1821. /* ATTR_DUAL */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "dual" },
  1822. /* ATTR_ENABLEALLOCATE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "enable_allocate" },
  1823. /* ATTR_ENCODE */ { 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "encode" },
  1824. /* ATTR_ENDPOINT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "endpoint" },
  1825. /* ATTR_ENTRY */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "entry" },
  1826. /* ATTR_EXPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "explicit_handle" },
  1827. /* ATTR_FAULTSTATUS */ { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "fault_status" },
  1828. /* ATTR_FORCEALLOCATE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "force_allocate" },
  1829. /* ATTR_HANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "handle" },
  1830. /* ATTR_HELPCONTEXT */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpcontext" },
  1831. /* ATTR_HELPFILE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpfile" },
  1832. /* ATTR_HELPSTRING */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpstring" },
  1833. /* ATTR_HELPSTRINGCONTEXT */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpstringcontext" },
  1834. /* ATTR_HELPSTRINGDLL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpstringdll" },
  1835. /* ATTR_HIDDEN */ { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, "hidden" },
  1836. /* ATTR_ID */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "id" },
  1837. /* ATTR_IDEMPOTENT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "idempotent" },
  1838. /* ATTR_IGNORE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "ignore" },
  1839. /* ATTR_IIDIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "iid_is" },
  1840. /* ATTR_IMMEDIATEBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "immediatebind" },
  1841. /* ATTR_IMPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "implicit_handle" },
  1842. /* ATTR_IN */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "in" },
  1843. /* ATTR_INLINE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inline" },
  1844. /* ATTR_INPUTSYNC */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inputsync" },
  1845. /* ATTR_LENGTHIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "length_is" },
  1846. /* ATTR_LIBLCID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "lcid" },
  1847. /* ATTR_LICENSED */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "licensed" },
  1848. /* ATTR_LOCAL */ { 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "local" },
  1849. /* ATTR_MAYBE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "maybe" },
  1850. /* ATTR_MESSAGE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "message" },
  1851. /* ATTR_NOCODE */ { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nocode" },
  1852. /* ATTR_NONBROWSABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonbrowsable" },
  1853. /* ATTR_NONCREATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "noncreatable" },
  1854. /* ATTR_NONEXTENSIBLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonextensible" },
  1855. /* ATTR_NOTIFY */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "notify" },
  1856. /* ATTR_NOTIFYFLAG */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "notify_flag" },
  1857. /* ATTR_OBJECT */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "object" },
  1858. /* ATTR_ODL */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "odl" },
  1859. /* ATTR_OLEAUTOMATION */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "oleautomation" },
  1860. /* ATTR_OPTIMIZE */ { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "optimize" },
  1861. /* ATTR_OPTIONAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "optional" },
  1862. /* ATTR_OUT */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "out" },
  1863. /* ATTR_PARAMLCID */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "lcid" },
  1864. /* ATTR_PARTIALIGNORE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "partial_ignore" },
  1865. /* ATTR_POINTERDEFAULT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "pointer_default" },
  1866. /* ATTR_POINTERTYPE */ { 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, "ref, unique or ptr" },
  1867. /* ATTR_PROGID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "progid" },
  1868. /* ATTR_PROPGET */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propget" },
  1869. /* ATTR_PROPPUT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propput" },
  1870. /* ATTR_PROPPUTREF */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propputref" },
  1871. /* ATTR_PROXY */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "proxy" },
  1872. /* ATTR_PUBLIC */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "public" },
  1873. /* ATTR_RANGE */ { 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, "range" },
  1874. /* ATTR_READONLY */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "readonly" },
  1875. /* ATTR_REPRESENTAS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "represent_as" },
  1876. /* ATTR_REQUESTEDIT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "requestedit" },
  1877. /* ATTR_RESTRICTED */ { 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, "restricted" },
  1878. /* ATTR_RETVAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "retval" },
  1879. /* ATTR_SIZEIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "size_is" },
  1880. /* ATTR_SOURCE */ { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "source" },
  1881. /* ATTR_STRICTCONTEXTHANDLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "strict_context_handle" },
  1882. /* ATTR_STRING */ { 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, "string" },
  1883. /* ATTR_SWITCHIS */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "switch_is" },
  1884. /* ATTR_SWITCHTYPE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, "switch_type" },
  1885. /* ATTR_THREADING */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "threading" },
  1886. /* ATTR_TRANSMITAS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "transmit_as" },
  1887. /* ATTR_UIDEFAULT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "uidefault" },
  1888. /* ATTR_USESGETLASTERROR */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "usesgetlasterror" },
  1889. /* ATTR_USERMARSHAL */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "user_marshal" },
  1890. /* ATTR_UUID */ { 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "uuid" },
  1891. /* ATTR_V1ENUM */ { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, "v1_enum" },
  1892. /* ATTR_VARARG */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "vararg" },
  1893. /* ATTR_VERSION */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, "version" },
  1894. /* ATTR_VIPROGID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "vi_progid" },
  1895. /* ATTR_WIREMARSHAL */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "wire_marshal" },
  1896. };
  1897. const char *get_attr_display_name(enum attr_type type)
  1898. {
  1899. return allowed_attr[type].display_name;
  1900. }
  1901. static attr_list_t *check_iface_attrs(const char *name, attr_list_t *attrs)
  1902. {
  1903. const attr_t *attr;
  1904. if (!attrs) return attrs;
  1905. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  1906. {
  1907. if (!allowed_attr[attr->type].on_interface)
  1908. error_loc("inapplicable attribute %s for interface %s\n",
  1909. allowed_attr[attr->type].display_name, name);
  1910. }
  1911. return attrs;
  1912. }
  1913. static attr_list_t *check_function_attrs(const char *name, attr_list_t *attrs)
  1914. {
  1915. const attr_t *attr;
  1916. if (!attrs) return attrs;
  1917. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  1918. {
  1919. if (!allowed_attr[attr->type].on_function)
  1920. error_loc("inapplicable attribute %s for function %s\n",
  1921. allowed_attr[attr->type].display_name, name);
  1922. }
  1923. return attrs;
  1924. }
  1925. static void check_arg_attrs(const var_t *arg)
  1926. {
  1927. const attr_t *attr;
  1928. if (arg->attrs)
  1929. {
  1930. LIST_FOR_EACH_ENTRY(attr, arg->attrs, const attr_t, entry)
  1931. {
  1932. if (!allowed_attr[attr->type].on_arg)
  1933. error_loc("inapplicable attribute %s for argument %s\n",
  1934. allowed_attr[attr->type].display_name, arg->name);
  1935. }
  1936. }
  1937. }
  1938. static attr_list_t *check_typedef_attrs(attr_list_t *attrs)
  1939. {
  1940. const attr_t *attr;
  1941. if (!attrs) return attrs;
  1942. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  1943. {
  1944. if (!allowed_attr[attr->type].on_type)
  1945. error_loc("inapplicable attribute %s for typedef\n",
  1946. allowed_attr[attr->type].display_name);
  1947. }
  1948. return attrs;
  1949. }
  1950. static attr_list_t *check_enum_attrs(attr_list_t *attrs)
  1951. {
  1952. const attr_t *attr;
  1953. if (!attrs) return attrs;
  1954. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  1955. {
  1956. if (!allowed_attr[attr->type].on_enum)
  1957. error_loc("inapplicable attribute %s for enum\n",
  1958. allowed_attr[attr->type].display_name);
  1959. }
  1960. return attrs;
  1961. }
  1962. static attr_list_t *check_struct_attrs(attr_list_t *attrs)
  1963. {
  1964. const attr_t *attr;
  1965. if (!attrs) return attrs;
  1966. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  1967. {
  1968. if (!allowed_attr[attr->type].on_struct)
  1969. error_loc("inapplicable attribute %s for struct\n",
  1970. allowed_attr[attr->type].display_name);
  1971. }
  1972. return attrs;
  1973. }
  1974. static attr_list_t *check_union_attrs(attr_list_t *attrs)
  1975. {
  1976. const attr_t *attr;
  1977. if (!attrs) return attrs;
  1978. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  1979. {
  1980. if (!allowed_attr[attr->type].on_union)
  1981. error_loc("inapplicable attribute %s for union\n",
  1982. allowed_attr[attr->type].display_name);
  1983. }
  1984. return attrs;
  1985. }
  1986. static attr_list_t *check_field_attrs(const char *name, attr_list_t *attrs)
  1987. {
  1988. const attr_t *attr;
  1989. if (!attrs) return attrs;
  1990. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  1991. {
  1992. if (!allowed_attr[attr->type].on_field)
  1993. error_loc("inapplicable attribute %s for field %s\n",
  1994. allowed_attr[attr->type].display_name, name);
  1995. }
  1996. return attrs;
  1997. }
  1998. static attr_list_t *check_library_attrs(const char *name, attr_list_t *attrs)
  1999. {
  2000. const attr_t *attr;
  2001. if (!attrs) return attrs;
  2002. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  2003. {
  2004. if (!allowed_attr[attr->type].on_library)
  2005. error_loc("inapplicable attribute %s for library %s\n",
  2006. allowed_attr[attr->type].display_name, name);
  2007. }
  2008. return attrs;
  2009. }
  2010. static attr_list_t *check_dispiface_attrs(const char *name, attr_list_t *attrs)
  2011. {
  2012. const attr_t *attr;
  2013. if (!attrs) return attrs;
  2014. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  2015. {
  2016. if (!allowed_attr[attr->type].on_dispinterface)
  2017. error_loc("inapplicable attribute %s for dispinterface %s\n",
  2018. allowed_attr[attr->type].display_name, name);
  2019. }
  2020. return attrs;
  2021. }
  2022. static attr_list_t *check_module_attrs(const char *name, attr_list_t *attrs)
  2023. {
  2024. const attr_t *attr;
  2025. if (!attrs) return attrs;
  2026. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  2027. {
  2028. if (!allowed_attr[attr->type].on_module)
  2029. error_loc("inapplicable attribute %s for module %s\n",
  2030. allowed_attr[attr->type].display_name, name);
  2031. }
  2032. return attrs;
  2033. }
  2034. static attr_list_t *check_coclass_attrs(const char *name, attr_list_t *attrs)
  2035. {
  2036. const attr_t *attr;
  2037. if (!attrs) return attrs;
  2038. LIST_FOR_EACH_ENTRY(attr, attrs, const attr_t, entry)
  2039. {
  2040. if (!allowed_attr[attr->type].on_coclass)
  2041. error_loc("inapplicable attribute %s for coclass %s\n",
  2042. allowed_attr[attr->type].display_name, name);
  2043. }
  2044. return attrs;
  2045. }
  2046. static int is_allowed_conf_type(const type_t *type)
  2047. {
  2048. switch (type_get_type(type))
  2049. {
  2050. case TYPE_ENUM:
  2051. return TRUE;
  2052. case TYPE_BASIC:
  2053. switch (type_basic_get_type(type))
  2054. {
  2055. case TYPE_BASIC_INT8:
  2056. case TYPE_BASIC_INT16:
  2057. case TYPE_BASIC_INT32:
  2058. case TYPE_BASIC_INT64:
  2059. case TYPE_BASIC_INT:
  2060. case TYPE_BASIC_CHAR:
  2061. case TYPE_BASIC_HYPER:
  2062. case TYPE_BASIC_BYTE:
  2063. case TYPE_BASIC_WCHAR:
  2064. return TRUE;
  2065. default:
  2066. return FALSE;
  2067. }
  2068. case TYPE_ALIAS:
  2069. /* shouldn't get here because of type_get_type call above */
  2070. assert(0);
  2071. /* fall through */
  2072. case TYPE_STRUCT:
  2073. case TYPE_UNION:
  2074. case TYPE_ENCAPSULATED_UNION:
  2075. case TYPE_ARRAY:
  2076. case TYPE_POINTER:
  2077. case TYPE_VOID:
  2078. case TYPE_MODULE:
  2079. case TYPE_COCLASS:
  2080. case TYPE_FUNCTION:
  2081. case TYPE_INTERFACE:
  2082. case TYPE_BITFIELD:
  2083. return FALSE;
  2084. }
  2085. return FALSE;
  2086. }
  2087. static int is_ptr_guid_type(const type_t *type)
  2088. {
  2089. /* first, make sure it is a pointer to something */
  2090. if (!is_ptr(type)) return FALSE;
  2091. /* second, make sure it is a pointer to something of size sizeof(GUID),
  2092. * i.e. 16 bytes */
  2093. return (type_memsize(type_pointer_get_ref(type)) == 16);
  2094. }
  2095. static void check_conformance_expr_list(const char *attr_name, const var_t *arg, const type_t *container_type, expr_list_t *expr_list)
  2096. {
  2097. expr_t *dim;
  2098. struct expr_loc expr_loc;
  2099. expr_loc.v = arg;
  2100. expr_loc.attr = attr_name;
  2101. if (expr_list) LIST_FOR_EACH_ENTRY(dim, expr_list, expr_t, entry)
  2102. {
  2103. if (dim->type != EXPR_VOID)
  2104. {
  2105. const type_t *expr_type = expr_resolve_type(&expr_loc, container_type, dim);
  2106. if (!is_allowed_conf_type(expr_type))
  2107. error_loc_info(&arg->loc_info, "expression must resolve to integral type <= 32bits for attribute %s\n",
  2108. attr_name);
  2109. }
  2110. }
  2111. }
  2112. static void check_remoting_fields(const var_t *var, type_t *type);
  2113. /* checks that properties common to fields and arguments are consistent */
  2114. static void check_field_common(const type_t *container_type,
  2115. const char *container_name, const var_t *arg)
  2116. {
  2117. type_t *type = arg->type;
  2118. int more_to_do;
  2119. const char *container_type_name;
  2120. const char *var_type;
  2121. switch (type_get_type(container_type))
  2122. {
  2123. case TYPE_STRUCT:
  2124. container_type_name = "struct";
  2125. var_type = "field";
  2126. break;
  2127. case TYPE_UNION:
  2128. container_type_name = "union";
  2129. var_type = "arm";
  2130. break;
  2131. case TYPE_ENCAPSULATED_UNION:
  2132. container_type_name = "encapsulated union";
  2133. var_type = "arm";
  2134. break;
  2135. case TYPE_FUNCTION:
  2136. container_type_name = "function";
  2137. var_type = "parameter";
  2138. break;
  2139. default:
  2140. /* should be no other container types */
  2141. assert(0);
  2142. return;
  2143. }
  2144. if (is_attr(arg->attrs, ATTR_LENGTHIS) &&
  2145. (is_attr(arg->attrs, ATTR_STRING) || is_aliaschain_attr(arg->type, ATTR_STRING)))
  2146. error_loc_info(&arg->loc_info,
  2147. "string and length_is specified for argument %s are mutually exclusive attributes\n",
  2148. arg->name);
  2149. if (is_attr(arg->attrs, ATTR_SIZEIS))
  2150. {
  2151. expr_list_t *size_is_exprs = get_attrp(arg->attrs, ATTR_SIZEIS);
  2152. check_conformance_expr_list("size_is", arg, container_type, size_is_exprs);
  2153. }
  2154. if (is_attr(arg->attrs, ATTR_LENGTHIS))
  2155. {
  2156. expr_list_t *length_is_exprs = get_attrp(arg->attrs, ATTR_LENGTHIS);
  2157. check_conformance_expr_list("length_is", arg, container_type, length_is_exprs);
  2158. }
  2159. if (is_attr(arg->attrs, ATTR_IIDIS))
  2160. {
  2161. struct expr_loc expr_loc;
  2162. expr_t *expr = get_attrp(arg->attrs, ATTR_IIDIS);
  2163. if (expr->type != EXPR_VOID)
  2164. {
  2165. const type_t *expr_type;
  2166. expr_loc.v = arg;
  2167. expr_loc.attr = "iid_is";
  2168. expr_type = expr_resolve_type(&expr_loc, container_type, expr);
  2169. if (!expr_type || !is_ptr_guid_type(expr_type))
  2170. error_loc_info(&arg->loc_info, "expression must resolve to pointer to GUID type for attribute iid_is\n");
  2171. }
  2172. }
  2173. if (is_attr(arg->attrs, ATTR_SWITCHIS))
  2174. {
  2175. struct expr_loc expr_loc;
  2176. expr_t *expr = get_attrp(arg->attrs, ATTR_SWITCHIS);
  2177. if (expr->type != EXPR_VOID)
  2178. {
  2179. const type_t *expr_type;
  2180. expr_loc.v = arg;
  2181. expr_loc.attr = "switch_is";
  2182. expr_type = expr_resolve_type(&expr_loc, container_type, expr);
  2183. if (!expr_type || !is_allowed_conf_type(expr_type))
  2184. error_loc_info(&arg->loc_info, "expression must resolve to integral type <= 32bits for attribute %s\n",
  2185. expr_loc.attr);
  2186. }
  2187. }
  2188. do
  2189. {
  2190. more_to_do = FALSE;
  2191. switch (typegen_detect_type(type, arg->attrs, TDT_IGNORE_STRINGS))
  2192. {
  2193. case TGT_STRUCT:
  2194. case TGT_UNION:
  2195. check_remoting_fields(arg, type);
  2196. break;
  2197. case TGT_INVALID:
  2198. {
  2199. const char *reason = "is invalid";
  2200. switch (type_get_type(type))
  2201. {
  2202. case TYPE_VOID:
  2203. reason = "cannot derive from void *";
  2204. break;
  2205. case TYPE_FUNCTION:
  2206. reason = "cannot be a function pointer";
  2207. break;
  2208. case TYPE_BITFIELD:
  2209. reason = "cannot be a bit-field";
  2210. break;
  2211. case TYPE_COCLASS:
  2212. reason = "cannot be a class";
  2213. break;
  2214. case TYPE_INTERFACE:
  2215. reason = "cannot be a non-pointer to an interface";
  2216. break;
  2217. case TYPE_MODULE:
  2218. reason = "cannot be a module";
  2219. break;
  2220. default:
  2221. break;
  2222. }
  2223. error_loc_info(&arg->loc_info, "%s \'%s\' of %s \'%s\' %s\n",
  2224. var_type, arg->name, container_type_name, container_name, reason);
  2225. break;
  2226. }
  2227. case TGT_CTXT_HANDLE:
  2228. case TGT_CTXT_HANDLE_POINTER:
  2229. if (type_get_type(container_type) != TYPE_FUNCTION)
  2230. error_loc_info(&arg->loc_info,
  2231. "%s \'%s\' of %s \'%s\' cannot be a context handle\n",
  2232. var_type, arg->name, container_type_name,
  2233. container_name);
  2234. break;
  2235. case TGT_STRING:
  2236. {
  2237. const type_t *t = type;
  2238. while (is_ptr(t))
  2239. t = type_pointer_get_ref(t);
  2240. if (is_aliaschain_attr(t, ATTR_RANGE))
  2241. warning_loc_info(&arg->loc_info, "%s: range not verified for a string of ranged types\n", arg->name);
  2242. break;
  2243. }
  2244. case TGT_POINTER:
  2245. type = type_pointer_get_ref(type);
  2246. more_to_do = TRUE;
  2247. break;
  2248. case TGT_ARRAY:
  2249. type = type_array_get_element(type);
  2250. more_to_do = TRUE;
  2251. break;
  2252. case TGT_USER_TYPE:
  2253. case TGT_IFACE_POINTER:
  2254. case TGT_BASIC:
  2255. case TGT_ENUM:
  2256. case TGT_RANGE:
  2257. /* nothing to do */
  2258. break;
  2259. }
  2260. } while (more_to_do);
  2261. }
  2262. static void check_remoting_fields(const var_t *var, type_t *type)
  2263. {
  2264. const var_t *field;
  2265. const var_list_t *fields = NULL;
  2266. type = type_get_real_type(type);
  2267. if (type->checked)
  2268. return;
  2269. type->checked = TRUE;
  2270. if (type_get_type(type) == TYPE_STRUCT)
  2271. {
  2272. if (type_is_complete(type))
  2273. fields = type_struct_get_fields(type);
  2274. else
  2275. error_loc_info(&var->loc_info, "undefined type declaration %s\n", type->name);
  2276. }
  2277. else if (type_get_type(type) == TYPE_UNION || type_get_type(type) == TYPE_ENCAPSULATED_UNION)
  2278. fields = type_union_get_cases(type);
  2279. if (fields) LIST_FOR_EACH_ENTRY( field, fields, const var_t, entry )
  2280. if (field->type) check_field_common(type, type->name, field);
  2281. }
  2282. /* checks that arguments for a function make sense for marshalling and unmarshalling */
  2283. static void check_remoting_args(const var_t *func)
  2284. {
  2285. const char *funcname = func->name;
  2286. const var_t *arg;
  2287. if (func->type->details.function->args) LIST_FOR_EACH_ENTRY( arg, func->type->details.function->args, const var_t, entry )
  2288. {
  2289. const type_t *type = arg->type;
  2290. /* check that [out] parameters have enough pointer levels */
  2291. if (is_attr(arg->attrs, ATTR_OUT))
  2292. {
  2293. switch (typegen_detect_type(type, arg->attrs, TDT_ALL_TYPES))
  2294. {
  2295. case TGT_BASIC:
  2296. case TGT_ENUM:
  2297. case TGT_RANGE:
  2298. case TGT_STRUCT:
  2299. case TGT_UNION:
  2300. case TGT_CTXT_HANDLE:
  2301. case TGT_USER_TYPE:
  2302. error_loc_info(&arg->loc_info, "out parameter \'%s\' of function \'%s\' is not a pointer\n", arg->name, funcname);
  2303. break;
  2304. case TGT_IFACE_POINTER:
  2305. error_loc_info(&arg->loc_info, "out interface pointer \'%s\' of function \'%s\' is not a double pointer\n", arg->name, funcname);
  2306. break;
  2307. case TGT_STRING:
  2308. if (is_ptr(type) ||
  2309. (is_array(type) &&
  2310. (!type_array_has_conformance(type) ||
  2311. type_array_get_conformance(type)->type == EXPR_VOID)))
  2312. error_loc_info(&arg->loc_info, "out parameter \'%s\' of function \'%s\' cannot be an unsized string\n", arg->name, funcname);
  2313. break;
  2314. case TGT_INVALID:
  2315. /* already error'd before we get here */
  2316. case TGT_CTXT_HANDLE_POINTER:
  2317. case TGT_POINTER:
  2318. case TGT_ARRAY:
  2319. /* OK */
  2320. break;
  2321. }
  2322. }
  2323. check_field_common(func->type, funcname, arg);
  2324. }
  2325. if (type_get_type(type_function_get_rettype(func->type)) != TYPE_VOID)
  2326. {
  2327. var_t var;
  2328. var = *func;
  2329. var.type = type_function_get_rettype(func->type);
  2330. var.name = xstrdup("return value");
  2331. check_field_common(func->type, funcname, &var);
  2332. free(var.name);
  2333. }
  2334. }
  2335. static void add_explicit_handle_if_necessary(var_t *func)
  2336. {
  2337. const var_t* explicit_handle_var;
  2338. const var_t* explicit_generic_handle_var = NULL;
  2339. const var_t* context_handle_var = NULL;
  2340. /* check for a defined binding handle */
  2341. explicit_handle_var = get_explicit_handle_var(func);
  2342. if (!explicit_handle_var)
  2343. {
  2344. explicit_generic_handle_var = get_explicit_generic_handle_var(func);
  2345. if (!explicit_generic_handle_var)
  2346. {
  2347. context_handle_var = get_context_handle_var(func);
  2348. if (!context_handle_var)
  2349. {
  2350. /* no explicit handle specified so add
  2351. * "[in] handle_t IDL_handle" as the first parameter to the
  2352. * function */
  2353. var_t *idl_handle = make_var(xstrdup("IDL_handle"));
  2354. idl_handle->attrs = append_attr(NULL, make_attr(ATTR_IN));
  2355. idl_handle->type = find_type_or_error("handle_t", 0);
  2356. type_function_add_head_arg(func->type, idl_handle);
  2357. }
  2358. }
  2359. }
  2360. }
  2361. static void check_functions(const type_t *iface, int is_inside_library)
  2362. {
  2363. const statement_t *stmt;
  2364. if (is_attr(iface->attrs, ATTR_EXPLICIT_HANDLE))
  2365. {
  2366. STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
  2367. {
  2368. var_t *func = stmt->u.var;
  2369. add_explicit_handle_if_necessary(func);
  2370. }
  2371. }
  2372. if (!is_inside_library && !is_attr(iface->attrs, ATTR_LOCAL))
  2373. {
  2374. STATEMENTS_FOR_EACH_FUNC( stmt, type_iface_get_stmts(iface) )
  2375. {
  2376. const var_t *func = stmt->u.var;
  2377. if (!is_attr(func->attrs, ATTR_LOCAL))
  2378. check_remoting_args(func);
  2379. }
  2380. }
  2381. }
  2382. static void check_statements(const statement_list_t *stmts, int is_inside_library)
  2383. {
  2384. const statement_t *stmt;
  2385. if (stmts) LIST_FOR_EACH_ENTRY(stmt, stmts, const statement_t, entry)
  2386. {
  2387. if (stmt->type == STMT_LIBRARY)
  2388. check_statements(stmt->u.lib->stmts, TRUE);
  2389. else if (stmt->type == STMT_TYPE && type_get_type(stmt->u.type) == TYPE_INTERFACE)
  2390. check_functions(stmt->u.type, is_inside_library);
  2391. }
  2392. }
  2393. static void check_all_user_types(const statement_list_t *stmts)
  2394. {
  2395. const statement_t *stmt;
  2396. if (stmts) LIST_FOR_EACH_ENTRY(stmt, stmts, const statement_t, entry)
  2397. {
  2398. if (stmt->type == STMT_LIBRARY)
  2399. check_all_user_types(stmt->u.lib->stmts);
  2400. else if (stmt->type == STMT_TYPE && type_get_type(stmt->u.type) == TYPE_INTERFACE &&
  2401. !is_local(stmt->u.type->attrs))
  2402. {
  2403. const statement_t *stmt_func;
  2404. STATEMENTS_FOR_EACH_FUNC(stmt_func, type_iface_get_stmts(stmt->u.type)) {
  2405. const var_t *func = stmt_func->u.var;
  2406. check_for_additional_prototype_types(func->type->details.function->args);
  2407. }
  2408. }
  2409. }
  2410. }
  2411. int is_valid_uuid(const char *s)
  2412. {
  2413. int i;
  2414. for (i = 0; i < 36; ++i)
  2415. if (i == 8 || i == 13 || i == 18 || i == 23)
  2416. {
  2417. if (s[i] != '-')
  2418. return FALSE;
  2419. }
  2420. else
  2421. if (!isxdigit(s[i]))
  2422. return FALSE;
  2423. return s[i] == '\0';
  2424. }
  2425. static statement_t *make_statement(enum statement_type type)
  2426. {
  2427. statement_t *stmt = xmalloc(sizeof(*stmt));
  2428. stmt->type = type;
  2429. return stmt;
  2430. }
  2431. static statement_t *make_statement_type_decl(type_t *type)
  2432. {
  2433. statement_t *stmt = make_statement(STMT_TYPE);
  2434. stmt->u.type = type;
  2435. return stmt;
  2436. }
  2437. static statement_t *make_statement_reference(type_t *type)
  2438. {
  2439. statement_t *stmt = make_statement(STMT_TYPEREF);
  2440. stmt->u.type = type;
  2441. return stmt;
  2442. }
  2443. static statement_t *make_statement_declaration(var_t *var)
  2444. {
  2445. statement_t *stmt = make_statement(STMT_DECLARATION);
  2446. stmt->u.var = var;
  2447. if (var->stgclass == STG_EXTERN && var->eval)
  2448. warning("'%s' initialised and declared extern\n", var->name);
  2449. if (is_const_decl(var))
  2450. {
  2451. if (var->eval)
  2452. reg_const(var);
  2453. }
  2454. else if (type_get_type(var->type) == TYPE_FUNCTION)
  2455. check_function_attrs(var->name, var->attrs);
  2456. else if (var->stgclass == STG_NONE || var->stgclass == STG_REGISTER)
  2457. error_loc("instantiation of data is illegal\n");
  2458. return stmt;
  2459. }
  2460. static statement_t *make_statement_library(typelib_t *typelib)
  2461. {
  2462. statement_t *stmt = make_statement(STMT_LIBRARY);
  2463. stmt->u.lib = typelib;
  2464. return stmt;
  2465. }
  2466. static statement_t *make_statement_cppquote(const char *str)
  2467. {
  2468. statement_t *stmt = make_statement(STMT_CPPQUOTE);
  2469. stmt->u.str = str;
  2470. return stmt;
  2471. }
  2472. static statement_t *make_statement_importlib(const char *str)
  2473. {
  2474. statement_t *stmt = make_statement(STMT_IMPORTLIB);
  2475. stmt->u.str = str;
  2476. return stmt;
  2477. }
  2478. static statement_t *make_statement_import(const char *str)
  2479. {
  2480. statement_t *stmt = make_statement(STMT_IMPORT);
  2481. stmt->u.str = str;
  2482. return stmt;
  2483. }
  2484. static statement_t *make_statement_module(type_t *type)
  2485. {
  2486. statement_t *stmt = make_statement(STMT_MODULE);
  2487. stmt->u.type = type;
  2488. return stmt;
  2489. }
  2490. static statement_t *make_statement_typedef(declarator_list_t *decls)
  2491. {
  2492. declarator_t *decl, *next;
  2493. statement_t *stmt;
  2494. type_list_t **type_list;
  2495. if (!decls) return NULL;
  2496. stmt = make_statement(STMT_TYPEDEF);
  2497. stmt->u.type_list = NULL;
  2498. type_list = &stmt->u.type_list;
  2499. LIST_FOR_EACH_ENTRY_SAFE( decl, next, decls, declarator_t, entry )
  2500. {
  2501. var_t *var = decl->var;
  2502. type_t *type = find_type_or_error(var->name, 0);
  2503. *type_list = xmalloc(sizeof(type_list_t));
  2504. (*type_list)->type = type;
  2505. (*type_list)->next = NULL;
  2506. type_list = &(*type_list)->next;
  2507. free(decl);
  2508. free(var);
  2509. }
  2510. return stmt;
  2511. }
  2512. static statement_list_t *append_statement(statement_list_t *list, statement_t *stmt)
  2513. {
  2514. if (!stmt) return list;
  2515. if (!list)
  2516. {
  2517. list = xmalloc( sizeof(*list) );
  2518. list_init( list );
  2519. }
  2520. list_add_tail( list, &stmt->entry );
  2521. return list;
  2522. }
  2523. void init_loc_info(loc_info_t *i)
  2524. {
  2525. i->input_name = input_name ? input_name : "stdin";
  2526. i->line_number = line_number;
  2527. i->near_text = parser_text;
  2528. }
  2529. static void check_def(const type_t *t)
  2530. {
  2531. if (t->defined)
  2532. error_loc("%s: redefinition error; original definition was at %s:%d\n",
  2533. t->name, t->loc_info.input_name, t->loc_info.line_number);
  2534. }