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
40 /* Copied from wtypes.h. Not included directly because that would create a
41 * circular dependency (after all, wtypes.h is generated by widl...) */
80 VT_STREAMED_OBJECT
= 68,
81 VT_STORED_OBJECT
= 69,
91 VT_ILLEGALMASKED
= 0xfff,
95 /* List of oleauto types that should be recognized by name.
96 * (most of) these seem to be intrinsic types in mktyplib. */
98 static struct oatype
{
105 {"DECIMAL", VT_DECIMAL
},
106 {"HRESULT", VT_HRESULT
},
108 {"LPWSTR", VT_LPWSTR
},
110 {"VARIANT", VT_VARIANT
}
112 #define NTYPES (sizeof(oatypes)/sizeof(oatypes[0]))
113 #define KWP(p) ((struct oatype *)(p))
115 static int kw_cmp_func(const void *s1
, const void *s2
)
117 return strcmp(KWP(s1
)->kw
, KWP(s2
)->kw
);
120 static unsigned short builtin_vt(const char *kw
)
122 struct oatype key
, *kwp
;
125 kwp
= bsearch(&key
, oatypes
, NTYPES
, sizeof(oatypes
[0]), kw_cmp_func
);
129 for (kwp
=NULL
, i
=0; i
< NTYPES
; i
++)
130 if (!kw_cmp_func(&key
, &oatypes
[i
])) {
142 static int match(const char*n
, const char*m
)
145 return !strcmp(n
, m
);
148 unsigned short get_type_vt(type_t
*t
)
153 vt
= builtin_vt(t
->name
);
165 return VT_I2
; /* mktyplib seems to parse wchar_t as short */
171 if (t
->ref
&& match(t
->ref
->name
, "int")) return VT_INT
;
174 if (t
->ref
&& match(t
->ref
->name
, "int")) return VT_UINT
;
177 if (t
->sign
< 0) return VT_UI8
;
178 if (t
->ref
&& match(t
->ref
->name
, "MIDL_uhyper")) return VT_UI8
;
188 /* it's a pointer... */
189 if (t
->ref
&& t
->ref
->type
== RPC_FC_IP
) {
190 /* it's to an interface, which one? */
191 if (match(t
->ref
->name
, "IDispatch"))
193 if (match(t
->ref
->name
, "IUnknown"))
196 /* FIXME: should we recurse and add a VT_BYREF? */
197 /* Or just return VT_PTR? */
198 error("get_type_vt: unknown-deref-type: %d\n", t
->ref
->type
);
201 error("get_type_vt: unknown-type: %d\n", t
->type
);
206 unsigned short get_var_vt(var_t
*v
)
211 vt
= builtin_vt(v
->tname
);
215 return get_type_vt(v
->type
);
218 void start_typelib(char *name
, attr_t
*attrs
)
221 if (!do_everything
&& !typelib_only
) return;
222 typelib
= fopen(typelib_name
, "wb");
225 void end_typelib(void)
227 if (typelib
) fclose(typelib
);
231 void add_interface(type_t
*iface
)
233 if (!typelib
) return;
235 /* FIXME: add interface and dependent types to typelib */
236 printf("add interface: %s\n", iface
->name
);
239 void add_coclass(class_t
*cls
)
241 ifref_t
*lcur
= cls
->ifaces
;
245 while (NEXT_LINK(lcur
)) lcur
= NEXT_LINK(lcur
);
248 if (!typelib
) return;
250 /* install interfaces the coclass depends on */
253 add_interface(cur
->iface
);
254 cur
= PREV_LINK(cur
);
257 /* FIXME: add coclass to typelib */
258 printf("add coclass: %s\n", cls
->name
);
261 void add_module(type_t
*module
)
263 if (!typelib
) return;
265 /* FIXME: add module to typelib */
266 printf("add module: %s\n", module
->name
);