4 * Copyright 2004 Ove Kaaven
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 static typelib_t *typelib;
41 /* List of oleauto types that should be recognized by name.
42 * (most of) these seem to be intrinsic types in mktyplib. */
44 static struct oatype {
51 {"DECIMAL", VT_DECIMAL},
52 {"HRESULT", VT_HRESULT},
54 {"LPWSTR", VT_LPWSTR},
56 {"VARIANT", VT_VARIANT},
57 {"VARIANT_BOOL", VT_BOOL}
59 #define NTYPES (sizeof(oatypes)/sizeof(oatypes[0]))
60 #define KWP(p) ((const struct oatype *)(p))
62 static int kw_cmp_func(const void *s1, const void *s2)
64 return strcmp(KWP(s1)->kw, KWP(s2)->kw);
67 static unsigned short builtin_vt(const char *kw)
69 struct oatype key, *kwp;
72 kwp = bsearch(&key, oatypes, NTYPES, sizeof(oatypes[0]), kw_cmp_func);
76 for (kwp=NULL, i=0; i < NTYPES; i++)
77 if (!kw_cmp_func(&key, &oatypes[i])) {
89 static int match(const char*n, const char*m)
95 unsigned short get_type_vt(type_t *t)
99 chat("get_type_vt: %p type->name %s\n", t, t->name);
101 vt = builtin_vt(t->name);
113 return VT_I2; /* mktyplib seems to parse wchar_t as short */
119 if (t->ref && match(t->ref->name, "int")) return VT_INT;
122 if (t->ref && match(t->ref->name, "int")) return VT_UINT;
125 if (t->sign < 0) return VT_UI8;
126 if (t->ref && match(t->ref->name, "MIDL_uhyper")) return VT_UI8;
139 error("get_type_vt: unknown-deref-type: %d\n", t->ref->type);
142 if(match(t->name, "IUnknown"))
144 if(match(t->name, "IDispatch"))
146 return VT_USERDEFINED;
152 case RPC_FC_CPSTRUCT:
153 case RPC_FC_CVSTRUCT:
154 case RPC_FC_BOGUS_STRUCT:
155 return VT_USERDEFINED;
158 return VT_USERDEFINED;
161 error("get_type_vt: unknown type: 0x%02x\n", t->type);
166 unsigned short get_var_vt(var_t *v)
170 chat("get_var_vt: %p tname %s\n", v, v->tname);
172 vt = builtin_vt(v->tname);
176 return get_type_vt(v->type);
179 void start_typelib(char *name, attr_t *attrs)
182 if (!do_typelib) return;
184 typelib = xmalloc(sizeof(*typelib));
185 typelib->name = xstrdup(name);
186 typelib->filename = xstrdup(typelib_name);
187 typelib->attrs = attrs;
190 void end_typelib(void)
193 if (!typelib) return;
195 create_msft_typelib(typelib);
199 void add_interface(type_t *iface)
201 typelib_entry_t *entry;
202 if (!typelib) return;
204 chat("add interface: %s\n", iface->name);
205 entry = xmalloc(sizeof(*entry));
206 entry->kind = TKIND_INTERFACE;
207 entry->u.interface = iface;
208 LINK(entry, typelib->entry);
209 typelib->entry = entry;
212 void add_coclass(class_t *cls)
214 typelib_entry_t *entry;
216 if (!typelib) return;
218 chat("add coclass: %s\n", cls->name);
220 entry = xmalloc(sizeof(*entry));
221 entry->kind = TKIND_COCLASS;
222 entry->u.class = cls;
223 LINK(entry, typelib->entry);
224 typelib->entry = entry;
227 void add_module(type_t *module)
229 typelib_entry_t *entry;
230 if (!typelib) return;
232 chat("add module: %s\n", module->name);
233 entry = xmalloc(sizeof(*entry));
234 entry->kind = TKIND_MODULE;
235 entry->u.module = module;
236 LINK(entry, typelib->entry);
237 typelib->entry = entry;
240 void add_struct(type_t *structure)
242 typelib_entry_t *entry;
243 if (!typelib) return;
245 chat("add struct: %s\n", structure->name);
246 entry = xmalloc(sizeof(*entry));
247 entry->kind = TKIND_RECORD;
248 entry->u.structure = structure;
249 LINK(entry, typelib->entry);
250 typelib->entry = entry;
253 void add_enum(type_t *enumeration)
255 typelib_entry_t *entry;
256 if (!typelib) return;
258 chat("add enum: %s\n", enumeration->name);
259 entry = xmalloc(sizeof(*entry));
260 entry->kind = TKIND_ENUM;
261 entry->u.enumeration = enumeration;
262 LINK(entry, typelib->entry);
263 typelib->entry = entry;
266 void add_typedef(type_t *tdef, var_t *name)
268 typelib_entry_t *entry;
269 if (!typelib) return;
271 entry = xmalloc(sizeof(*entry));
272 entry->kind = TKIND_ALIAS;
273 entry->u.tdef = xmalloc(sizeof(*entry->u.tdef));
274 memcpy(entry->u.tdef, name, sizeof(*name));
275 entry->u.tdef->type = tdef;
276 entry->u.tdef->name = xstrdup(name->name);
277 LINK(entry, typelib->entry);
278 typelib->entry = entry;