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
45 /* Berkeley yacc (byacc) doesn't seem to know about these */
46 /* Some *BSD supplied versions do define these though */
48 # define YYEMPTY (-1) /* Empty lookahead value of yychar */
51 # define YYLEX yylex()
54 #elif defined(YYBISON)
55 /* Bison was used for original development */
56 /* #define YYEMPTY -2 */
57 /* #define YYLEX yylex() */
60 /* No yacc we know yet */
61 # if !defined(YYEMPTY) || !defined(YYLEX)
62 # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
63 # elif defined(__GNUC__) /* gcc defines the #warning directive */
64 # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
65 /* #else we just take a chance that it works... */
69 #define YYERROR_VERBOSE
71 unsigned char pointer_default
= RPC_FC_UP
;
72 static int is_object_interface
= FALSE
;
74 typedef
struct list typelist_t
;
86 typedef
struct _decl_spec_t
90 enum storage_class stgclass
;
93 typelist_t incomplete_types
= LIST_INIT
(incomplete_types
);
95 static void add_incomplete
(type_t
*t
);
96 static void fix_incomplete
(void);
97 static void fix_incomplete_types
(type_t
*complete_type
);
99 static str_list_t
*append_str
(str_list_t
*list
, char *str
);
100 static attr_list_t
*append_attr
(attr_list_t
*list
, attr_t
*attr
);
101 static attr_list_t
*append_attr_list
(attr_list_t
*new_list
, attr_list_t
*old_list
);
102 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
);
103 static attr_t
*make_attr
(enum attr_type type
);
104 static attr_t
*make_attrv
(enum attr_type type
, unsigned long val
);
105 static attr_t
*make_attrp
(enum attr_type type
, void *val
);
106 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
);
107 static array_dims_t
*append_array
(array_dims_t
*list
, expr_t
*expr
);
108 static void set_type
(var_t
*v
, decl_spec_t
*decl_spec
, const declarator_t
*decl
, int top
);
109 static var_list_t
*set_var_types
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_list_t
*decls
);
110 static ifref_list_t
*append_ifref
(ifref_list_t
*list
, ifref_t
*iface
);
111 static ifref_t
*make_ifref
(type_t
*iface
);
112 static var_list_t
*append_var
(var_list_t
*list
, var_t
*var
);
113 static var_list_t
*append_var_list
(var_list_t
*list
, var_list_t
*vars
);
114 static var_t
*make_var
(char *name
);
115 static declarator_list_t
*append_declarator
(declarator_list_t
*list
, declarator_t
*p
);
116 static declarator_t
*make_declarator
(var_t
*var
);
117 static func_list_t
*append_func
(func_list_t
*list
, func_t
*func
);
118 static func_t
*make_func
(var_t
*def
);
119 static type_t
*make_class
(char *name
);
120 static type_t
*make_safearray
(type_t
*type
);
121 static type_t
*make_builtin
(char *name
);
122 static type_t
*make_int
(int sign
);
123 static typelib_t
*make_library
(const char *name
, const attr_list_t
*attrs
);
124 static type_t
*append_ptrchain_type
(type_t
*ptrchain
, type_t
*type
);
126 static type_t
*type_new_enum
(char *name
, var_list_t
*enums
);
127 static type_t
*type_new_struct
(char *name
, int defined
, var_list_t
*fields
);
128 static type_t
*type_new_nonencapsulated_union
(char *name
, var_list_t
*fields
);
129 static type_t
*type_new_encapsulated_union
(char *name
, var_t
*switch_field
, var_t
*union_field
, var_list_t
*cases
);
131 static type_t
*reg_type
(type_t
*type
, const char *name
, int t
);
132 static type_t
*reg_typedefs
(decl_spec_t
*decl_spec
, var_list_t
*names
, attr_list_t
*attrs
);
133 static type_t
*find_type_or_error
(const char *name
, int t
);
134 static type_t
*find_type_or_error2
(char *name
, int t
);
135 static type_t
*get_type
(unsigned char type
, char *name
, int t
);
137 static var_t
*reg_const
(var_t
*var
);
139 static char *gen_name
(void);
140 static void check_arg
(var_t
*arg
);
141 static void check_statements
(const statement_list_t
*stmts
, int is_inside_library
);
142 static void check_all_user_types
(const statement_list_t
*stmts
);
143 static attr_list_t
*check_iface_attrs
(const char *name
, attr_list_t
*attrs
);
144 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
);
145 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
);
146 static attr_list_t
*check_enum_attrs
(attr_list_t
*attrs
);
147 static attr_list_t
*check_struct_attrs
(attr_list_t
*attrs
);
148 static attr_list_t
*check_union_attrs
(attr_list_t
*attrs
);
149 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
);
150 static attr_list_t
*check_library_attrs
(const char *name
, attr_list_t
*attrs
);
151 static attr_list_t
*check_dispiface_attrs
(const char *name
, attr_list_t
*attrs
);
152 static attr_list_t
*check_module_attrs
(const char *name
, attr_list_t
*attrs
);
153 static attr_list_t
*check_coclass_attrs
(const char *name
, attr_list_t
*attrs
);
154 const char *get_attr_display_name
(enum attr_type type
);
155 static void add_explicit_handle_if_necessary
(var_t
*func
);
156 static void check_def
(const type_t
*t
);
158 static statement_t
*make_statement
(enum statement_type type
);
159 static statement_t
*make_statement_type_decl
(type_t
*type
);
160 static statement_t
*make_statement_reference
(type_t
*type
);
161 static statement_t
*make_statement_declaration
(var_t
*var
);
162 static statement_t
*make_statement_library
(typelib_t
*typelib
);
163 static statement_t
*make_statement_cppquote
(const char *str
);
164 static statement_t
*make_statement_importlib
(const char *str
);
165 static statement_t
*make_statement_module
(type_t
*type
);
166 static statement_t
*make_statement_typedef
(var_list_t
*names
);
167 static statement_t
*make_statement_import
(const char *str
);
168 static statement_t
*make_statement_typedef
(var_list_t
*names
);
169 static statement_list_t
*append_statement
(statement_list_t
*list
, statement_t
*stmt
);
178 attr_list_t
*attr_list
;
179 str_list_t
*str_list
;
181 expr_list_t
*expr_list
;
182 array_dims_t
*array_dims
;
185 var_list_t
*var_list
;
186 declarator_t
*declarator
;
187 declarator_list_t
*declarator_list
;
189 func_list_t
*func_list
;
190 statement_t
*statement
;
191 statement_list_t
*stmt_list
;
193 ifref_list_t
*ifref_list
;
198 interface_info_t ifinfo
;
200 struct _import_t
*import
;
201 struct _decl_spec_t
*declspec
;
202 enum storage_class stgclass
;
205 %token
<str
> aIDENTIFIER
206 %token
<str
> aKNOWNTYPE
207 %token
<num
> aNUM aHEXNUM
209 %token
<str
> aSTRING aWSTRING
214 %token EQUALITY INEQUALITY
215 %token GREATEREQUAL LESSEQUAL
216 %token LOGICALOR LOGICALAND
217 %token tAGGREGATABLE tALLOCATE tAPPOBJECT tASYNC tASYNCUUID
218 %token tAUTOHANDLE tBINDABLE tBOOLEAN tBROADCAST tBYTE tBYTECOUNT
219 %token tCALLAS tCALLBACK tCASE tCDECL tCHAR tCOCLASS tCODE tCOMMSTATUS
220 %token tCONST tCONTEXTHANDLE tCONTEXTHANDLENOSERIALIZE
221 %token tCONTEXTHANDLESERIALIZE tCONTROL tCPPQUOTE
223 %token tDEFAULTCOLLELEM
225 %token tDEFAULTVTABLE
227 %token tDISPINTERFACE
228 %token tDLLNAME tDOUBLE tDUAL
230 %token tENTRY tENUM tERRORSTATUST
231 %token tEXPLICITHANDLE tEXTERN
237 %token tHELPCONTEXT tHELPFILE
238 %token tHELPSTRING tHELPSTRINGCONTEXT tHELPSTRINGDLL
240 %token tHYPER tID tIDEMPOTENT
242 %token tIMMEDIATEBIND
243 %token tIMPLICITHANDLE
244 %token tIMPORT tIMPORTLIB
245 %token tIN tIN_LINE tINLINE
250 %token tLENGTHIS tLIBRARY
257 %token tNONEXTENSIBLE
259 %token tOBJECT tODL tOLEAUTOMATION
263 %token tPOINTERDEFAULT
265 %token tPROPGET tPROPPUT tPROPPUTREF
269 %token tREADONLY tREF
278 %token tSIZEIS tSIZEOF
283 %token tSTRICTCONTEXTHANDLE
284 %token tSTRING tSTRUCT
285 %token tSWITCH tSWITCHIS tSWITCHTYPE
297 %token tWCHAR tWIREMARSHAL
299 %type
<attr
> attribute type_qualifier function_specifier
300 %type
<attr_list
> m_attributes attributes attrib_list m_type_qual_list
301 %type
<str_list
> str_list
302 %type
<expr
> m_expr expr expr_const expr_int_const array
303 %type
<expr_list
> m_exprs
/* exprs expr_list */ expr_list_int_const
304 %type
<ifinfo
> interfacehdr
305 %type
<stgclass
> storage_cls_spec
306 %type
<declspec
> decl_spec decl_spec_no_type m_decl_spec_no_type
307 %type
<type
> inherit interface interfacedef interfacedec
308 %type
<type
> dispinterface dispinterfacehdr dispinterfacedef
309 %type
<type
> module modulehdr moduledef
310 %type
<type
> base_type int_std
311 %type
<type
> enumdef structdef uniondef typedecl
313 %type
<ifref
> coclass_int
314 %type
<ifref_list
> coclass_ints
315 %type
<var
> arg ne_union_field union_field s_field case
enum declaration
316 %type
<var_list
> m_args no_args args fields ne_union_fields cases enums enum_list dispint_props field
317 %type
<var
> m_ident ident
318 %type
<declarator
> declarator direct_declarator init_declarator
319 %type
<declarator_list
> declarator_list
321 %type
<type
> coclass coclasshdr coclassdef
322 %type
<num
> pointer_type version
323 %type
<str
> libraryhdr callconv cppquote importlib import t_ident
324 %type
<uuid
> uuid_string
325 %type
<import
> import_start
326 %type
<typelib
> library_start librarydef
327 %type
<statement
> statement typedef
328 %type
<stmt_list
> gbl_statements imp_statements int_statements dispint_meths
337 %left EQUALITY INEQUALITY
338 %left
'<' '>' LESSEQUAL GREATEREQUAL
342 %right
'!' '~' CAST PPTR POS NEG ADDRESSOF tSIZEOF
343 %left
'.' MEMBERPTR
'[' ']'
347 input: gbl_statements
{ fix_incomplete
();
348 check_statements
($1, FALSE
);
349 check_all_user_types
($1);
356 write_local_stubs
($1);
360 gbl_statements: { $$
= NULL
; }
361 | gbl_statements interfacedec
{ $$
= append_statement
($1, make_statement_reference
($2)); }
362 | gbl_statements interfacedef
{ $$
= append_statement
($1, make_statement_type_decl
($2)); }
363 | gbl_statements coclass
';' { $$
= $1;
364 reg_type
($2, $2->name
, 0);
366 | gbl_statements coclassdef
{ $$
= append_statement
($1, make_statement_type_decl
($2));
367 reg_type
($2, $2->name
, 0);
369 | gbl_statements moduledef
{ $$
= append_statement
($1, make_statement_module
($2)); }
370 | gbl_statements librarydef
{ $$
= append_statement
($1, make_statement_library
($2)); }
371 | gbl_statements statement
{ $$
= append_statement
($1, $2); }
374 imp_statements: { $$
= NULL
; }
375 | imp_statements interfacedec
{ $$
= append_statement
($1, make_statement_reference
($2)); }
376 | imp_statements interfacedef
{ $$
= append_statement
($1, make_statement_type_decl
($2)); }
377 | imp_statements coclass
';' { $$
= $1; reg_type
($2, $2->name
, 0); }
378 | imp_statements coclassdef
{ $$
= append_statement
($1, make_statement_type_decl
($2));
379 reg_type
($2, $2->name
, 0);
381 | imp_statements moduledef
{ $$
= append_statement
($1, make_statement_module
($2)); }
382 | imp_statements statement
{ $$
= append_statement
($1, $2); }
383 | imp_statements importlib
{ $$
= append_statement
($1, make_statement_importlib
($2)); }
384 | imp_statements librarydef
{ $$
= append_statement
($1, make_statement_library
($2)); }
387 int_statements: { $$
= NULL
; }
388 | int_statements statement
{ $$
= append_statement
($1, $2); }
396 cppquote
{ $$
= make_statement_cppquote
($1); }
397 | typedecl
';' { $$
= make_statement_type_decl
($1); }
398 | declaration
';' { $$
= make_statement_declaration
($1); }
399 | import
{ $$
= make_statement_import
($1); }
400 | typedef
';' { $$
= $1; }
407 | attributes enumdef
{ $$
= $2; $$
->attrs
= check_enum_attrs
($1); }
408 | attributes structdef
{ $$
= $2; $$
->attrs
= check_struct_attrs
($1); }
409 | attributes uniondef
{ $$
= $2; $$
->attrs
= check_union_attrs
($1); }
412 cppquote: tCPPQUOTE
'(' aSTRING
')' { $$
= $3; }
414 import_start: tIMPORT aSTRING
';' { assert
(yychar == YYEMPTY
);
415 $$
= xmalloc
(sizeof
(struct _import_t
));
417 $$
->import_performed
= do_import
($2);
418 if
(!$$
->import_performed
) yychar = aEOF
;
422 import: import_start imp_statements aEOF
{ $$
= $1->name
;
423 if
($1->import_performed
) pop_import
();
428 importlib: tIMPORTLIB
'(' aSTRING
')'
429 semicolon_opt
{ $$
= $3; if
(!parse_only
) add_importlib
($3); }
432 libraryhdr: tLIBRARY aIDENTIFIER
{ $$
= $2; }
434 library_start: attributes libraryhdr
'{' { $$
= make_library
($2, check_library_attrs
($2, $1));
435 if
(!parse_only
) start_typelib
($$
);
438 librarydef: library_start imp_statements
'}'
439 semicolon_opt
{ $$
= $1;
441 if
(!parse_only
) end_typelib
();
445 m_args: { $$
= NULL
; }
449 no_args: tVOID
{ $$
= NULL
; }
452 args: arg
{ check_arg
($1); $$
= append_var
( NULL
, $1 ); }
453 | args
',' arg
{ check_arg
($3); $$
= append_var
( $1, $3); }
457 /* split into two rules to get bison to resolve a tVOID conflict */
458 arg: attributes decl_spec declarator
{ $$
= $3->var
;
460 if
($2->stgclass
!= STG_NONE
&& $2->stgclass
!= STG_REGISTER
)
461 error_loc
("invalid storage class for function parameter\n");
462 set_type
($$
, $2, $3, TRUE
);
465 | decl_spec declarator
{ $$
= $2->var
;
466 if
($1->stgclass
!= STG_NONE
&& $1->stgclass
!= STG_REGISTER
)
467 error_loc
("invalid storage class for function parameter\n");
468 set_type
($$
, $1, $2, TRUE
);
473 array: '[' m_expr
']' { $$
= $2; }
474 |
'[' '*' ']' { $$
= make_expr
(EXPR_VOID
); }
477 m_attributes: { $$
= NULL
; }
482 '[' attrib_list
']' { $$
= $2; }
485 attrib_list: attribute
{ $$
= append_attr
( NULL
, $1 ); }
486 | attrib_list
',' attribute
{ $$
= append_attr
( $1, $3 ); }
487 | attrib_list
']' '[' attribute
{ $$
= append_attr
( $1, $4 ); }
490 str_list: aSTRING
{ $$
= append_str
( NULL
, $1 ); }
491 | str_list
',' aSTRING
{ $$
= append_str
( $1, $3 ); }
494 attribute: { $$
= NULL
; }
495 | tAGGREGATABLE
{ $$
= make_attr
(ATTR_AGGREGATABLE
); }
496 | tAPPOBJECT
{ $$
= make_attr
(ATTR_APPOBJECT
); }
497 | tASYNC
{ $$
= make_attr
(ATTR_ASYNC
); }
498 | tAUTOHANDLE
{ $$
= make_attr
(ATTR_AUTO_HANDLE
); }
499 | tBINDABLE
{ $$
= make_attr
(ATTR_BINDABLE
); }
500 | tBROADCAST
{ $$
= make_attr
(ATTR_BROADCAST
); }
501 | tCALLAS
'(' ident
')' { $$
= make_attrp
(ATTR_CALLAS
, $3); }
502 | tCASE
'(' expr_list_int_const
')' { $$
= make_attrp
(ATTR_CASE
, $3); }
503 | tCONTEXTHANDLE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); }
504 | tCONTEXTHANDLENOSERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_DONT_SERIALIZE */ }
505 | tCONTEXTHANDLESERIALIZE
{ $$
= make_attrv
(ATTR_CONTEXTHANDLE
, 0); /* RPC_CONTEXT_HANDLE_SERIALIZE */ }
506 | tCONTROL
{ $$
= make_attr
(ATTR_CONTROL
); }
507 | tDEFAULT
{ $$
= make_attr
(ATTR_DEFAULT
); }
508 | tDEFAULTCOLLELEM
{ $$
= make_attr
(ATTR_DEFAULTCOLLELEM
); }
509 | tDEFAULTVALUE
'(' expr_const
')' { $$
= make_attrp
(ATTR_DEFAULTVALUE
, $3); }
510 | tDEFAULTVTABLE
{ $$
= make_attr
(ATTR_DEFAULTVTABLE
); }
511 | tDISPLAYBIND
{ $$
= make_attr
(ATTR_DISPLAYBIND
); }
512 | tDLLNAME
'(' aSTRING
')' { $$
= make_attrp
(ATTR_DLLNAME
, $3); }
513 | tDUAL
{ $$
= make_attr
(ATTR_DUAL
); }
514 | tENDPOINT
'(' str_list
')' { $$
= make_attrp
(ATTR_ENDPOINT
, $3); }
515 | tENTRY
'(' expr_const
')' { $$
= make_attrp
(ATTR_ENTRY
, $3); }
516 | tEXPLICITHANDLE
{ $$
= make_attr
(ATTR_EXPLICIT_HANDLE
); }
517 | tHANDLE
{ $$
= make_attr
(ATTR_HANDLE
); }
518 | tHELPCONTEXT
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_HELPCONTEXT
, $3); }
519 | tHELPFILE
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPFILE
, $3); }
520 | tHELPSTRING
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRING
, $3); }
521 | tHELPSTRINGCONTEXT
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_HELPSTRINGCONTEXT
, $3); }
522 | tHELPSTRINGDLL
'(' aSTRING
')' { $$
= make_attrp
(ATTR_HELPSTRINGDLL
, $3); }
523 | tHIDDEN
{ $$
= make_attr
(ATTR_HIDDEN
); }
524 | tID
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_ID
, $3); }
525 | tIDEMPOTENT
{ $$
= make_attr
(ATTR_IDEMPOTENT
); }
526 | tIIDIS
'(' expr
')' { $$
= make_attrp
(ATTR_IIDIS
, $3); }
527 | tIMMEDIATEBIND
{ $$
= make_attr
(ATTR_IMMEDIATEBIND
); }
528 | tIMPLICITHANDLE
'(' tHANDLET aIDENTIFIER
')' { $$
= make_attrp
(ATTR_IMPLICIT_HANDLE
, $4); }
529 | tIN
{ $$
= make_attr
(ATTR_IN
); }
530 | tINPUTSYNC
{ $$
= make_attr
(ATTR_INPUTSYNC
); }
531 | tLENGTHIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_LENGTHIS
, $3); }
532 | tLCID
'(' expr_int_const
')' { $$
= make_attrp
(ATTR_LIBLCID
, $3); }
533 | tLOCAL
{ $$
= make_attr
(ATTR_LOCAL
); }
534 | tNONBROWSABLE
{ $$
= make_attr
(ATTR_NONBROWSABLE
); }
535 | tNONCREATABLE
{ $$
= make_attr
(ATTR_NONCREATABLE
); }
536 | tNONEXTENSIBLE
{ $$
= make_attr
(ATTR_NONEXTENSIBLE
); }
537 | tOBJECT
{ $$
= make_attr
(ATTR_OBJECT
); }
538 | tODL
{ $$
= make_attr
(ATTR_ODL
); }
539 | tOLEAUTOMATION
{ $$
= make_attr
(ATTR_OLEAUTOMATION
); }
540 | tOPTIONAL
{ $$
= make_attr
(ATTR_OPTIONAL
); }
541 | tOUT
{ $$
= make_attr
(ATTR_OUT
); }
542 | tPOINTERDEFAULT
'(' pointer_type
')' { $$
= make_attrv
(ATTR_POINTERDEFAULT
, $3); }
543 | tPROPGET
{ $$
= make_attr
(ATTR_PROPGET
); }
544 | tPROPPUT
{ $$
= make_attr
(ATTR_PROPPUT
); }
545 | tPROPPUTREF
{ $$
= make_attr
(ATTR_PROPPUTREF
); }
546 | tPUBLIC
{ $$
= make_attr
(ATTR_PUBLIC
); }
547 | tRANGE
'(' expr_int_const
',' expr_int_const
')'
548 { expr_list_t
*list
= append_expr
( NULL
, $3 );
549 list
= append_expr
( list
, $5 );
550 $$
= make_attrp
(ATTR_RANGE
, list
); }
551 | tREADONLY
{ $$
= make_attr
(ATTR_READONLY
); }
552 | tREQUESTEDIT
{ $$
= make_attr
(ATTR_REQUESTEDIT
); }
553 | tRESTRICTED
{ $$
= make_attr
(ATTR_RESTRICTED
); }
554 | tRETVAL
{ $$
= make_attr
(ATTR_RETVAL
); }
555 | tSIZEIS
'(' m_exprs
')' { $$
= make_attrp
(ATTR_SIZEIS
, $3); }
556 | tSOURCE
{ $$
= make_attr
(ATTR_SOURCE
); }
557 | tSTRICTCONTEXTHANDLE
{ $$
= make_attr
(ATTR_STRICTCONTEXTHANDLE
); }
558 | tSTRING
{ $$
= make_attr
(ATTR_STRING
); }
559 | tSWITCHIS
'(' expr
')' { $$
= make_attrp
(ATTR_SWITCHIS
, $3); }
560 | tSWITCHTYPE
'(' type
')' { $$
= make_attrp
(ATTR_SWITCHTYPE
, $3); }
561 | tTRANSMITAS
'(' type
')' { $$
= make_attrp
(ATTR_TRANSMITAS
, $3); }
562 | tUUID
'(' uuid_string
')' { $$
= make_attrp
(ATTR_UUID
, $3); }
563 | tV1ENUM
{ $$
= make_attr
(ATTR_V1ENUM
); }
564 | tVARARG
{ $$
= make_attr
(ATTR_VARARG
); }
565 | tVERSION
'(' version
')' { $$
= make_attrv
(ATTR_VERSION
, $3); }
566 | tWIREMARSHAL
'(' type
')' { $$
= make_attrp
(ATTR_WIREMARSHAL
, $3); }
567 | pointer_type
{ $$
= make_attrv
(ATTR_POINTERTYPE
, $1); }
572 | aSTRING
{ if
(!is_valid_uuid
($1))
573 error_loc
("invalid UUID: %s\n", $1);
574 $$
= parse_uuid
($1); }
577 callconv: tCDECL
{ $$
= $
<str
>1; }
578 | tFASTCALL
{ $$
= $
<str
>1; }
579 | tPASCAL
{ $$
= $
<str
>1; }
580 | tSTDCALL
{ $$
= $
<str
>1; }
583 cases: { $$
= NULL
; }
584 | cases case
{ $$
= append_var
( $1, $2 ); }
587 case: tCASE expr_int_const
':' union_field
{ attr_t
*a
= make_attrp
(ATTR_CASE
, append_expr
( NULL
, $2 ));
588 $$
= $4; if
(!$$
) $$
= make_var
(NULL
);
589 $$
->attrs
= append_attr
( $$
->attrs
, a
);
591 | tDEFAULT
':' union_field
{ attr_t
*a
= make_attr
(ATTR_DEFAULT
);
592 $$
= $3; if
(!$$
) $$
= make_var
(NULL
);
593 $$
->attrs
= append_attr
( $$
->attrs
, a
);
597 enums: { $$
= NULL
; }
598 | enum_list
',' { $$
= $1; }
602 enum_list: enum { if
(!$1->eval
)
603 $1->eval
= make_exprl
(EXPR_NUM
, 0 /* default for first enum entry */);
604 $$
= append_var
( NULL
, $1 );
606 | enum_list
',' enum { if
(!$3->eval
)
608 var_t
*last
= LIST_ENTRY
( list_tail
($$
), var_t
, entry
);
609 $3->eval
= make_exprl
(EXPR_NUM
, last
->eval
->cval
+ 1);
611 $$
= append_var
( $1, $3 );
615 enum: ident
'=' expr_int_const
{ $$
= reg_const
($1);
617 $$
->type
= make_int
(0);
619 | ident
{ $$
= reg_const
($1);
620 $$
->type
= make_int
(0);
624 enumdef: tENUM t_ident
'{' enums
'}' { $$
= type_new_enum
($2, $4); }
627 m_exprs: m_expr
{ $$
= append_expr
( NULL
, $1 ); }
628 | m_exprs
',' m_expr
{ $$
= append_expr
( $1, $3 ); }
632 exprs: { $$ = make_expr(EXPR_VOID); }
637 | expr_list ',' expr { LINK($3, $1); $$ = $3; }
641 m_expr: { $$
= make_expr
(EXPR_VOID
); }
645 expr: aNUM
{ $$
= make_exprl
(EXPR_NUM
, $1); }
646 | aHEXNUM
{ $$
= make_exprl
(EXPR_HEXNUM
, $1); }
647 | aDOUBLE
{ $$
= make_exprd
(EXPR_DOUBLE
, $1); }
648 | tFALSE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 0); }
649 | tNULL
{ $$
= make_exprl
(EXPR_NUM
, 0); }
650 | tTRUE
{ $$
= make_exprl
(EXPR_TRUEFALSE
, 1); }
651 | aSTRING
{ $$
= make_exprs
(EXPR_STRLIT
, $1); }
652 | aWSTRING
{ $$
= make_exprs
(EXPR_WSTRLIT
, $1); }
653 | aIDENTIFIER
{ $$
= make_exprs
(EXPR_IDENTIFIER
, $1); }
654 | expr
'?' expr
':' expr
{ $$
= make_expr3
(EXPR_COND
, $1, $3, $5); }
655 | expr LOGICALOR expr
{ $$
= make_expr2
(EXPR_LOGOR
, $1, $3); }
656 | expr LOGICALAND expr
{ $$
= make_expr2
(EXPR_LOGAND
, $1, $3); }
657 | expr
'|' expr
{ $$
= make_expr2
(EXPR_OR
, $1, $3); }
658 | expr
'^' expr
{ $$
= make_expr2
(EXPR_XOR
, $1, $3); }
659 | expr
'&' expr
{ $$
= make_expr2
(EXPR_AND
, $1, $3); }
660 | expr EQUALITY expr
{ $$
= make_expr2
(EXPR_EQUALITY
, $1, $3); }
661 | expr INEQUALITY expr
{ $$
= make_expr2
(EXPR_INEQUALITY
, $1, $3); }
662 | expr
'>' expr
{ $$
= make_expr2
(EXPR_GTR
, $1, $3); }
663 | expr
'<' expr
{ $$
= make_expr2
(EXPR_LESS
, $1, $3); }
664 | expr GREATEREQUAL expr
{ $$
= make_expr2
(EXPR_GTREQL
, $1, $3); }
665 | expr LESSEQUAL expr
{ $$
= make_expr2
(EXPR_LESSEQL
, $1, $3); }
666 | expr SHL expr
{ $$
= make_expr2
(EXPR_SHL
, $1, $3); }
667 | expr SHR expr
{ $$
= make_expr2
(EXPR_SHR
, $1, $3); }
668 | expr
'+' expr
{ $$
= make_expr2
(EXPR_ADD
, $1, $3); }
669 | expr
'-' expr
{ $$
= make_expr2
(EXPR_SUB
, $1, $3); }
670 | expr
'%' expr
{ $$
= make_expr2
(EXPR_MOD
, $1, $3); }
671 | expr
'*' expr
{ $$
= make_expr2
(EXPR_MUL
, $1, $3); }
672 | expr
'/' expr
{ $$
= make_expr2
(EXPR_DIV
, $1, $3); }
673 |
'!' expr
{ $$
= make_expr1
(EXPR_LOGNOT
, $2); }
674 |
'~' expr
{ $$
= make_expr1
(EXPR_NOT
, $2); }
675 |
'+' expr %prec POS
{ $$
= make_expr1
(EXPR_POS
, $2); }
676 |
'-' expr %prec NEG
{ $$
= make_expr1
(EXPR_NEG
, $2); }
677 |
'&' expr %prec ADDRESSOF
{ $$
= make_expr1
(EXPR_ADDRESSOF
, $2); }
678 |
'*' expr %prec PPTR
{ $$
= make_expr1
(EXPR_PPTR
, $2); }
679 | expr MEMBERPTR aIDENTIFIER
{ $$
= make_expr2
(EXPR_MEMBER
, make_expr1
(EXPR_PPTR
, $1), make_exprs
(EXPR_IDENTIFIER
, $3)); }
680 | expr
'.' aIDENTIFIER
{ $$
= make_expr2
(EXPR_MEMBER
, $1, make_exprs
(EXPR_IDENTIFIER
, $3)); }
681 |
'(' type
')' expr %prec CAST
{ $$
= make_exprt
(EXPR_CAST
, $2, $4); }
682 | tSIZEOF
'(' type
')' { $$
= make_exprt
(EXPR_SIZEOF
, $3, NULL
); }
683 | expr
'[' expr
']' { $$
= make_expr2
(EXPR_ARRAY
, $1, $3); }
684 |
'(' expr
')' { $$
= $2; }
687 expr_list_int_const: expr_int_const
{ $$
= append_expr
( NULL
, $1 ); }
688 | expr_list_int_const
',' expr_int_const
{ $$
= append_expr
( $1, $3 ); }
691 expr_int_const: expr
{ $$
= $1;
693 error_loc
("expression is not an integer constant\n");
697 expr_const: expr
{ $$
= $1;
698 if
(!$$
->is_const
&& $$
->type
!= EXPR_STRLIT
&& $$
->type
!= EXPR_WSTRLIT
)
699 error_loc
("expression is not constant\n");
703 fields: { $$
= NULL
; }
704 | fields field
{ $$
= append_var_list
($1, $2); }
707 field: m_attributes decl_spec declarator_list
';'
708 { const char *first
= LIST_ENTRY
(list_head
($3), declarator_t
, entry
)->var
->name
;
709 check_field_attrs
(first
, $1);
710 $$
= set_var_types
($1, $2, $3);
712 | m_attributes uniondef
';' { var_t
*v
= make_var
(NULL
);
713 v
->type
= $2; v
->attrs
= $1;
714 $$
= append_var
(NULL
, v
);
719 s_field
';' { $$
= $1; }
720 | attributes
';' { $$
= make_var
(NULL
); $$
->attrs
= $1; }
723 ne_union_fields: { $$
= NULL
; }
724 | ne_union_fields ne_union_field
{ $$
= append_var
( $1, $2 ); }
728 s_field
';' { $$
= $1; }
732 s_field: m_attributes decl_spec declarator
{ $$
= $3->var
;
733 $$
->attrs
= check_field_attrs
($$
->name
, $1);
734 set_type
($$
, $2, $3, FALSE
);
740 m_attributes decl_spec declarator
{ var_t
*v
= $3->var
;
741 v
->attrs
= check_function_attrs
(v
->name
, $1);
742 set_type
(v
, $2, $3, FALSE
);
749 attributes decl_spec init_declarator
752 set_type
($$
, $2, $3, FALSE
);
755 | decl_spec init_declarator
{ $$
= $2->var
;
756 set_type
($$
, $1, $2, FALSE
);
761 m_ident: { $$
= NULL
; }
765 t_ident: { $$
= NULL
; }
766 | aIDENTIFIER
{ $$
= $1; }
767 | aKNOWNTYPE
{ $$
= $1; }
770 ident: aIDENTIFIER
{ $$
= make_var
($1); }
771 /* some "reserved words" used in attributes are also used as field names in some MS IDL files */
772 | aKNOWNTYPE
{ $$
= make_var
($
<str
>1); }
775 base_type: tBYTE
{ $$
= make_builtin
($
<str
>1); }
776 | tWCHAR
{ $$
= make_builtin
($
<str
>1); }
778 | tSIGNED int_std
{ $$
= $2; $$
->sign
= 1; }
779 | tUNSIGNED int_std
{ $$
= $2; $$
->sign
= -1;
781 case RPC_FC_CHAR
: break
;
782 case RPC_FC_SMALL
: $$
->type
= RPC_FC_USMALL
; break
;
783 case RPC_FC_SHORT
: $$
->type
= RPC_FC_USHORT
; break
;
784 case RPC_FC_LONG
: $$
->type
= RPC_FC_ULONG
; break
;
786 if
($$
->name
[0] == 'h') /* hyper, as opposed to __int64 */
788 $$
= type_new_alias
($$
, "MIDL_uhyper");
795 | tUNSIGNED
{ $$
= make_int
(-1); }
796 | tFLOAT
{ $$
= make_builtin
($
<str
>1); }
797 | tSINGLE
{ $$
= find_type
("float", 0); }
798 | tDOUBLE
{ $$
= make_builtin
($
<str
>1); }
799 | tBOOLEAN
{ $$
= make_builtin
($
<str
>1); }
800 | tERRORSTATUST
{ $$
= make_builtin
($
<str
>1); }
801 | tHANDLET
{ $$
= make_builtin
($
<str
>1); }
808 int_std: tINT
{ $$
= make_builtin
($
<str
>1); }
809 | tSHORT m_int
{ $$
= make_builtin
($
<str
>1); }
810 | tSMALL
{ $$
= make_builtin
($
<str
>1); }
811 | tLONG m_int
{ $$
= make_builtin
($
<str
>1); }
812 | tHYPER m_int
{ $$
= make_builtin
($
<str
>1); }
813 | tINT64
{ $$
= make_builtin
($
<str
>1); }
814 | tCHAR
{ $$
= make_builtin
($
<str
>1); }
817 coclass: tCOCLASS aIDENTIFIER
{ $$
= make_class
($2); }
818 | tCOCLASS aKNOWNTYPE
{ $$
= find_type
($2, 0);
819 if
($$
->type
!= RPC_FC_COCLASS
)
820 error_loc
("%s was not declared a coclass at %s:%d\n",
821 $2, $$
->loc_info.input_name
,
822 $$
->loc_info.line_number
);
826 coclasshdr: attributes coclass
{ $$
= $2;
828 $$
->attrs
= check_coclass_attrs
($2->name
, $1);
832 coclassdef: coclasshdr
'{' coclass_ints
'}' semicolon_opt
833 { $$
= type_coclass_define
($1, $3); }
836 coclass_ints: { $$
= NULL
; }
837 | coclass_ints coclass_int
{ $$
= append_ifref
( $1, $2 ); }
841 m_attributes interfacedec
{ $$
= make_ifref
($2); $$
->attrs
= $1; }
844 dispinterface: tDISPINTERFACE aIDENTIFIER
{ $$
= get_type
(RPC_FC_IP
, $2, 0); }
845 | tDISPINTERFACE aKNOWNTYPE
{ $$
= get_type
(RPC_FC_IP
, $2, 0); }
848 dispinterfacehdr: attributes dispinterface
{ attr_t
*attrs
;
849 is_object_interface
= TRUE
;
852 attrs
= make_attr
(ATTR_DISPINTERFACE
);
853 $$
->attrs
= append_attr
( check_dispiface_attrs
($2->name
, $1), attrs
);
858 dispint_props: tPROPERTIES
':' { $$
= NULL
; }
859 | dispint_props s_field
';' { $$
= append_var
( $1, $2 ); }
862 dispint_meths: tMETHODS
':' { $$
= NULL
; }
863 | dispint_meths funcdef
';' { $$
= append_func
( $1, $2 ); }
866 dispinterfacedef: dispinterfacehdr
'{'
870 type_dispinterface_define
($$
, $3, $4);
873 '{' interface
';' '}' { $$
= $1;
874 type_dispinterface_define_from_iface
($$
, $3);
878 inherit: { $$
= NULL
; }
879 |
':' aKNOWNTYPE
{ $$
= find_type_or_error2
($2, 0); }
882 interface: tINTERFACE aIDENTIFIER
{ $$
= get_type
(RPC_FC_IP
, $2, 0); }
883 | tINTERFACE aKNOWNTYPE
{ $$
= get_type
(RPC_FC_IP
, $2, 0); }
886 interfacehdr: attributes interface
{ $$.interface
= $2;
887 $$.old_pointer_default
= pointer_default
;
888 if
(is_attr
($1, ATTR_POINTERDEFAULT
))
889 pointer_default
= get_attrv
($1, ATTR_POINTERDEFAULT
);
890 is_object_interface
= is_object
($1);
892 $2->attrs
= check_iface_attrs
($2->name
, $1);
897 interfacedef: interfacehdr inherit
898 '{' int_statements
'}' semicolon_opt
{ $$
= $1.interface
;
899 type_interface_define
($$
, $2, $4);
900 pointer_default
= $1.old_pointer_default
;
902 /* MIDL is able to import the definition of a base class from inside the
903 * definition of a derived class, I'll try to support it with this rule */
904 | interfacehdr
':' aIDENTIFIER
905 '{' import int_statements
'}'
906 semicolon_opt
{ $$
= $1.interface
;
907 type_interface_define
($$
, find_type_or_error2
($3, 0), $6);
908 pointer_default
= $1.old_pointer_default
;
910 | dispinterfacedef semicolon_opt
{ $$
= $1; }
914 interface
';' { $$
= $1; }
915 | dispinterface
';' { $$
= $1; }
918 module: tMODULE aIDENTIFIER
{ $$
= type_new_module
($2); }
919 | tMODULE aKNOWNTYPE
{ $$
= type_new_module
($2); }
922 modulehdr: attributes module
{ $$
= $2;
923 $$
->attrs
= check_module_attrs
($2->name
, $1);
927 moduledef: modulehdr
'{' int_statements
'}'
928 semicolon_opt
{ $$
= $1;
929 type_module_define
($$
, $3);
934 tEXTERN
{ $$
= STG_EXTERN
; }
935 | tSTATIC
{ $$
= STG_STATIC
; }
936 | tREGISTER
{ $$
= STG_REGISTER
; }
940 tINLINE
{ $$
= make_attr
(ATTR_INLINE
); }
944 tCONST
{ $$
= make_attr
(ATTR_CONST
); }
947 m_type_qual_list: { $$
= NULL
; }
948 | m_type_qual_list type_qualifier
{ $$
= append_attr
($1, $2); }
951 decl_spec: type m_decl_spec_no_type
{ $$
= make_decl_spec
($1, $2, NULL
, NULL
, STG_NONE
); }
952 | decl_spec_no_type type m_decl_spec_no_type
953 { $$
= make_decl_spec
($2, $1, $3, NULL
, STG_NONE
); }
956 m_decl_spec_no_type: { $$
= NULL
; }
961 type_qualifier m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, $1, STG_NONE
); }
962 | function_specifier m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, $1, STG_NONE
); }
963 | storage_cls_spec m_decl_spec_no_type
{ $$
= make_decl_spec
(NULL
, $2, NULL
, NULL
, $1); }
967 '*' m_type_qual_list declarator %prec PPTR
968 { $$
= $3; $$
->type
= append_ptrchain_type
($$
->type
, type_new_pointer
(NULL
, $2)); }
969 | callconv declarator
{ $$
= $2; $$
->type
->attrs
= append_attr
($$
->type
->attrs
, make_attrp
(ATTR_CALLCONV
, $1)); }
974 ident
{ $$
= make_declarator
($1); }
975 |
'(' declarator
')' { $$
= $2; }
976 | direct_declarator array
{ $$
= $1; $$
->array
= append_array
($$
->array
, $2); }
977 | direct_declarator
'(' m_args
')' { $$
= $1;
978 $$
->func_type
= append_ptrchain_type
($$
->type
, type_new_function
($3));
984 declarator
{ $$
= append_declarator
( NULL
, $1 ); }
985 | declarator_list
',' declarator
{ $$
= append_declarator
( $1, $3 ); }
989 declarator
{ $$
= $1; }
990 | declarator
'=' expr_const
{ $$
= $1; $1->var
->eval
= $3; }
994 tREF
{ $$
= RPC_FC_RP
; }
995 | tUNIQUE
{ $$
= RPC_FC_UP
; }
996 | tPTR
{ $$
= RPC_FC_FP
; }
999 structdef: tSTRUCT t_ident
'{' fields
'}' { $$
= type_new_struct
($2, TRUE
, $4); }
1002 type: tVOID
{ $$
= find_type_or_error
("void", 0); }
1003 | aKNOWNTYPE
{ $$
= find_type_or_error
($1, 0); }
1004 | base_type
{ $$
= $1; }
1005 | enumdef
{ $$
= $1; }
1006 | tENUM aIDENTIFIER
{ $$
= find_type_or_error2
($2, tsENUM
); }
1007 | structdef
{ $$
= $1; }
1008 | tSTRUCT aIDENTIFIER
{ $$
= type_new_struct
($2, FALSE
, NULL
); }
1009 | uniondef
{ $$
= $1; }
1010 | tUNION aIDENTIFIER
{ $$
= find_type_or_error2
($2, tsUNION
); }
1011 | tSAFEARRAY
'(' type
')' { $$
= make_safearray
($3); }
1014 typedef: tTYPEDEF m_attributes decl_spec declarator_list
1015 { reg_typedefs
($3, $4, check_typedef_attrs
($2));
1016 $$
= make_statement_typedef
($4);
1020 uniondef: tUNION t_ident
'{' ne_union_fields
'}'
1021 { $$
= type_new_nonencapsulated_union
($2, $4); }
1023 tSWITCH
'(' s_field
')'
1024 m_ident
'{' cases
'}' { $$
= type_new_encapsulated_union
($2, $5, $7, $9); }
1028 aNUM
{ $$
= MAKEVERSION
($1, 0); }
1029 | aNUM
'.' aNUM
{ $$
= MAKEVERSION
($1, $3); }
1034 static void decl_builtin
(const char *name
, unsigned char type
)
1036 type_t
*t
= make_type
(type
, NULL
);
1037 t
->name
= xstrdup
(name
);
1038 reg_type
(t
, name
, 0);
1041 static type_t
*make_builtin
(char *name
)
1043 /* NAME is strdup'd in the lexer */
1044 type_t
*t
= duptype
(find_type_or_error
(name
, 0), 0);
1049 static type_t
*make_int
(int sign
)
1051 type_t
*t
= duptype
(find_type_or_error
("int", 0), 1);
1055 t
->type
= t
->type
== RPC_FC_LONG ? RPC_FC_ULONG
: RPC_FC_USHORT
;
1060 void init_types
(void)
1062 decl_builtin
("void", 0);
1063 decl_builtin
("byte", RPC_FC_BYTE
);
1064 decl_builtin
("wchar_t", RPC_FC_WCHAR
);
1065 decl_builtin
("int", RPC_FC_LONG
); /* win32 */
1066 decl_builtin
("short", RPC_FC_SHORT
);
1067 decl_builtin
("small", RPC_FC_SMALL
);
1068 decl_builtin
("long", RPC_FC_LONG
);
1069 decl_builtin
("hyper", RPC_FC_HYPER
);
1070 decl_builtin
("__int64", RPC_FC_HYPER
);
1071 decl_builtin
("char", RPC_FC_CHAR
);
1072 decl_builtin
("float", RPC_FC_FLOAT
);
1073 decl_builtin
("double", RPC_FC_DOUBLE
);
1074 decl_builtin
("boolean", RPC_FC_BYTE
);
1075 decl_builtin
("error_status_t", RPC_FC_ERROR_STATUS_T
);
1076 decl_builtin
("handle_t", RPC_FC_BIND_PRIMITIVE
);
1079 static str_list_t
*append_str
(str_list_t
*list
, char *str
)
1081 struct str_list_entry_t
*entry
;
1083 if
(!str
) return list
;
1086 list
= xmalloc
( sizeof
(*list
) );
1089 entry
= xmalloc
( sizeof
(*entry
) );
1091 list_add_tail
( list
, &entry
->entry
);
1095 static attr_list_t
*append_attr
(attr_list_t
*list
, attr_t
*attr
)
1097 attr_t
*attr_existing
;
1098 if
(!attr
) return list
;
1101 list
= xmalloc
( sizeof
(*list
) );
1104 LIST_FOR_EACH_ENTRY
(attr_existing
, list
, attr_t
, entry
)
1105 if
(attr_existing
->type
== attr
->type
)
1107 parser_warning
("duplicate attribute %s\n", get_attr_display_name
(attr
->type
));
1108 /* use the last attribute, like MIDL does */
1109 list_remove
(&attr_existing
->entry
);
1112 list_add_tail
( list
, &attr
->entry
);
1116 static attr_list_t
*move_attr
(attr_list_t
*dst
, attr_list_t
*src
, enum attr_type type
)
1119 if
(!src
) return dst
;
1120 LIST_FOR_EACH_ENTRY
(attr
, src
, attr_t
, entry
)
1121 if
(attr
->type
== type
)
1123 list_remove
(&attr
->entry
);
1124 return append_attr
(dst
, attr
);
1129 static attr_list_t
*append_attr_list
(attr_list_t
*new_list
, attr_list_t
*old_list
)
1133 if
(!old_list
) return new_list
;
1135 while
((entry
= list_head
(old_list
)))
1137 attr_t
*attr
= LIST_ENTRY
(entry
, attr_t
, entry
);
1139 new_list
= append_attr
(new_list
, attr
);
1144 static attr_list_t
*dupattrs
(const attr_list_t
*list
)
1146 attr_list_t
*new_list
;
1149 if
(!list
) return NULL
;
1151 new_list
= xmalloc
( sizeof
(*list
) );
1152 list_init
( new_list
);
1153 LIST_FOR_EACH_ENTRY
(attr
, list
, const attr_t
, entry
)
1155 attr_t
*new_attr
= xmalloc
(sizeof
(*new_attr
));
1157 list_add_tail
(new_list
, &new_attr
->entry
);
1162 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
)
1164 decl_spec_t
*declspec
= left ? left
: right
;
1167 declspec
= xmalloc
(sizeof
(*declspec
));
1168 declspec
->type
= NULL
;
1169 declspec
->attrs
= NULL
;
1170 declspec
->stgclass
= STG_NONE
;
1172 declspec
->type
= type
;
1173 if
(left
&& declspec
!= left
)
1175 declspec
->attrs
= append_attr_list
(declspec
->attrs
, left
->attrs
);
1176 if
(declspec
->stgclass
== STG_NONE
)
1177 declspec
->stgclass
= left
->stgclass
;
1178 else if
(left
->stgclass
!= STG_NONE
)
1179 error_loc
("only one storage class can be specified\n");
1180 assert
(!left
->type
);
1183 if
(right
&& declspec
!= right
)
1185 declspec
->attrs
= append_attr_list
(declspec
->attrs
, right
->attrs
);
1186 if
(declspec
->stgclass
== STG_NONE
)
1187 declspec
->stgclass
= right
->stgclass
;
1188 else if
(right
->stgclass
!= STG_NONE
)
1189 error_loc
("only one storage class can be specified\n");
1190 assert
(!right
->type
);
1194 declspec
->attrs
= append_attr
(declspec
->attrs
, attr
);
1195 if
(declspec
->stgclass
== STG_NONE
)
1196 declspec
->stgclass
= stgclass
;
1197 else if
(stgclass
!= STG_NONE
)
1198 error_loc
("only one storage class can be specified\n");
1200 /* apply attributes to type */
1201 if
(type
&& declspec
->attrs
)
1204 declspec
->type
= duptype
(type
, 1);
1205 attrs
= dupattrs
(type
->attrs
);
1206 declspec
->type
->attrs
= append_attr_list
(attrs
, declspec
->attrs
);
1207 declspec
->attrs
= NULL
;
1213 static attr_t
*make_attr
(enum attr_type type
)
1215 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1221 static attr_t
*make_attrv
(enum attr_type type
, unsigned long val
)
1223 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1229 static attr_t
*make_attrp
(enum attr_type type
, void *val
)
1231 attr_t
*a
= xmalloc
(sizeof
(attr_t
));
1237 static expr_list_t
*append_expr
(expr_list_t
*list
, expr_t
*expr
)
1239 if
(!expr
) return list
;
1242 list
= xmalloc
( sizeof
(*list
) );
1245 list_add_tail
( list
, &expr
->entry
);
1249 static array_dims_t
*append_array
(array_dims_t
*list
, expr_t
*expr
)
1251 if
(!expr
) return list
;
1254 list
= xmalloc
( sizeof
(*list
) );
1257 list_add_tail
( list
, &expr
->entry
);
1261 static struct list type_pool
= LIST_INIT
(type_pool
);
1268 type_t
*alloc_type
(void)
1270 type_pool_node_t
*node
= xmalloc
(sizeof
*node
);
1271 list_add_tail
(&type_pool
, &node
->link
);
1275 void set_all_tfswrite
(int val
)
1277 type_pool_node_t
*node
;
1278 LIST_FOR_EACH_ENTRY
(node
, &type_pool
, type_pool_node_t
, link
)
1279 node
->data.tfswrite
= val
;
1282 void clear_all_offsets
(void)
1284 type_pool_node_t
*node
;
1285 LIST_FOR_EACH_ENTRY
(node
, &type_pool
, type_pool_node_t
, link
)
1286 node
->data.typestring_offset
= node
->data.ptrdesc
= 0;
1289 type_t
*make_type
(unsigned char type
, type_t
*ref
)
1291 type_t
*t
= alloc_type
();
1297 memset
(&t
->details
, 0, sizeof
(t
->details
));
1298 t
->typestring_offset
= 0;
1300 t
->declarray
= FALSE
;
1301 t
->ignore
= (parse_only
!= 0);
1305 t
->user_types_registered
= FALSE
;
1306 t
->tfswrite
= FALSE
;
1308 t
->is_alias
= FALSE
;
1309 t
->typelib_idx
= -1;
1310 init_loc_info
(&t
->loc_info
);
1314 static type_t
*type_new_enum
(char *name
, var_list_t
*enums
)
1316 type_t
*t
= get_type
(RPC_FC_ENUM16
, name
, tsENUM
);
1319 t
->details.enumeration
= xmalloc
(sizeof
(*t
->details.enumeration
));
1320 t
->details.enumeration
->enums
= enums
;
1323 t
->details.enumeration
= NULL
;
1328 static type_t
*type_new_struct
(char *name
, int defined
, var_list_t
*fields
)
1330 type_t
*tag_type
= name ? find_type
(name
, tsSTRUCT
) : NULL
;
1331 type_t
*t
= make_type
(RPC_FC_STRUCT
, NULL
);
1333 if
(defined ||
(tag_type
&& tag_type
->details.structure
))
1335 if
(tag_type
&& tag_type
->details.structure
)
1337 t
->details.structure
= tag_type
->details.structure
;
1338 t
->type
= tag_type
->type
;
1342 t
->details.structure
= xmalloc
(sizeof
(*t
->details.structure
));
1343 t
->details.structure
->fields
= fields
;
1350 reg_type
(t
, name
, tsSTRUCT
);
1357 static type_t
*type_new_nonencapsulated_union
(char *name
, var_list_t
*fields
)
1359 type_t
*t
= get_type
(RPC_FC_NON_ENCAPSULATED_UNION
, name
, tsUNION
);
1360 t
->details.structure
= xmalloc
(sizeof
(*t
->details.structure
));
1361 t
->details.structure
->fields
= fields
;
1366 static type_t
*type_new_encapsulated_union
(char *name
, var_t
*switch_field
, var_t
*union_field
, var_list_t
*cases
)
1368 type_t
*t
= get_type
(RPC_FC_ENCAPSULATED_UNION
, name
, tsUNION
);
1369 if
(!union_field
) union_field
= make_var
( xstrdup
("tagged_union") );
1370 union_field
->type
= make_type
(RPC_FC_NON_ENCAPSULATED_UNION
, NULL
);
1371 union_field
->type
->details.structure
= xmalloc
(sizeof
(*union_field
->type
->details.structure
));
1372 union_field
->type
->details.structure
->fields
= cases
;
1373 union_field
->type
->defined
= TRUE
;
1374 t
->details.structure
= xmalloc
(sizeof
(*t
->details.structure
));
1375 t
->details.structure
->fields
= append_var
( NULL
, switch_field
);
1376 t
->details.structure
->fields
= append_var
( t
->details.structure
->fields
, union_field
);
1381 static void type_function_add_head_arg
(type_t
*type
, var_t
*arg
)
1383 if
(!type
->details.function
->args
)
1385 type
->details.function
->args
= xmalloc
( sizeof
(*type
->details.function
->args
) );
1386 list_init
( type
->details.function
->args
);
1388 list_add_head
( type
->details.function
->args
, &arg
->entry
);
1391 static type_t
*append_ptrchain_type
(type_t
*ptrchain
, type_t
*type
)
1393 type_t
*ptrchain_type
;
1396 for
(ptrchain_type
= ptrchain
; ptrchain_type
->ref
; ptrchain_type
= ptrchain_type
->ref
)
1398 ptrchain_type
->ref
= type
;
1402 static void set_type
(var_t
*v
, decl_spec_t
*decl_spec
, const declarator_t
*decl
,
1405 expr_list_t
*sizes
= get_attrp
(v
->attrs
, ATTR_SIZEIS
);
1406 expr_list_t
*lengs
= get_attrp
(v
->attrs
, ATTR_LENGTHIS
);
1410 array_dims_t
*arr
= decl ? decl
->array
: NULL
;
1411 type_t
*func_type
= decl ? decl
->func_type
: NULL
;
1412 type_t
*type
= decl_spec
->type
;
1414 if
(is_attr
(type
->attrs
, ATTR_INLINE
))
1417 error_loc
("inline attribute applied to non-function type\n");
1421 /* move inline attribute from return type node to function node */
1422 for
(t
= func_type
; is_ptr
(t
); t
= type_pointer_get_ref
(t
))
1424 t
->attrs
= move_attr
(t
->attrs
, type
->attrs
, ATTR_INLINE
);
1428 /* add type onto the end of the pointers in pident->type */
1429 v
->type
= append_ptrchain_type
(decl ? decl
->type
: NULL
, type
);
1430 v
->stgclass
= decl_spec
->stgclass
;
1432 /* the highest level of pointer specified should default to the var's ptr attr
1433 * or (RPC_FC_RP if not specified and it's a top level ptr), not
1434 * pointer_default so we need to fix that up here */
1437 int ptr_attr
= get_attrv
(v
->attrs
, ATTR_POINTERTYPE
);
1438 const type_t
*ptr
= NULL
;
1439 /* pointer attributes on the left side of the type belong to the function
1440 * pointer, if one is being declared */
1441 type_t
**pt
= func_type ?
&func_type
: &v
->type
;
1442 for
(ptr
= *pt
; ptr
&& !ptr_attr
; )
1444 ptr_attr
= get_attrv
(ptr
->attrs
, ATTR_POINTERTYPE
);
1445 if
(!ptr_attr
&& type_is_alias
(ptr
))
1446 ptr
= type_alias_get_aliasee
(ptr
);
1450 if
(ptr
&& is_ptr
(ptr
) && (ptr_attr || top
))
1452 /* duplicate type to avoid changing original type */
1453 *pt
= duptype
(*pt
, 1);
1454 (*pt
)->type
= ptr_attr ? ptr_attr
: RPC_FC_RP
;
1457 error_loc
("%s: pointer attribute applied to non-pointer type\n", v
->name
);
1460 if
(is_attr
(v
->attrs
, ATTR_STRING
) && !is_ptr
(v
->type
) && !arr
)
1461 error_loc
("'%s': [string] attribute applied to non-pointer, non-array type\n",
1464 if
(is_attr
(v
->attrs
, ATTR_V1ENUM
))
1466 if
(v
->type
->type
== RPC_FC_ENUM16
)
1467 v
->type
->type
= RPC_FC_ENUM32
;
1469 error_loc
("'%s': [v1_enum] attribute applied to non-enum type\n", v
->name
);
1474 if
(arr
) LIST_FOR_EACH_ENTRY_REV
(dim
, arr
, expr_t
, entry
)
1477 error_loc
("%s: only the first array dimension can be unspecified\n", v
->name
);
1482 error_loc
("%s: array dimension must be positive\n", v
->name
);
1484 /* FIXME: should use a type_memsize that allows us to pass in a pointer size */
1487 unsigned int align
= 0;
1488 size_t size
= type_memsize
(v
->type
, &align
);
1490 if
(0xffffffffuL
/ size
< (unsigned long) dim
->cval
)
1491 error_loc
("%s: total array size is too large\n", v
->name
);
1497 *ptype
= type_new_array
(NULL
, *ptype
, TRUE
,
1498 dim
->is_const ? dim
->cval
: 0,
1499 dim
->is_const ? NULL
: dim
, NULL
);
1503 if
(sizes
) LIST_FOR_EACH_ENTRY
(dim
, sizes
, expr_t
, entry
)
1505 if
(dim
->type
!= EXPR_VOID
)
1507 if
(is_array
(*ptype
))
1509 if
(type_array_get_conformance
(*ptype
)->is_const
)
1510 error_loc
("%s: cannot specify size_is for a fixed sized array\n", v
->name
);
1512 *ptype
= type_new_array
((*ptype
)->name
,
1513 type_array_get_element
(*ptype
), TRUE
,
1516 else if
(is_ptr
(*ptype
))
1517 *ptype
= type_new_array
((*ptype
)->name
, type_pointer_get_ref
(*ptype
), FALSE
,
1520 error_loc
("%s: size_is attribute applied to illegal type\n", v
->name
);
1523 ptype
= &(*ptype
)->ref
;
1525 error_loc
("%s: too many expressions in size_is attribute\n", v
->name
);
1529 if
(lengs
) LIST_FOR_EACH_ENTRY
(dim
, lengs
, expr_t
, entry
)
1531 if
(dim
->type
!= EXPR_VOID
)
1533 if
(is_array
(*ptype
))
1535 *ptype
= type_new_array
((*ptype
)->name
,
1536 type_array_get_element
(*ptype
),
1537 (*ptype
)->declarray
,
1538 type_array_get_dim
(*ptype
),
1539 type_array_get_conformance
(*ptype
),
1543 error_loc
("%s: length_is attribute applied to illegal type\n", v
->name
);
1546 ptype
= &(*ptype
)->ref
;
1548 error_loc
("%s: too many expressions in length_is attribute\n", v
->name
);
1551 /* v->type is currently pointing to the type on the left-side of the
1552 * declaration, so we need to fix this up so that it is the return type of the
1553 * function and make v->type point to the function side of the declaration */
1557 type_t
*return_type
= v
->type
;
1558 v
->type
= func_type
;
1559 for
(ft
= v
->type
; is_ptr
(ft
); ft
= type_pointer_get_ref
(ft
))
1561 assert
(ft
->type
== RPC_FC_FUNCTION
);
1562 ft
->ref
= return_type
;
1563 /* move calling convention attribute, if present, from pointer nodes to
1565 for
(t
= v
->type
; is_ptr
(t
); t
= type_pointer_get_ref
(t
))
1566 ft
->attrs
= move_attr
(ft
->attrs
, t
->attrs
, ATTR_CALLCONV
);
1567 if
(is_object_interface
&& !is_attr
(ft
->attrs
, ATTR_CALLCONV
))
1569 static char *stdmethodcalltype
;
1570 if
(!stdmethodcalltype
) stdmethodcalltype
= strdup
("STDMETHODCALLTYPE");
1571 ft
->attrs
= append_attr
(NULL
, make_attrp
(ATTR_CALLCONV
, stdmethodcalltype
));
1577 for
(t
= v
->type
; is_ptr
(t
); t
= type_pointer_get_ref
(t
))
1578 if
(is_attr
(t
->attrs
, ATTR_CALLCONV
))
1579 error_loc
("calling convention applied to non-function-pointer type\n");
1583 static var_list_t
*set_var_types
(attr_list_t
*attrs
, decl_spec_t
*decl_spec
, declarator_list_t
*decls
)
1585 declarator_t
*decl
, *next
;
1586 var_list_t
*var_list
= NULL
;
1588 LIST_FOR_EACH_ENTRY_SAFE
( decl
, next
, decls
, declarator_t
, entry
)
1590 var_t
*var
= decl
->var
;
1593 set_type
(var
, decl_spec
, decl
, 0);
1594 var_list
= append_var
(var_list
, var
);
1600 static ifref_list_t
*append_ifref
(ifref_list_t
*list
, ifref_t
*iface
)
1602 if
(!iface
) return list
;
1605 list
= xmalloc
( sizeof
(*list
) );
1608 list_add_tail
( list
, &iface
->entry
);
1612 static ifref_t
*make_ifref
(type_t
*iface
)
1614 ifref_t
*l
= xmalloc
(sizeof
(ifref_t
));
1620 static var_list_t
*append_var
(var_list_t
*list
, var_t
*var
)
1622 if
(!var
) return list
;
1625 list
= xmalloc
( sizeof
(*list
) );
1628 list_add_tail
( list
, &var
->entry
);
1632 static var_list_t
*append_var_list
(var_list_t
*list
, var_list_t
*vars
)
1634 if
(!vars
) return list
;
1637 list
= xmalloc
( sizeof
(*list
) );
1640 list_move_tail
( list
, vars
);
1644 static var_t
*make_var
(char *name
)
1646 var_t
*v
= xmalloc
(sizeof
(var_t
));
1651 v
->stgclass
= STG_NONE
;
1652 init_loc_info
(&v
->loc_info
);
1656 static declarator_list_t
*append_declarator
(declarator_list_t
*list
, declarator_t
*d
)
1658 if
(!d
) return list
;
1660 list
= xmalloc
(sizeof
(*list
));
1663 list_add_tail
(list
, &d
->entry
);
1667 static declarator_t
*make_declarator
(var_t
*var
)
1669 declarator_t
*d
= xmalloc
(sizeof
(*d
));
1672 d
->func_type
= NULL
;
1677 static func_list_t
*append_func
(func_list_t
*list
, func_t
*func
)
1679 if
(!func
) return list
;
1682 list
= xmalloc
( sizeof
(*list
) );
1685 list_add_tail
( list
, &func
->entry
);
1689 static func_t
*make_func
(var_t
*def
)
1691 func_t
*f
= xmalloc
(sizeof
(func_t
));
1696 static type_t
*make_class
(char *name
)
1698 type_t
*c
= make_type
(RPC_FC_COCLASS
, NULL
);
1703 static type_t
*make_safearray
(type_t
*type
)
1705 type_t
*sa
= find_type_or_error
("SAFEARRAY", 0);
1707 return make_type
(pointer_default
, sa
);
1710 static typelib_t
*make_library
(const char *name
, const attr_list_t
*attrs
)
1712 typelib_t
*typelib
= xmalloc
(sizeof
(*typelib
));
1713 typelib
->name
= xstrdup
(name
);
1714 typelib
->filename
= NULL
;
1715 typelib
->attrs
= attrs
;
1716 list_init
( &typelib
->importlibs
);
1722 static int hash_ident
(const char *name
)
1724 const char *p
= name
;
1726 /* a simple sum hash is probably good enough */
1731 return sum
& (HASHMAX
-1);
1734 /***** type repository *****/
1743 struct rtype
*type_hash
[HASHMAX
];
1745 static type_t
*reg_type
(type_t
*type
, const char *name
, int t
)
1750 error_loc
("registering named type without name\n");
1753 hash
= hash_ident
(name
);
1754 nt
= xmalloc
(sizeof
(struct rtype
));
1758 nt
->next
= type_hash
[hash
];
1759 type_hash
[hash
] = nt
;
1760 if
((t
== tsSTRUCT || t
== tsUNION
))
1761 fix_incomplete_types
(type
);
1765 static int is_incomplete
(const type_t
*t
)
1767 return
!t
->defined
&& (is_struct
(t
->type
) || is_union
(t
->type
));
1770 static void add_incomplete
(type_t
*t
)
1772 struct typenode
*tn
= xmalloc
(sizeof
*tn
);
1774 list_add_tail
(&incomplete_types
, &tn
->entry
);
1777 static void fix_type
(type_t
*t
)
1779 if
(type_is_alias
(t
) && is_incomplete
(t
)) {
1780 type_t
*ot
= type_alias_get_aliasee
(t
);
1782 if
(is_struct
(ot
->type
) || is_union
(ot
->type
))
1783 t
->details.structure
= ot
->details.structure
;
1784 t
->defined
= ot
->defined
;
1788 static void fix_incomplete
(void)
1790 struct typenode
*tn
, *next
;
1792 LIST_FOR_EACH_ENTRY_SAFE
(tn
, next
, &incomplete_types
, struct typenode
, entry
) {
1794 list_remove
(&tn
->entry
);
1799 static void fix_incomplete_types
(type_t
*complete_type
)
1801 struct typenode
*tn
, *next
;
1803 LIST_FOR_EACH_ENTRY_SAFE
(tn
, next
, &incomplete_types
, struct typenode
, entry
)
1805 if
(((is_struct
(complete_type
->type
) && is_struct
(tn
->type
->type
)) ||
1806 (is_union
(complete_type
->type
) && is_union
(tn
->type
->type
))) &&
1807 !strcmp
(complete_type
->name
, tn
->type
->name
))
1809 tn
->type
->details.structure
= complete_type
->details.structure
;
1810 tn
->type
->type
= complete_type
->type
;
1811 list_remove
(&tn
->entry
);
1817 static type_t
*reg_typedefs
(decl_spec_t
*decl_spec
, declarator_list_t
*decls
, attr_list_t
*attrs
)
1819 const declarator_t
*decl
;
1820 int is_str
= is_attr
(attrs
, ATTR_STRING
);
1821 type_t
*type
= decl_spec
->type
;
1825 type_t
*t
= decl_spec
->type
;
1829 t
= type_pointer_get_ref
(t
);
1832 if
(c
!= RPC_FC_CHAR
&& c
!= RPC_FC_BYTE
&& c
!= RPC_FC_WCHAR
)
1834 decl
= LIST_ENTRY
( list_head
( decls
), const declarator_t
, entry
);
1835 error_loc
("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays\n",
1840 /* We must generate names for tagless enum, struct or union.
1841 Typedef-ing a tagless enum, struct or union means we want the typedef
1842 to be included in a library hence the public attribute. */
1843 if
((type
->type
== RPC_FC_ENUM16 || type
->type
== RPC_FC_ENUM32 ||
1844 is_struct
(type
->type
) || is_union
(type
->type
)) &&
1845 !type
->name
&& !parse_only
)
1847 if
(! is_attr
(attrs
, ATTR_PUBLIC
))
1848 attrs
= append_attr
( attrs
, make_attr
(ATTR_PUBLIC
) );
1849 type
->name
= gen_name
();
1851 else if
(is_attr
(attrs
, ATTR_UUID
) && !is_attr
(attrs
, ATTR_PUBLIC
))
1852 attrs
= append_attr
( attrs
, make_attr
(ATTR_PUBLIC
) );
1854 LIST_FOR_EACH_ENTRY
( decl
, decls
, const declarator_t
, entry
)
1856 var_t
*name
= decl
->var
;
1861 cur
= find_type
(name
->name
, 0);
1863 error_loc
("%s: redefinition error; original definition was at %s:%d\n",
1864 cur
->name
, cur
->loc_info.input_name
,
1865 cur
->loc_info.line_number
);
1867 /* set the attributes to allow set_type to do some checks on them */
1868 name
->attrs
= attrs
;
1869 set_type
(name
, decl_spec
, decl
, 0);
1870 cur
= type_new_alias
(name
->type
, name
->name
);
1873 if
(is_incomplete
(cur
))
1874 add_incomplete
(cur
);
1875 reg_type
(cur
, cur
->name
, 0);
1881 type_t
*find_type
(const char *name
, int t
)
1883 struct rtype
*cur
= type_hash
[hash_ident
(name
)];
1884 while
(cur
&& (cur
->t
!= t || strcmp
(cur
->name
, name
)))
1886 return cur ? cur
->type
: NULL
;
1889 static type_t
*find_type_or_error
(const char *name
, int t
)
1891 type_t
*type
= find_type
(name
, t
);
1893 error_loc
("type '%s' not found\n", name
);
1899 static type_t
*find_type_or_error2
(char *name
, int t
)
1901 type_t
*tp
= find_type_or_error
(name
, t
);
1906 int is_type
(const char *name
)
1908 return find_type
(name
, 0) != NULL
;
1911 static type_t
*get_type
(unsigned char type
, char *name
, int t
)
1915 tp
= find_type
(name
, t
);
1921 tp
= make_type
(type
, NULL
);
1923 if
(!name
) return tp
;
1924 return reg_type
(tp
, name
, t
);
1927 /***** constant repository *****/
1932 struct rconst
*next
;
1935 struct rconst
*const_hash
[HASHMAX
];
1937 static var_t
*reg_const
(var_t
*var
)
1942 error_loc
("registering constant without name\n");
1945 hash
= hash_ident
(var
->name
);
1946 nc
= xmalloc
(sizeof
(struct rconst
));
1947 nc
->name
= var
->name
;
1949 nc
->next
= const_hash
[hash
];
1950 const_hash
[hash
] = nc
;
1954 var_t
*find_const
(const char *name
, int f
)
1956 struct rconst
*cur
= const_hash
[hash_ident
(name
)];
1957 while
(cur
&& strcmp
(cur
->name
, name
))
1960 if
(f
) error_loc
("constant '%s' not found\n", name
);
1966 static char *gen_name
(void)
1968 static const char format
[] = "__WIDL_%s_generated_name_%08lX";
1969 static unsigned long n
= 0;
1970 static const char *file_id
;
1976 char *dst
= dup_basename
(input_name
, ".idl");
1980 if
(! isalnum
((unsigned char) *dst
))
1983 size
= sizeof format
- 7 + strlen
(file_id
) + 8;
1986 name
= xmalloc
(size
);
1987 sprintf
(name
, format
, file_id
, n
++);
1993 unsigned int dce_compatible
: 1;
1994 unsigned int acf
: 1;
1995 unsigned int on_interface
: 1;
1996 unsigned int on_function
: 1;
1997 unsigned int on_arg
: 1;
1998 unsigned int on_type
: 1;
1999 unsigned int on_enum
: 1;
2000 unsigned int on_struct
: 1;
2001 unsigned int on_union
: 1;
2002 unsigned int on_field
: 1;
2003 unsigned int on_library
: 1;
2004 unsigned int on_dispinterface
: 1;
2005 unsigned int on_module
: 1;
2006 unsigned int on_coclass
: 1;
2007 const char *display_name
;
2010 struct allowed_attr allowed_attr
[] =
2012 /* attr { D ACF I Fn ARG T En St Un Fi L DI M C <display name> } */
2013 /* ATTR_AGGREGATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "aggregatable" },
2014 /* ATTR_APPOBJECT */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "appobject" },
2015 /* ATTR_ASYNC */ { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "async" },
2016 /* ATTR_AUTO_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "auto_handle" },
2017 /* ATTR_BINDABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "bindable" },
2018 /* ATTR_BROADCAST */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "broadcast" },
2019 /* ATTR_CALLAS */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "call_as" },
2020 /* ATTR_CALLCONV */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
},
2021 /* ATTR_CASE */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "case" },
2022 /* ATTR_CONST */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "const" },
2023 /* ATTR_CONTEXTHANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "context_handle" },
2024 /* ATTR_CONTROL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, "control" },
2025 /* ATTR_DEFAULT */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, "default" },
2026 /* ATTR_DEFAULTCOLLELEM */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultcollelem" },
2027 /* ATTR_DEFAULTVALUE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultvalue" },
2028 /* ATTR_DEFAULTVTABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "defaultvtable" },
2029 /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
},
2030 /* ATTR_DISPLAYBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "displaybind" },
2031 /* ATTR_DLLNAME */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, "dllname" },
2032 /* ATTR_DUAL */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "dual" },
2033 /* ATTR_ENDPOINT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "endpoint" },
2034 /* ATTR_ENTRY */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "entry" },
2035 /* ATTR_EXPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "explicit_handle" },
2036 /* ATTR_HANDLE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "handle" },
2037 /* ATTR_HELPCONTEXT */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpcontext" },
2038 /* ATTR_HELPFILE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpfile" },
2039 /* ATTR_HELPSTRING */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpstring" },
2040 /* ATTR_HELPSTRINGCONTEXT */ { 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "helpstringcontext" },
2041 /* ATTR_HELPSTRINGDLL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "helpstringdll" },
2042 /* ATTR_HIDDEN */ { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, "hidden" },
2043 /* ATTR_ID */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "id" },
2044 /* ATTR_IDEMPOTENT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "idempotent" },
2045 /* ATTR_IIDIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "iid_is" },
2046 /* ATTR_IMMEDIATEBIND */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "immediatebind" },
2047 /* ATTR_IMPLICIT_HANDLE */ { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "implicit_handle" },
2048 /* ATTR_IN */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "in" },
2049 /* ATTR_INLINE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inline" },
2050 /* ATTR_INPUTSYNC */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inputsync" },
2051 /* ATTR_LENGTHIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "length_is" },
2052 /* ATTR_LIBLCID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "lcid" },
2053 /* ATTR_LOCAL */ { 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "local" },
2054 /* ATTR_NONBROWSABLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonbrowsable" },
2055 /* ATTR_NONCREATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "noncreatable" },
2056 /* ATTR_NONEXTENSIBLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonextensible" },
2057 /* ATTR_OBJECT */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "object" },
2058 /* ATTR_ODL */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "odl" },
2059 /* ATTR_OLEAUTOMATION */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "oleautomation" },
2060 /* ATTR_OPTIONAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "optional" },
2061 /* ATTR_OUT */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "out" },
2062 /* ATTR_POINTERDEFAULT */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "pointer_default" },
2063 /* ATTR_POINTERTYPE */ { 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, "ref, unique or ptr" },
2064 /* ATTR_PROPGET */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propget" },
2065 /* ATTR_PROPPUT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propput" },
2066 /* ATTR_PROPPUTREF */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propputref" },
2067 /* ATTR_PUBLIC */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "public" },
2068 /* ATTR_RANGE */ { 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, "range" },
2069 /* ATTR_READONLY */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "readonly" },
2070 /* ATTR_REQUESTEDIT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "requestedit" },
2071 /* ATTR_RESTRICTED */ { 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, "restricted" },
2072 /* ATTR_RETVAL */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "retval" },
2073 /* ATTR_SIZEIS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "size_is" },
2074 /* ATTR_SOURCE */ { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "source" },
2075 /* ATTR_STRICTCONTEXTHANDLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "strict_context_handle" },
2076 /* ATTR_STRING */ { 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, "string" },
2077 /* ATTR_SWITCHIS */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, "switch_is" },
2078 /* ATTR_SWITCHTYPE */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, "switch_type" },
2079 /* ATTR_TRANSMITAS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "transmit_as" },
2080 /* ATTR_UUID */ { 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, "uuid" },
2081 /* ATTR_V1ENUM */ { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, "v1_enum" },
2082 /* ATTR_VARARG */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "vararg" },
2083 /* ATTR_VERSION */ { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "version" },
2084 /* ATTR_WIREMARSHAL */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, "wire_marshal" },
2087 const char *get_attr_display_name
(enum attr_type type
)
2089 return allowed_attr
[type
].display_name
;
2092 static attr_list_t
*check_iface_attrs
(const char *name
, attr_list_t
*attrs
)
2095 if
(!attrs
) return attrs
;
2096 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2098 if
(!allowed_attr
[attr
->type
].on_interface
)
2099 error_loc
("inapplicable attribute %s for interface %s\n",
2100 allowed_attr
[attr
->type
].display_name
, name
);
2105 static attr_list_t
*check_function_attrs
(const char *name
, attr_list_t
*attrs
)
2108 if
(!attrs
) return attrs
;
2109 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2111 if
(!allowed_attr
[attr
->type
].on_function
)
2112 error_loc
("inapplicable attribute %s for function %s\n",
2113 allowed_attr
[attr
->type
].display_name
, name
);
2118 static void check_arg
(var_t
*arg
)
2120 const type_t
*t
= arg
->type
;
2123 if
(t
->type
== 0 && ! is_var_ptr
(arg
))
2124 error_loc
("argument '%s' has void type\n", arg
->name
);
2128 LIST_FOR_EACH_ENTRY
(attr
, arg
->attrs
, const attr_t
, entry
)
2130 if
(!allowed_attr
[attr
->type
].on_arg
)
2131 error_loc
("inapplicable attribute %s for argument %s\n",
2132 allowed_attr
[attr
->type
].display_name
, arg
->name
);
2137 static attr_list_t
*check_typedef_attrs
(attr_list_t
*attrs
)
2140 if
(!attrs
) return attrs
;
2141 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2143 if
(!allowed_attr
[attr
->type
].on_type
)
2144 error_loc
("inapplicable attribute %s for typedef\n",
2145 allowed_attr
[attr
->type
].display_name
);
2150 static attr_list_t
*check_enum_attrs
(attr_list_t
*attrs
)
2153 if
(!attrs
) return attrs
;
2154 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2156 if
(!allowed_attr
[attr
->type
].on_enum
)
2157 error_loc
("inapplicable attribute %s for enum\n",
2158 allowed_attr
[attr
->type
].display_name
);
2163 static attr_list_t
*check_struct_attrs
(attr_list_t
*attrs
)
2166 if
(!attrs
) return attrs
;
2167 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2169 if
(!allowed_attr
[attr
->type
].on_struct
)
2170 error_loc
("inapplicable attribute %s for struct\n",
2171 allowed_attr
[attr
->type
].display_name
);
2176 static attr_list_t
*check_union_attrs
(attr_list_t
*attrs
)
2179 if
(!attrs
) return attrs
;
2180 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2182 if
(!allowed_attr
[attr
->type
].on_union
)
2183 error_loc
("inapplicable attribute %s for union\n",
2184 allowed_attr
[attr
->type
].display_name
);
2189 static attr_list_t
*check_field_attrs
(const char *name
, attr_list_t
*attrs
)
2192 if
(!attrs
) return attrs
;
2193 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2195 if
(!allowed_attr
[attr
->type
].on_field
)
2196 error_loc
("inapplicable attribute %s for field %s\n",
2197 allowed_attr
[attr
->type
].display_name
, name
);
2202 static attr_list_t
*check_library_attrs
(const char *name
, attr_list_t
*attrs
)
2205 if
(!attrs
) return attrs
;
2206 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2208 if
(!allowed_attr
[attr
->type
].on_library
)
2209 error_loc
("inapplicable attribute %s for library %s\n",
2210 allowed_attr
[attr
->type
].display_name
, name
);
2215 static attr_list_t
*check_dispiface_attrs
(const char *name
, attr_list_t
*attrs
)
2218 if
(!attrs
) return attrs
;
2219 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2221 if
(!allowed_attr
[attr
->type
].on_dispinterface
)
2222 error_loc
("inapplicable attribute %s for dispinterface %s\n",
2223 allowed_attr
[attr
->type
].display_name
, name
);
2228 static attr_list_t
*check_module_attrs
(const char *name
, attr_list_t
*attrs
)
2231 if
(!attrs
) return attrs
;
2232 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2234 if
(!allowed_attr
[attr
->type
].on_module
)
2235 error_loc
("inapplicable attribute %s for module %s\n",
2236 allowed_attr
[attr
->type
].display_name
, name
);
2241 static attr_list_t
*check_coclass_attrs
(const char *name
, attr_list_t
*attrs
)
2244 if
(!attrs
) return attrs
;
2245 LIST_FOR_EACH_ENTRY
(attr
, attrs
, const attr_t
, entry
)
2247 if
(!allowed_attr
[attr
->type
].on_coclass
)
2248 error_loc
("inapplicable attribute %s for coclass %s\n",
2249 allowed_attr
[attr
->type
].display_name
, name
);
2254 static int is_allowed_conf_type
(const type_t
*type
)
2275 static int is_ptr_guid_type
(const type_t
*type
)
2277 unsigned int align
= 0;
2279 /* first, make sure it is a pointer to something */
2280 if
(!is_ptr
(type
)) return FALSE
;
2282 /* second, make sure it is a pointer to something of size sizeof(GUID),
2284 return
(type_memsize
(type_pointer_get_ref
(type
), &align
) == 16);
2287 static void check_conformance_expr_list
(const char *attr_name
, const var_t
*arg
, const type_t
*container_type
, expr_list_t
*expr_list
)
2290 struct expr_loc expr_loc
;
2292 expr_loc.attr
= attr_name
;
2293 if
(expr_list
) LIST_FOR_EACH_ENTRY
(dim
, expr_list
, expr_t
, entry
)
2295 if
(dim
->type
!= EXPR_VOID
)
2297 const type_t
*expr_type
= expr_resolve_type
(&expr_loc
, container_type
, dim
);
2298 if
(!is_allowed_conf_type
(expr_type
))
2299 error_loc_info
(&arg
->loc_info
, "expression must resolve to integral type <= 32bits for attribute %s\n",
2305 static void check_remoting_fields
(const var_t
*var
, type_t
*type
);
2307 /* checks that properties common to fields and arguments are consistent */
2308 static void check_field_common
(const type_t
*container_type
,
2309 const char *container_name
, const var_t
*arg
)
2311 type_t
*type
= arg
->type
;
2312 int is_wire_marshal
= 0;
2313 int is_context_handle
= 0;
2314 const char *container_type_name
= NULL
;
2316 if
(is_struct
(container_type
->type
))
2317 container_type_name
= "struct";
2318 else if
(is_union
(container_type
->type
))
2319 container_type_name
= "union";
2320 else if
(container_type
->type
== RPC_FC_FUNCTION
)
2321 container_type_name
= "function";
2323 if
(is_attr
(arg
->attrs
, ATTR_LENGTHIS
) &&
2324 (is_attr
(arg
->attrs
, ATTR_STRING
) || is_aliaschain_attr
(arg
->type
, ATTR_STRING
)))
2325 error_loc_info
(&arg
->loc_info
,
2326 "string and length_is specified for argument %s are mutually exclusive attributes\n",
2329 if
(is_attr
(arg
->attrs
, ATTR_SIZEIS
))
2331 expr_list_t
*size_is_exprs
= get_attrp
(arg
->attrs
, ATTR_SIZEIS
);
2332 check_conformance_expr_list
("size_is", arg
, container_type
, size_is_exprs
);
2334 if
(is_attr
(arg
->attrs
, ATTR_LENGTHIS
))
2336 expr_list_t
*length_is_exprs
= get_attrp
(arg
->attrs
, ATTR_LENGTHIS
);
2337 check_conformance_expr_list
("length_is", arg
, container_type
, length_is_exprs
);
2339 if
(is_attr
(arg
->attrs
, ATTR_IIDIS
))
2341 struct expr_loc expr_loc
;
2342 expr_t
*expr
= get_attrp
(arg
->attrs
, ATTR_IIDIS
);
2343 if
(expr
->type
!= EXPR_VOID
)
2345 const type_t
*expr_type
;
2347 expr_loc.attr
= "iid_is";
2348 expr_type
= expr_resolve_type
(&expr_loc
, container_type
, expr
);
2349 if
(!expr_type ||
!is_ptr_guid_type
(expr_type
))
2350 error_loc_info
(&arg
->loc_info
, "expression must resolve to pointer to GUID type for attribute iid_is\n");
2353 if
(is_attr
(arg
->attrs
, ATTR_SWITCHIS
))
2355 struct expr_loc expr_loc
;
2356 expr_t
*expr
= get_attrp
(arg
->attrs
, ATTR_SWITCHIS
);
2357 if
(expr
->type
!= EXPR_VOID
)
2359 const type_t
*expr_type
;
2361 expr_loc.attr
= "switch_is";
2362 expr_type
= expr_resolve_type
(&expr_loc
, container_type
, expr
);
2363 if
(!expr_type ||
!is_allowed_conf_type
(expr_type
))
2364 error_loc_info
(&arg
->loc_info
, "expression must resolve to integral type <= 32bits for attribute %s\n",
2369 /* get fundamental type for the argument */
2372 if
(is_attr
(type
->attrs
, ATTR_WIREMARSHAL
))
2374 is_wire_marshal
= 1;
2377 if
(is_attr
(type
->attrs
, ATTR_CONTEXTHANDLE
))
2379 is_context_handle
= 1;
2382 if
(type_is_alias
(type
))
2383 type
= type_alias_get_aliasee
(type
);
2384 else if
(is_ptr
(type
))
2385 type
= type_pointer_get_ref
(type
);
2386 else if
(is_array
(type
))
2387 type
= type_array_get_element
(type
);
2392 if
(type
->type
== 0 && !is_attr
(arg
->attrs
, ATTR_IIDIS
) && !is_wire_marshal
&& !is_context_handle
)
2393 error_loc_info
(&arg
->loc_info
, "parameter \'%s\' of %s \'%s\' cannot derive from void *\n", arg
->name
, container_type_name
, container_name
);
2394 else if
(type
->type
== RPC_FC_FUNCTION
)
2395 error_loc_info
(&arg
->loc_info
, "parameter \'%s\' of %s \'%s\' cannot be a function pointer\n", arg
->name
, container_type_name
, container_name
);
2396 else if
(!is_wire_marshal
&& (is_struct
(type
->type
) || is_union
(type
->type
)))
2397 check_remoting_fields
(arg
, type
);
2400 static void check_remoting_fields
(const var_t
*var
, type_t
*type
)
2403 const var_list_t
*fields
= NULL
;
2405 type
= type_get_real_type
(type
);
2410 type
->checked
= TRUE
;
2412 if
(is_struct
(type
->type
))
2414 if
(type_is_complete
(type
))
2415 fields
= type_struct_get_fields
(type
);
2417 error_loc_info
(&var
->loc_info
, "undefined type declaration %s\n", type
->name
);
2419 else if
(is_union
(type
->type
))
2420 fields
= type_union_get_cases
(type
);
2422 if
(fields
) LIST_FOR_EACH_ENTRY
( field
, fields
, const var_t
, entry
)
2423 if
(field
->type
) check_field_common
(type
, type
->name
, field
);
2426 /* checks that arguments for a function make sense for marshalling and unmarshalling */
2427 static void check_remoting_args
(const var_t
*func
)
2429 const char *funcname
= func
->name
;
2432 if
(func
->type
->details.function
->args
) LIST_FOR_EACH_ENTRY
( arg
, func
->type
->details.function
->args
, const var_t
, entry
)
2435 const type_t
*type
= arg
->type
;
2437 /* get pointer level and fundamental type for the argument */
2440 if
(is_attr
(type
->attrs
, ATTR_WIREMARSHAL
))
2442 if
(is_attr
(type
->attrs
, ATTR_CONTEXTHANDLE
))
2444 if
(type_is_alias
(type
))
2445 type
= type_alias_get_aliasee
(type
);
2446 else if
(is_ptr
(type
))
2449 type
= type_pointer_get_ref
(type
);
2455 /* check that [out] parameters have enough pointer levels */
2456 if
(is_attr
(arg
->attrs
, ATTR_OUT
))
2458 if
(!is_array
(type
))
2461 error_loc_info
(&arg
->loc_info
, "out parameter \'%s\' of function \'%s\' is not a pointer\n", arg
->name
, funcname
);
2462 if
(type
->type
== RPC_FC_IP
&& ptr_level
== 1)
2463 error_loc_info
(&arg
->loc_info
, "out interface pointer \'%s\' of function \'%s\' is not a double pointer\n", arg
->name
, funcname
);
2467 check_field_common
(func
->type
, funcname
, arg
);
2471 static void add_explicit_handle_if_necessary
(var_t
*func
)
2473 const var_t
* explicit_handle_var
;
2474 const var_t
* explicit_generic_handle_var
= NULL
;
2475 const var_t
* context_handle_var
= NULL
;
2477 /* check for a defined binding handle */
2478 explicit_handle_var
= get_explicit_handle_var
(func
);
2479 if
(!explicit_handle_var
)
2481 explicit_generic_handle_var
= get_explicit_generic_handle_var
(func
);
2482 if
(!explicit_generic_handle_var
)
2484 context_handle_var
= get_context_handle_var
(func
);
2485 if
(!context_handle_var
)
2487 /* no explicit handle specified so add
2488 * "[in] handle_t IDL_handle" as the first parameter to the
2490 var_t
*idl_handle
= make_var
(xstrdup
("IDL_handle"));
2491 idl_handle
->attrs
= append_attr
(NULL
, make_attr
(ATTR_IN
));
2492 idl_handle
->type
= find_type_or_error
("handle_t", 0);
2493 type_function_add_head_arg
(func
->type
, idl_handle
);
2499 static void check_functions
(const type_t
*iface
, int is_inside_library
)
2501 const statement_t
*stmt
;
2502 if
(is_attr
(iface
->attrs
, ATTR_EXPLICIT_HANDLE
))
2504 STATEMENTS_FOR_EACH_FUNC
( stmt
, type_iface_get_stmts
(iface
) )
2506 var_t
*func
= stmt
->u.var
;
2507 add_explicit_handle_if_necessary
(func
);
2510 if
(!is_inside_library
&& !is_attr
(iface
->attrs
, ATTR_LOCAL
))
2512 STATEMENTS_FOR_EACH_FUNC
( stmt
, type_iface_get_stmts
(iface
) )
2514 const var_t
*func
= stmt
->u.var
;
2515 if
(!is_attr
(func
->attrs
, ATTR_LOCAL
))
2516 check_remoting_args
(func
);
2521 static void check_statements
(const statement_list_t
*stmts
, int is_inside_library
)
2523 const statement_t
*stmt
;
2525 if
(stmts
) LIST_FOR_EACH_ENTRY
(stmt
, stmts
, const statement_t
, entry
)
2527 if
(stmt
->type
== STMT_LIBRARY
)
2528 check_statements
(stmt
->u.lib
->stmts
, TRUE
);
2529 else if
(stmt
->type
== STMT_TYPE
&& stmt
->u.type
->type
== RPC_FC_IP
)
2530 check_functions
(stmt
->u.type
, is_inside_library
);
2534 static void check_all_user_types
(const statement_list_t
*stmts
)
2536 const statement_t
*stmt
;
2538 if
(stmts
) LIST_FOR_EACH_ENTRY
(stmt
, stmts
, const statement_t
, entry
)
2540 if
(stmt
->type
== STMT_LIBRARY
)
2541 check_all_user_types
(stmt
->u.lib
->stmts
);
2542 else if
(stmt
->type
== STMT_TYPE
&& stmt
->u.type
->type
== RPC_FC_IP
&&
2543 !is_local
(stmt
->u.type
->attrs
))
2545 const statement_t
*stmt_func
;
2546 STATEMENTS_FOR_EACH_FUNC
(stmt_func
, type_iface_get_stmts
(stmt
->u.type
)) {
2547 const var_t
*func
= stmt_func
->u.var
;
2548 check_for_additional_prototype_types
(func
->type
->details.function
->args
);
2554 int is_valid_uuid
(const char *s
)
2558 for
(i
= 0; i
< 36; ++i
)
2559 if
(i
== 8 || i
== 13 || i
== 18 || i
== 23)
2565 if
(!isxdigit
(s
[i
]))
2568 return s
[i
] == '\0';
2571 static statement_t
*make_statement
(enum statement_type type
)
2573 statement_t
*stmt
= xmalloc
(sizeof
(*stmt
));
2578 static statement_t
*make_statement_type_decl
(type_t
*type
)
2580 statement_t
*stmt
= make_statement
(STMT_TYPE
);
2581 stmt
->u.type
= type
;
2585 static statement_t
*make_statement_reference
(type_t
*type
)
2587 statement_t
*stmt
= make_statement
(STMT_TYPEREF
);
2588 stmt
->u.type
= type
;
2592 static statement_t
*make_statement_declaration
(var_t
*var
)
2594 statement_t
*stmt
= make_statement
(STMT_DECLARATION
);
2596 if
(var
->stgclass
== STG_EXTERN
&& var
->eval
)
2597 warning
("'%s' initialised and declared extern\n", var
->name
);
2598 if
(is_const_decl
(var
))
2603 else if
((var
->stgclass
== STG_NONE || var
->stgclass
== STG_REGISTER
) &&
2604 var
->type
->type
!= RPC_FC_FUNCTION
)
2605 error_loc
("instantiation of data is illegal\n");
2609 static statement_t
*make_statement_library
(typelib_t
*typelib
)
2611 statement_t
*stmt
= make_statement
(STMT_LIBRARY
);
2612 stmt
->u.lib
= typelib
;
2616 static statement_t
*make_statement_cppquote
(const char *str
)
2618 statement_t
*stmt
= make_statement
(STMT_CPPQUOTE
);
2623 static statement_t
*make_statement_importlib
(const char *str
)
2625 statement_t
*stmt
= make_statement
(STMT_IMPORTLIB
);
2630 static statement_t
*make_statement_import
(const char *str
)
2632 statement_t
*stmt
= make_statement
(STMT_IMPORT
);
2637 static statement_t
*make_statement_module
(type_t
*type
)
2639 statement_t
*stmt
= make_statement
(STMT_MODULE
);
2640 stmt
->u.type
= type
;
2644 static statement_t
*make_statement_typedef
(declarator_list_t
*decls
)
2646 declarator_t
*decl
, *next
;
2648 type_list_t
**type_list
;
2650 if
(!decls
) return NULL
;
2652 stmt
= make_statement
(STMT_TYPEDEF
);
2653 stmt
->u.type_list
= NULL
;
2654 type_list
= &stmt
->u.type_list
;
2656 LIST_FOR_EACH_ENTRY_SAFE
( decl
, next
, decls
, declarator_t
, entry
)
2658 var_t
*var
= decl
->var
;
2659 type_t
*type
= find_type_or_error
(var
->name
, 0);
2660 *type_list
= xmalloc
(sizeof
(type_list_t
));
2661 (*type_list
)->type
= type
;
2662 (*type_list
)->next
= NULL
;
2664 type_list
= &(*type_list
)->next
;
2672 static statement_list_t
*append_statement
(statement_list_t
*list
, statement_t
*stmt
)
2674 if
(!stmt
) return list
;
2677 list
= xmalloc
( sizeof
(*list
) );
2680 list_add_tail
( list
, &stmt
->entry
);
2684 void init_loc_info
(loc_info_t
*i
)
2686 i
->input_name
= input_name ? input_name
: "stdin";
2687 i
->line_number
= line_number
;
2688 i
->near_text
= parser_text
;
2691 static void check_def
(const type_t
*t
)
2694 error_loc
("%s: redefinition error; original definition was at %s:%d\n",
2695 t
->name
, t
->loc_info.input_name
, t
->loc_info.line_number
);