5 * Copyright 2002 Ove Kaaven
6 * Copyright 2006-2008 Robert Shearman
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.
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.
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
42 /* Berkeley yacc (byacc) doesn't seem to know about these */
43 /* Some *BSD supplied versions do define these though */
45 # define YYEMPTY (-1) /* Empty lookahead value of yychar */
48 # define YYLEX yylex()
51 #elif defined(YYBISON)
52 /* Bison was used for original development */
53 /* #define YYEMPTY -2 */
54 /* #define YYLEX yylex() */
57 /* No yacc we know yet */
58 # if !defined(YYEMPTY) || !defined(YYLEX)
59 # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
60 # elif defined(__GNUC__) /* gcc defines the #warning directive */
61 # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
62 /* #else we just take a chance that it works... */
66 #define YYERROR_VERBOSE
68 unsigned char pointer_default
= RPC_FC_UP
;
69 static int is_object_interface
= FALSE
;
71 typedef
struct list typelist_t
;
83 typedef
struct _decl_spec_t
87 enum storage_class stgclass
;
90 typelist_t incomplete_types
= LIST_INIT
(incomplete_types
);
92 static void add_incomplete
(type_t
*t
);
93 static void fix_incomplete
(void);
94 static void fix_incomplete_types
(type_t
*complete_type
);
96 static str_list_t
*append_str
(str_list_t
*list
, char *str
);
97 static attr_list_t
*append_attr
(attr_list_t
*list
, attr_t
*attr
);
98 static attr_list_t
*append_attr_list
(attr_list_t
*new_list
, attr_list_t
*old_list
);
99 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
);
100 static attr_t
*make_attr
(enum attr_type type
);
101 static attr_t
*make_attrv
(enum attr_type type
, unsigned long val
);
102 static attr_t
*make_attrp
(enum attr_type type
, void *val
);
103 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
);
104 static array_dims_t
*append_array
(array_dims_t
*list
, expr_t
*expr
);
105 static void set_type
(var_t
*v
, decl_spec_t
*decl_spec
, const declarator_t
*decl
, int top
);
106 static var_list_t
*set_var_types
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_list_t
*decls
);
107 static ifref_list_t
*append_ifref
(ifref_list_t
*list
, ifref_t
*iface
);
108 static ifref_t
*make_ifref
(type_t
*iface
);
109 static var_list_t
*append_var
(var_list_t
*list
, var_t
*var
);
110 static var_list_t
*append_var_list
(var_list_t
*list
, var_list_t
*vars
);
111 static var_t
*make_var
(char *name
);
112 static declarator_list_t
*append_declarator
(declarator_list_t
*list
, declarator_t
*p
);
113 static declarator_t
*make_declarator
(var_t
*var
);
114 static func_list_t
*append_func
(func_list_t
*list
, func_t
*func
);
115 static func_t
*make_func
(var_t
*def
);
116 static type_t
*make_class
(char *name
);
117 static type_t
*make_safearray
(type_t
*type
);
118 static type_t
*make_builtin
(char *name
);
119 static type_t
*make_int
(int sign
);
120 static typelib_t
*make_library
(const char *name
, const attr_list_t
*attrs
);
121 static type_t
*append_ptrchain_type
(type_t
*ptrchain
, type_t
*type
);
123 static type_t
*type_new_enum
(char *name
, var_list_t
*enums
);
124 static type_t
*type_new_struct
(char *name
, int defined
, var_list_t
*fields
);
125 static type_t
*type_new_nonencapsulated_union
(char *name
, var_list_t
*fields
);
126 static type_t
*type_new_encapsulated_union
(char *name
, var_t
*switch_field
, var_t
*union_field
, var_list_t
*cases
);
128 static type_t
*reg_type
(type_t
*type
, const char *name
, int t
);
129 static type_t
*reg_typedefs
(decl_spec_t
*decl_spec
, var_list_t
*names
, attr_list_t
*attrs
);
130 static type_t
*find_type_or_error
(const char *name
, int t
);
131 static type_t
*find_type_or_error2
(char *name
, int t
);
132 static type_t
*get_type
(unsigned char type
, char *name
, int t
);
134 static var_t
*reg_const
(var_t
*var
);
136 static char *gen_name
(void);
137 static void check_arg
(var_t
*arg
);
138 static void check_statements
(const statement_list_t
*stmts
, int is_inside_library
);
139 static void check_all_user_types
(const statement_list_t
*stmts
);
140 static attr_list_t
*check_iface_attrs
(const char *name
, attr_list_t
*attrs
);
141 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
);
142 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
);
143 static attr_list_t
*check_enum_attrs
(attr_list_t
*attrs
);
144 static attr_list_t
*check_struct_attrs
(attr_list_t
*attrs
);
145 static attr_list_t
*check_union_attrs
(attr_list_t
*attrs
);
146 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
);
147 static attr_list_t
*check_library_attrs
(const char *name
, attr_list_t
*attrs
);
148 static attr_list_t
*check_dispiface_attrs
(const char *name
, attr_list_t
*attrs
);
149 static attr_list_t
*check_module_attrs
(const char *name
, attr_list_t
*attrs
);
150 static attr_list_t
*check_coclass_attrs
(const char *name
, attr_list_t
*attrs
);
151 const char *get_attr_display_name
(enum attr_type type
);
152 static void add_explicit_handle_if_necessary
(var_t
*func
);
153 static void check_def
(const type_t
*t
);
155 static statement_t
*make_statement
(enum statement_type type
);
156 static statement_t
*make_statement_type_decl
(type_t
*type
);
157 static statement_t
*make_statement_reference
(type_t
*type
);
158 static statement_t
*make_statement_declaration
(var_t
*var
);
159 static statement_t
*make_statement_library
(typelib_t
*typelib
);
160 static statement_t
*make_statement_cppquote
(const char *str
);
161 static statement_t
*make_statement_importlib
(const char *str
);
162 static statement_t
*make_statement_module
(type_t
*type
);
163 static statement_t
*make_statement_typedef
(var_list_t
*names
);
164 static statement_t
*make_statement_import
(const char *str
);
165 static statement_t
*make_statement_typedef
(var_list_t
*names
);
166 static statement_list_t
*append_statement
(statement_list_t
*list
, statement_t
*stmt
);
175 attr_list_t
*attr_list
;
176 str_list_t
*str_list
;
178 expr_list_t
*expr_list
;
179 array_dims_t
*array_dims
;
182 var_list_t
*var_list
;
183 declarator_t
*declarator
;
184 declarator_list_t
*declarator_list
;
186 func_list_t
*func_list
;
187 statement_t
*statement
;
188 statement_list_t
*stmt_list
;
190 ifref_list_t
*ifref_list
;
195 interface_info_t ifinfo
;
197 struct _import_t
*import
;
198 struct _decl_spec_t
*declspec
;
199 enum storage_class stgclass
;
202 %token
<str
> aIDENTIFIER
203 %token
<str
> aKNOWNTYPE
204 %token
<num
> aNUM aHEXNUM
206 %token
<str
> aSTRING aWSTRING
211 %token EQUALITY INEQUALITY
212 %token GREATEREQUAL LESSEQUAL
213 %token LOGICALOR LOGICALAND
214 %token tAGGREGATABLE tALLOCATE tAPPOBJECT tASYNC tASYNCUUID
215 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
216 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
217 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
218 %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
220 %token tDEFAULTCOLLELEM
222 %token tDEFAULTVTABLE
224 %token tDISPINTERFACE
225 %token tDLLNAME tDOUBLE tDUAL
227 %token tENTRY tENUM tERRORSTATUST
228 %token tEXPLICITHANDLE tEXTERN
234 %token tHELPCONTEXT tHELPFILE
235 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
237 %token tHYPER tID tIDEMPOTENT
239 %token tIMMEDIATEBIND
240 %token tIMPLICITHANDLE
241 %token tIMPORT tIMPORTLIB
242 %token tIN tIN_LINE tINLINE
247 %token tLENGTHIS tLIBRARY
254 %token tNONEXTENSIBLE
256 %token tOBJECT tODL tOLEAUTOMATION
260 %token tPOINTERDEFAULT
262 %token tPROPGET tPROPPUT tPROPPUTREF
266 %token tREADONLY tREF
275 %token tSIZEIS tSIZEOF
280 %token tSTRICTCONTEXTHANDLE
281 %token tSTRING tSTRUCT
282 %token tSWITCH tSWITCHIS tSWITCHTYPE
294 %token tWCHAR tWIREMARSHAL
296 %type
<attr
> attribute type_qualifier function_specifier
297 %type
<attr_list
> m_attributes attributes attrib_list m_type_qual_list
298 %type
<str_list
> str_list
299 %type
<expr
> m_expr expr expr_const expr_int_const array
300 %type
<expr_list
> m_exprs
/* exprs expr_list */ expr_list_int_const
301 %type
<ifinfo
> interfacehdr
302 %type
<stgclass
> storage_cls_spec
303 %type
<declspec
> decl_spec decl_spec_no_type m_decl_spec_no_type
304 %type
<type
> inherit interface interfacedef interfacedec
305 %type
<type
> dispinterface dispinterfacehdr dispinterfacedef
306 %type
<type
> module modulehdr moduledef
307 %type
<type
> base_type int_std
308 %type
<type
> enumdef structdef uniondef typedecl
310 %type
<ifref
> coclass_int
311 %type
<ifref_list
> coclass_ints
312 %type
<var
> arg ne_union_field union_field s_field case
enum declaration
313 %type
<var_list
> m_args no_args args fields ne_union_fields cases enums enum_list dispint_props field
314 %type
<var
> m_ident ident
315 %type
<declarator
> declarator direct_declarator init_declarator
316 %type
<declarator_list
> declarator_list
318 %type
<type
> coclass coclasshdr coclassdef
319 %type
<num
> pointer_type version
320 %type
<str
> libraryhdr callconv cppquote importlib import t_ident
321 %type
<uuid
> uuid_string
322 %type
<import
> import_start
323 %type
<typelib
> library_start librarydef
324 %type
<statement
> statement typedef
325 %type
<stmt_list
> gbl_statements imp_statements int_statements dispint_meths
334 %left EQUALITY INEQUALITY
335 %left
'<' '>' LESSEQUAL GREATEREQUAL
339 %right
'!' '~' CAST PPTR POS NEG ADDRESSOF tSIZEOF
340 %left
'.' MEMBERPTR
'[' ']'
344 input: gbl_statements
{ fix_incomplete
();
345 check_statements
($1, FALSE
);
346 check_all_user_types
($1);
353 write_local_stubs
($1);
357 gbl_statements: { $$
= NULL
; }
358 | gbl_statements interfacedec
{ $$
= append_statement
($1, make_statement_reference
($2)); }
359 | gbl_statements interfacedef
{ $$
= append_statement
($1, make_statement_type_decl
($2)); }
360 | gbl_statements coclass
';' { $$
= $1;
361 reg_type
($2, $2->name
, 0);
363 | gbl_statements coclassdef
{ $$
= append_statement
($1, make_statement_type_decl
($2));
364 reg_type
($2, $2->name
, 0);
366 | gbl_statements moduledef
{ $$
= append_statement
($1, make_statement_module
($2)); }
367 | gbl_statements librarydef
{ $$
= append_statement
($1, make_statement_library
($2)); }
368 | gbl_statements statement
{ $$
= append_statement
($1, $2); }
371 imp_statements: { $$
= NULL
; }
372 | imp_statements interfacedec
{ $$
= append_statement
($1, make_statement_reference
($2)); }
373 | imp_statements interfacedef
{ $$
= append_statement
($1, make_statement_type_decl
($2)); }
374 | imp_statements coclass
';' { $$
= $1; reg_type
($2, $2->name
, 0); }
375 | imp_statements coclassdef
{ $$
= append_statement
($1, make_statement_type_decl
($2));
376 reg_type
($2, $2->name
, 0);
378 | imp_statements moduledef
{ $$
= append_statement
($1, make_statement_module
($2)); }
379 | imp_statements statement
{ $$
= append_statement
($1, $2); }
380 | imp_statements importlib
{ $$
= append_statement
($1, make_statement_importlib
($2)); }
381 | imp_statements librarydef
{ $$
= append_statement
($1, make_statement_library
($2)); }
384 int_statements: { $$
= NULL
; }
385 | int_statements statement
{ $$
= append_statement
($1, $2); }
393 cppquote
{ $$
= make_statement_cppquote
($1); }
394 | typedecl
';' { $$
= make_statement_type_decl
($1); }
395 | declaration
';' { $$
= make_statement_declaration
($1); }
396 | import
{ $$
= make_statement_import
($1); }
397 | typedef
';' { $$
= $1; }
404 | attributes enumdef
{ $$
= $2; $$
->attrs
= check_enum_attrs
($1); }
405 | attributes structdef
{ $$
= $2; $$
->attrs
= check_struct_attrs
($1); }
406 | attributes uniondef
{ $$
= $2; $$
->attrs
= check_union_attrs
($1); }
409 cppquote: tCPPQUOTE
'(' aSTRING
')' { $$
= $3; }
411 import_start: tIMPORT aSTRING
';' { assert
(yychar == YYEMPTY
);
412 $$
= xmalloc
(sizeof
(struct _import_t
));
414 $$
->import_performed
= do_import
($2);
415 if
(!$$
->import_performed
) yychar = aEOF
;
419 import: import_start imp_statements aEOF
{ $$
= $1->name
;
420 if
($1->import_performed
) pop_import
();
425 importlib: tIMPORTLIB
'(' aSTRING
')'
426 semicolon_opt
{ $$
= $3; if
(!parse_only
) add_importlib
($3); }
429 libraryhdr: tLIBRARY aIDENTIFIER
{ $$
= $2; }
431 library_start: attributes libraryhdr
'{' { $$
= make_library
($2, check_library_attrs
($2, $1));
432 if
(!parse_only
) start_typelib
($$
);
435 librarydef: library_start imp_statements
'}'
436 semicolon_opt
{ $$
= $1;
438 if
(!parse_only
) end_typelib
();
442 m_args: { $$
= NULL
; }
446 no_args: tVOID
{ $$
= NULL
; }
449 args: arg
{ check_arg
($1); $$
= append_var
( NULL
, $1 ); }
450 | args
',' arg
{ check_arg
($3); $$
= append_var
( $1, $3); }
454 /* split into two rules to get bison to resolve a tVOID conflict */
455 arg: attributes decl_spec declarator
{ $$
= $3->var
;
457 if
($2->stgclass
!= STG_NONE
&& $2->stgclass
!= STG_REGISTER
)
458 error_loc
("invalid storage class for function parameter\n");
459 set_type
($$
, $2, $3, TRUE
);
462 | decl_spec declarator
{ $$
= $2->var
;
463 if
($1->stgclass
!= STG_NONE
&& $1->stgclass
!= STG_REGISTER
)
464 error_loc
("invalid storage class for function parameter\n");
465 set_type
($$
, $1, $2, TRUE
);
470 array: '[' m_expr
']' { $$
= $2; }
471 |
'[' '*' ']' { $$
= make_expr
(EXPR_VOID
); }
474 m_attributes: { $$
= NULL
; }
479 '[' attrib_list
']' { $$
= $2; }
482 attrib_list: attribute
{ $$
= append_attr
( NULL
, $1 ); }
483 | attrib_list
',' attribute
{ $$
= append_attr
( $1, $3 ); }
484 | attrib_list
']' '[' attribute
{ $$
= append_attr
( $1, $4 ); }
487 str_list: aSTRING
{ $$
= append_str
( NULL
, $1 ); }
488 | str_list
',' aSTRING
{ $$
= append_str
( $1, $3 ); }
491 attribute: { $$
= NULL
; }
492 | tAGGREGATABLE
{ $$
= make_attr
(ATTR_AGGREGATABLE
); }
493 | tAPPOBJECT
{ $$
= make_attr
(ATTR_APPOBJECT
); }
494 | tASYNC
{ $$
= make_attr
(ATTR_ASYNC
); }
495 | tAUTOHANDLE
{ $$
= make_attr
(ATTR_AUTO_HANDLE
); }
496 | tBINDABLE
{ $$
= make_attr
(ATTR_BINDABLE
); }
497 | tBROADCAST
{ $$
= make_attr
(ATTR_BROADCAST
); }
498 | tCALLAS
'(' ident
')' { $$
= make_attrp
(ATTR_CALLAS
, $3); }
499 | tCASE
'(' expr_list_int_const
')' { $$
= make_attrp
(ATTR_CASE
, $3); }
500 | tCONTEXTHANDLE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); }
501 | tCONTEXTHANDLENOSERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
502 | tCONTEXTHANDLESERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
503 | tCONTROL
{ $$
= make_attr
(ATTR_CONTROL
); }
504 | tDEFAULT
{ $$
= make_attr
(ATTR_DEFAULT
); }
505 | tDEFAULTCOLLELEM
{ $$
= make_attr
(ATTR_DEFAULTCOLLELEM
); }
506 | tDEFAULTVALUE
'(' expr_const
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE
, $3); }
507 | tDEFAULTVTABLE
{ $$
= make_attr
(ATTR_DEFAULTVTABLE
); }
508 | tDISPLAYBIND
{ $$
= make_attr
(ATTR_DISPLAYBIND
); }
509 | tDLLNAME
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DLLNAME
, $3); }
510 | tDUAL
{ $$
= make_attr
(ATTR_DUAL
); }
511 | tENDPOINT
'(' str_list
')' { $$
= make_attrp
(ATTR_ENDPOINT
, $3); }
512 | tENTRY
'(' expr_const
')' { $$
= make_attrp
(ATTR_ENTRY
, $3); }
513 | tEXPLICITHANDLE
{ $$
= make_attr
(ATTR_EXPLICIT_HANDLE
); }
514 | tHANDLE
{ $$
= make_attr
(ATTR_HANDLE
); }
515 | tHELPCONTEXT
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_HELPCONTEXT
, $3); }
516 | tHELPFILE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPFILE
, $3); }
517 | tHELPSTRING
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRING
, $3); }
518 | tHELPSTRINGCONTEXT
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_HELPSTRINGCONTEXT
, $3); }
519 | tHELPSTRINGDLL
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRINGDLL
, $3); }
520 | tHIDDEN
{ $$
= make_attr
(ATTR_HIDDEN
); }
521 | tID
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_ID
, $3); }
522 | tIDEMPOTENT
{ $$
= make_attr
(ATTR_IDEMPOTENT
); }
523 | tIIDIS
'(' expr
')' { $$
= make_attrp
(ATTR_IIDIS
, $3); }
524 | tIMMEDIATEBIND
{ $$
= make_attr
(ATTR_IMMEDIATEBIND
); }
525 | tIMPLICITHANDLE
'(' tHANDLET aIDENTIFIER
')' { $$
= make_attrp
(ATTR_IMPLICIT_HANDLE
, $4); }
526 | tIN
{ $$
= make_attr
(ATTR_IN
); }
527 | tINPUTSYNC
{ $$
= make_attr
(ATTR_INPUTSYNC
); }
528 | tLENGTHIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_LENGTHIS
, $3); }
529 | tLCID
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_LIBLCID
, $3); }
530 | tLOCAL
{ $$
= make_attr
(ATTR_LOCAL
); }
531 | tNONBROWSABLE
{ $$
= make_attr
(ATTR_NONBROWSABLE
); }
532 | tNONCREATABLE
{ $$
= make_attr
(ATTR_NONCREATABLE
); }
533 | tNONEXTENSIBLE
{ $$
= make_attr
(ATTR_NONEXTENSIBLE
); }
534 | tOBJECT
{ $$
= make_attr
(ATTR_OBJECT
); }
535 | tODL
{ $$
= make_attr
(ATTR_ODL
); }
536 | tOLEAUTOMATION
{ $$
= make_attr
(ATTR_OLEAUTOMATION
); }
537 | tOPTIONAL
{ $$
= make_attr
(ATTR_OPTIONAL
); }
538 | tOUT
{ $$
= make_attr
(ATTR_OUT
); }
539 | tPOINTERDEFAULT
'(' pointer_type
')' { $$
= make_attrv
(ATTR_POINTERDEFAULT
, $3); }
540 | tPROPGET
{ $$
= make_attr
(ATTR_PROPGET
); }
541 | tPROPPUT
{ $$
= make_attr
(ATTR_PROPPUT
); }
542 | tPROPPUTREF
{ $$
= make_attr
(ATTR_PROPPUTREF
); }
543 | tPUBLIC
{ $$
= make_attr
(ATTR_PUBLIC
); }
544 | tRANGE
'(' expr_int_const
',' expr_int_const
')'
545 { expr_list_t
*list
= append_expr
( NULL
, $3 );
546 list
= append_expr
( list
, $5 );
547 $$
= make_attrp
(ATTR_RANGE
, list
); }
548 | tREADONLY
{ $$
= make_attr
(ATTR_READONLY
); }
549 | tREQUESTEDIT
{ $$
= make_attr
(ATTR_REQUESTEDIT
); }
550 | tRESTRICTED
{ $$
= make_attr
(ATTR_RESTRICTED
); }
551 | tRETVAL
{ $$
= make_attr
(ATTR_RETVAL
); }
552 | tSIZEIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_SIZEIS
, $3); }
553 | tSOURCE
{ $$
= make_attr
(ATTR_SOURCE
); }
554 | tSTRICTCONTEXTHANDLE
{ $$
= make_attr
(ATTR_STRICTCONTEXTHANDLE
); }
555 | tSTRING
{ $$
= make_attr
(ATTR_STRING
); }
556 | tSWITCHIS
'(' expr
')' { $$
= make_attrp
(ATTR_SWITCHIS
, $3); }
557 | tSWITCHTYPE
'(' type
')' { $$
= make_attrp
(ATTR_SWITCHTYPE
, $3); }
558 | tTRANSMITAS
'(' type
')' { $$
= make_attrp
(ATTR_TRANSMITAS
, $3); }
559 | tUUID
'(' uuid_string
')' { $$
= make_attrp
(ATTR_UUID
, $3); }
560 | tV1ENUM
{ $$
= make_attr
(ATTR_V1ENUM
); }
561 | tVARARG
{ $$
= make_attr
(ATTR_VARARG
); }
562 | tVERSION
'(' version
')' { $$
= make_attrv
(ATTR_VERSION
, $3); }
563 | tWIREMARSHAL
'(' type
')' { $$
= make_attrp
(ATTR_WIREMARSHAL
, $3); }
564 | pointer_type
{ $$
= make_attrv
(ATTR_POINTERTYPE
, $1); }
569 | aSTRING
{ if
(!is_valid_uuid
($1))
570 error_loc
("invalid UUID: %s\n", $1);
571 $$
= parse_uuid
($1); }
574 callconv: tCDECL
{ $$
= $
<str
>1; }
575 | tFASTCALL
{ $$
= $
<str
>1; }
576 | tPASCAL
{ $$
= $
<str
>1; }
577 | tSTDCALL
{ $$
= $
<str
>1; }
580 cases: { $$
= NULL
; }
581 | cases case
{ $$
= append_var
( $1, $2 ); }
584 case: tCASE expr_int_const
':' union_field
{ attr_t
*a
= make_attrp
(ATTR_CASE
, append_expr
( NULL
, $2 ));
585 $$
= $4; if
(!$$
) $$
= make_var
(NULL
);
586 $$
->attrs
= append_attr
( $$
->attrs
, a
);
588 | tDEFAULT
':' union_field
{ attr_t
*a
= make_attr
(ATTR_DEFAULT
);
589 $$
= $3; if
(!$$
) $$
= make_var
(NULL
);
590 $$
->attrs
= append_attr
( $$
->attrs
, a
);
594 enums: { $$
= NULL
; }
595 | enum_list
',' { $$
= $1; }
599 enum_list: enum { if
(!$1->eval
)
600 $1->eval
= make_exprl
(EXPR_NUM
, 0 /* default for first enum entry */);
601 $$
= append_var
( NULL
, $1 );
603 | enum_list
',' enum { if
(!$3->eval
)
605 var_t
*last
= LIST_ENTRY
( list_tail
($$
), var_t
, entry
);
606 $3->eval
= make_exprl
(EXPR_NUM
, last
->eval
->cval
+ 1);
608 $$
= append_var
( $1, $3 );
612 enum: ident
'=' expr_int_const
{ $$
= reg_const
($1);
614 $$
->type
= make_int
(0);
616 | ident
{ $$
= reg_const
($1);
617 $$
->type
= make_int
(0);
621 enumdef: tENUM t_ident
'{' enums
'}' { $$
= type_new_enum
($2, $4); }
624 m_exprs: m_expr
{ $$
= append_expr
( NULL
, $1 ); }
625 | m_exprs
',' m_expr
{ $$
= append_expr
( $1, $3 ); }
629 exprs: { $$ = make_expr(EXPR_VOID); }
634 | expr_list ',' expr { LINK($3, $1); $$ = $3; }
638 m_expr: { $$
= make_expr
(EXPR_VOID
); }
642 expr: aNUM
{ $$
= make_exprl
(EXPR_NUM
, $1); }
643 | aHEXNUM
{ $$
= make_exprl
(EXPR_HEXNUM
, $1); }
644 | aDOUBLE
{ $$
= make_exprd
(EXPR_DOUBLE
, $1); }
645 | tFALSE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 0); }
646 | tNULL
{ $$
= make_exprl
(EXPR_NUM
, 0); }
647 | tTRUE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 1); }
648 | aSTRING
{ $$
= make_exprs
(EXPR_STRLIT
, $1); }
649 | aWSTRING
{ $$
= make_exprs
(EXPR_WSTRLIT
, $1); }
650 | aIDENTIFIER
{ $$
= make_exprs
(EXPR_IDENTIFIER
, $1); }
651 | expr
'?' expr
':' expr
{ $$
= make_expr3
(EXPR_COND
, $1, $3, $5); }
652 | expr LOGICALOR expr
{ $$
= make_expr2
(EXPR_LOGOR
, $1, $3); }
653 | expr LOGICALAND expr
{ $$
= make_expr2
(EXPR_LOGAND
, $1, $3); }
654 | expr
'|' expr
{ $$
= make_expr2
(EXPR_OR
, $1, $3); }
655 | expr
'^' expr
{ $$
= make_expr2
(EXPR_XOR
, $1, $3); }
656 | expr
'&' expr
{ $$
= make_expr2
(EXPR_AND
, $1, $3); }
657 | expr EQUALITY expr
{ $$
= make_expr2
(EXPR_EQUALITY
, $1, $3); }
658 | expr INEQUALITY expr
{ $$
= make_expr2
(EXPR_INEQUALITY
, $1, $3); }
659 | expr
'>' expr
{ $$
= make_expr2
(EXPR_GTR
, $1, $3); }
660 | expr
'<' expr
{ $$
= make_expr2
(EXPR_LESS
, $1, $3); }
661 | expr GREATEREQUAL expr
{ $$
= make_expr2
(EXPR_GTREQL
, $1, $3); }
662 | expr LESSEQUAL expr
{ $$
= make_expr2
(EXPR_LESSEQL
, $1, $3); }
663 | expr SHL expr
{ $$
= make_expr2
(EXPR_SHL
, $1, $3); }
664 | expr SHR expr
{ $$
= make_expr2
(EXPR_SHR
, $1, $3); }
665 | expr
'+' expr
{ $$
= make_expr2
(EXPR_ADD
, $1, $3); }
666 | expr
'-' expr
{ $$
= make_expr2
(EXPR_SUB
, $1, $3); }
667 | expr
'%' expr
{ $$
= make_expr2
(EXPR_MOD
, $1, $3); }
668 | expr
'*' expr
{ $$
= make_expr2
(EXPR_MUL
, $1, $3); }
669 | expr
'/' expr
{ $$
= make_expr2
(EXPR_DIV
, $1, $3); }
670 |
'!' expr
{ $$
= make_expr1
(EXPR_LOGNOT
, $2); }
671 |
'~' expr
{ $$
= make_expr1
(EXPR_NOT
, $2); }
672 |
'+' expr %prec POS
{ $$
= make_expr1
(EXPR_POS
, $2); }
673 |
'-' expr %prec NEG
{ $$
= make_expr1
(EXPR_NEG
, $2); }
674 |
'&' expr %prec ADDRESSOF
{ $$
= make_expr1
(EXPR_ADDRESSOF
, $2); }
675 |
'*' expr %prec PPTR
{ $$
= make_expr1
(EXPR_PPTR
, $2); }
676 | expr MEMBERPTR aIDENTIFIER
{ $$
= make_expr2
(EXPR_MEMBER
, make_expr1
(EXPR_PPTR
, $1), make_exprs
(EXPR_IDENTIFIER
, $3)); }
677 | expr
'.' aIDENTIFIER
{ $$
= make_expr2
(EXPR_MEMBER
, $1, make_exprs
(EXPR_IDENTIFIER
, $3)); }
678 |
'(' type
')' expr %prec CAST
{ $$
= make_exprt
(EXPR_CAST
, $2, $4); }
679 | tSIZEOF
'(' type
')' { $$
= make_exprt
(EXPR_SIZEOF
, $3, NULL
); }
680 | expr
'[' expr
']' { $$
= make_expr2
(EXPR_ARRAY
, $1, $3); }
681 |
'(' expr
')' { $$
= $2; }
684 expr_list_int_const: expr_int_const
{ $$
= append_expr
( NULL
, $1 ); }
685 | expr_list_int_const
',' expr_int_const
{ $$
= append_expr
( $1, $3 ); }
688 expr_int_const: expr
{ $$
= $1;
690 error_loc
("expression is not an integer constant\n");
694 expr_const: expr
{ $$
= $1;
695 if
(!$$
->is_const
&& $$
->type
!= EXPR_STRLIT
&& $$
->type
!= EXPR_WSTRLIT
)
696 error_loc
("expression is not constant\n");
700 fields: { $$
= NULL
; }
701 | fields field
{ $$
= append_var_list
($1, $2); }
704 field: m_attributes decl_spec declarator_list
';'
705 { const char *first
= LIST_ENTRY
(list_head
($3), declarator_t
, entry
)->var
->name
;
706 check_field_attrs
(first
, $1);
707 $$
= set_var_types
($1, $2, $3);
709 | m_attributes uniondef
';' { var_t
*v
= make_var
(NULL
);
710 v
->type
= $2; v
->attrs
= $1;
711 $$
= append_var
(NULL
, v
);
716 s_field
';' { $$
= $1; }
717 | attributes
';' { $$
= make_var
(NULL
); $$
->attrs
= $1; }
720 ne_union_fields: { $$
= NULL
; }
721 | ne_union_fields ne_union_field
{ $$
= append_var
( $1, $2 ); }
725 s_field
';' { $$
= $1; }
729 s_field: m_attributes decl_spec declarator
{ $$
= $3->var
;
730 $$
->attrs
= check_field_attrs
($$
->name
, $1);
731 set_type
($$
, $2, $3, FALSE
);
737 m_attributes decl_spec declarator
{ var_t
*v
= $3->var
;
738 v
->attrs
= check_function_attrs
(v
->name
, $1);
739 set_type
(v
, $2, $3, FALSE
);
746 attributes decl_spec init_declarator
749 set_type
($$
, $2, $3, FALSE
);
752 | decl_spec init_declarator
{ $$
= $2->var
;
753 set_type
($$
, $1, $2, FALSE
);
758 m_ident: { $$
= NULL
; }
762 t_ident: { $$
= NULL
; }
763 | aIDENTIFIER
{ $$
= $1; }
764 | aKNOWNTYPE
{ $$
= $1; }
767 ident: aIDENTIFIER
{ $$
= make_var
($1); }
768 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
769 | aKNOWNTYPE
{ $$
= make_var
($
<str
>1); }
772 base_type: tBYTE
{ $$
= make_builtin
($
<str
>1); }
773 | tWCHAR
{ $$
= make_builtin
($
<str
>1); }
775 | tSIGNED int_std
{ $$
= $2; $$
->sign
= 1; }
776 | tUNSIGNED int_std
{ $$
= $2; $$
->sign
= -1;
778 case RPC_FC_CHAR
: break
;
779 case RPC_FC_SMALL
: $$
->type
= RPC_FC_USMALL
; break
;
780 case RPC_FC_SHORT
: $$
->type
= RPC_FC_USHORT
; break
;
781 case RPC_FC_LONG
: $$
->type
= RPC_FC_ULONG
; break
;
783 if
($$
->name
[0] == 'h') /* hyper, as opposed to __int64 */
785 $$
= type_new_alias
($$
, "MIDL_uhyper");
792 | tUNSIGNED
{ $$
= make_int
(-1); }
793 | tFLOAT
{ $$
= make_builtin
($
<str
>1); }
794 | tSINGLE
{ $$
= find_type
("float", 0); }
795 | tDOUBLE
{ $$
= make_builtin
($
<str
>1); }
796 | tBOOLEAN
{ $$
= make_builtin
($
<str
>1); }
797 | tERRORSTATUST
{ $$
= make_builtin
($
<str
>1); }
798 | tHANDLET
{ $$
= make_builtin
($
<str
>1); }
805 int_std: tINT
{ $$
= make_builtin
($
<str
>1); }
806 | tSHORT m_int
{ $$
= make_builtin
($
<str
>1); }
807 | tSMALL
{ $$
= make_builtin
($
<str
>1); }
808 | tLONG m_int
{ $$
= make_builtin
($
<str
>1); }
809 | tHYPER m_int
{ $$
= make_builtin
($
<str
>1); }
810 | tINT64
{ $$
= make_builtin
($
<str
>1); }
811 | tCHAR
{ $$
= make_builtin
($
<str
>1); }
814 coclass: tCOCLASS aIDENTIFIER
{ $$
= make_class
($2); }
815 | tCOCLASS aKNOWNTYPE
{ $$
= find_type
($2, 0);
816 if
($$
->type
!= RPC_FC_COCLASS
)
817 error_loc
("%s was not declared a coclass at %s:%d\n",
818 $2, $$
->loc_info.input_name
,
819 $$
->loc_info.line_number
);
823 coclasshdr: attributes coclass
{ $$
= $2;
825 $$
->attrs
= check_coclass_attrs
($2->name
, $1);
829 coclassdef: coclasshdr
'{' coclass_ints
'}' semicolon_opt
830 { $$
= type_coclass_define
($1, $3); }
833 coclass_ints: { $$
= NULL
; }
834 | coclass_ints coclass_int
{ $$
= append_ifref
( $1, $2 ); }
838 m_attributes interfacedec
{ $$
= make_ifref
($2); $$
->attrs
= $1; }
841 dispinterface: tDISPINTERFACE aIDENTIFIER
{ $$
= get_type
(RPC_FC_IP
, $2, 0); }
842 | tDISPINTERFACE aKNOWNTYPE
{ $$
= get_type
(RPC_FC_IP
, $2, 0); }
845 dispinterfacehdr: attributes dispinterface
{ attr_t
*attrs
;
846 is_object_interface
= TRUE
;
849 attrs
= make_attr
(ATTR_DISPINTERFACE
);
850 $$
->attrs
= append_attr
( check_dispiface_attrs
($2->name
, $1), attrs
);
855 dispint_props: tPROPERTIES
':' { $$
= NULL
; }
856 | dispint_props s_field
';' { $$
= append_var
( $1, $2 ); }
859 dispint_meths: tMETHODS
':' { $$
= NULL
; }
860 | dispint_meths funcdef
';' { $$
= append_func
( $1, $2 ); }
863 dispinterfacedef: dispinterfacehdr
'{'
867 type_dispinterface_define
($$
, $3, $4);
870 '{' interface
';' '}' { $$
= $1;
871 type_dispinterface_define_from_iface
($$
, $3);
875 inherit: { $$
= NULL
; }
876 |
':' aKNOWNTYPE
{ $$
= find_type_or_error2
($2, 0); }
879 interface: tINTERFACE aIDENTIFIER
{ $$
= get_type
(RPC_FC_IP
, $2, 0); }
880 | tINTERFACE aKNOWNTYPE
{ $$
= get_type
(RPC_FC_IP
, $2, 0); }
883 interfacehdr: attributes interface
{ $$.interface
= $2;
884 $$.old_pointer_default
= pointer_default
;
885 if
(is_attr
($1, ATTR_POINTERDEFAULT
))
886 pointer_default
= get_attrv
($1, ATTR_POINTERDEFAULT
);
887 is_object_interface
= is_object
($1);
889 $2->attrs
= check_iface_attrs
($2->name
, $1);
894 interfacedef: interfacehdr inherit
895 '{' int_statements
'}' semicolon_opt
{ $$
= $1.interface
;
896 type_interface_define
($$
, $2, $4);
897 pointer_default
= $1.old_pointer_default
;
899 /* MIDL is able to import the definition of a base class from inside the
900 * definition of a derived class, I'll try to support it with this rule */
901 | interfacehdr
':' aIDENTIFIER
902 '{' import int_statements
'}'
903 semicolon_opt
{ $$
= $1.interface
;
904 type_interface_define
($$
, find_type_or_error2
($3, 0), $6);
905 pointer_default
= $1.old_pointer_default
;
907 | dispinterfacedef semicolon_opt
{ $$
= $1; }
911 interface
';' { $$
= $1; }
912 | dispinterface
';' { $$
= $1; }
915 module: tMODULE aIDENTIFIER
{ $$
= type_new_module
($2); }
916 | tMODULE aKNOWNTYPE
{ $$
= type_new_module
($2); }
919 modulehdr: attributes module
{ $$
= $2;
920 $$
->attrs
= check_module_attrs
($2->name
, $1);
924 moduledef: modulehdr
'{' int_statements
'}'
925 semicolon_opt
{ $$
= $1;
926 type_module_define
($$
, $3);
931 tEXTERN
{ $$
= STG_EXTERN
; }
932 | tSTATIC
{ $$
= STG_STATIC
; }
933 | tREGISTER
{ $$
= STG_REGISTER
; }
937 tINLINE
{ $$
= make_attr
(ATTR_INLINE
); }
941 tCONST
{ $$
= make_attr
(ATTR_CONST
); }
944 m_type_qual_list: { $$
= NULL
; }
945 | m_type_qual_list type_qualifier
{ $$
= append_attr
($1, $2); }
948 decl_spec: type m_decl_spec_no_type
{ $$
= make_decl_spec
($1, $2, NULL
, NULL
, STG_NONE
); }
949 | decl_spec_no_type type m_decl_spec_no_type
950 { $$
= make_decl_spec
($2, $1, $3, NULL
, STG_NONE
); }
953 m_decl_spec_no_type: { $$
= NULL
; }
958 type_qualifier m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, $1, STG_NONE
); }
959 | function_specifier m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, $1, STG_NONE
); }
960 | storage_cls_spec m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, NULL
, $1); }
964 '*' m_type_qual_list declarator %prec PPTR
965 { $$
= $3; $$
->type
= append_ptrchain_type
($$
->type
, type_new_pointer
(NULL
, $2)); }
966 | callconv declarator
{ $$
= $2; $$
->type
->attrs
= append_attr
($$
->type
->attrs
, make_attrp
(ATTR_CALLCONV
, $1)); }
971 ident
{ $$
= make_declarator
($1); }
972 |
'(' declarator
')' { $$
= $2; }
973 | direct_declarator array
{ $$
= $1; $$
->array
= append_array
($$
->array
, $2); }
974 | direct_declarator
'(' m_args
')' { $$
= $1;
975 $$
->func_type
= append_ptrchain_type
($$
->type
, type_new_function
($3));
981 declarator
{ $$
= append_declarator
( NULL
, $1 ); }
982 | declarator_list
',' declarator
{ $$
= append_declarator
( $1, $3 ); }
986 declarator
{ $$
= $1; }
987 | declarator
'=' expr_const
{ $$
= $1; $1->var
->eval
= $3; }
991 tREF
{ $$
= RPC_FC_RP
; }
992 | tUNIQUE
{ $$
= RPC_FC_UP
; }
993 | tPTR
{ $$
= RPC_FC_FP
; }
996 structdef: tSTRUCT t_ident
'{' fields
'}' { $$
= type_new_struct
($2, TRUE
, $4); }
999 type: tVOID
{ $$
= find_type_or_error
("void", 0); }
1000 | aKNOWNTYPE
{ $$
= find_type_or_error
($1, 0); }
1001 | base_type
{ $$
= $1; }
1002 | enumdef
{ $$
= $1; }
1003 | tENUM aIDENTIFIER
{ $$
= find_type_or_error2
($2, tsENUM
); }
1004 | structdef
{ $$
= $1; }
1005 | tSTRUCT aIDENTIFIER
{ $$
= type_new_struct
($2, FALSE
, NULL
); }
1006 | uniondef
{ $$
= $1; }
1007 | tUNION aIDENTIFIER
{ $$
= find_type_or_error2
($2, tsUNION
); }
1008 | tSAFEARRAY
'(' type
')' { $$
= make_safearray
($3); }
1011 typedef: tTYPEDEF m_attributes decl_spec declarator_list
1012 { reg_typedefs
($3, $4, check_typedef_attrs
($2));
1013 $$
= make_statement_typedef
($4);
1017 uniondef: tUNION t_ident
'{' ne_union_fields
'}'
1018 { $$
= type_new_nonencapsulated_union
($2, $4); }
1020 tSWITCH
'(' s_field
')'
1021 m_ident
'{' cases
'}' { $$
= type_new_encapsulated_union
($2, $5, $7, $9); }
1025 aNUM
{ $$
= MAKEVERSION
($1, 0); }
1026 | aNUM
'.' aNUM
{ $$
= MAKEVERSION
($1, $3); }
1031 static void decl_builtin
(const char *name
, unsigned char type
)
1033 type_t
*t
= make_type
(type
, NULL
);
1034 t
->name
= xstrdup
(name
);
1035 reg_type
(t
, name
, 0);
1038 static type_t
*make_builtin
(char *name
)
1040 /* NAME is strdup'd in the lexer */
1041 type_t
*t
= duptype
(find_type_or_error
(name
, 0), 0);
1046 static type_t
*make_int
(int sign
)
1048 type_t
*t
= duptype
(find_type_or_error
("int", 0), 1);
1052 t
->type
= t
->type
== RPC_FC_LONG ? RPC_FC_ULONG
: RPC_FC_USHORT
;
1057 void init_types
(void)
1059 decl_builtin
("void", 0);
1060 decl_builtin
("byte", RPC_FC_BYTE
);
1061 decl_builtin
("wchar_t", RPC_FC_WCHAR
);
1062 decl_builtin
("int", RPC_FC_LONG
); /* win32 */
1063 decl_builtin
("short", RPC_FC_SHORT
);
1064 decl_builtin
("small", RPC_FC_SMALL
);
1065 decl_builtin
("long", RPC_FC_LONG
);
1066 decl_builtin
("hyper", RPC_FC_HYPER
);
1067 decl_builtin
("__int64", RPC_FC_HYPER
);
1068 decl_builtin
("char", RPC_FC_CHAR
);
1069 decl_builtin
("float", RPC_FC_FLOAT
);
1070 decl_builtin
("double", RPC_FC_DOUBLE
);
1071 decl_builtin
("boolean", RPC_FC_BYTE
);
1072 decl_builtin
("error_status_t", RPC_FC_ERROR_STATUS_T
);
1073 decl_builtin
("handle_t", RPC_FC_BIND_PRIMITIVE
);
1076 static str_list_t
*append_str
(str_list_t
*list
, char *str
)
1078 struct str_list_entry_t
*entry
;
1080 if
(!str
) return list
;
1083 list
= xmalloc
( sizeof
(*list
) );
1086 entry
= xmalloc
( sizeof
(*entry
) );
1088 list_add_tail
( list
, &entry
->entry
);
1092 static attr_list_t
*append_attr
(attr_list_t
*list
, attr_t
*attr
)
1094 attr_t
*attr_existing
;
1095 if
(!attr
) return list
;
1098 list
= xmalloc
( sizeof
(*list
) );
1101 LIST_FOR_EACH_ENTRY
(attr_existing
, list
, attr_t
, entry
)
1102 if
(attr_existing
->type
== attr
->type
)
1104 parser_warning
("duplicate attribute %s\n", get_attr_display_name
(attr
->type
));
1105 /* use the last attribute, like MIDL does */
1106 list_remove
(&attr_existing
->entry
);
1109 list_add_tail
( list
, &attr
->entry
);
1113 static attr_list_t
*move_attr
(attr_list_t
*dst
, attr_list_t
*src
, enum attr_type type
)
1116 if
(!src
) return dst
;
1117 LIST_FOR_EACH_ENTRY
(attr
, src
, attr_t
, entry
)
1118 if
(attr
->type
== type
)
1120 list_remove
(&attr
->entry
);
1121 return append_attr
(dst
, attr
);
1126 static attr_list_t
*append_attr_list
(attr_list_t
*new_list
, attr_list_t
*old_list
)
1130 if
(!old_list
) return new_list
;
1132 while
((entry
= list_head
(old_list
)))
1134 attr_t
*attr
= LIST_ENTRY
(entry
, attr_t
, entry
);
1136 new_list
= append_attr
(new_list
, attr
);
1141 static attr_list_t
*dupattrs
(const attr_list_t
*list
)
1143 attr_list_t
*new_list
;
1146 if
(!list
) return NULL
;
1148 new_list
= xmalloc
( sizeof
(*list
) );
1149 list_init
( new_list
);
1150 LIST_FOR_EACH_ENTRY
(attr
, list
, const attr_t
, entry
)
1152 attr_t
*new_attr
= xmalloc
(sizeof
(*new_attr
));
1154 list_add_tail
(new_list
, &new_attr
->entry
);
1159 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
)
1161 decl_spec_t
*declspec
= left ? left
: right
;
1164 declspec
= xmalloc
(sizeof
(*declspec
));
1165 declspec
->type
= NULL
;
1166 declspec
->attrs
= NULL
;
1167 declspec
->stgclass
= STG_NONE
;
1169 declspec
->type
= type
;
1170 if
(left
&& declspec
!= left
)
1172 declspec
->attrs
= append_attr_list
(declspec
->attrs
, left
->attrs
);
1173 if
(declspec
->stgclass
== STG_NONE
)
1174 declspec
->stgclass
= left
->stgclass
;
1175 else if
(left
->stgclass
!= STG_NONE
)
1176 error_loc
("only one storage class can be specified\n");
1177 assert
(!left
->type
);
1180 if
(right
&& declspec
!= right
)
1182 declspec
->attrs
= append_attr_list
(declspec
->attrs
, right
->attrs
);
1183 if
(declspec
->stgclass
== STG_NONE
)
1184 declspec
->stgclass
= right
->stgclass
;
1185 else if
(right
->stgclass
!= STG_NONE
)
1186 error_loc
("only one storage class can be specified\n");
1187 assert
(!right
->type
);
1191 declspec
->attrs
= append_attr
(declspec
->attrs
, attr
);
1192 if
(declspec
->stgclass
== STG_NONE
)
1193 declspec
->stgclass
= stgclass
;
1194 else if
(stgclass
!= STG_NONE
)
1195 error_loc
("only one storage class can be specified\n");
1197 /* apply attributes to type */
1198 if
(type
&& declspec
->attrs
)
1201 declspec
->type
= duptype
(type
, 1);
1202 attrs
= dupattrs
(type
->attrs
);
1203 declspec
->type
->attrs
= append_attr_list
(attrs
, declspec
->attrs
);
1204 declspec
->attrs
= NULL
;
1210 static attr_t
*make_attr
(enum attr_type type
)
1212 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1218 static attr_t
*make_attrv
(enum attr_type type
, unsigned long val
)
1220 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1226 static attr_t
*make_attrp
(enum attr_type type
, void *val
)
1228 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1234 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
)
1236 if
(!expr
) return list
;
1239 list
= xmalloc
( sizeof
(*list
) );
1242 list_add_tail
( list
, &expr
->entry
);
1246 static array_dims_t
*append_array
(array_dims_t
*list
, expr_t
*expr
)
1248 if
(!expr
) return list
;
1251 list
= xmalloc
( sizeof
(*list
) );
1254 list_add_tail
( list
, &expr
->entry
);
1258 static struct list type_pool
= LIST_INIT
(type_pool
);
1265 type_t
*alloc_type
(void)
1267 type_pool_node_t
*node
= xmalloc
(sizeof
*node
);
1268 list_add_tail
(&type_pool
, &node
->link
);
1272 void set_all_tfswrite
(int val
)
1274 type_pool_node_t
*node
;
1275 LIST_FOR_EACH_ENTRY
(node
, &type_pool
, type_pool_node_t
, link
)
1276 node
->data.tfswrite
= val
;
1279 void clear_all_offsets
(void)
1281 type_pool_node_t
*node
;
1282 LIST_FOR_EACH_ENTRY
(node
, &type_pool
, type_pool_node_t
, link
)
1283 node
->data.typestring_offset
= node
->data.ptrdesc
= 0;
1286 type_t
*make_type
(unsigned char type
, type_t
*ref
)
1288 type_t
*t
= alloc_type
();
1294 memset
(&t
->details
, 0, sizeof
(t
->details
));
1295 t
->typestring_offset
= 0;
1297 t
->declarray
= FALSE
;
1298 t
->ignore
= (parse_only
!= 0);
1302 t
->user_types_registered
= FALSE
;
1303 t
->tfswrite
= FALSE
;
1305 t
->is_alias
= FALSE
;
1306 t
->typelib_idx
= -1;
1307 init_loc_info
(&t
->loc_info
);
1311 static type_t
*type_new_enum
(char *name
, var_list_t
*enums
)
1313 type_t
*t
= get_type
(RPC_FC_ENUM16
, name
, tsENUM
);
1316 t
->details.enumeration
= xmalloc
(sizeof
(*t
->details.enumeration
));
1317 t
->details.enumeration
->enums
= enums
;
1320 t
->details.enumeration
= NULL
;
1325 static type_t
*type_new_struct
(char *name
, int defined
, var_list_t
*fields
)
1327 type_t
*tag_type
= name ? find_type
(name
, tsSTRUCT
) : NULL
;
1328 type_t
*t
= make_type
(RPC_FC_STRUCT
, NULL
);
1330 if
(defined ||
(tag_type
&& tag_type
->details.structure
))
1332 if
(tag_type
&& tag_type
->details.structure
)
1334 t
->details.structure
= tag_type
->details.structure
;
1335 t
->type
= tag_type
->type
;
1339 t
->details.structure
= xmalloc
(sizeof
(*t
->details.structure
));
1340 t
->details.structure
->fields
= fields
;
1347 reg_type
(t
, name
, tsSTRUCT
);
1354 static type_t
*type_new_nonencapsulated_union
(char *name
, var_list_t
*fields
)
1356 type_t
*t
= get_type
(RPC_FC_NON_ENCAPSULATED_UNION
, name
, tsUNION
);
1357 t
->details.structure
= xmalloc
(sizeof
(*t
->details.structure
));
1358 t
->details.structure
->fields
= fields
;
1363 static type_t
*type_new_encapsulated_union
(char *name
, var_t
*switch_field
, var_t
*union_field
, var_list_t
*cases
)
1365 type_t
*t
= get_type
(RPC_FC_ENCAPSULATED_UNION
, name
, tsUNION
);
1366 if
(!union_field
) union_field
= make_var
( xstrdup
("tagged_union") );
1367 union_field
->type
= make_type
(RPC_FC_NON_ENCAPSULATED_UNION
, NULL
);
1368 union_field
->type
->details.structure
= xmalloc
(sizeof
(*union_field
->type
->details.structure
));
1369 union_field
->type
->details.structure
->fields
= cases
;
1370 union_field
->type
->defined
= TRUE
;
1371 t
->details.structure
= xmalloc
(sizeof
(*t
->details.structure
));
1372 t
->details.structure
->fields
= append_var
( NULL
, switch_field
);
1373 t
->details.structure
->fields
= append_var
( t
->details.structure
->fields
, union_field
);
1378 static void type_function_add_head_arg
(type_t
*type
, var_t
*arg
)
1380 if
(!type
->details.function
->args
)
1382 type
->details.function
->args
= xmalloc
( sizeof
(*type
->details.function
->args
) );
1383 list_init
( type
->details.function
->args
);
1385 list_add_head
( type
->details.function
->args
, &arg
->entry
);
1388 static type_t
*append_ptrchain_type
(type_t
*ptrchain
, type_t
*type
)
1390 type_t
*ptrchain_type
;
1393 for
(ptrchain_type
= ptrchain
; ptrchain_type
->ref
; ptrchain_type
= ptrchain_type
->ref
)
1395 ptrchain_type
->ref
= type
;
1399 static void set_type
(var_t
*v
, decl_spec_t
*decl_spec
, const declarator_t
*decl
,
1402 expr_list_t
*sizes
= get_attrp
(v
->attrs
, ATTR_SIZEIS
);
1403 expr_list_t
*lengs
= get_attrp
(v
->attrs
, ATTR_LENGTHIS
);
1407 array_dims_t
*arr
= decl ? decl
->array
: NULL
;
1408 type_t
*func_type
= decl ? decl
->func_type
: NULL
;
1409 type_t
*type
= decl_spec
->type
;
1411 if
(is_attr
(type
->attrs
, ATTR_INLINE
))
1414 error_loc
("inline attribute applied to non-function type\n");
1418 /* move inline attribute from return type node to function node */
1419 for
(t
= func_type
; is_ptr
(t
); t
= type_pointer_get_ref
(t
))
1421 t
->attrs
= move_attr
(t
->attrs
, type
->attrs
, ATTR_INLINE
);
1425 /* add type onto the end of the pointers in pident->type */
1426 v
->type
= append_ptrchain_type
(decl ? decl
->type
: NULL
, type
);
1427 v
->stgclass
= decl_spec
->stgclass
;
1429 /* the highest level of pointer specified should default to the var's ptr attr
1430 * or (RPC_FC_RP if not specified and it's a top level ptr), not
1431 * pointer_default so we need to fix that up here */
1434 int ptr_attr
= get_attrv
(v
->attrs
, ATTR_POINTERTYPE
);
1435 const type_t
*ptr
= NULL
;
1436 /* pointer attributes on the left side of the type belong to the function
1437 * pointer, if one is being declared */
1438 type_t
**pt
= func_type ?
&func_type
: &v
->type
;
1439 for
(ptr
= *pt
; ptr
&& !ptr_attr
; )
1441 ptr_attr
= get_attrv
(ptr
->attrs
, ATTR_POINTERTYPE
);
1442 if
(!ptr_attr
&& type_is_alias
(ptr
))
1443 ptr
= type_alias_get_aliasee
(ptr
);
1447 if
(ptr
&& is_ptr
(ptr
) && (ptr_attr || top
))
1449 /* duplicate type to avoid changing original type */
1450 *pt
= duptype
(*pt
, 1);
1451 (*pt
)->type
= ptr_attr ? ptr_attr
: RPC_FC_RP
;
1454 error_loc
("%s: pointer attribute applied to non-pointer type\n", v
->name
);
1457 if
(is_attr
(v
->attrs
, ATTR_STRING
) && !is_ptr
(v
->type
) && !arr
)
1458 error_loc
("'%s': [string] attribute applied to non-pointer, non-array type\n",
1461 if
(is_attr
(v
->attrs
, ATTR_V1ENUM
))
1463 if
(v
->type
->type
== RPC_FC_ENUM16
)
1464 v
->type
->type
= RPC_FC_ENUM32
;
1466 error_loc
("'%s': [v1_enum] attribute applied to non-enum type\n", v
->name
);
1471 if
(arr
) LIST_FOR_EACH_ENTRY_REV
(dim
, arr
, expr_t
, entry
)
1474 error_loc
("%s: only the first array dimension can be unspecified\n", v
->name
);
1479 error_loc
("%s: array dimension must be positive\n", v
->name
);
1481 /* FIXME: should use a type_memsize that allows us to pass in a pointer size */
1484 unsigned int align
= 0;
1485 unsigned int size
= type_memsize
(v
->type
, &align
);
1487 if
(0xffffffffu
/ size
< dim
->cval
)
1488 error_loc
("%s: total array size is too large\n", v
->name
);
1494 *ptype
= type_new_array
(NULL
, *ptype
, TRUE
,
1495 dim
->is_const ? dim
->cval
: 0,
1496 dim
->is_const ? NULL
: dim
, NULL
);
1500 if
(sizes
) LIST_FOR_EACH_ENTRY
(dim
, sizes
, expr_t
, entry
)
1502 if
(dim
->type
!= EXPR_VOID
)
1504 if
(is_array
(*ptype
))
1506 if
(type_array_get_conformance
(*ptype
)->is_const
)
1507 error_loc
("%s: cannot specify size_is for a fixed sized array\n", v
->name
);
1509 *ptype
= type_new_array
((*ptype
)->name
,
1510 type_array_get_element
(*ptype
), TRUE
,
1513 else if
(is_ptr
(*ptype
))
1514 *ptype
= type_new_array
((*ptype
)->name
, type_pointer_get_ref
(*ptype
), FALSE
,
1517 error_loc
("%s: size_is attribute applied to illegal type\n", v
->name
);
1520 ptype
= &(*ptype
)->ref
;
1522 error_loc
("%s: too many expressions in size_is attribute\n", v
->name
);
1526 if
(lengs
) LIST_FOR_EACH_ENTRY
(dim
, lengs
, expr_t
, entry
)
1528 if
(dim
->type
!= EXPR_VOID
)
1530 if
(is_array
(*ptype
))
1532 *ptype
= type_new_array
((*ptype
)->name
,
1533 type_array_get_element
(*ptype
),
1534 (*ptype
)->declarray
,
1535 type_array_get_dim
(*ptype
),
1536 type_array_get_conformance
(*ptype
),
1540 error_loc
("%s: length_is attribute applied to illegal type\n", v
->name
);
1543 ptype
= &(*ptype
)->ref
;
1545 error_loc
("%s: too many expressions in length_is attribute\n", v
->name
);
1548 /* v->type is currently pointing to the type on the left-side of the
1549 * declaration, so we need to fix this up so that it is the return type of the
1550 * function and make v->type point to the function side of the declaration */
1554 type_t
*return_type
= v
->type
;
1555 v
->type
= func_type
;
1556 for
(ft
= v
->type
; is_ptr
(ft
); ft
= type_pointer_get_ref
(ft
))
1558 assert
(ft
->type
== RPC_FC_FUNCTION
);
1559 ft
->ref
= return_type
;
1560 /* move calling convention attribute, if present, from pointer nodes to
1562 for
(t
= v
->type
; is_ptr
(t
); t
= type_pointer_get_ref
(t
))
1563 ft
->attrs
= move_attr
(ft
->attrs
, t
->attrs
, ATTR_CALLCONV
);
1564 if
(is_object_interface
&& !is_attr
(ft
->attrs
, ATTR_CALLCONV
))
1566 static char *stdmethodcalltype
;
1567 if
(!stdmethodcalltype
) stdmethodcalltype
= strdup
("STDMETHODCALLTYPE");
1568 ft
->attrs
= append_attr
(NULL
, make_attrp
(ATTR_CALLCONV
, stdmethodcalltype
));
1574 for
(t
= v
->type
; is_ptr
(t
); t
= type_pointer_get_ref
(t
))
1575 if
(is_attr
(t
->attrs
, ATTR_CALLCONV
))
1576 error_loc
("calling convention applied to non-function-pointer type\n");
1580 static var_list_t
*set_var_types
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_list_t
*decls
)
1582 declarator_t
*decl
, *next
;
1583 var_list_t
*var_list
= NULL
;
1585 LIST_FOR_EACH_ENTRY_SAFE
( decl
, next
, decls
, declarator_t
, entry
)
1587 var_t
*var
= decl
->var
;
1590 set_type
(var
, decl_spec
, decl
, 0);
1591 var_list
= append_var
(var_list
, var
);
1597 static ifref_list_t
*append_ifref
(ifref_list_t
*list
, ifref_t
*iface
)
1599 if
(!iface
) return list
;
1602 list
= xmalloc
( sizeof
(*list
) );
1605 list_add_tail
( list
, &iface
->entry
);
1609 static ifref_t
*make_ifref
(type_t
*iface
)
1611 ifref_t
*l
= xmalloc
(sizeof
(ifref_t
));
1617 static var_list_t
*append_var
(var_list_t
*list
, var_t
*var
)
1619 if
(!var
) return list
;
1622 list
= xmalloc
( sizeof
(*list
) );
1625 list_add_tail
( list
, &var
->entry
);
1629 static var_list_t
*append_var_list
(var_list_t
*list
, var_list_t
*vars
)
1631 if
(!vars
) return list
;
1634 list
= xmalloc
( sizeof
(*list
) );
1637 list_move_tail
( list
, vars
);
1641 static var_t
*make_var
(char *name
)
1643 var_t
*v
= xmalloc
(sizeof
(var_t
));
1648 v
->stgclass
= STG_NONE
;
1649 init_loc_info
(&v
->loc_info
);
1653 static declarator_list_t
*append_declarator
(declarator_list_t
*list
, declarator_t
*d
)
1655 if
(!d
) return list
;
1657 list
= xmalloc
(sizeof
(*list
));
1660 list_add_tail
(list
, &d
->entry
);
1664 static declarator_t
*make_declarator
(var_t
*var
)
1666 declarator_t
*d
= xmalloc
(sizeof
(*d
));
1669 d
->func_type
= NULL
;
1674 static func_list_t
*append_func
(func_list_t
*list
, func_t
*func
)
1676 if
(!func
) return list
;
1679 list
= xmalloc
( sizeof
(*list
) );
1682 list_add_tail
( list
, &func
->entry
);
1686 static func_t
*make_func
(var_t
*def
)
1688 func_t
*f
= xmalloc
(sizeof
(func_t
));
1693 static type_t
*make_class
(char *name
)
1695 type_t
*c
= make_type
(RPC_FC_COCLASS
, NULL
);
1700 static type_t
*make_safearray
(type_t
*type
)
1702 type_t
*sa
= find_type_or_error
("SAFEARRAY", 0);
1704 return make_type
(pointer_default
, sa
);
1707 static typelib_t
*make_library
(const char *name
, const attr_list_t
*attrs
)
1709 typelib_t
*typelib
= xmalloc
(sizeof
(*typelib
));
1710 typelib
->name
= xstrdup
(name
);
1711 typelib
->filename
= NULL
;
1712 typelib
->attrs
= attrs
;
1713 list_init
( &typelib
->importlibs
);
1719 static int hash_ident
(const char *name
)
1721 const char *p
= name
;
1723 /* a simple sum hash is probably good enough */
1728 return sum
& (HASHMAX
-1);
1731 /***** type repository *****/
1740 struct rtype
*type_hash
[HASHMAX
];
1742 static type_t
*reg_type
(type_t
*type
, const char *name
, int t
)
1747 error_loc
("registering named type without name\n");
1750 hash
= hash_ident
(name
);
1751 nt
= xmalloc
(sizeof
(struct rtype
));
1755 nt
->next
= type_hash
[hash
];
1756 type_hash
[hash
] = nt
;
1757 if
((t
== tsSTRUCT || t
== tsUNION
))
1758 fix_incomplete_types
(type
);
1762 static int is_incomplete
(const type_t
*t
)
1764 return
!t
->defined
&& (is_struct
(t
->type
) || is_union
(t
->type
));
1767 static void add_incomplete
(type_t
*t
)
1769 struct typenode
*tn
= xmalloc
(sizeof
*tn
);
1771 list_add_tail
(&incomplete_types
, &tn
->entry
);
1774 static void fix_type
(type_t
*t
)
1776 if
(type_is_alias
(t
) && is_incomplete
(t
)) {
1777 type_t
*ot
= type_alias_get_aliasee
(t
);
1779 if
(is_struct
(ot
->type
) || is_union
(ot
->type
))
1780 t
->details.structure
= ot
->details.structure
;
1781 t
->defined
= ot
->defined
;
1785 static void fix_incomplete
(void)
1787 struct typenode
*tn
, *next
;
1789 LIST_FOR_EACH_ENTRY_SAFE
(tn
, next
, &incomplete_types
, struct typenode
, entry
) {
1791 list_remove
(&tn
->entry
);
1796 static void fix_incomplete_types
(type_t
*complete_type
)
1798 struct typenode
*tn
, *next
;
1800 LIST_FOR_EACH_ENTRY_SAFE
(tn
, next
, &incomplete_types
, struct typenode
, entry
)
1802 if
(((is_struct
(complete_type
->type
) && is_struct
(tn
->type
->type
)) ||
1803 (is_union
(complete_type
->type
) && is_union
(tn
->type
->type
))) &&
1804 !strcmp
(complete_type
->name
, tn
->type
->name
))
1806 tn
->type
->details.structure
= complete_type
->details.structure
;
1807 tn
->type
->type
= complete_type
->type
;
1808 list_remove
(&tn
->entry
);
1814 static type_t
*reg_typedefs
(decl_spec_t
*decl_spec
, declarator_list_t
*decls
, attr_list_t
*attrs
)
1816 const declarator_t
*decl
;
1817 int is_str
= is_attr
(attrs
, ATTR_STRING
);
1818 type_t
*type
= decl_spec
->type
;
1822 type_t
*t
= decl_spec
->type
;
1826 t
= type_pointer_get_ref
(t
);
1829 if
(c
!= RPC_FC_CHAR
&& c
!= RPC_FC_BYTE
&& c
!= RPC_FC_WCHAR
)
1831 decl
= LIST_ENTRY
( list_head
( decls
), const declarator_t
, entry
);
1832 error_loc
("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
1837 /* We must generate names for tagless enum, struct or union.
1838 Typedef-ing a tagless enum, struct or union means we want the typedef
1839 to be included in a library hence the public attribute. */
1840 if
((type
->type
== RPC_FC_ENUM16 || type
->type
== RPC_FC_ENUM32 ||
1841 is_struct
(type
->type
) || is_union
(type
->type
)) &&
1842 !type
->name
&& !parse_only
)
1844 if
(! is_attr
(attrs
, ATTR_PUBLIC
))
1845 attrs
= append_attr
( attrs
, make_attr
(ATTR_PUBLIC
) );
1846 type
->name
= gen_name
();
1848 else if
(is_attr
(attrs
, ATTR_UUID
) && !is_attr
(attrs
, ATTR_PUBLIC
))
1849 attrs
= append_attr
( attrs
, make_attr
(ATTR_PUBLIC
) );
1851 LIST_FOR_EACH_ENTRY
( decl
, decls
, const declarator_t
, entry
)
1853 var_t
*name
= decl
->var
;
1858 cur
= find_type
(name
->name
, 0);
1860 error_loc
("%s: redefinition error; original definition was at %s:%d\n",
1861 cur
->name
, cur
->loc_info.input_name
,
1862 cur
->loc_info.line_number
);
1864 /* set the attributes to allow set_type to do some checks on them */
1865 name
->attrs
= attrs
;
1866 set_type
(name
, decl_spec
, decl
, 0);
1867 cur
= type_new_alias
(name
->type
, name
->name
);
1870 if
(is_incomplete
(cur
))
1871 add_incomplete
(cur
);
1872 reg_type
(cur
, cur
->name
, 0);
1878 type_t
*find_type
(const char *name
, int t
)
1880 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
1881 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
1883 return cur ? cur
->type
: NULL
;
1886 static type_t
*find_type_or_error
(const char *name
, int t
)
1888 type_t
*type
= find_type
(name
, t
);
1890 error_loc
("type '%s' not found\n", name
);
1896 static type_t
*find_type_or_error2
(char *name
, int t
)
1898 type_t
*tp
= find_type_or_error
(name
, t
);
1903 int is_type
(const char *name
)
1905 return find_type
(name
, 0) != NULL
;
1908 static type_t
*get_type
(unsigned char type
, char *name
, int t
)
1912 tp
= find_type
(name
, t
);
1918 tp
= make_type
(type
, NULL
);
1920 if
(!name
) return tp
;
1921 return reg_type
(tp
, name
, t
);
1924 /***** constant repository *****/
1929 struct rconst
*next
;
1932 struct rconst
*const_hash
[HASHMAX
];
1934 static var_t
*reg_const
(var_t
*var
)
1939 error_loc
("registering constant without name\n");
1942 hash
= hash_ident
(var
->name
);
1943 nc
= xmalloc
(sizeof
(struct rconst
));
1944 nc
->name
= var
->name
;
1946 nc
->next
= const_hash
[hash
];
1947 const_hash
[hash
] = nc
;
1951 var_t
*find_const
(const char *name
, int f
)
1953 struct rconst
*cur
= const_hash
[hash_ident
(name
)];
1954 while
(cur
&& strcmp
(cur
->name
, name
))
1957 if
(f
) error_loc
("constant '%s' not found\n", name
);
1963 static char *gen_name
(void)
1965 static const char format
[] = "__WIDL_%s_generated_name_%08lX";
1966 static unsigned long n
= 0;
1967 static const char *file_id
;
1973 char *dst
= dup_basename
(input_name
, ".idl");
1977 if
(! isalnum
((unsigned char) *dst
))
1980 size
= sizeof format
- 7 + strlen
(file_id
) + 8;
1983 name
= xmalloc
(size
);
1984 sprintf
(name
, format
, file_id
, n
++);
1990 unsigned int dce_compatible
: 1;
1991 unsigned int acf
: 1;
1992 unsigned int on_interface
: 1;
1993 unsigned int on_function
: 1;
1994 unsigned int on_arg
: 1;
1995 unsigned int on_type
: 1;
1996 unsigned int on_enum
: 1;
1997 unsigned int on_struct
: 1;
1998 unsigned int on_union
: 1;
1999 unsigned int on_field
: 1;
2000 unsigned int on_library
: 1;
2001 unsigned int on_dispinterface
: 1;
2002 unsigned int on_module
: 1;
2003 unsigned int on_coclass
: 1;
2004 const char *display_name
;
2007 struct allowed_attr allowed_attr
[] =
2009 /* attr { D ACF I Fn ARG T En St Un Fi L DI M C <display name> } */
2010 /* ATTR_AGGREGATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "aggregatable" },
2011 /* ATTR_APPOBJECT */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "appobject" },
2012 /* ATTR_ASYNC */ { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "async" },
2013 /* ATTR_AUTO_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "auto_handle" },
2014 /* ATTR_BINDABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "bindable" },
2015 /* ATTR_BROADCAST */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "broadcast" },
2016 /* ATTR_CALLAS */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "call_as" },
2017 /* ATTR_CALLCONV */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
},
2018 /* ATTR_CASE */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "case" },
2019 /* ATTR_CONST */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "const" },
2020 /* ATTR_CONTEXTHANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "context_handle" },
2021 /* ATTR_CONTROL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, "control" },
2022 /* ATTR_DEFAULT */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, "default" },
2023 /* ATTR_DEFAULTCOLLELEM */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultcollelem" },
2024 /* ATTR_DEFAULTVALUE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultvalue" },
2025 /* ATTR_DEFAULTVTABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "defaultvtable" },
2026 /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
},
2027 /* ATTR_DISPLAYBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "displaybind" },
2028 /* ATTR_DLLNAME */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, "dllname" },
2029 /* ATTR_DUAL */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "dual" },
2030 /* ATTR_ENDPOINT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "endpoint" },
2031 /* ATTR_ENTRY */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "entry" },
2032 /* ATTR_EXPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "explicit_handle" },
2033 /* ATTR_HANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "handle" },
2034 /* ATTR_HELPCONTEXT */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpcontext" },
2035 /* ATTR_HELPFILE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpfile" },
2036 /* ATTR_HELPSTRING */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpstring" },
2037 /* ATTR_HELPSTRINGCONTEXT */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpstringcontext" },
2038 /* ATTR_HELPSTRINGDLL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpstringdll" },
2039 /* ATTR_HIDDEN */ { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, "hidden" },
2040 /* ATTR_ID */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "id" },
2041 /* ATTR_IDEMPOTENT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "idempotent" },
2042 /* ATTR_IIDIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "iid_is" },
2043 /* ATTR_IMMEDIATEBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "immediatebind" },
2044 /* ATTR_IMPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "implicit_handle" },
2045 /* ATTR_IN */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "in" },
2046 /* ATTR_INLINE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inline" },
2047 /* ATTR_INPUTSYNC */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inputsync" },
2048 /* ATTR_LENGTHIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "length_is" },
2049 /* ATTR_LIBLCID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "lcid" },
2050 /* ATTR_LOCAL */ { 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "local" },
2051 /* ATTR_NONBROWSABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonbrowsable" },
2052 /* ATTR_NONCREATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "noncreatable" },
2053 /* ATTR_NONEXTENSIBLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonextensible" },
2054 /* ATTR_OBJECT */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "object" },
2055 /* ATTR_ODL */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "odl" },
2056 /* ATTR_OLEAUTOMATION */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "oleautomation" },
2057 /* ATTR_OPTIONAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "optional" },
2058 /* ATTR_OUT */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "out" },
2059 /* ATTR_POINTERDEFAULT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "pointer_default" },
2060 /* ATTR_POINTERTYPE */ { 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, "ref, unique or ptr" },
2061 /* ATTR_PROPGET */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propget" },
2062 /* ATTR_PROPPUT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propput" },
2063 /* ATTR_PROPPUTREF */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propputref" },
2064 /* ATTR_PUBLIC */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "public" },
2065 /* ATTR_RANGE */ { 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, "range" },
2066 /* ATTR_READONLY */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "readonly" },
2067 /* ATTR_REQUESTEDIT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "requestedit" },
2068 /* ATTR_RESTRICTED */ { 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, "restricted" },
2069 /* ATTR_RETVAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "retval" },
2070 /* ATTR_SIZEIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "size_is" },
2071 /* ATTR_SOURCE */ { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "source" },
2072 /* ATTR_STRICTCONTEXTHANDLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "strict_context_handle" },
2073 /* ATTR_STRING */ { 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, "string" },
2074 /* ATTR_SWITCHIS */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "switch_is" },
2075 /* ATTR_SWITCHTYPE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, "switch_type" },
2076 /* ATTR_TRANSMITAS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "transmit_as" },
2077 /* ATTR_UUID */ { 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "uuid" },
2078 /* ATTR_V1ENUM */ { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, "v1_enum" },
2079 /* ATTR_VARARG */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "vararg" },
2080 /* ATTR_VERSION */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "version" },
2081 /* ATTR_WIREMARSHAL */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "wire_marshal" },
2084 const char *get_attr_display_name
(enum attr_type type
)
2086 return allowed_attr
[type
].display_name
;
2089 static attr_list_t
*check_iface_attrs
(const char *name
, attr_list_t
*attrs
)
2092 if
(!attrs
) return attrs
;
2093 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2095 if
(!allowed_attr
[attr
->type
].on_interface
)
2096 error_loc
("inapplicable attribute %s for interface %s\n",
2097 allowed_attr
[attr
->type
].display_name
, name
);
2102 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
)
2105 if
(!attrs
) return attrs
;
2106 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2108 if
(!allowed_attr
[attr
->type
].on_function
)
2109 error_loc
("inapplicable attribute %s for function %s\n",
2110 allowed_attr
[attr
->type
].display_name
, name
);
2115 static void check_arg
(var_t
*arg
)
2117 const type_t
*t
= arg
->type
;
2120 if
(t
->type
== 0 && ! is_var_ptr
(arg
))
2121 error_loc
("argument '%s' has void type\n", arg
->name
);
2125 LIST_FOR_EACH_ENTRY
(attr
, arg
->attrs
, const attr_t
, entry
)
2127 if
(!allowed_attr
[attr
->type
].on_arg
)
2128 error_loc
("inapplicable attribute %s for argument %s\n",
2129 allowed_attr
[attr
->type
].display_name
, arg
->name
);
2134 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
)
2137 if
(!attrs
) return attrs
;
2138 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2140 if
(!allowed_attr
[attr
->type
].on_type
)
2141 error_loc
("inapplicable attribute %s for typedef\n",
2142 allowed_attr
[attr
->type
].display_name
);
2147 static attr_list_t
*check_enum_attrs
(attr_list_t
*attrs
)
2150 if
(!attrs
) return attrs
;
2151 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2153 if
(!allowed_attr
[attr
->type
].on_enum
)
2154 error_loc
("inapplicable attribute %s for enum\n",
2155 allowed_attr
[attr
->type
].display_name
);
2160 static attr_list_t
*check_struct_attrs
(attr_list_t
*attrs
)
2163 if
(!attrs
) return attrs
;
2164 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2166 if
(!allowed_attr
[attr
->type
].on_struct
)
2167 error_loc
("inapplicable attribute %s for struct\n",
2168 allowed_attr
[attr
->type
].display_name
);
2173 static attr_list_t
*check_union_attrs
(attr_list_t
*attrs
)
2176 if
(!attrs
) return attrs
;
2177 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2179 if
(!allowed_attr
[attr
->type
].on_union
)
2180 error_loc
("inapplicable attribute %s for union\n",
2181 allowed_attr
[attr
->type
].display_name
);
2186 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
)
2189 if
(!attrs
) return attrs
;
2190 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2192 if
(!allowed_attr
[attr
->type
].on_field
)
2193 error_loc
("inapplicable attribute %s for field %s\n",
2194 allowed_attr
[attr
->type
].display_name
, name
);
2199 static attr_list_t
*check_library_attrs
(const char *name
, attr_list_t
*attrs
)
2202 if
(!attrs
) return attrs
;
2203 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2205 if
(!allowed_attr
[attr
->type
].on_library
)
2206 error_loc
("inapplicable attribute %s for library %s\n",
2207 allowed_attr
[attr
->type
].display_name
, name
);
2212 static attr_list_t
*check_dispiface_attrs
(const char *name
, attr_list_t
*attrs
)
2215 if
(!attrs
) return attrs
;
2216 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2218 if
(!allowed_attr
[attr
->type
].on_dispinterface
)
2219 error_loc
("inapplicable attribute %s for dispinterface %s\n",
2220 allowed_attr
[attr
->type
].display_name
, name
);
2225 static attr_list_t
*check_module_attrs
(const char *name
, attr_list_t
*attrs
)
2228 if
(!attrs
) return attrs
;
2229 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2231 if
(!allowed_attr
[attr
->type
].on_module
)
2232 error_loc
("inapplicable attribute %s for module %s\n",
2233 allowed_attr
[attr
->type
].display_name
, name
);
2238 static attr_list_t
*check_coclass_attrs
(const char *name
, attr_list_t
*attrs
)
2241 if
(!attrs
) return attrs
;
2242 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2244 if
(!allowed_attr
[attr
->type
].on_coclass
)
2245 error_loc
("inapplicable attribute %s for coclass %s\n",
2246 allowed_attr
[attr
->type
].display_name
, name
);
2251 static int is_allowed_conf_type
(const type_t
*type
)
2272 static int is_ptr_guid_type
(const type_t
*type
)
2274 unsigned int align
= 0;
2276 /* first, make sure it is a pointer to something */
2277 if
(!is_ptr
(type
)) return FALSE
;
2279 /* second, make sure it is a pointer to something of size sizeof(GUID),
2281 return
(type_memsize
(type_pointer_get_ref
(type
), &align
) == 16);
2284 static void check_conformance_expr_list
(const char *attr_name
, const var_t
*arg
, const type_t
*container_type
, expr_list_t
*expr_list
)
2287 struct expr_loc expr_loc
;
2289 expr_loc.attr
= attr_name
;
2290 if
(expr_list
) LIST_FOR_EACH_ENTRY
(dim
, expr_list
, expr_t
, entry
)
2292 if
(dim
->type
!= EXPR_VOID
)
2294 const type_t
*expr_type
= expr_resolve_type
(&expr_loc
, container_type
, dim
);
2295 if
(!is_allowed_conf_type
(expr_type
))
2296 error_loc_info
(&arg
->loc_info
, "expression must resolve to integral type <= 32bits for attribute %s\n",
2302 static void check_remoting_fields
(const var_t
*var
, type_t
*type
);
2304 /* checks that properties common to fields and arguments are consistent */
2305 static void check_field_common
(const type_t
*container_type
,
2306 const char *container_name
, const var_t
*arg
)
2308 type_t
*type
= arg
->type
;
2309 int is_wire_marshal
= 0;
2310 int is_context_handle
= 0;
2311 const char *container_type_name
= NULL
;
2313 if
(is_struct
(container_type
->type
))
2314 container_type_name
= "struct";
2315 else if
(is_union
(container_type
->type
))
2316 container_type_name
= "union";
2317 else if
(container_type
->type
== RPC_FC_FUNCTION
)
2318 container_type_name
= "function";
2320 if
(is_attr
(arg
->attrs
, ATTR_LENGTHIS
) &&
2321 (is_attr
(arg
->attrs
, ATTR_STRING
) || is_aliaschain_attr
(arg
->type
, ATTR_STRING
)))
2322 error_loc_info
(&arg
->loc_info
,
2323 "string and length_is specified for argument %s are mutually exclusive attributes\n",
2326 if
(is_attr
(arg
->attrs
, ATTR_SIZEIS
))
2328 expr_list_t
*size_is_exprs
= get_attrp
(arg
->attrs
, ATTR_SIZEIS
);
2329 check_conformance_expr_list
("size_is", arg
, container_type
, size_is_exprs
);
2331 if
(is_attr
(arg
->attrs
, ATTR_LENGTHIS
))
2333 expr_list_t
*length_is_exprs
= get_attrp
(arg
->attrs
, ATTR_LENGTHIS
);
2334 check_conformance_expr_list
("length_is", arg
, container_type
, length_is_exprs
);
2336 if
(is_attr
(arg
->attrs
, ATTR_IIDIS
))
2338 struct expr_loc expr_loc
;
2339 expr_t
*expr
= get_attrp
(arg
->attrs
, ATTR_IIDIS
);
2340 if
(expr
->type
!= EXPR_VOID
)
2342 const type_t
*expr_type
;
2344 expr_loc.attr
= "iid_is";
2345 expr_type
= expr_resolve_type
(&expr_loc
, container_type
, expr
);
2346 if
(!expr_type ||
!is_ptr_guid_type
(expr_type
))
2347 error_loc_info
(&arg
->loc_info
, "expression must resolve to pointer to GUID type for attribute iid_is\n");
2350 if
(is_attr
(arg
->attrs
, ATTR_SWITCHIS
))
2352 struct expr_loc expr_loc
;
2353 expr_t
*expr
= get_attrp
(arg
->attrs
, ATTR_SWITCHIS
);
2354 if
(expr
->type
!= EXPR_VOID
)
2356 const type_t
*expr_type
;
2358 expr_loc.attr
= "switch_is";
2359 expr_type
= expr_resolve_type
(&expr_loc
, container_type
, expr
);
2360 if
(!expr_type ||
!is_allowed_conf_type
(expr_type
))
2361 error_loc_info
(&arg
->loc_info
, "expression must resolve to integral type <= 32bits for attribute %s\n",
2366 /* get fundamental type for the argument */
2369 if
(is_attr
(type
->attrs
, ATTR_WIREMARSHAL
))
2371 is_wire_marshal
= 1;
2374 if
(is_attr
(type
->attrs
, ATTR_CONTEXTHANDLE
))
2376 is_context_handle
= 1;
2379 if
(type_is_alias
(type
))
2380 type
= type_alias_get_aliasee
(type
);
2381 else if
(is_ptr
(type
))
2382 type
= type_pointer_get_ref
(type
);
2383 else if
(is_array
(type
))
2384 type
= type_array_get_element
(type
);
2389 if
(type
->type
== 0 && !is_attr
(arg
->attrs
, ATTR_IIDIS
) && !is_wire_marshal
&& !is_context_handle
)
2390 error_loc_info
(&arg
->loc_info
, "parameter \'%s\' of %s \'%s\' cannot derive from void *\n", arg
->name
, container_type_name
, container_name
);
2391 else if
(type
->type
== RPC_FC_FUNCTION
)
2392 error_loc_info
(&arg
->loc_info
, "parameter \'%s\' of %s \'%s\' cannot be a function pointer\n", arg
->name
, container_type_name
, container_name
);
2393 else if
(!is_wire_marshal
&& (is_struct
(type
->type
) || is_union
(type
->type
)))
2394 check_remoting_fields
(arg
, type
);
2397 static void check_remoting_fields
(const var_t
*var
, type_t
*type
)
2400 const var_list_t
*fields
= NULL
;
2402 type
= type_get_real_type
(type
);
2407 type
->checked
= TRUE
;
2409 if
(is_struct
(type
->type
))
2411 if
(type_is_complete
(type
))
2412 fields
= type_struct_get_fields
(type
);
2414 error_loc_info
(&var
->loc_info
, "undefined type declaration %s\n", type
->name
);
2416 else if
(is_union
(type
->type
))
2417 fields
= type_union_get_cases
(type
);
2419 if
(fields
) LIST_FOR_EACH_ENTRY
( field
, fields
, const var_t
, entry
)
2420 if
(field
->type
) check_field_common
(type
, type
->name
, field
);
2423 /* checks that arguments for a function make sense for marshalling and unmarshalling */
2424 static void check_remoting_args
(const var_t
*func
)
2426 const char *funcname
= func
->name
;
2429 if
(func
->type
->details.function
->args
) LIST_FOR_EACH_ENTRY
( arg
, func
->type
->details.function
->args
, const var_t
, entry
)
2432 const type_t
*type
= arg
->type
;
2434 /* get pointer level and fundamental type for the argument */
2437 if
(is_attr
(type
->attrs
, ATTR_WIREMARSHAL
))
2439 if
(is_attr
(type
->attrs
, ATTR_CONTEXTHANDLE
))
2441 if
(type_is_alias
(type
))
2442 type
= type_alias_get_aliasee
(type
);
2443 else if
(is_ptr
(type
))
2446 type
= type_pointer_get_ref
(type
);
2452 /* check that [out] parameters have enough pointer levels */
2453 if
(is_attr
(arg
->attrs
, ATTR_OUT
))
2455 if
(!is_array
(type
))
2458 error_loc_info
(&arg
->loc_info
, "out parameter \'%s\' of function \'%s\' is not a pointer\n", arg
->name
, funcname
);
2459 if
(type
->type
== RPC_FC_IP
&& ptr_level
== 1)
2460 error_loc_info
(&arg
->loc_info
, "out interface pointer \'%s\' of function \'%s\' is not a double pointer\n", arg
->name
, funcname
);
2464 check_field_common
(func
->type
, funcname
, arg
);
2468 static void add_explicit_handle_if_necessary
(var_t
*func
)
2470 const var_t
* explicit_handle_var
;
2471 const var_t
* explicit_generic_handle_var
= NULL
;
2472 const var_t
* context_handle_var
= NULL
;
2474 /* check for a defined binding handle */
2475 explicit_handle_var
= get_explicit_handle_var
(func
);
2476 if
(!explicit_handle_var
)
2478 explicit_generic_handle_var
= get_explicit_generic_handle_var
(func
);
2479 if
(!explicit_generic_handle_var
)
2481 context_handle_var
= get_context_handle_var
(func
);
2482 if
(!context_handle_var
)
2484 /* no explicit handle specified so add
2485 * "[in] handle_t IDL_handle" as the first parameter to the
2487 var_t
*idl_handle
= make_var
(xstrdup
("IDL_handle"));
2488 idl_handle
->attrs
= append_attr
(NULL
, make_attr
(ATTR_IN
));
2489 idl_handle
->type
= find_type_or_error
("handle_t", 0);
2490 type_function_add_head_arg
(func
->type
, idl_handle
);
2496 static void check_functions
(const type_t
*iface
, int is_inside_library
)
2498 const statement_t
*stmt
;
2499 if
(is_attr
(iface
->attrs
, ATTR_EXPLICIT_HANDLE
))
2501 STATEMENTS_FOR_EACH_FUNC
( stmt
, type_iface_get_stmts
(iface
) )
2503 var_t
*func
= stmt
->u.var
;
2504 add_explicit_handle_if_necessary
(func
);
2507 if
(!is_inside_library
&& !is_attr
(iface
->attrs
, ATTR_LOCAL
))
2509 STATEMENTS_FOR_EACH_FUNC
( stmt
, type_iface_get_stmts
(iface
) )
2511 const var_t
*func
= stmt
->u.var
;
2512 if
(!is_attr
(func
->attrs
, ATTR_LOCAL
))
2513 check_remoting_args
(func
);
2518 static void check_statements
(const statement_list_t
*stmts
, int is_inside_library
)
2520 const statement_t
*stmt
;
2522 if
(stmts
) LIST_FOR_EACH_ENTRY
(stmt
, stmts
, const statement_t
, entry
)
2524 if
(stmt
->type
== STMT_LIBRARY
)
2525 check_statements
(stmt
->u.lib
->stmts
, TRUE
);
2526 else if
(stmt
->type
== STMT_TYPE
&& stmt
->u.type
->type
== RPC_FC_IP
)
2527 check_functions
(stmt
->u.type
, is_inside_library
);
2531 static void check_all_user_types
(const statement_list_t
*stmts
)
2533 const statement_t
*stmt
;
2535 if
(stmts
) LIST_FOR_EACH_ENTRY
(stmt
, stmts
, const statement_t
, entry
)
2537 if
(stmt
->type
== STMT_LIBRARY
)
2538 check_all_user_types
(stmt
->u.lib
->stmts
);
2539 else if
(stmt
->type
== STMT_TYPE
&& stmt
->u.type
->type
== RPC_FC_IP
&&
2540 !is_local
(stmt
->u.type
->attrs
))
2542 const statement_t
*stmt_func
;
2543 STATEMENTS_FOR_EACH_FUNC
(stmt_func
, type_iface_get_stmts
(stmt
->u.type
)) {
2544 const var_t
*func
= stmt_func
->u.var
;
2545 check_for_additional_prototype_types
(func
->type
->details.function
->args
);
2551 int is_valid_uuid
(const char *s
)
2555 for
(i
= 0; i
< 36; ++i
)
2556 if
(i
== 8 || i
== 13 || i
== 18 || i
== 23)
2562 if
(!isxdigit
(s
[i
]))
2565 return s
[i
] == '\0';
2568 static statement_t
*make_statement
(enum statement_type type
)
2570 statement_t
*stmt
= xmalloc
(sizeof
(*stmt
));
2575 static statement_t
*make_statement_type_decl
(type_t
*type
)
2577 statement_t
*stmt
= make_statement
(STMT_TYPE
);
2578 stmt
->u.type
= type
;
2582 static statement_t
*make_statement_reference
(type_t
*type
)
2584 statement_t
*stmt
= make_statement
(STMT_TYPEREF
);
2585 stmt
->u.type
= type
;
2589 static statement_t
*make_statement_declaration
(var_t
*var
)
2591 statement_t
*stmt
= make_statement
(STMT_DECLARATION
);
2593 if
(var
->stgclass
== STG_EXTERN
&& var
->eval
)
2594 warning
("'%s' initialised and declared extern\n", var
->name
);
2595 if
(is_const_decl
(var
))
2600 else if
((var
->stgclass
== STG_NONE || var
->stgclass
== STG_REGISTER
) &&
2601 var
->type
->type
!= RPC_FC_FUNCTION
)
2602 error_loc
("instantiation of data is illegal\n");
2606 static statement_t
*make_statement_library
(typelib_t
*typelib
)
2608 statement_t
*stmt
= make_statement
(STMT_LIBRARY
);
2609 stmt
->u.lib
= typelib
;
2613 static statement_t
*make_statement_cppquote
(const char *str
)
2615 statement_t
*stmt
= make_statement
(STMT_CPPQUOTE
);
2620 static statement_t
*make_statement_importlib
(const char *str
)
2622 statement_t
*stmt
= make_statement
(STMT_IMPORTLIB
);
2627 static statement_t
*make_statement_import
(const char *str
)
2629 statement_t
*stmt
= make_statement
(STMT_IMPORT
);
2634 static statement_t
*make_statement_module
(type_t
*type
)
2636 statement_t
*stmt
= make_statement
(STMT_MODULE
);
2637 stmt
->u.type
= type
;
2641 static statement_t
*make_statement_typedef
(declarator_list_t
*decls
)
2643 declarator_t
*decl
, *next
;
2645 type_list_t
**type_list
;
2647 if
(!decls
) return NULL
;
2649 stmt
= make_statement
(STMT_TYPEDEF
);
2650 stmt
->u.type_list
= NULL
;
2651 type_list
= &stmt
->u.type_list
;
2653 LIST_FOR_EACH_ENTRY_SAFE
( decl
, next
, decls
, declarator_t
, entry
)
2655 var_t
*var
= decl
->var
;
2656 type_t
*type
= find_type_or_error
(var
->name
, 0);
2657 *type_list
= xmalloc
(sizeof
(type_list_t
));
2658 (*type_list
)->type
= type
;
2659 (*type_list
)->next
= NULL
;
2661 type_list
= &(*type_list
)->next
;
2669 static statement_list_t
*append_statement
(statement_list_t
*list
, statement_t
*stmt
)
2671 if
(!stmt
) return list
;
2674 list
= xmalloc
( sizeof
(*list
) );
2677 list_add_tail
( list
, &stmt
->entry
);
2681 void init_loc_info
(loc_info_t
*i
)
2683 i
->input_name
= input_name ? input_name
: "stdin";
2684 i
->line_number
= line_number
;
2685 i
->near_text
= parser_text
;
2688 static void check_def
(const type_t
*t
)
2691 error_loc
("%s: redefinition error; original definition was at %s:%d\n",
2692 t
->name
, t
->loc_info.input_name
, t
->loc_info.line_number
);