widltypes.h 12.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * IDL Compiler
 *
 * Copyright 2002 Ove Kaaven
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 22 23
 */

#ifndef __WIDL_WIDLTYPES_H
#define __WIDL_WIDLTYPES_H

24
#include <stdarg.h>
25
#include <assert.h>
26
#include "guiddef.h"
27
#include "ndrtypes.h"
28
#include "wine/list.h"
29

30 31 32 33 34
#ifndef UUID_DEFINED
#define UUID_DEFINED
typedef GUID UUID;
#endif

35 36 37
#define TRUE 1
#define FALSE 0

38
typedef struct _loc_info_t loc_info_t;
39
typedef struct _attr_t attr_t;
40
typedef struct _expr_t expr_t;
41 42
typedef struct _type_t type_t;
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 47
typedef struct _importlib_t importlib_t;
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 array_dims_t;
63
typedef struct list user_type_list_t;
64
typedef struct list context_handle_list_t;
65
typedef struct list generic_handle_list_t;
66
typedef struct list statement_list_t;
67
typedef struct list warning_list_t;
68

69 70
enum attr_type
{
71
    ATTR_AGGREGATABLE,
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 83
    ATTR_CODE,
    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 97
    ATTR_DLLNAME,
    ATTR_DUAL,
98 99
    ATTR_ENABLEALLOCATE,
    ATTR_ENCODE,
100
    ATTR_ENDPOINT,
101
    ATTR_ENTRY,
102
    ATTR_EXPLICIT_HANDLE,
103 104
    ATTR_FAULTSTATUS,
    ATTR_FORCEALLOCATE,
105
    ATTR_HANDLE,
106 107
    ATTR_HELPCONTEXT,
    ATTR_HELPFILE,
108
    ATTR_HELPSTRING,
109 110
    ATTR_HELPSTRINGCONTEXT,
    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 126 127
    ATTR_MAYBE,
    ATTR_MESSAGE,
    ATTR_NOCODE,
128
    ATTR_NONBROWSABLE,
Huw Davies's avatar
Huw Davies committed
129
    ATTR_NONCREATABLE,
130
    ATTR_NONEXTENSIBLE,
131 132
    ATTR_NOTIFY,
    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 142
    ATTR_POINTERDEFAULT,
    ATTR_POINTERTYPE,
143
    ATTR_PROGID,
144 145
    ATTR_PROPGET,
    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 160
    ATTR_SWITCHIS,
    ATTR_SWITCHTYPE,
161
    ATTR_THREADING,
162
    ATTR_TRANSMITAS,
163 164 165
    ATTR_UIDEFAULT,
    ATTR_USERMARSHAL,
    ATTR_USESGETLASTERROR,
166
    ATTR_UUID,
167
    ATTR_V1ENUM,
168
    ATTR_VARARG,
169
    ATTR_VERSION,
170
    ATTR_VIPROGID,
171
    ATTR_WIREMARSHAL
172 173
};

174 175 176 177
enum expr_type
{
    EXPR_VOID,
    EXPR_NUM,
178
    EXPR_HEXNUM,
179
    EXPR_DOUBLE,
180 181
    EXPR_IDENTIFIER,
    EXPR_NEG,
182
    EXPR_NOT,
183 184
    EXPR_PPTR,
    EXPR_CAST,
185
    EXPR_SIZEOF,
186 187 188 189 190 191 192 193
    EXPR_SHL,
    EXPR_SHR,
    EXPR_MUL,
    EXPR_DIV,
    EXPR_ADD,
    EXPR_SUB,
    EXPR_AND,
    EXPR_OR,
194
    EXPR_COND,
195
    EXPR_TRUEFALSE,
196
    EXPR_ADDRESSOF,
197
    EXPR_MEMBER,
198
    EXPR_ARRAY,
199
    EXPR_MOD,
200 201 202 203 204 205 206 207 208 209 210
    EXPR_LOGOR,
    EXPR_LOGAND,
    EXPR_XOR,
    EXPR_EQUALITY,
    EXPR_INEQUALITY,
    EXPR_GTR,
    EXPR_LESS,
    EXPR_GTREQL,
    EXPR_LESSEQL,
    EXPR_LOGNOT,
    EXPR_POS,
211 212
    EXPR_STRLIT,
    EXPR_WSTRLIT,
213
    EXPR_CHARCONST,
214 215
};

216 217
enum type_kind
{
218 219
    TKIND_PRIMITIVE = -1,
    TKIND_ENUM,
220 221 222 223 224 225 226 227 228
    TKIND_RECORD,
    TKIND_MODULE,
    TKIND_INTERFACE,
    TKIND_DISPATCH,
    TKIND_COCLASS,
    TKIND_ALIAS,
    TKIND_UNION,
    TKIND_MAX
};
229

