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
}
58 #define NTYPES (sizeof(oatypes)/sizeof(oatypes[0]))
59 #define KWP(p) ((const struct oatype *)(p))
61 static int kw_cmp_func(const void *s1
, const void *s2
)
63 return strcmp(KWP(s1
)->kw
, KWP(s2
)->kw
);
66 static unsigned short builtin_vt(const char *kw
)
68 struct oatype key
, *kwp
;
71 kwp
= bsearch(&key
, oatypes
, NTYPES
, sizeof(oatypes
[0]), kw_cmp_func
);
75 for (kwp
=NULL
, i
=0; i
< NTYPES
; i
++)
76 if (!kw_cmp_func(&key
, &oatypes
[i
])) {
88 static int match(const char*n
, const char*m
)
94 unsigned short get_type_vt(type_t
*t
)
98 chat("get_type_vt: %p type->name %s\n", t
, t
->name
);
100 vt
= builtin_vt(t
->name
);
112 return VT_I2
; /* mktyplib seems to parse wchar_t as short */
118 if (t
->ref
&& match(t
->ref
->name
, "int")) return VT_INT
;
121 if (t
->ref
&& match(t
->ref
->name
, "int")) return VT_UINT
;
124 if (t
->sign
< 0) return VT_UI8
;
125 if (t
->ref
&& match(t
->ref
->name
, "MIDL_uhyper")) return VT_UI8
;
138 error("get_type_vt: unknown-deref-type: %d\n", t
->ref
->type
);
141 if(match(t
->name
, "IUnknown"))
143 if(match(t
->name
, "IDispatch"))
145 return VT_USERDEFINED
;
149 return VT_USERDEFINED
;
152 return VT_USERDEFINED
;
155 error("get_type_vt: unknown-type: %d\n", t
->type
);
160 unsigned short get_var_vt(var_t
*v
)
164 chat("get_var_vt: %p tname %s\n", v
, v
->tname
);
166 vt
= builtin_vt(v
->tname
);
170 return get_type_vt(v
->type
);
173 void start_typelib(char *name
, attr_t
*attrs
)
176 if (!do_typelib
) return;
178 typelib
= xmalloc(sizeof(*typelib
));
179 typelib
->name
= xstrdup(name
);
180 typelib
->filename
= xstrdup(typelib_name
);
181 typelib
->attrs
= attrs
;
184 void end_typelib(void)
187 if (!typelib
) return;
189 create_msft_typelib(typelib
);
193 void add_interface(type_t
*iface
)
195 typelib_entry_t
*entry
;
196 if (!typelib
) return;
198 chat("add interface: %s\n", iface
->name
);
199 entry
= xmalloc(sizeof(*entry
));
200 entry
->kind
= TKIND_INTERFACE
;
201 entry
->u
.interface
= iface
;
202 LINK(entry
, typelib
->entry
);
203 typelib
->entry
= entry
;
206 void add_coclass(class_t
*cls
)
208 ifref_t
*lcur
= cls
->ifaces
;
210 typelib_entry_t
*entry
;
213 while (NEXT_LINK(lcur
)) lcur
= NEXT_LINK(lcur
);
216 if (!typelib
) return;
218 /* install interfaces the coclass depends on */
221 add_interface(cur
->iface
);
222 cur
= PREV_LINK(cur
);
224 entry
= xmalloc(sizeof(*entry
));
225 entry
->kind
= TKIND_COCLASS
;
226 entry
->u
.class = cls
;
227 LINK(entry
, typelib
->entry
);
228 typelib
->entry
= entry
;
231 void add_module(type_t
*module
)
233 typelib_entry_t
*entry
;
234 if (!typelib
) return;
236 chat("add module: %s\n", module
->name
);
237 entry
= xmalloc(sizeof(*entry
));
238 entry
->kind
= TKIND_MODULE
;
239 entry
->u
.module
= module
;
240 LINK(entry
, typelib
->entry
);
241 typelib
->entry
= entry
;
244 void add_struct(type_t
*structure
)
246 typelib_entry_t
*entry
;
247 if (!typelib
) return;
249 chat("add struct: %s\n", structure
->name
);
250 entry
= xmalloc(sizeof(*entry
));
251 entry
->kind
= TKIND_RECORD
;
252 entry
->u
.structure
= structure
;
253 LINK(entry
, typelib
->entry
);
254 typelib
->entry
= entry
;
257 void add_enum(type_t
*enumeration
)
259 typelib_entry_t
*entry
;
260 if (!typelib
) return;
262 chat("add enum: %s\n", enumeration
->name
);
263 entry
= xmalloc(sizeof(*entry
));
264 entry
->kind
= TKIND_ENUM
;
265 entry
->u
.enumeration
= enumeration
;
266 LINK(entry
, typelib
->entry
);
267 typelib
->entry
= entry
;
270 void add_typedef(type_t
*tdef
, var_t
*name
)
272 typelib_entry_t
*entry
;
273 if (!typelib
) return;
275 entry
= xmalloc(sizeof(*entry
));
276 entry
->kind
= TKIND_ALIAS
;
277 entry
->u
.tdef
= xmalloc(sizeof(*entry
->u
.tdef
));
278 memcpy(entry
->u
.tdef
, name
, sizeof(*name
));
279 entry
->u
.tdef
->type
= tdef
;
280 entry
->u
.tdef
->name
= xstrdup(name
->name
);
281 LINK(entry
, typelib
->entry
);
282 typelib
->entry
= entry
;