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