230 231 232 233 234 235 236 237
enum storage_class
{
    STG_NONE,
    STG_STATIC,
    STG_EXTERN,
    STG_REGISTER,
};

238 239 240
enum statement_type
{
    STMT_LIBRARY,
241
    STMT_DECLARATION,
242 243 244 245 246 247
    STMT_TYPE,
    STMT_TYPEREF,
    STMT_MODULE,
    STMT_TYPEDEF,
    STMT_IMPORT,
    STMT_IMPORTLIB,
248
    STMT_PRAGMA,
249 250 251
    STMT_CPPQUOTE
};

252 253 254 255 256 257 258 259 260
enum threading_type
{
    THREADING_APARTMENT = 1,
    THREADING_NEUTRAL,
    THREADING_SINGLE,
    THREADING_FREE,
    THREADING_BOTH
};

261 262 263 264 265 266 267
enum type_basic_type
{
    TYPE_BASIC_INT8 = 1,
    TYPE_BASIC_INT16,
    TYPE_BASIC_INT32,
    TYPE_BASIC_INT64,
    TYPE_BASIC_INT,
268
    TYPE_BASIC_INT3264,
269 270 271 272 273 274 275 276 277 278 279 280 281 282
    TYPE_BASIC_CHAR,
    TYPE_BASIC_HYPER,
    TYPE_BASIC_BYTE,
    TYPE_BASIC_WCHAR,
    TYPE_BASIC_FLOAT,
    TYPE_BASIC_DOUBLE,
    TYPE_BASIC_ERROR_STATUS_T,
    TYPE_BASIC_HANDLE,
};

#define TYPE_BASIC_MAX TYPE_BASIC_HANDLE
#define TYPE_BASIC_INT_MIN TYPE_BASIC_INT8
#define TYPE_BASIC_INT_MAX TYPE_BASIC_HYPER

283 284 285 286 287 288 289
struct _loc_info_t
{
    const char *input_name;
    int line_number;
    const char *near_text;
};

290 291 292 293 294 295
struct str_list_entry_t
{
    char *str;
    struct list entry;
};

296
struct _attr_t {
297
  enum attr_type type;
298
  union {
299
    unsigned int ival;
300 301 302
    void *pval;
  } u;
  /* parser-internal */
303
  struct list entry;
304 305
};

306 307
struct _expr_t {
  enum expr_type type;
308
  const expr_t *ref;
309
  union {
310
    int lval;
311
    double dval;
312 313
    const char *sval;
    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 324 325 326 327 328 329 330 331 332 333 334 335
struct struct_details
{
  var_list_t *fields;
};

struct enumeration_details
{
  var_list_t *enums;
};

struct func_details
{
  var_list_t *args;
336
  struct _var_t *retval;
337
  int idx;
338 339 340 341
};

struct iface_details
{
342
  statement_list_t *stmts;
Rob Shearman's avatar
Rob Shearman committed
343
  var_list_t *disp_methods;
344
  var_list_t *disp_props;
345
  struct _type_t *inherit;
346
  struct _type_t *disp_inherit;
347 348
};

349 350 351 352 353
struct module_details
{
  statement_list_t *stmts;
};

354 355
struct array_details
{
356 357
  expr_t *size_is;
  expr_t *length_is;
358 359
  struct _type_t *elem;
  unsigned int dim;
360 361
  unsigned char ptr_def_fc;
  unsigned char declptr; /* if declared as a pointer */
362
  unsigned short ptr_tfsoff;  /* offset of pointer definition for declptr */
363 364
};

365 366 367 368 369
struct coclass_details
{
  ifref_list_t *ifaces;
};

370 371 372 373 374 375
struct basic_details
{
  enum type_basic_type type;
  int sign;
};

376 377
struct pointer_details
{
378
  struct _type_t *ref;
379
  unsigned char def_fc;
380 381
};

382 383 384 385 386 387
struct bitfield_details
{
  struct _type_t *field;
  const expr_t *bits;
};

388 389 390 391 392 393 394 395 396 397
#define HASHMAX 64

struct namespace {
    const char *name;
    struct namespace *parent;
    struct list entry;
    struct list children;
    struct rtype *type_hash[HASHMAX];
};

398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
enum type_type
{
    TYPE_VOID,
    TYPE_BASIC, /* ints, floats and handles */
    TYPE_ENUM,
    TYPE_STRUCT,
    TYPE_ENCAPSULATED_UNION,
    TYPE_UNION,
    TYPE_ALIAS,
    TYPE_MODULE,
    TYPE_COCLASS,
    TYPE_FUNCTION,
    TYPE_INTERFACE,
    TYPE_POINTER,
    TYPE_ARRAY,
413
    TYPE_BITFIELD,
414 415
};

416
struct _type_t {
417
  const char *name;
418
  struct namespace *namespace;
419
  enum type_type type_type;
420
  attr_list_t *attrs;
421 422 423 424 425 426
  union
  {
    struct struct_details *structure;
    struct enumeration_details *enumeration;
    struct func_details *function;
    struct iface_details *iface;
427
    struct module_details *module;
428
    struct array_details array;
429
    struct coclass_details coclass;
430
    struct basic_details basic;
431
    struct pointer_details pointer;
432
    struct bitfield_details bitfield;
433
  } details;
434
  const char *c_name;
435
  type_t *orig;                   /* dup'd types */
436
  unsigned int typestring_offset;
437
  unsigned int ptrdesc;           /* used for complex structs */
438
  int typelib_idx;
439
  loc_info_t loc_info;
440 441 442 443
  unsigned int ignore : 1;
  unsigned int defined : 1;
  unsigned int written : 1;
  unsigned int user_types_registered : 1;
444
  unsigned int tfswrite : 1;   /* if the type needs to be written to the TFS */
445
  unsigned int checked : 1;
446
  unsigned int is_alias : 1; /* is the type an alias? */
447 448 449 450 451
};

struct _var_t {
  char *name;
  type_t *type;
452
  attr_list_t *attrs;
453
  expr_t *eval;
454
  enum storage_class stgclass;
455
  unsigned int procstring_offset;
456
  unsigned int typestring_offset;
457

458 459
  struct _loc_info_t loc_info;

460
  /* parser-internal */
461
  struct list entry;
462 463
};

464
struct _declarator_t {
465
  var_t *var;
466 467
  type_t *type;
  type_t *func_type;
468
  array_dims_t *array;
469
  expr_t *bits;
470 471 472 473 474

