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;
151 return VT_USERDEFINED;
154 return VT_USERDEFINED;
157 error("get_type_vt: unknown-type: %d\n", t->type);
162 unsigned short get_var_vt(var_t *v)
166 chat("get_var_vt: %p tname %s\n", v, v->tname);
168 vt = builtin_vt(v->tname);
172 return get_type_vt(v->type);
175 void start_typelib(char *name, attr_t *attrs)
178 if (!do_typelib) return;
180 typelib = xmalloc(sizeof(*typelib));
181 typelib->name = xstrdup(name);
182 typelib->filename = xstrdup(typelib_name);
183 typelib->attrs = attrs;
186 void end_typelib(void)
189 if (!typelib) return;
191 create_msft_typelib(typelib);
195 void add_interface(type_t *iface)
197 typelib_entry_t *entry;
198 if (!typelib) return;
200 chat("add interface: %s\n", iface->name);
201 entry = xmalloc(sizeof(*entry));
202 entry->kind = TKIND_INTERFACE;
203 entry->u.interface = iface;
204 LINK(entry, typelib->entry);
205 typelib->entry = entry;
208 void add_coclass(class_t *cls)
210 typelib_entry_t *entry;
212 if (!typelib) return;
214 chat("add coclass: %s\n", cls->name);
216 entry = xmalloc(sizeof(*entry));
217 entry->kind = TKIND_COCLASS;
218 entry->u.class = cls;
219 LINK(entry, typelib->entry);
220 typelib->entry = entry;
223 void add_module(type_t *module)
225 typelib_entry_t *entry;
226 if (!typelib) return;
228 chat("add module: %s\n", module->name);
229 entry = xmalloc(sizeof(*entry));
230 entry->kind = TKIND_MODULE;
231 entry->u.module = module;
232 LINK(entry, typelib->entry);
233 typelib->entry = entry;
236 void add_struct(type_t *structure)
238 typelib_entry_t *entry;
239 if (!typelib) return;
241 chat("add struct: %s\n", structure->name);
242 entry = xmalloc(sizeof(*entry));
243 entry->kind = TKIND_RECORD;
244 entry->u.structure = structure;
245 LINK(entry, typelib->entry);
246 typelib->entry = entry;
249 void add_enum(type_t *enumeration)
251 typelib_entry_t *entry;
252 if (!typelib) return;
254 chat("add enum: %s\n", enumeration->name);
255 entry = xmalloc(sizeof(*entry));
256 entry->kind = TKIND_ENUM;
257 entry->u.enumeration = enumeration;
258 LINK(entry, typelib->entry);
259 typelib->entry = entry;
262 void add_typedef(type_t *tdef, var_t *name)
264 typelib_entry_t *entry;
265 if (!typelib) return;
267 entry = xmalloc(sizeof(*entry));
268 entry->kind = TKIND_ALIAS;
269 entry->u.tdef = xmalloc(sizeof(*entry->u.tdef));
270 memcpy(entry->u.tdef, name, sizeof(*name));
271 entry->u.tdef->type = tdef;
272 entry->u.tdef->name = xstrdup(name->name);
273 LINK(entry, typelib->entry);
274 typelib->entry = entry;