widltypes.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /*
  2. * IDL Compiler
  3. *
  4. * Copyright 2002 Ove Kaaven
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19. */
  20. #ifndef __WIDL_WIDLTYPES_H
  21. #define __WIDL_WIDLTYPES_H
  22. #include <stdarg.h>
  23. #include <assert.h>
  24. #include "guiddef.h"
  25. #include "ndrtypes.h"
  26. #include "wine/list.h"
  27. #ifndef UUID_DEFINED
  28. #define UUID_DEFINED
  29. typedef GUID UUID;
  30. #endif
  31. #define TRUE 1
  32. #define FALSE 0
  33. typedef struct _loc_info_t loc_info_t;
  34. typedef struct _attr_t attr_t;
  35. typedef struct _attr_custdata_t attr_custdata_t;
  36. typedef struct _expr_t expr_t;
  37. typedef struct _type_t type_t;
  38. typedef struct _var_t var_t;
  39. typedef struct _decl_spec_t decl_spec_t;
  40. typedef struct _declarator_t declarator_t;
  41. typedef struct _typeref_t typeref_t;
  42. typedef struct _typelib_entry_t typelib_entry_t;
  43. typedef struct _importlib_t importlib_t;
  44. typedef struct _importinfo_t importinfo_t;
  45. typedef struct _typelib_t typelib_t;
  46. typedef struct _user_type_t user_type_t;
  47. typedef struct _user_type_t context_handle_t;
  48. typedef struct _user_type_t generic_handle_t;
  49. typedef struct _statement_t statement_t;
  50. typedef struct _warning_t warning_t;
  51. typedef struct list attr_list_t;
  52. typedef struct list str_list_t;
  53. typedef struct list expr_list_t;
  54. typedef struct list var_list_t;
  55. typedef struct list declarator_list_t;
  56. typedef struct list typeref_list_t;
  57. typedef struct list user_type_list_t;
  58. typedef struct list context_handle_list_t;
  59. typedef struct list generic_handle_list_t;
  60. typedef struct list statement_list_t;
  61. typedef struct list warning_list_t;
  62. enum attr_type
  63. {
  64. ATTR_ACTIVATABLE,
  65. ATTR_AGGREGATABLE,
  66. ATTR_ALLOCATE,
  67. ATTR_ANNOTATION,
  68. ATTR_APPOBJECT,
  69. ATTR_ASYNC,
  70. ATTR_ASYNCUUID,
  71. ATTR_AUTO_HANDLE,
  72. ATTR_BINDABLE,
  73. ATTR_BROADCAST,
  74. ATTR_CALLAS,
  75. ATTR_CALLCONV, /* calling convention pseudo-attribute */
  76. ATTR_CASE,
  77. ATTR_CODE,
  78. ATTR_COMMSTATUS,
  79. ATTR_CONTEXTHANDLE,
  80. ATTR_CONTRACT,
  81. ATTR_CONTRACTVERSION,
  82. ATTR_CONTROL,
  83. ATTR_CUSTOM,
  84. ATTR_DECODE,
  85. ATTR_DEFAULT,
  86. ATTR_DEFAULTBIND,
  87. ATTR_DEFAULTCOLLELEM,
  88. ATTR_DEFAULTVALUE,
  89. ATTR_DEFAULTVTABLE,
  90. ATTR_DISABLECONSISTENCYCHECK,
  91. ATTR_DISPINTERFACE,
  92. ATTR_DISPLAYBIND,
  93. ATTR_DLLNAME,
  94. ATTR_DUAL,
  95. ATTR_ENABLEALLOCATE,
  96. ATTR_ENCODE,
  97. ATTR_ENDPOINT,
  98. ATTR_ENTRY,
  99. ATTR_EVENTADD,
  100. ATTR_EVENTREMOVE,
  101. ATTR_EXCLUSIVETO,
  102. ATTR_EXPLICIT_HANDLE,
  103. ATTR_FAULTSTATUS,
  104. ATTR_FLAGS,
  105. ATTR_FORCEALLOCATE,
  106. ATTR_HANDLE,
  107. ATTR_HELPCONTEXT,
  108. ATTR_HELPFILE,
  109. ATTR_HELPSTRING,
  110. ATTR_HELPSTRINGCONTEXT,
  111. ATTR_HELPSTRINGDLL,
  112. ATTR_HIDDEN,
  113. ATTR_ID,
  114. ATTR_IDEMPOTENT,
  115. ATTR_IGNORE,
  116. ATTR_IIDIS,
  117. ATTR_IMMEDIATEBIND,
  118. ATTR_IMPLICIT_HANDLE,
  119. ATTR_IN,
  120. ATTR_INPUTSYNC,
  121. ATTR_LENGTHIS,
  122. ATTR_LIBLCID,
  123. ATTR_LICENSED,
  124. ATTR_LOCAL,
  125. ATTR_MARSHALING_BEHAVIOR,
  126. ATTR_MAYBE,
  127. ATTR_MESSAGE,
  128. ATTR_NOCODE,
  129. ATTR_NONBROWSABLE,
  130. ATTR_NONCREATABLE,
  131. ATTR_NONEXTENSIBLE,
  132. ATTR_NOTIFY,
  133. ATTR_NOTIFYFLAG,
  134. ATTR_OBJECT,
  135. ATTR_ODL,
  136. ATTR_OLEAUTOMATION,
  137. ATTR_OPTIMIZE,
  138. ATTR_OPTIONAL,
  139. ATTR_OUT,
  140. ATTR_PARAMLCID,
  141. ATTR_PARTIALIGNORE,
  142. ATTR_POINTERDEFAULT,
  143. ATTR_POINTERTYPE,
  144. ATTR_PROGID,
  145. ATTR_PROPGET,
  146. ATTR_PROPPUT,
  147. ATTR_PROPPUTREF,
  148. ATTR_PROXY,
  149. ATTR_PUBLIC,
  150. ATTR_RANGE,
  151. ATTR_READONLY,
  152. ATTR_REPRESENTAS,
  153. ATTR_REQUESTEDIT,
  154. ATTR_RESTRICTED,
  155. ATTR_RETVAL,
  156. ATTR_SIZEIS,
  157. ATTR_SOURCE,
  158. ATTR_STATIC,
  159. ATTR_STRICTCONTEXTHANDLE,
  160. ATTR_STRING,
  161. ATTR_SWITCHIS,
  162. ATTR_SWITCHTYPE,
  163. ATTR_THREADING,
  164. ATTR_TRANSMITAS,
  165. ATTR_UIDEFAULT,
  166. ATTR_USERMARSHAL,
  167. ATTR_USESGETLASTERROR,
  168. ATTR_UUID,
  169. ATTR_V1ENUM,
  170. ATTR_VARARG,
  171. ATTR_VERSION,
  172. ATTR_VIPROGID,
  173. ATTR_WIREMARSHAL
  174. };
  175. enum expr_type
  176. {
  177. EXPR_VOID,
  178. EXPR_NUM,
  179. EXPR_HEXNUM,
  180. EXPR_DOUBLE,
  181. EXPR_IDENTIFIER,
  182. EXPR_NEG,
  183. EXPR_NOT,
  184. EXPR_PPTR,
  185. EXPR_CAST,
  186. EXPR_SIZEOF,
  187. EXPR_SHL,
  188. EXPR_SHR,
  189. EXPR_MUL,
  190. EXPR_DIV,
  191. EXPR_ADD,
  192. EXPR_SUB,
  193. EXPR_AND,
  194. EXPR_OR,
  195. EXPR_COND,
  196. EXPR_TRUEFALSE,
  197. EXPR_ADDRESSOF,
  198. EXPR_MEMBER,
  199. EXPR_ARRAY,
  200. EXPR_MOD,
  201. EXPR_LOGOR,
  202. EXPR_LOGAND,
  203. EXPR_XOR,
  204. EXPR_EQUALITY,
  205. EXPR_INEQUALITY,
  206. EXPR_GTR,
  207. EXPR_LESS,
  208. EXPR_GTREQL,
  209. EXPR_LESSEQL,
  210. EXPR_LOGNOT,
  211. EXPR_POS,
  212. EXPR_STRLIT,
  213. EXPR_WSTRLIT,
  214. EXPR_CHARCONST,
  215. };
  216. enum type_kind
  217. {
  218. TKIND_PRIMITIVE = -1,
  219. TKIND_ENUM,
  220. TKIND_RECORD,
  221. TKIND_MODULE,
  222. TKIND_INTERFACE,
  223. TKIND_DISPATCH,
  224. TKIND_COCLASS,
  225. TKIND_ALIAS,
  226. TKIND_UNION,
  227. TKIND_MAX
  228. };
  229. enum storage_class
  230. {
  231. STG_NONE,
  232. STG_STATIC,
  233. STG_EXTERN,
  234. STG_REGISTER,
  235. };
  236. enum type_qualifier
  237. {
  238. TYPE_QUALIFIER_CONST = 1,
  239. };
  240. enum function_specifier
  241. {
  242. FUNCTION_SPECIFIER_INLINE = 1,
  243. };
  244. enum statement_type
  245. {
  246. STMT_LIBRARY,
  247. STMT_DECLARATION,
  248. STMT_TYPE,
  249. STMT_TYPEREF,
  250. STMT_MODULE,
  251. STMT_TYPEDEF,
  252. STMT_IMPORT,
  253. STMT_IMPORTLIB,
  254. STMT_PRAGMA,
  255. STMT_CPPQUOTE
  256. };
  257. enum threading_type
  258. {
  259. THREADING_APARTMENT = 1,
  260. THREADING_NEUTRAL,
  261. THREADING_SINGLE,
  262. THREADING_FREE,
  263. THREADING_BOTH
  264. };
  265. enum marshaling_type
  266. {
  267. MARSHALING_INVALID = 0,
  268. MARSHALING_NONE,
  269. MARSHALING_AGILE,
  270. MARSHALING_STANDARD,
  271. };
  272. enum type_basic_type
  273. {
  274. TYPE_BASIC_INT8 = 1,
  275. TYPE_BASIC_INT16,
  276. TYPE_BASIC_INT32,
  277. TYPE_BASIC_INT64,
  278. TYPE_BASIC_INT,
  279. TYPE_BASIC_INT3264,
  280. TYPE_BASIC_LONG,
  281. TYPE_BASIC_CHAR,
  282. TYPE_BASIC_HYPER,
  283. TYPE_BASIC_BYTE,
  284. TYPE_BASIC_WCHAR,
  285. TYPE_BASIC_FLOAT,
  286. TYPE_BASIC_DOUBLE,
  287. TYPE_BASIC_ERROR_STATUS_T,
  288. TYPE_BASIC_HANDLE,
  289. };
  290. #define TYPE_BASIC_MAX TYPE_BASIC_HANDLE
  291. #define TYPE_BASIC_INT_MIN TYPE_BASIC_INT8
  292. #define TYPE_BASIC_INT_MAX TYPE_BASIC_HYPER
  293. struct _loc_info_t
  294. {
  295. const char *input_name;
  296. int line_number;
  297. const char *near_text;
  298. };
  299. struct str_list_entry_t
  300. {
  301. char *str;
  302. struct list entry;
  303. };
  304. struct _decl_spec_t
  305. {
  306. type_t *type;
  307. enum storage_class stgclass;
  308. enum type_qualifier qualifier;
  309. enum function_specifier func_specifier;
  310. };
  311. struct _attr_t {
  312. enum attr_type type;
  313. union {
  314. unsigned int ival;
  315. void *pval;
  316. } u;
  317. /* parser-internal */
  318. struct list entry;
  319. };
  320. struct _expr_t {
  321. enum expr_type type;
  322. const expr_t *ref;
  323. union {
  324. int lval;
  325. double dval;
  326. const char *sval;
  327. const expr_t *ext;
  328. decl_spec_t tref;
  329. } u;
  330. const expr_t *ext2;
  331. int is_const;
  332. int cval;
  333. /* parser-internal */
  334. struct list entry;
  335. };
  336. struct _attr_custdata_t {
  337. GUID id;
  338. expr_t *pval;
  339. };
  340. struct struct_details
  341. {
  342. var_list_t *fields;
  343. };
  344. struct enumeration_details
  345. {
  346. var_list_t *enums;
  347. };
  348. struct func_details
  349. {
  350. var_list_t *args;
  351. struct _var_t *retval;
  352. };
  353. struct iface_details
  354. {
  355. statement_list_t *stmts;
  356. var_list_t *disp_methods;
  357. var_list_t *disp_props;
  358. struct _type_t *inherit;
  359. struct _type_t *disp_inherit;
  360. struct _type_t *async_iface;
  361. typeref_list_t *requires;
  362. };
  363. struct module_details
  364. {
  365. statement_list_t *stmts;
  366. };
  367. struct array_details
  368. {
  369. expr_t *size_is;
  370. expr_t *length_is;
  371. struct _decl_spec_t elem;
  372. unsigned int dim;
  373. unsigned char declptr; /* if declared as a pointer */
  374. unsigned short ptr_tfsoff; /* offset of pointer definition for declptr */
  375. };
  376. struct coclass_details
  377. {
  378. typeref_list_t *ifaces;
  379. };
  380. struct basic_details
  381. {
  382. enum type_basic_type type;
  383. int sign;
  384. };
  385. struct pointer_details
  386. {
  387. struct _decl_spec_t ref;
  388. };
  389. struct bitfield_details
  390. {
  391. struct _type_t *field;
  392. const expr_t *bits;
  393. };
  394. struct alias_details
  395. {
  396. struct _decl_spec_t aliasee;
  397. };
  398. struct runtimeclass_details
  399. {
  400. typeref_list_t *ifaces;
  401. };
  402. struct parameterized_details
  403. {
  404. type_t *type;
  405. typeref_list_t *params;
  406. };
  407. struct delegate_details
  408. {
  409. type_t *iface;
  410. };
  411. #define HASHMAX 64
  412. struct namespace {
  413. const char *name;
  414. struct namespace *parent;
  415. struct list entry;
  416. struct list children;
  417. struct rtype *type_hash[HASHMAX];
  418. };
  419. enum type_type
  420. {
  421. TYPE_VOID,
  422. TYPE_BASIC, /* ints, floats and handles */
  423. TYPE_ENUM,
  424. TYPE_STRUCT,
  425. TYPE_ENCAPSULATED_UNION,
  426. TYPE_UNION,
  427. TYPE_ALIAS,
  428. TYPE_MODULE,
  429. TYPE_COCLASS,
  430. TYPE_FUNCTION,
  431. TYPE_INTERFACE,
  432. TYPE_POINTER,
  433. TYPE_ARRAY,
  434. TYPE_BITFIELD,
  435. TYPE_APICONTRACT,
  436. TYPE_RUNTIMECLASS,
  437. TYPE_PARAMETERIZED_TYPE,
  438. TYPE_PARAMETER,
  439. TYPE_DELEGATE,
  440. };
  441. struct _type_t {
  442. const char *name;
  443. struct namespace *namespace;
  444. enum type_type type_type;
  445. attr_list_t *attrs;
  446. union
  447. {
  448. struct struct_details *structure;
  449. struct enumeration_details *enumeration;
  450. struct func_details *function;
  451. struct iface_details *iface;
  452. struct module_details *module;
  453. struct array_details array;
  454. struct coclass_details coclass;
  455. struct basic_details basic;
  456. struct pointer_details pointer;
  457. struct bitfield_details bitfield;
  458. struct alias_details alias;
  459. struct runtimeclass_details runtimeclass;
  460. struct parameterized_details parameterized;
  461. struct delegate_details delegate;
  462. } details;
  463. const char *c_name;
  464. const char *signature;
  465. const char *qualified_name;
  466. const char *impl_name;
  467. const char *short_name;
  468. unsigned int typestring_offset;
  469. unsigned int ptrdesc; /* used for complex structs */
  470. int typelib_idx;
  471. loc_info_t loc_info;
  472. unsigned int ignore : 1;
  473. unsigned int defined : 1;
  474. unsigned int written : 1;
  475. unsigned int user_types_registered : 1;
  476. unsigned int tfswrite : 1; /* if the type needs to be written to the TFS */
  477. unsigned int checked : 1;
  478. };
  479. struct _var_t {
  480. char *name;
  481. decl_spec_t declspec;
  482. attr_list_t *attrs;
  483. expr_t *eval;
  484. unsigned int typestring_offset;
  485. /* fields specific to functions */
  486. unsigned int procstring_offset, func_idx;
  487. struct _loc_info_t loc_info;
  488. unsigned int declonly : 1;
  489. /* parser-internal */
  490. struct list entry;
  491. };
  492. struct _declarator_t {
  493. var_t *var;
  494. type_t *type;
  495. enum type_qualifier qualifier;
  496. expr_t *bits;
  497. /* parser-internal */
  498. struct list entry;
  499. };
  500. struct _typeref_t {
  501. type_t *type;
  502. attr_list_t *attrs;
  503. /* parser-internal */
  504. struct list entry;
  505. };
  506. struct _typelib_entry_t {
  507. type_t *type;
  508. struct list entry;
  509. };
  510. struct _importinfo_t {
  511. int offset;
  512. GUID guid;
  513. int flags;
  514. int id;
  515. char *name;
  516. importlib_t *importlib;
  517. };
  518. struct _importlib_t {
  519. int offset;
  520. char *name;
  521. int version;
  522. GUID guid;
  523. importinfo_t *importinfos;
  524. int ntypeinfos;
  525. int allocated;
  526. struct list entry;
  527. };
  528. struct _typelib_t {
  529. char *name;
  530. const attr_list_t *attrs;
  531. struct list importlibs;
  532. statement_list_t *stmts;
  533. type_t **reg_ifaces;
  534. unsigned int reg_iface_count;
  535. };
  536. struct _user_type_t {
  537. struct list entry;
  538. const char *name;
  539. };
  540. struct _statement_t {
  541. struct list entry;
  542. enum statement_type type;
  543. union
  544. {
  545. type_t *type;
  546. const char *str;
  547. var_t *var;
  548. typelib_t *lib;
  549. typeref_list_t *type_list;
  550. } u;
  551. unsigned int declonly : 1; /* for STMT_TYPE and STMT_TYPEDEF */
  552. };
  553. struct _warning_t {
  554. int num;
  555. struct list entry;
  556. };
  557. typedef enum {
  558. SYS_WIN16,
  559. SYS_WIN32,
  560. SYS_MAC,
  561. SYS_WIN64
  562. } syskind_t;
  563. extern user_type_list_t user_type_list;
  564. extern context_handle_list_t context_handle_list;
  565. extern generic_handle_list_t generic_handle_list;
  566. void check_for_additional_prototype_types(type_t *type);
  567. void init_types(void);
  568. type_t *alloc_type(void);
  569. void set_all_tfswrite(int val);
  570. void clear_all_offsets(void);
  571. #define tsENUM 1
  572. #define tsSTRUCT 2
  573. #define tsUNION 3
  574. var_t *find_const(const char *name, int f);
  575. type_t *find_type(const char *name, struct namespace *namespace, int t);
  576. type_t *make_type(enum type_type type);
  577. type_t *get_type(enum type_type type, char *name, struct namespace *namespace, int t);
  578. type_t *reg_type(type_t *type, const char *name, struct namespace *namespace, int t);
  579. var_t *make_var(char *name);
  580. var_list_t *append_var(var_list_t *list, var_t *var);
  581. void init_loc_info(loc_info_t *);
  582. char *format_namespace(struct namespace *namespace, const char *prefix, const char *separator, const char *suffix,
  583. const char *abi_prefix);
  584. char *format_parameterized_type_name(type_t *type, typeref_list_t *params);
  585. static inline enum type_type type_get_type_detect_alias(const type_t *type)
  586. {
  587. return type->type_type;
  588. }
  589. #define STATEMENTS_FOR_EACH_FUNC(stmt, stmts) \
  590. if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, statement_t, entry ) \
  591. if (stmt->type == STMT_DECLARATION && stmt->u.var->declspec.stgclass == STG_NONE && \
  592. type_get_type_detect_alias(stmt->u.var->declspec.type) == TYPE_FUNCTION)
  593. static inline int statements_has_func(const statement_list_t *stmts)
  594. {
  595. const statement_t *stmt;
  596. int has_func = 0;
  597. STATEMENTS_FOR_EACH_FUNC(stmt, stmts)
  598. {
  599. has_func = 1;
  600. break;
  601. }
  602. return has_func;
  603. }
  604. static inline int is_global_namespace(const struct namespace *namespace)
  605. {
  606. return !namespace->name;
  607. }
  608. static inline decl_spec_t *init_declspec(decl_spec_t *declspec, type_t *type)
  609. {
  610. declspec->type = type;
  611. declspec->stgclass = STG_NONE;
  612. declspec->qualifier = 0;
  613. declspec->func_specifier = 0;
  614. return declspec;
  615. }
  616. #endif