  /* parser-internal */
  struct list entry;
};

475 476
struct _ifref_t {
  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 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
struct _importinfo_t {
    int offset;
    GUID guid;
    int flags;
    int id;

    char *name;

    importlib_t *importlib;
};

struct _importlib_t {
    char *name;

    int version;
    GUID guid;

    importinfo_t *importinfos;
    int ntypeinfos;

    int allocated;

510
    struct list entry;
511 512
};

513 514
struct _typelib_t {
    char *name;
515
    const attr_list_t *attrs;
516
    struct list importlibs;
517
    statement_list_t *stmts;
518 519
};

520 521 522 523 524
struct _user_type_t {
    struct list entry;
    const char *name;
};

525 526 527 528 529
struct _type_list_t {
    type_t *type;
    struct _type_list_t *next;
};

530 531 532 533 534 535 536 537 538 539
struct _statement_t {
    struct list entry;
    enum statement_type type;
    union
    {
        ifref_t iface;
        type_t *type;
        const char *str;
        var_t *var;
        typelib_t *lib;
540
        type_list_t *type_list;
541 542 543
    } u;
};

544 545 546 547 548
struct _warning_t {
    int num;
    struct list entry;
};

549 550 551 552 553 554 555 556
typedef enum {
    SYS_WIN16,
    SYS_WIN32,
    SYS_MAC,
    SYS_WIN64
} syskind_t;

extern syskind_t typelib_kind;
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 564
type_t *alloc_type(void);
void set_all_tfswrite(int val);
565
void clear_all_offsets(void);
566

567 568 569 570
#define tsENUM   1
#define tsSTRUCT 2
#define tsUNION  3

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 575
type_t *get_type(enum type_type type, char *name, struct namespace *namespace, int t);
type_t *reg_type(type_t *type, const char *name, struct namespace *namespace, int t);
576 577 578 579
void add_incomplete(type_t *t);

var_t *make_var(char *name);
var_list_t *append_var(var_list_t *list, var_t *var);
580

581 582
void init_loc_info(loc_info_t *);

583 584
char *format_namespace(struct namespace *namespace, const char *prefix, const char *separator, const char *suffix);

585
static inline var_list_t *type_get_function_args(const type_t *func_type)
586
{
587 588 589
  return func_type->details.function->args;
}

590 591 592 593
static inline enum type_type type_get_type_detect_alias(const type_t *type)
{
    if (type->is_alias)
        return TYPE_ALIAS;
594
    return type->type_type;
595 596
}

597 598 599
#define STATEMENTS_FOR_EACH_FUNC(stmt, stmts) \
  if (stmts) LIST_FOR_EACH_ENTRY( stmt, stmts, statement_t, entry ) \
    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 603 604 605 606 607 608 609 610 611

static inline int statements_has_func(const statement_list_t *stmts)
{
  const statement_t *stmt;
  int has_func = 0;
  STATEMENTS_FOR_EACH_FUNC(stmt, stmts)
  {
    has_func = 1;
    break;
  }
  return has_func;
612 613
}

614 615 616 617 618
static inline int is_global_namespace(const struct namespace *namespace)
{
    return !namespace->name;
}

619
#endif