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