wineps: Don't use CDECL for private functions.
[wine.git] / tools / widl / attribute.c
blobb9aa99c9228d239d58ebfe78af2676b5efac9a1c
1 /*
2 * Copyright 2002 Ove Kaaven
3 * Copyright 2006-2008 Robert Shearman
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
22 #include "widl.h"
23 #include "typetree.h"
25 #include "parser.tab.h"
27 attr_t *attr_int( struct location where, enum attr_type attr_type, unsigned int val )
29 attr_t *a = xmalloc( sizeof(attr_t) );
30 a->where = where;
31 a->type = attr_type;
32 a->u.ival = val;
33 return a;
36 attr_t *attr_ptr( struct location where, enum attr_type attr_type, void *val )
38 attr_t *a = xmalloc( sizeof(attr_t) );
39 a->where = where;
40 a->type = attr_type;
41 a->u.pval = val;
42 return a;
45 int is_attr( const attr_list_t *list, enum attr_type attr_type )
47 const attr_t *attr;
48 if (!list) return 0;
49 LIST_FOR_EACH_ENTRY( attr, list, const attr_t, entry )
50 if (attr->type == attr_type) return 1;
51 return 0;
54 int is_ptrchain_attr( const var_t *var, enum attr_type attr_type )
56 type_t *type = var->declspec.type;
57 if (is_attr( var->attrs, attr_type )) return 1;
58 for (;;)
60 if (is_attr( type->attrs, attr_type )) return 1;
61 else if (type_is_alias( type )) type = type_alias_get_aliasee_type( type );
62 else if (type_is_ptr( type )) type = type_pointer_get_ref_type( type );
63 else return 0;
67 int is_aliaschain_attr( const type_t *type, enum attr_type attr_type )
69 const type_t *t = type;
70 for (;;)
72 if (is_attr( t->attrs, attr_type )) return 1;
73 else if (type_is_alias( t )) t = type_alias_get_aliasee_type( t );
74 else return 0;
78 unsigned int get_attrv( const attr_list_t *list, enum attr_type attr_type )
80 const attr_t *attr;
81 if (!list) return 0;
82 LIST_FOR_EACH_ENTRY( attr, list, const attr_t, entry )
83 if (attr->type == attr_type) return attr->u.ival;
84 return 0;
87 void *get_attrp( const attr_list_t *list, enum attr_type attr_type )
89 const attr_t *attr;
90 if (!list) return NULL;
91 LIST_FOR_EACH_ENTRY( attr, list, const attr_t, entry )
92 if (attr->type == attr_type) return attr->u.pval;
93 return NULL;
96 void *get_aliaschain_attrp( const type_t *type, enum attr_type attr_type )
98 for (;;)
100 if (is_attr( type->attrs, attr_type )) return get_attrp( type->attrs, attr_type );
101 if (!type_is_alias( type )) return NULL;
102 type = type_alias_get_aliasee_type( type );
106 struct allowed_attr
108 unsigned int dce_compatible : 1;
109 unsigned int acf : 1;
110 unsigned int multiple : 1;
112 unsigned int on_interface : 1;
113 unsigned int on_function : 1;
114 unsigned int on_arg : 1;
115 unsigned int on_type : 1;
116 unsigned int on_enum : 1;
117 unsigned int on_enum_member : 1;
118 unsigned int on_struct : 2;
119 unsigned int on_union : 1;
120 unsigned int on_field : 1;
121 unsigned int on_library : 1;
122 unsigned int on_dispinterface : 1;
123 unsigned int on_module : 1;
124 unsigned int on_coclass : 1;
125 unsigned int on_apicontract : 1;
126 unsigned int on_runtimeclass : 1;
127 const char *display_name;
130 struct allowed_attr allowed_attr[] =
132 /* attr { D ACF M I Fn ARG T En Enm St Un Fi L DI M C AC R <display name> } */
133 /* ATTR_ACTIVATABLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "activatable" },
134 /* ATTR_AGGREGATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "aggregatable" },
135 /* ATTR_ALLOCATE */ { 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "allocate" },
136 /* ATTR_ANNOTATION */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "annotation" },
137 /* ATTR_APPOBJECT */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "appobject" },
138 /* ATTR_ASYNC */ { 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "async" },
139 /* ATTR_ASYNCUUID */ { 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, "async_uuid" },
140 /* ATTR_AUTO_HANDLE */ { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "auto_handle" },
141 /* ATTR_BINDABLE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "bindable" },
142 /* ATTR_BROADCAST */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "broadcast" },
143 /* ATTR_CALLAS */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "call_as" },
144 /* ATTR_CALLCONV */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL },
145 /* ATTR_CASE */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "case" },
146 /* ATTR_CODE */ { 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "code" },
147 /* ATTR_COMMSTATUS */ { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "comm_status" },
148 /* ATTR_COMPOSABLE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "composable" },
149 /* ATTR_CONTEXTHANDLE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "context_handle" },
150 /* ATTR_CONTRACT */ { 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, "contract" },
151 /* ATTR_CONTRACTVERSION */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, "contractversion" },
152 /* ATTR_CONTROL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, "control" },
153 /* ATTR_CUSTOM */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, "custom" },
154 /* ATTR_DECODE */ { 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "decode" },
155 /* ATTR_DEFAULT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, "default" },
156 /* ATTR_DEFAULTBIND */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultbind" },
157 /* ATTR_DEFAULTCOLLELEM */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultcollelem" },
158 /* ATTR_DEFAULTVALUE */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "defaultvalue" },
159 /* ATTR_DEFAULTVTABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "defaultvtable" },
160 /* ATTR_DISABLECONSISTENCYCHECK */{ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "disable_consistency_check" },
161 /* ATTR_DISPINTERFACE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, NULL },
162 /* ATTR_DISPLAYBIND */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "displaybind" },
163 /* ATTR_DLLNAME */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, "dllname" },
164 /* ATTR_DUAL */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "dual" },
165 /* ATTR_ENABLEALLOCATE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "enable_allocate" },
166 /* ATTR_ENCODE */ { 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "encode" },
167 /* ATTR_ENDPOINT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "endpoint" },
168 /* ATTR_ENTRY */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "entry" },
169 /* ATTR_EVENTADD */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "eventadd" },
170 /* ATTR_EVENTREMOVE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "eventremove" },
171 /* ATTR_EXCLUSIVETO */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "exclusive_to" },
172 /* ATTR_EXPLICIT_HANDLE */ { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "explicit_handle" },
173 /* ATTR_FAULTSTATUS */ { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "fault_status" },
174 /* ATTR_FLAGS */ { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "flags" },
175 /* ATTR_FORCEALLOCATE */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "force_allocate" },
176 /* ATTR_HANDLE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "handle" },
177 /* ATTR_HELPCONTEXT */ { 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, "helpcontext" },
178 /* ATTR_HELPFILE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "helpfile" },
179 /* ATTR_HELPSTRING */ { 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, "helpstring" },
180 /* ATTR_HELPSTRINGCONTEXT */ { 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, "helpstringcontext" },
181 /* ATTR_HELPSTRINGDLL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "helpstringdll" },
182 /* ATTR_HIDDEN */ { 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, "hidden" },
183 /* ATTR_ID */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, "id" },
184 /* ATTR_IDEMPOTENT */ { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "idempotent" },
185 /* ATTR_IGNORE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "ignore" },
186 /* ATTR_IIDIS */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "iid_is" },
187 /* ATTR_IMMEDIATEBIND */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "immediatebind" },
188 /* ATTR_IMPLICIT_HANDLE */ { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "implicit_handle" },
189 /* ATTR_IN */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "in" },
190 /* ATTR_INPUTSYNC */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "inputsync" },
191 /* ATTR_LENGTHIS */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "length_is" },
192 /* ATTR_LIBLCID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, "lcid" },
193 /* ATTR_LICENSED */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "licensed" },
194 /* ATTR_LOCAL */ { 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "local" },
195 /* ATTR_MARSHALING_BEHAVIOR */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "marshaling_behavior" },
196 /* ATTR_MAYBE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "maybe" },
197 /* ATTR_MESSAGE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "message" },
198 /* ATTR_NOCODE */ { 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nocode" },
199 /* ATTR_NONBROWSABLE */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonbrowsable" },
200 /* ATTR_NONCREATABLE */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "noncreatable" },
201 /* ATTR_NONEXTENSIBLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "nonextensible" },
202 /* ATTR_NOTIFY */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "notify" },
203 /* ATTR_NOTIFYFLAG */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "notify_flag" },
204 /* ATTR_OBJECT */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "object" },
205 /* ATTR_ODL */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "odl" },
206 /* ATTR_OLEAUTOMATION */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "oleautomation" },
207 /* ATTR_OPTIMIZE */ { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "optimize" },
208 /* ATTR_OPTIONAL */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "optional" },
209 /* ATTR_OUT */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "out" },
210 /* ATTR_OVERLOAD */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "overload" },
211 /* ATTR_PARAMLCID */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "lcid" },
212 /* ATTR_PARTIALIGNORE */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "partial_ignore" },
213 /* ATTR_POINTERDEFAULT */ { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "pointer_default" },
214 /* ATTR_POINTERTYPE */ { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "ref, unique or ptr" },
215 /* ATTR_PROGID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "progid" },
216 /* ATTR_PROPGET */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propget" },
217 /* ATTR_PROPPUT */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propput" },
218 /* ATTR_PROPPUTREF */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "propputref" },
219 /* ATTR_PROTECTED */ { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "protected" },
220 /* ATTR_PROXY */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "proxy" },
221 /* ATTR_PUBLIC */ { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "public" },
222 /* ATTR_RANGE */ { 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "range" },
223 /* ATTR_READONLY */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "readonly" },
224 /* ATTR_REPRESENTAS */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "represent_as" },
225 /* ATTR_REQUESTEDIT */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "requestedit" },
226 /* ATTR_RESTRICTED */ { 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, "restricted" },
227 /* ATTR_RETVAL */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "retval" },
228 /* ATTR_SIZEIS */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "size_is" },
229 /* ATTR_SOURCE */ { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, "source" },
230 /* ATTR_STATIC */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, "static" },
231 /* ATTR_STRICTCONTEXTHANDLE */ { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "strict_context_handle" },
232 /* ATTR_STRING */ { 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "string" },
233 /* ATTR_SWITCHIS */ { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "switch_is" },
234 /* ATTR_SWITCHTYPE */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "switch_type" },
235 /* ATTR_THREADING */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, "threading" },
236 /* ATTR_TRANSMITAS */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "transmit_as" },
237 /* ATTR_UIDEFAULT */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "uidefault" },
238 /* ATTR_USESGETLASTERROR */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "usesgetlasterror" },
239 /* ATTR_USERMARSHAL */ { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "user_marshal" },
240 /* ATTR_UUID */ { 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, "uuid" },
241 /* ATTR_V1ENUM */ { 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "v1_enum" },
242 /* ATTR_VARARG */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "vararg" },
243 /* ATTR_VERSION */ { 1, 0, 0, 1, 0, 0, 1, 1, 0, 2, 0, 0, 1, 0, 1, 1, 0, 1, "version" },
244 /* ATTR_VIPROGID */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, "vi_progid" },
245 /* ATTR_WIREMARSHAL */ { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "wire_marshal" },
248 static const char *get_attr_display_name( enum attr_type attr_type )
250 return allowed_attr[attr_type].display_name;
253 attr_list_t *append_attr( attr_list_t *list, attr_t *attr )
255 attr_t *attr_existing;
256 if (!attr) return list;
257 if (!list)
259 list = xmalloc( sizeof(*list) );
260 list_init( list );
262 if (!allowed_attr[attr->type].multiple)
264 LIST_FOR_EACH_ENTRY( attr_existing, list, attr_t, entry )
266 if (attr_existing->type != attr->type) continue;
267 warning_at( &attr->where, "duplicate attribute %s\n", get_attr_display_name( attr->type ) );
268 /* use the last attribute, like MIDL does */
269 list_remove( &attr_existing->entry );
270 break;
273 list_add_tail( list, &attr->entry );
274 return list;
277 attr_list_t *append_attr_list( attr_list_t *new_list, attr_list_t *old_list )
279 struct list *entry;
281 if (!old_list) return new_list;
283 while ((entry = list_head( old_list )))
285 attr_t *attr = LIST_ENTRY( entry, attr_t, entry );
286 list_remove( entry );
287 new_list = append_attr( new_list, attr );
289 return new_list;
292 attr_list_t *append_attribs( attr_list_t *l1, attr_list_t *l2 )
294 if (!l2) return l1;
295 if (!l1 || l1 == l2) return l2;
296 list_move_tail( l1, l2 );
297 return l1;
300 attr_list_t *map_attrs( const attr_list_t *list, map_attrs_filter_t filter )
302 attr_list_t *new_list;
303 const attr_t *attr;
304 attr_t *new_attr;
306 if (!list) return NULL;
308 new_list = xmalloc( sizeof(*list) );
309 list_init( new_list );
310 LIST_FOR_EACH_ENTRY( attr, list, const attr_t, entry )
312 if (filter && !filter( new_list, attr )) continue;
313 new_attr = xmalloc( sizeof(*new_attr) );
314 *new_attr = *attr;
315 list_add_tail( new_list, &new_attr->entry );
317 return new_list;
320 attr_list_t *move_attr( attr_list_t *dst, attr_list_t *src, enum attr_type type )
322 attr_t *attr;
323 if (!src) return dst;
324 LIST_FOR_EACH_ENTRY( attr, src, attr_t, entry )
326 if (attr->type == type)
328 list_remove( &attr->entry );
329 return append_attr( dst, attr );
332 return dst;
335 attr_list_t *check_apicontract_attrs( const char *name, attr_list_t *attrs )
337 const attr_t *attr;
338 if (!attrs) return NULL;
339 LIST_FOR_EACH_ENTRY( attr, attrs, const attr_t, entry )
341 if (!allowed_attr[attr->type].on_apicontract)
342 error_at( &attr->where, "inapplicable attribute %s for apicontract %s\n",
343 allowed_attr[attr->type].display_name, name );
345 return attrs;
348 attr_list_t *check_coclass_attrs( const char *name, attr_list_t *attrs )
350 const attr_t *attr;
351 if (!attrs) return NULL;
352 LIST_FOR_EACH_ENTRY( attr, attrs, const attr_t, entry )
354 if (!allowed_attr[attr->type].on_coclass)
355 error_at( &attr->where, "inapplicable attribute %s for coclass %s\n",
356 allowed_attr[attr->type].display_name, name );
358 return attrs;
361 attr_list_t *check_dispiface_attrs( const char *name, attr_list_t *attrs )
363 const attr_t *attr;
364 if (!attrs) return NULL;
365 LIST_FOR_EACH_ENTRY( attr, attrs, const attr_t, entry )
367 if (!allowed_attr[attr->type].on_dispinterface)
368 error_at( &attr->where, "inapplicable attribute %s for dispinterface %s\n",
369 allowed_attr[attr->type].display_name, name );
371 return attrs;
374 attr_list_t *check_enum_attrs( attr_list_t *attrs )
376 const attr_t *attr;
377 if (!attrs) return NULL;
378 LIST_FOR_EACH_ENTRY( attr, attrs, const attr_t, entry )
380 if (!allowed_attr[attr->type].on_enum)
381 error_at( &attr->where, "inapplicable attribute %s for enum\n",
382 allowed_attr[attr->type].display_name );
384 return attrs;
387 attr_list_t *check_enum_member_attrs( attr_list_t *attrs )
389 const attr_t *attr;
390 if (!attrs) return NULL;
391 LIST_FOR_EACH_ENTRY( attr, attrs, const attr_t, entry )
393 if (!allowed_attr[attr->type].on_enum_member)
394 error_at( &attr->where, "inapplicable attribute %s for enum member\n",
395 allowed_attr[attr->type].display_name );
397 return attrs;
400 attr_list_t *check_field_attrs( const char *name, attr_list_t *attrs )
402 const attr_t *attr;
403 if (!attrs) return NULL;
404 LIST_FOR_EACH_ENTRY( attr, attrs, const attr_t, entry )
406 if (!allowed_attr[attr->type].on_field)
407 error_at( &attr->where, "inapplicable attribute %s for field %s\n",
408 allowed_attr[attr->type].display_name, name );
410 return attrs;
413 attr_list_t *check_function_attrs( const char *name, attr_list_t *attrs )
415 const attr_t *attr;
416 if (!attrs) return NULL;
417 LIST_FOR_EACH_ENTRY( attr, attrs, const attr_t, entry )
419 if (!allowed_attr[attr->type].on_function)
420 error_at( &attr->where, "inapplicable attribute %s for function %s\n",
421 allowed_attr[attr->type].display_name, name );
423 return attrs;
426 attr_list_t *check_interface_attrs( const char *name, attr_list_t *attrs )
428 const attr_t *attr;
429 if (!attrs) return NULL;
430 LIST_FOR_EACH_ENTRY( attr, attrs, const attr_t, entry )
432 if (!allowed_attr[attr->type].on_interface)
433 error_at( &attr->where, "inapplicable attribute %s for interface %s\n",
434 allowed_attr[attr->type].display_name, name );
435 if (attr->type == ATTR_IMPLICIT_HANDLE)
437 const var_t *var = attr->u.pval;
438 if (type_get_type( var->declspec.type ) == TYPE_BASIC &&
439 type_basic_get_type( var->declspec.type ) == TYPE_BASIC_HANDLE)
440 continue;
441 if (is_aliaschain_attr( var->declspec.type, ATTR_HANDLE )) continue;
442 error_at( &attr->where, "attribute %s requires a handle type in interface %s\n",
443 allowed_attr[attr->type].display_name, name );
446 return attrs;
449 attr_list_t *check_library_attrs( const char *name, attr_list_t *attrs )
451 const attr_t *attr;
452 if (!attrs) return NULL;
453 LIST_FOR_EACH_ENTRY( attr, attrs, const attr_t, entry )
455 if (!allowed_attr[attr->type].on_library)
456 error_at( &attr->where, "inapplicable attribute %s for library %s\n",
457 allowed_attr[attr->type].display_name, name );
459 return attrs;
462 attr_list_t *check_module_attrs( const char *name, attr_list_t *attrs )
464 const attr_t *attr;
465 if (!attrs) return NULL;
466 LIST_FOR_EACH_ENTRY( attr, attrs, const attr_t, entry )
468 if (!allowed_attr[attr->type].on_module)
469 error_at( &attr->where, "inapplicable attribute %s for module %s\n",
470 allowed_attr[attr->type].display_name, name );
472 return attrs;
475 attr_list_t *check_runtimeclass_attrs( const char *name, attr_list_t *attrs )
477 const attr_t *attr;
478 if (!attrs) return NULL;
479 LIST_FOR_EACH_ENTRY( attr, attrs, const attr_t, entry )
481 if (!allowed_attr[attr->type].on_runtimeclass)
482 error_at( &attr->where, "inapplicable attribute %s for runtimeclass %s\n",
483 allowed_attr[attr->type].display_name, name );
485 return attrs;
488 attr_list_t *check_struct_attrs( attr_list_t *attrs )
490 int mask = winrt_mode ? 3 : 1;
491 const attr_t *attr;
492 if (!attrs) return NULL;
493 LIST_FOR_EACH_ENTRY( attr, attrs, const attr_t, entry )
495 if (!(allowed_attr[attr->type].on_struct & mask))
496 error_at( &attr->where, "inapplicable attribute %s for struct\n",
497 allowed_attr[attr->type].display_name );
499 return attrs;
502 attr_list_t *check_typedef_attrs( attr_list_t *attrs )
504 const attr_t *attr;
505 if (!attrs) return NULL;
506 LIST_FOR_EACH_ENTRY( attr, attrs, const attr_t, entry )
508 if (!allowed_attr[attr->type].on_type)
509 error_at( &attr->where, "inapplicable attribute %s for typedef\n",
510 allowed_attr[attr->type].display_name );
512 return attrs;
515 attr_list_t *check_union_attrs( attr_list_t *attrs )
517 const attr_t *attr;
518 if (!attrs) return NULL;
519 LIST_FOR_EACH_ENTRY( attr, attrs, const attr_t, entry )
521 if (!allowed_attr[attr->type].on_union)
522 error_at( &attr->where, "inapplicable attribute %s for union\n",
523 allowed_attr[attr->type].display_name );
525 return attrs;
528 void check_arg_attrs( const var_t *arg )
530 const attr_t *attr;
531 if (!arg->attrs) return;
532 LIST_FOR_EACH_ENTRY( attr, arg->attrs, const attr_t, entry )
534 if (!allowed_attr[attr->type].on_arg)
535 error_at( &attr->where, "inapplicable attribute %s for argument %s\n",
536 allowed_attr[attr->type].display_name, arg->name );