ReactOS 0.4.16-dev-1946-g52006dd
write_msft.c File Reference
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <ctype.h>
#include <time.h>
#include "widl.h"
#include "typelib.h"
#include "typelib_struct.h"
#include "utils.h"
#include "header.h"
#include "hash.h"
#include "typetree.h"
#include "parser.h"
#include "typegen.h"
Include dependency graph for write_msft.c:

Go to the source code of this file.

Classes

struct  tagMSFT_ImpFile
 
struct  _msft_typelib_t
 
struct  _msft_typeinfo_t
 

Typedefs

typedef struct tagMSFT_ImpFile MSFT_ImpFile
 
typedef struct _msft_typelib_t msft_typelib_t
 
typedef struct _msft_typeinfo_t msft_typeinfo_t
 

Enumerations

enum  MSFT_segment_index {
  MSFT_SEG_TYPEINFO = 0 , MSFT_SEG_IMPORTINFO , MSFT_SEG_IMPORTFILES , MSFT_SEG_REFERENCES ,
  MSFT_SEG_GUIDHASH , MSFT_SEG_GUID , MSFT_SEG_NAMEHASH , MSFT_SEG_NAME ,
  MSFT_SEG_STRING , MSFT_SEG_TYPEDESC , MSFT_SEG_ARRAYDESC , MSFT_SEG_CUSTDATA ,
  MSFT_SEG_CUSTDATAGUID , MSFT_SEG_UNKNOWN , MSFT_SEG_UNKNOWN2 , MSFT_SEG_MAX
}
 

Functions

static void ctl2_init_header (msft_typelib_t *typelib)
 
static void ctl2_init_segdir (msft_typelib_t *typelib)
 
static int ctl2_hash_guid (const struct uuid *guid)
 
static int ctl2_find_guid (msft_typelib_t *typelib, int hash_key, const struct uuid *guid)
 
static int ctl2_find_name (msft_typelib_t *typelib, char *name)
 
static int ctl2_encode_name (msft_typelib_t *typelib, const char *name, char **result)
 
static int ctl2_encode_string (const char *string, char **result)
 
static int ctl2_alloc_segment (msft_typelib_t *typelib, enum MSFT_segment_index segment, int size, int block_size)
 
static int ctl2_alloc_typeinfo (msft_typelib_t *typelib, int nameoffset)
 
static int ctl2_alloc_guid (msft_typelib_t *typelib, MSFT_GuidEntry *guid)
 
static int ctl2_alloc_name (msft_typelib_t *typelib, const char *name)
 
static int ctl2_alloc_string (msft_typelib_t *typelib, const char *string)
 
static int alloc_msft_importinfo (msft_typelib_t *typelib, MSFT_ImpInfo *impinfo)
 
static int alloc_importfile (msft_typelib_t *typelib, int guidoffset, int major_version, int minor_version, const char *filename)
 
static void alloc_importinfo (msft_typelib_t *typelib, importinfo_t *importinfo)
 
static importinfo_tfind_importinfo (msft_typelib_t *typelib, const char *name)
 
static void add_structure_typeinfo (msft_typelib_t *typelib, type_t *structure)
 
static void add_interface_typeinfo (msft_typelib_t *typelib, type_t *interface)
 
static void add_enum_typeinfo (msft_typelib_t *typelib, type_t *enumeration)
 
static void add_union_typeinfo (msft_typelib_t *typelib, type_t *tunion)
 
static void add_coclass_typeinfo (msft_typelib_t *typelib, type_t *cls)
 
static void add_dispinterface_typeinfo (msft_typelib_t *typelib, type_t *dispinterface)
 
static void add_typedef_typeinfo (msft_typelib_t *typelib, type_t *dispinterface)
 
static int encode_type (msft_typelib_t *typelib, int vt, type_t *type, int *encoded_type, int *decoded_size)
 
static void dump_type (type_t *t)
 
static int encode_var (msft_typelib_t *typelib, type_t *type, var_t *var, int *encoded_type, int *decoded_size)
 
static unsigned int get_ulong_val (unsigned int val, int vt)
 
static void write_int_value (msft_typelib_t *typelib, int *out, int vt, int value)
 
static void write_string_value (msft_typelib_t *typelib, int *out, const char *value)
 
static void write_default_value (msft_typelib_t *typelib, type_t *type, expr_t *expr, int *out)
 
static void set_custdata (msft_typelib_t *typelib, const struct uuid *guid, int vt, const void *value, int *offset)
 
static void set_custdata_attr (msft_typelib_t *typelib, attr_custdata_t *custdata, int *offset)
 
static int add_func_desc (msft_typeinfo_t *typeinfo, var_t *func, int index)
 
static void add_var_desc (msft_typeinfo_t *typeinfo, unsigned int index, var_t *var)
 
static void add_impl_type (msft_typeinfo_t *typeinfo, type_t *ref, importinfo_t *importinfo)
 
static msft_typeinfo_tcreate_msft_typeinfo (msft_typelib_t *typelib, enum type_kind kind, const char *name, const attr_list_t *attrs)
 
static void add_dispatch (msft_typelib_t *typelib)
 
static void add_module_typeinfo (msft_typelib_t *typelib, type_t *module)
 
static void add_type_typeinfo (msft_typelib_t *typelib, type_t *type)
 
static void add_entry (msft_typelib_t *typelib, const statement_t *stmt)
 
static void set_name (msft_typelib_t *typelib)
 
static void set_version (msft_typelib_t *typelib)
 
static void set_guid (msft_typelib_t *typelib)
 
static void set_doc_string (msft_typelib_t *typelib)
 
static void set_help_file_name (msft_typelib_t *typelib)
 
static void set_help_context (msft_typelib_t *typelib)
 
static void set_help_string_dll (msft_typelib_t *typelib)
 
static void set_help_string_context (msft_typelib_t *typelib)
 
static void set_lcid (msft_typelib_t *typelib)
 
static void set_lib_flags (msft_typelib_t *typelib)
 
static void ctl2_write_segment (msft_typelib_t *typelib, int segment)
 
static void ctl2_finalize_typeinfos (msft_typelib_t *typelib, int filesize)
 
static int ctl2_finalize_segment (msft_typelib_t *typelib, int filepos, int segment)
 
static void ctl2_write_typeinfos (msft_typelib_t *typelib)
 
static void save_all_changes (msft_typelib_t *typelib)
 
int create_msft_typelib (typelib_t *typelib)
 

Typedef Documentation

◆ MSFT_ImpFile

◆ msft_typeinfo_t

◆ msft_typelib_t

Enumeration Type Documentation

◆ MSFT_segment_index

Enumerator
MSFT_SEG_TYPEINFO 
MSFT_SEG_IMPORTINFO 
MSFT_SEG_IMPORTFILES 
MSFT_SEG_REFERENCES 
MSFT_SEG_GUIDHASH 
MSFT_SEG_GUID 
MSFT_SEG_NAMEHASH 
MSFT_SEG_NAME 
MSFT_SEG_STRING 
MSFT_SEG_TYPEDESC 
MSFT_SEG_ARRAYDESC 
MSFT_SEG_CUSTDATA 
MSFT_SEG_CUSTDATAGUID 
MSFT_SEG_UNKNOWN 
MSFT_SEG_UNKNOWN2 
MSFT_SEG_MAX 

Definition at line 49 of file write_msft.c.

49 {
50 MSFT_SEG_TYPEINFO = 0, /* type information */
51 MSFT_SEG_IMPORTINFO, /* import information */
52 MSFT_SEG_IMPORTFILES, /* import filenames */
53 MSFT_SEG_REFERENCES, /* references (?) */
54 MSFT_SEG_GUIDHASH, /* hash table for guids? */
55 MSFT_SEG_GUID, /* guid storage */
56 MSFT_SEG_NAMEHASH, /* hash table for names */
57 MSFT_SEG_NAME, /* name storage */
58 MSFT_SEG_STRING, /* string storage */
59 MSFT_SEG_TYPEDESC, /* type descriptions */
60 MSFT_SEG_ARRAYDESC, /* array descriptions */
61 MSFT_SEG_CUSTDATA, /* custom data */
62 MSFT_SEG_CUSTDATAGUID, /* custom data guids */
63 MSFT_SEG_UNKNOWN, /* ??? */
64 MSFT_SEG_UNKNOWN2, /* ??? */
65 MSFT_SEG_MAX /* total number of segments */
66};
@ MSFT_SEG_NAME
Definition: write_msft.c:57
@ MSFT_SEG_REFERENCES
Definition: write_msft.c:53
@ MSFT_SEG_NAMEHASH
Definition: write_msft.c:56
@ MSFT_SEG_STRING
Definition: write_msft.c:58
@ MSFT_SEG_MAX
Definition: write_msft.c:65
@ MSFT_SEG_IMPORTINFO
Definition: write_msft.c:51
@ MSFT_SEG_IMPORTFILES
Definition: write_msft.c:52
@ MSFT_SEG_GUIDHASH
Definition: write_msft.c:54
@ MSFT_SEG_CUSTDATA
Definition: write_msft.c:61
@ MSFT_SEG_TYPEDESC
Definition: write_msft.c:59
@ MSFT_SEG_CUSTDATAGUID
Definition: write_msft.c:62
@ MSFT_SEG_TYPEINFO
Definition: write_msft.c:50
@ MSFT_SEG_GUID
Definition: write_msft.c:55
@ MSFT_SEG_UNKNOWN2
Definition: write_msft.c:64
@ MSFT_SEG_ARRAYDESC
Definition: write_msft.c:60
@ MSFT_SEG_UNKNOWN
Definition: write_msft.c:63

Function Documentation

◆ add_coclass_typeinfo()

static void add_coclass_typeinfo ( msft_typelib_t typelib,
type_t cls 
)
static

Definition at line 2323 of file write_msft.c.

2324{
2325 msft_typeinfo_t *msft_typeinfo;
2326 typeref_t *iref;
2327 int num_ifaces = 0, offset, i;
2328 MSFT_RefRecord *ref, *first = NULL, *first_source = NULL;
2329 int have_default = 0, have_default_source = 0;
2330 const attr_t *attr;
2331 typeref_list_t *ifaces;
2332
2333 if (-1 < cls->typelib_idx)
2334 return;
2335
2336 cls->typelib_idx = typelib->typelib_header.nrtypeinfos;
2337 msft_typeinfo = create_msft_typeinfo(typelib, TKIND_COCLASS, cls->name, cls->attrs);
2338
2339 ifaces = type_coclass_get_ifaces(cls);
2340 if (ifaces) LIST_FOR_EACH_ENTRY( iref, ifaces, typeref_t, entry ) num_ifaces++;
2341
2343 num_ifaces * sizeof(*ref), 0);
2344
2345 i = 0;
2346 if (ifaces) LIST_FOR_EACH_ENTRY( iref, ifaces, typeref_t, entry ) {
2347 if(iref->type->typelib_idx == -1)
2349 ref = (MSFT_RefRecord*) (typelib->typelib_segment_data[MSFT_SEG_REFERENCES] + offset + i * sizeof(*ref));
2350 ref->reftype = typelib->typelib_typeinfo_offsets[iref->type->typelib_idx];
2351 ref->flags = 0;
2352 ref->oCustData = -1;
2353 ref->onext = -1;
2354 if(i < num_ifaces - 1)
2355 ref->onext = offset + (i + 1) * sizeof(*ref);
2356
2357 if (iref->attrs) LIST_FOR_EACH_ENTRY( attr, iref->attrs, const attr_t, entry ) {
2358 switch(attr->type) {
2359 case ATTR_DEFAULT:
2360 ref->flags |= 0x1; /* IMPLTYPEFLAG_FDEFAULT */
2361 break;
2362 case ATTR_DEFAULTVTABLE:
2363 ref->flags |= 0x8; /* IMPLTYPEFLAG_FDEFAULTVTABLE */
2364 break;
2365 case ATTR_RESTRICTED:
2366 ref->flags |= 0x4; /* IMPLTYPEFLAG_FRESTRICTED */
2367 break;
2368 case ATTR_SOURCE:
2369 ref->flags |= 0x2; /* IMPLTYPEFLAG_FSOURCE */
2370 break;
2371 default:
2372 warning("add_coclass_typeinfo: unhandled attr %d\n", attr->type);
2373 }
2374 }
2375 if(ref->flags & 0x1) { /* IMPLTYPEFLAG_FDEFAULT */
2376 if(ref->flags & 0x2) /* IMPLTYPEFLAG_SOURCE */
2377 have_default_source = 1;
2378 else
2379 have_default = 1;
2380 }
2381
2382 /* If the interface is non-restricted and we haven't already had one then
2383 remember it so that we can use it as a default later */
2384 if((ref->flags & 0x4) == 0) { /* IMPLTYPEFLAG_FRESTRICTED */
2385 if(ref->flags & 0x2) { /* IMPLTYPEFLAG_FSOURCE */
2386 if(!first_source)
2387 first_source = ref;
2388 }
2389 else if(!first)
2390 first = ref;
2391 }
2392 i++;
2393 }
2394
2395 /* If we haven't had a default interface, then set the default flags on the
2396 first ones */
2397 if(!have_default && first)
2398 first->flags |= 0x1;
2399 if(!have_default_source && first_source)
2400 first_source->flags |= 0x1;
2401
2402 msft_typeinfo->typeinfo->cImplTypes = num_ifaces;
2403 msft_typeinfo->typeinfo->size = pointer_size;
2404 msft_typeinfo->typeinfo->typekind |= 0x2200;
2405}
Definition: list.h:37
#define NULL
Definition: types.h:112
GLintptr offset
Definition: glext.h:5920
const GLint * first
Definition: glext.h:5794
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
uint32_t entry
Definition: isohybrid.c:63
#define warning(s)
Definition: debug.h:83
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
MSFT_TypeInfoBase * typeinfo
Definition: write_msft.c:97
attr_list_t * attrs
Definition: widltypes.h:503
int typelib_idx
Definition: widltypes.h:529
const char * name
Definition: widltypes.h:500
attr_list_t * attrs
Definition: widltypes.h:572
type_t * type
Definition: widltypes.h:571
Definition: cookie.c:202
Definition: send.c:48
static typeref_list_t * type_coclass_get_ifaces(const type_t *type)
Definition: typetree.h:379
unsigned int pointer_size
Definition: widl.c:147
@ TKIND_COCLASS
Definition: widltypes.h:239
@ ATTR_DEFAULT
Definition: widltypes.h:95
@ ATTR_DEFAULTVTABLE
Definition: widltypes.h:100
@ ATTR_RESTRICTED
Definition: widltypes.h:168
@ ATTR_SOURCE
Definition: widltypes.h:171
static void add_interface_typeinfo(msft_typelib_t *typelib, type_t *interface)
Definition: write_msft.c:2138
static msft_typeinfo_t * create_msft_typeinfo(msft_typelib_t *typelib, enum type_kind kind, const char *name, const attr_list_t *attrs)
Definition: write_msft.c:1881
static int ctl2_alloc_segment(msft_typelib_t *typelib, enum MSFT_segment_index segment, int size, int block_size)
Definition: write_msft.c:365

Referenced by add_type_typeinfo(), and encode_type().

◆ add_dispatch()

static void add_dispatch ( msft_typelib_t typelib)
static

Definition at line 2025 of file write_msft.c.

2026{
2027 int guid_offset, impfile_offset, hash_key;
2028 MSFT_GuidEntry guidentry;
2029 MSFT_ImpInfo impinfo;
2030 static const struct uuid stdole = {0x00020430,0x0000,0x0000,{0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
2031 static const struct uuid iid_idispatch = {0x00020400,0x0000,0x0000,{0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
2032
2033 if(typelib->typelib_header.dispatchpos != -1) return;
2034
2035 guidentry.guid = stdole;
2036 guidentry.hreftype = 2;
2037 guidentry.next_hash = -1;
2038 hash_key = ctl2_hash_guid(&guidentry.guid);
2039 guid_offset = ctl2_find_guid(typelib, hash_key, &guidentry.guid);
2040 if (guid_offset == -1)
2041 guid_offset = ctl2_alloc_guid(typelib, &guidentry);
2042 impfile_offset = alloc_importfile(typelib, guid_offset, 2, 0, "stdole2.tlb");
2043
2044 guidentry.guid = iid_idispatch;
2045 guidentry.hreftype = 1;
2046 guidentry.next_hash = -1;
2048 impinfo.oImpFile = impfile_offset;
2049 hash_key = ctl2_hash_guid(&guidentry.guid);
2050 guid_offset = ctl2_find_guid(typelib, hash_key, &guidentry.guid);
2051 if (guid_offset == -1)
2052 guid_offset = ctl2_alloc_guid(typelib, &guidentry);
2053 impinfo.oGuid = guid_offset;
2054 typelib->typelib_header.dispatchpos = alloc_msft_importinfo(typelib, &impinfo) | 0x01;
2055}
#define MSFT_IMPINFO_OFFSET_IS_GUID
Definition: typelib.h:174
Definition: msctf.idl:532
@ TKIND_INTERFACE
Definition: widltypes.h:237
static int ctl2_find_guid(msft_typelib_t *typelib, int hash_key, const struct uuid *guid)
Definition: write_msft.c:209
static int ctl2_alloc_guid(msft_typelib_t *typelib, MSFT_GuidEntry *guid)
Definition: write_msft.c:471
static int ctl2_hash_guid(const struct uuid *guid)
Definition: write_msft.c:187
static int alloc_importfile(msft_typelib_t *typelib, int guidoffset, int major_version, int minor_version, const char *filename)
Definition: write_msft.c:638
static int alloc_msft_importinfo(msft_typelib_t *typelib, MSFT_ImpInfo *impinfo)
Definition: write_msft.c:602

Referenced by add_dispinterface_typeinfo().

◆ add_dispinterface_typeinfo()

static void add_dispinterface_typeinfo ( msft_typelib_t typelib,
type_t dispinterface 
)
static

Definition at line 2057 of file write_msft.c.

2058{
2059 int num_parents = 0, num_funcs = 0;
2060 importinfo_t *importinfo = NULL;
2061 const statement_t *stmt_func;
2062 type_t *inherit, *ref;
2063 int idx = 0;
2064 var_t *func;
2065 var_t *var;
2066 msft_typeinfo_t *msft_typeinfo;
2067
2068 if (-1 < dispinterface->typelib_idx)
2069 return;
2070
2071 inherit = type_dispiface_get_inherit(dispinterface);
2072
2073 if (inherit)
2074 {
2075 importinfo = find_importinfo(typelib, inherit->name);
2076
2077 if (!importinfo && type_iface_get_inherit(inherit) && inherit->typelib_idx == -1)
2079 }
2080
2081 /* check typelib_idx again, it could have been added while resolving the parent interface */
2082 if (-1 < dispinterface->typelib_idx)
2083 return;
2084
2085 dispinterface->typelib_idx = typelib->typelib_header.nrtypeinfos;
2086 msft_typeinfo = create_msft_typeinfo(typelib, TKIND_DISPATCH, dispinterface->name,
2087 dispinterface->attrs);
2088
2089 msft_typeinfo->typeinfo->size = pointer_size;
2090 msft_typeinfo->typeinfo->typekind |= pointer_size << 11 | pointer_size << 6;
2091
2092 msft_typeinfo->typeinfo->flags |= 0x1000; /* TYPEFLAG_FDISPATCHABLE */
2094
2095 if (inherit)
2096 {
2097 add_impl_type(msft_typeinfo, inherit, importinfo);
2098 msft_typeinfo->typeinfo->typekind |= 0x10;
2099 }
2100
2101 /* count the number of inherited interfaces and non-local functions */
2102 for (ref = inherit; ref; ref = type_iface_get_inherit(ref))
2103 {
2104 num_parents++;
2106 {
2107 var_t *func = stmt_func->u.var;
2108 if (!is_local(func->attrs)) num_funcs++;
2109 }
2110 }
2111 msft_typeinfo->typeinfo->datatype2 = num_funcs << 16 | num_parents;
2112 msft_typeinfo->typeinfo->cbSizeVft = num_funcs * pointer_size;
2113
2114 msft_typeinfo->typeinfo->cImplTypes = 1; /* IDispatch */
2115
2116 /* count the no of methods, as the variable indices come after the funcs */
2117 if (dispinterface->details.iface->disp_methods)
2118 LIST_FOR_EACH_ENTRY( func, dispinterface->details.iface->disp_methods, var_t, entry )
2119 idx++;
2120
2121 if (type_dispiface_get_props(dispinterface))
2123 add_var_desc(msft_typeinfo, idx++, var);
2124
2125 if (type_dispiface_get_methods(dispinterface))
2126 {
2127 idx = 0;
2129 if(add_func_desc(msft_typeinfo, func, idx))
2130 idx++;
2131 }
2132
2133 typelib->typelib->reg_ifaces = xrealloc(typelib->typelib->reg_ifaces,
2134 (typelib->typelib->reg_iface_count + 1) * sizeof(dispinterface));
2135 typelib->typelib->reg_ifaces[typelib->typelib->reg_iface_count++] = dispinterface;
2136}
void * xrealloc(void *oldmem, size_t size)
Definition: uimain.c:736
unsigned int idx
Definition: utils.c:41
GLenum func
Definition: glext.h:6028
const char * var
Definition: shader.c:5666
int is_local(const attr_list_t *a)
Definition: header.c:982
var_t * var
Definition: widltypes.h:631
union _statement_t::@5358 u
union _type_t::@5357 details
struct iface_details * iface
Definition: widltypes.h:509
static var_list_t * type_dispiface_get_methods(const type_t *type)
Definition: typetree.h:236
static type_t * type_dispiface_get_inherit(const type_t *type)
Definition: typetree.h:243
static type_t * type_iface_get_inherit(const type_t *type)
Definition: typetree.h:208
static statement_list_t * type_iface_get_stmts(const type_t *type)
Definition: typetree.h:201
static var_list_t * type_dispiface_get_props(const type_t *type)
Definition: typetree.h:229
@ TKIND_DISPATCH
Definition: widltypes.h:238
#define STATEMENTS_FOR_EACH_FUNC(stmt, stmts)
Definition: widltypes.h:684
static int add_func_desc(msft_typeinfo_t *typeinfo, var_t *func, int index)
Definition: write_msft.c:1311
static void add_dispatch(msft_typelib_t *typelib)
Definition: write_msft.c:2025
static importinfo_t * find_importinfo(msft_typelib_t *typelib, const char *name)
Definition: write_msft.c:724
static void add_var_desc(msft_typeinfo_t *typeinfo, unsigned int index, var_t *var)
Definition: write_msft.c:1661
static void add_impl_type(msft_typeinfo_t *typeinfo, type_t *ref, importinfo_t *importinfo)
Definition: write_msft.c:1864

Referenced by add_interface_typeinfo().

◆ add_entry()

static void add_entry ( msft_typelib_t typelib,
const statement_t stmt 
)
static

Definition at line 2459 of file write_msft.c.

2460{
2461 switch(stmt->type) {
2462 case STMT_LIBRARY:
2463 case STMT_IMPORT:
2464 case STMT_PRAGMA:
2465 case STMT_CPPQUOTE:
2466 case STMT_DECLARATION:
2467 /* not included in typelib */
2468 break;
2469 case STMT_IMPORTLIB:
2470 /* not processed here */
2471 break;
2472 case STMT_TYPEDEF:
2473 {
2474 typeref_t *ref;
2476 /* if the type is public then add the typedef, otherwise attempt
2477 * to add the aliased type */
2478 if (is_attr(ref->type->attrs, ATTR_PUBLIC))
2480 else
2482 }
2483 break;
2484 }
2485 case STMT_MODULE:
2487 break;
2488 case STMT_TYPE:
2489 case STMT_TYPEREF:
2490 {
2491 type_t *type = stmt->u.type;
2493 break;
2494 }
2495 }
2496}
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
int is_attr(const attr_list_t *list, enum attr_type attr_type)
Definition: attribute.c:45
statement_type_t type
Definition: parser.h:124
typeref_list_t * type_list
Definition: widltypes.h:633
static type_t * type_alias_get_aliasee_type(const type_t *type)
Definition: typetree.h:373
@ ATTR_PUBLIC
Definition: widltypes.h:163
@ STMT_MODULE
Definition: widltypes.h:269
@ STMT_IMPORT
Definition: widltypes.h:271
@ STMT_IMPORTLIB
Definition: widltypes.h:272
@ STMT_TYPE
Definition: widltypes.h:267
@ STMT_DECLARATION
Definition: widltypes.h:266
@ STMT_LIBRARY
Definition: widltypes.h:265
@ STMT_TYPEDEF
Definition: widltypes.h:270
@ STMT_CPPQUOTE
Definition: widltypes.h:274
@ STMT_TYPEREF
Definition: widltypes.h:268
@ STMT_PRAGMA
Definition: widltypes.h:273
static void add_module_typeinfo(msft_typelib_t *typelib, type_t *module)
Definition: write_msft.c:2407
static void add_typedef_typeinfo(msft_typelib_t *typelib, type_t *dispinterface)
Definition: write_msft.c:2287
static void add_type_typeinfo(msft_typelib_t *typelib, type_t *type)
Definition: write_msft.c:2429

Referenced by create_msft_typelib().

◆ add_enum_typeinfo()

static void add_enum_typeinfo ( msft_typelib_t typelib,
type_t enumeration 
)
static

Definition at line 2248 of file write_msft.c.

2249{
2250 int idx = 0;
2251 var_t *cur;
2252 msft_typeinfo_t *msft_typeinfo;
2253
2254 if (-1 < enumeration->typelib_idx)
2255 return;
2256
2257 enumeration->typelib_idx = typelib->typelib_header.nrtypeinfos;
2258 msft_typeinfo = create_msft_typeinfo(typelib, TKIND_ENUM, enumeration->name, enumeration->attrs);
2259 msft_typeinfo->typeinfo->size = 0;
2260
2261 if (type_enum_get_values(enumeration))
2263 add_var_desc(msft_typeinfo, idx++, cur);
2264}
FxCollectionEntry * cur
static var_list_t * type_enum_get_values(const type_t *type)
Definition: typetree.h:163
@ TKIND_ENUM
Definition: widltypes.h:234

Referenced by add_type_typeinfo(), and encode_type().

◆ add_func_desc()

static int add_func_desc ( msft_typeinfo_t typeinfo,
var_t func,
int  index 
)
static

Definition at line 1311 of file write_msft.c.

1312{
1313 int offset, name_offset;
1314 int *typedata, typedata_size;
1315 int i, id, next_idx;
1316 int decoded_size, extra_attr = 0;
1317 int num_params = 0, num_optional = 0, num_defaults = 0;
1318 int has_arg_custdata = 0;
1319 var_t *arg;
1320 unsigned char *namedata;
1321 const attr_t *attr;
1322 unsigned int funcflags = 0, callconv = 4 /* CC_STDCALL */;
1323 unsigned int funckind, invokekind = 1 /* INVOKE_FUNC */;
1324 int help_context = 0, help_string_context = 0, help_string_offset = -1;
1325 int func_custdata_offset = -1;
1326 int entry = -1, entry_is_ord = 0;
1327 int lcid_retval_count = 0;
1328
1329 chat("add_func_desc(%p,%d)\n", typeinfo, index);
1330
1331 id = ((0x6000 | (typeinfo->typeinfo->datatype2 & 0xffff)) << 16) | index;
1332
1333 switch(typeinfo->typekind) {
1334 case TKIND_DISPATCH:
1335 funckind = 0x4; /* FUNC_DISPATCH */
1336 break;
1337 case TKIND_MODULE:
1338 funckind = 0x3; /* FUNC_STATIC */
1339 break;
1340 default:
1341 funckind = 0x1; /* FUNC_PUREVIRTUAL */
1342 break;
1343 }
1344
1345 if (is_local( func->attrs )) {
1346 chat("add_func_desc: skipping local function\n");
1347 return FALSE;
1348 }
1349
1350 if (type_function_get_args(func->declspec.type))
1352 {
1353 num_params++;
1354 if (arg->attrs) LIST_FOR_EACH_ENTRY( attr, arg->attrs, const attr_t, entry ) {
1355 if(attr->type == ATTR_DEFAULTVALUE)
1356 num_defaults++;
1357 else if(attr->type == ATTR_OPTIONAL)
1358 num_optional++;
1359 else if(attr->type == ATTR_CUSTOM)
1360 has_arg_custdata = 1;
1361 }
1362 }
1363
1364 chat("add_func_desc: num of params %d\n", num_params);
1365
1366 name_offset = ctl2_alloc_name(typeinfo->typelib, func->name);
1367
1368 if (func->attrs) LIST_FOR_EACH_ENTRY( attr, func->attrs, const attr_t, entry ) {
1369 expr_t *expr = attr->u.pval;
1370 switch(attr->type) {
1371 case ATTR_BINDABLE:
1372 funcflags |= 0x4; /* FUNCFLAG_FBINDABLE */
1373 break;
1374 case ATTR_CUSTOM:
1375 set_custdata_attr(typeinfo->typelib, attr->u.pval, &func_custdata_offset);
1376 break;
1377 case ATTR_DEFAULTBIND:
1378 funcflags |= 0x20; /* FUNCFLAG_FDEFAULTBIND */
1379 break;
1381 funcflags |= 0x100; /* FUNCFLAG_FDEFAULTCOLLELEM */
1382 break;
1383 case ATTR_DISPLAYBIND:
1384 funcflags |= 0x10; /* FUNCFLAG_FDISPLAYBIND */
1385 break;
1386 case ATTR_ENTRY:
1387 extra_attr = max(extra_attr, 3);
1388 if (expr->type == EXPR_STRLIT || expr->type == EXPR_WSTRLIT)
1389 entry = ctl2_alloc_string(typeinfo->typelib, attr->u.pval);
1390 else {
1391 entry = expr->cval;
1392 entry_is_ord = 1;
1393 }
1394 break;
1395 case ATTR_HELPCONTEXT:
1396 extra_attr = max(extra_attr, 1);
1397 help_context = expr->u.integer.value;
1398 break;
1399 case ATTR_HELPSTRING:
1400 extra_attr = max(extra_attr, 2);
1401 help_string_offset = ctl2_alloc_string(typeinfo->typelib, attr->u.pval);
1402 break;
1404 extra_attr = max(extra_attr, 6);
1405 help_string_context = expr->u.integer.value;
1406 break;
1407 case ATTR_HIDDEN:
1408 funcflags |= 0x40; /* FUNCFLAG_FHIDDEN */
1409 break;
1410 case ATTR_ID:
1411 id = expr->cval;
1412 break;
1413 case ATTR_IMMEDIATEBIND:
1414 funcflags |= 0x1000; /* FUNCFLAG_FIMMEDIATEBIND */
1415 break;
1416 case ATTR_NONBROWSABLE:
1417 funcflags |= 0x400; /* FUNCFLAG_FNONBROWSABLE */
1418 break;
1419 case ATTR_OUT:
1420 break;
1422 case ATTR_OVERLOAD:
1423 break;
1424 case ATTR_PROPGET:
1425 invokekind = 0x2; /* INVOKE_PROPERTYGET */
1426 break;
1427 case ATTR_PROPPUT:
1428 invokekind = 0x4; /* INVOKE_PROPERTYPUT */
1429 break;
1430 case ATTR_PROPPUTREF:
1431 invokekind = 0x8; /* INVOKE_PROPERTYPUTREF */
1432 break;
1433 /* FIXME: FUNCFLAG_FREPLACEABLE */
1434 case ATTR_REQUESTEDIT:
1435 funcflags |= 0x8; /* FUNCFLAG_FREQUESTEDIT */
1436 break;
1437 case ATTR_RESTRICTED:
1438 funcflags |= 0x1; /* FUNCFLAG_FRESTRICTED */
1439 break;
1440 case ATTR_SOURCE:
1441 funcflags |= 0x2; /* FUNCFLAG_FSOURCE */
1442 break;
1443 case ATTR_UIDEFAULT:
1444 funcflags |= 0x200; /* FUNCFLAG_FUIDEFAULT */
1445 break;
1447 funcflags |= 0x80; /* FUNCFLAG_FUSESGETLASTERROR */
1448 break;
1449 case ATTR_VARARG:
1450 if (num_optional || num_defaults)
1451 warning("add_func_desc: ignoring vararg in function with optional or defaultvalue params\n");
1452 else
1453 num_optional = -1;
1454 break;
1455 default:
1456 break;
1457 }
1458 }
1459
1460 if(has_arg_custdata || func_custdata_offset != -1) {
1461 extra_attr = max(extra_attr, 7 + num_params);
1462 }
1463
1464 /* allocate type data space for us */
1465 typedata_size = 0x18 + extra_attr * sizeof(int) + (num_params * (num_defaults ? 16 : 12));
1466
1467 if (!typeinfo->func_data) {
1468 typeinfo->func_data = xmalloc(0x100);
1469 typeinfo->func_data_allocated = 0x100;
1470 typeinfo->func_data[0] = 0;
1471 }
1472
1473 if(typeinfo->func_data[0] + typedata_size + sizeof(int) > typeinfo->func_data_allocated) {
1474 typeinfo->func_data_allocated = max(typeinfo->func_data_allocated * 2,
1475 typeinfo->func_data[0] + typedata_size + sizeof(int));
1476 typeinfo->func_data = xrealloc(typeinfo->func_data, typeinfo->func_data_allocated);
1477 }
1478
1479 offset = typeinfo->func_data[0];
1480 typeinfo->func_data[0] += typedata_size;
1481 typedata = typeinfo->func_data + (offset >> 2) + 1;
1482
1483
1484 /* find func with the same name - if it exists use its id */
1485 for(i = 0; i < (typeinfo->typeinfo->cElement & 0xffff); i++) {
1486 if(name_offset == typeinfo->func_names[i]) {
1487 id = typeinfo->func_indices[i];
1488 break;
1489 }
1490 }
1491
1492 /* find the first func with the same id and link via the hiword of typedata[4] */
1493 next_idx = index;
1494 for(i = 0; i < (typeinfo->typeinfo->cElement & 0xffff); i++) {
1495 if(id == typeinfo->func_indices[i]) {
1496 next_idx = typeinfo->func_data[(typeinfo->func_offsets[i] >> 2) + 1 + 4] >> 16;
1497 typeinfo->func_data[(typeinfo->func_offsets[i] >> 2) + 1 + 4] &= 0xffff;
1498 typeinfo->func_data[(typeinfo->func_offsets[i] >> 2) + 1 + 4] |= (index << 16);
1499 break;
1500 }
1501 }
1502
1503 /* fill out the basic type information */
1504 typedata[0] = typedata_size | (index << 16);
1505 encode_var(typeinfo->typelib, type_function_get_rettype(func->declspec.type), func,
1506 &typedata[1], &decoded_size);
1507 typedata[2] = funcflags;
1508 typedata[3] = ((52 /*sizeof(FUNCDESC)*/ + decoded_size) << 16) | typeinfo->typeinfo->cbSizeVft;
1509 typedata[4] = (next_idx << 16) | (callconv << 8) | (invokekind << 3) | funckind;
1510 if(has_arg_custdata || func_custdata_offset != -1) typedata[4] |= 0x0080;
1511 if(num_defaults) typedata[4] |= 0x1000;
1512 if(entry_is_ord) typedata[4] |= 0x2000;
1513 typedata[5] = (num_optional << 16) | num_params;
1514
1515 /* NOTE: High word of typedata[3] is total size of FUNCDESC + size of all ELEMDESCs for params + TYPEDESCs for pointer params and return types. */
1516 /* That is, total memory allocation required to reconstitute the FUNCDESC in its entirety. */
1517 typedata[3] += (16 /*sizeof(ELEMDESC)*/ * num_params) << 16;
1518 typedata[3] += (24 /*sizeof(PARAMDESCEX)*/ * num_defaults) << 16;
1519
1520 switch(extra_attr) {
1521 default:
1522 if(extra_attr > 7 + num_params) warning("unknown number of optional attrs\n");
1523 /* typedata[13..+num_params] = arg_custdata_offset handled in below loop */
1524 case 7: typedata[12] = func_custdata_offset;
1525 case 6: typedata[11] = help_string_context;
1526 case 5: typedata[10] = -1;
1527 case 4: typedata[9] = -1;
1528 case 3: typedata[8] = entry;
1529 case 2: typedata[7] = help_string_offset;
1530 case 1: typedata[6] = help_context;
1531 case 0:
1532 break;
1533 }
1534
1535 if (type_function_get_args(func->declspec.type))
1536 {
1537 i = 0;
1539 {
1540 int paramflags = 0;
1541 int *paramdata = typedata + 6 + extra_attr + (num_defaults ? num_params : 0) + i * 3;
1542 int *defaultdata = num_defaults ? typedata + 6 + extra_attr + i : NULL;
1543 int arg_custdata_offset = -1;
1544
1545 if(defaultdata) *defaultdata = -1;
1546
1547 encode_var(typeinfo->typelib, arg->declspec.type, arg, paramdata, &decoded_size);
1548 if (arg->attrs) LIST_FOR_EACH_ENTRY( attr, arg->attrs, const attr_t, entry ) {
1549 switch(attr->type) {
1550 case ATTR_CUSTOM:
1551 set_custdata_attr(typeinfo->typelib, attr->u.pval, &arg_custdata_offset);
1552 break;
1553 case ATTR_DEFAULTVALUE:
1554 {
1555 paramflags |= 0x30; /* PARAMFLAG_FHASDEFAULT | PARAMFLAG_FOPT */
1556 write_default_value(typeinfo->typelib, arg->declspec.type, (expr_t *)attr->u.pval, defaultdata);
1557 break;
1558 }
1559 case ATTR_IN:
1560 paramflags |= 0x01; /* PARAMFLAG_FIN */
1561 break;
1562 case ATTR_OPTIONAL:
1563 paramflags |= 0x10; /* PARAMFLAG_FOPT */
1564 break;
1565 case ATTR_OUT:
1566 paramflags |= 0x02; /* PARAMFLAG_FOUT */
1567 break;
1568 case ATTR_PARAMLCID:
1569 paramflags |= 0x04; /* PARAMFLAG_LCID */
1570 lcid_retval_count++;
1571 break;
1572 case ATTR_RETVAL:
1573 paramflags |= 0x08; /* PARAMFLAG_FRETVAL */
1574 lcid_retval_count++;
1575 break;
1576 default:
1577 chat("unhandled param attr %d\n", attr->type);
1578 break;
1579 }
1580 if(extra_attr > 7 + i) {
1581 typedata[13+i] = arg_custdata_offset;
1582 }
1583 }
1584 paramdata[1] = -1;
1585 paramdata[2] = paramflags;
1586 typedata[3] += decoded_size << 16;
1587
1588 i++;
1589 }
1590 }
1591
1592 if(lcid_retval_count == 1)
1593 typedata[4] |= 0x4000;
1594 else if(lcid_retval_count == 2)
1595 typedata[4] |= 0x8000;
1596
1597 if(typeinfo->funcs_allocated == 0) {
1598 typeinfo->funcs_allocated = 10;
1599 typeinfo->func_indices = xmalloc(typeinfo->funcs_allocated * sizeof(int));
1600 typeinfo->func_names = xmalloc(typeinfo->funcs_allocated * sizeof(int));
1601 typeinfo->func_offsets = xmalloc(typeinfo->funcs_allocated * sizeof(int));
1602 }
1603 if(typeinfo->funcs_allocated == (typeinfo->typeinfo->cElement & 0xffff)) {
1604 typeinfo->funcs_allocated *= 2;
1605 typeinfo->func_indices = xrealloc(typeinfo->func_indices, typeinfo->funcs_allocated * sizeof(int));
1606 typeinfo->func_names = xrealloc(typeinfo->func_names, typeinfo->funcs_allocated * sizeof(int));
1607 typeinfo->func_offsets = xrealloc(typeinfo->func_offsets, typeinfo->funcs_allocated * sizeof(int));
1608 }
1609
1610 /* update the index data */
1611 typeinfo->func_indices[typeinfo->typeinfo->cElement & 0xffff] = id;
1612 typeinfo->func_offsets[typeinfo->typeinfo->cElement & 0xffff] = offset;
1613 typeinfo->func_names[typeinfo->typeinfo->cElement & 0xffff] = name_offset;
1614
1615 /* ??? */
1616 if (!typeinfo->typeinfo->res2) typeinfo->typeinfo->res2 = 0x20;
1617 typeinfo->typeinfo->res2 <<= 1;
1618 /* ??? */
1619 if (index < 2) typeinfo->typeinfo->res2 += num_params << 4;
1620
1621 if (typeinfo->typeinfo->res3 == -1) typeinfo->typeinfo->res3 = 0;
1622 typeinfo->typeinfo->res3 += 0x38 + num_params * 0x10;
1623 if(num_defaults) typeinfo->typeinfo->res3 += num_params * 0x4;
1624
1625 /* adjust size of VTBL */
1626 if(funckind != 0x3 /* FUNC_STATIC */)
1627 typeinfo->typeinfo->cbSizeVft += pointer_size;
1628
1629 /* Increment the number of function elements */
1630 typeinfo->typeinfo->cElement += 1;
1631
1632 namedata = typeinfo->typelib->typelib_segment_data[MSFT_SEG_NAME] + name_offset;
1633 if (*((int *)namedata) == -1) {
1634 *((int *)namedata) = typeinfo->typelib->typelib_typeinfo_offsets[typeinfo->typeinfo->typekind >> 16];
1635 if(typeinfo->typekind == TKIND_MODULE)
1636 namedata[9] |= 0x10;
1637 } else
1638 namedata[9] &= ~0x10;
1639
1640 if(typeinfo->typekind == TKIND_MODULE)
1641 namedata[9] |= 0x20;
1642
1643 if (type_function_get_args(func->declspec.type))
1644 {
1645 i = 0;
1647 {
1648 /* don't give the last arg of a [propput*] func a name */
1649 if(i != num_params - 1 || (invokekind != 0x4 /* INVOKE_PROPERTYPUT */ && invokekind != 0x8 /* INVOKE_PROPERTYPUTREF */))
1650 {
1651 int *paramdata = typedata + 6 + extra_attr + (num_defaults ? num_params : 0) + i * 3;
1652 offset = ctl2_alloc_name(typeinfo->typelib, arg->name);
1653 paramdata[1] = offset;
1654 }
1655 i++;
1656 }
1657 }
1658 return TRUE;
1659}
void * xmalloc(int size)
Definition: uimain.c:747
#define index(s, c)
Definition: various.h:29
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t _In_ bool _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY _In_ uint8_t _In_ uint64_t decoded_size
Definition: btrfs_drv.h:1365
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLuint index
Definition: glext.h:6031
GLuint id
Definition: glext.h:5910
#define ATTR_HIDDEN
Definition: mkdosfs.c:367
void chat(const char *s,...)
Definition: utils.c:79
Definition: query.h:86
union expr::@560 u
int type
Definition: query.h:87
#define max(a, b)
Definition: svc.c:63
static type_t * type_function_get_rettype(const type_t *type)
Definition: typetree.h:158
static var_list_t * type_function_get_args(const type_t *type)
Definition: typetree.h:139
@ EXPR_WSTRLIT
Definition: widltypes.h:227
@ EXPR_STRLIT
Definition: widltypes.h:226
@ TKIND_MODULE
Definition: widltypes.h:236
@ ATTR_IN
Definition: widltypes.h:131
@ ATTR_RETVAL
Definition: widltypes.h:169
@ ATTR_PROPPUT
Definition: widltypes.h:159
@ ATTR_DEFAULT_OVERLOAD
Definition: widltypes.h:96
@ ATTR_DEFAULTBIND
Definition: widltypes.h:97
@ ATTR_VARARG
Definition: widltypes.h:184
@ ATTR_PROPPUTREF
Definition: widltypes.h:160
@ ATTR_IMMEDIATEBIND
Definition: widltypes.h:129
@ ATTR_DEFAULTCOLLELEM
Definition: widltypes.h:98
@ ATTR_ENTRY
Definition: widltypes.h:110
@ ATTR_OVERLOAD
Definition: widltypes.h:152
@ ATTR_REQUESTEDIT
Definition: widltypes.h:167
@ ATTR_UIDEFAULT
Definition: widltypes.h:179
@ ATTR_DISPLAYBIND
Definition: widltypes.h:104
@ ATTR_OUT
Definition: widltypes.h:151
@ ATTR_PROPGET
Definition: widltypes.h:158
@ ATTR_HELPSTRINGCONTEXT
Definition: widltypes.h:122
@ ATTR_BINDABLE
Definition: widltypes.h:81
@ ATTR_OPTIONAL
Definition: widltypes.h:150
@ ATTR_ID
Definition: widltypes.h:125
@ ATTR_HELPCONTEXT
Definition: widltypes.h:119
@ ATTR_HELPSTRING
Definition: widltypes.h:121
@ ATTR_PARAMLCID
Definition: widltypes.h:153
@ ATTR_NONBROWSABLE
Definition: widltypes.h:141
@ ATTR_CUSTOM
Definition: widltypes.h:93
@ ATTR_DEFAULTVALUE
Definition: widltypes.h:99
@ ATTR_USESGETLASTERROR
Definition: widltypes.h:181
void * arg
Definition: msvc.h:10
static void set_custdata_attr(msft_typelib_t *typelib, attr_custdata_t *custdata, int *offset)
Definition: write_msft.c:1295
static int ctl2_alloc_name(msft_typelib_t *typelib, const char *name)
Definition: write_msft.c:519
static int ctl2_alloc_string(msft_typelib_t *typelib, const char *string)
Definition: write_msft.c:566
static int encode_var(msft_typelib_t *typelib, type_t *type, var_t *var, int *encoded_type, int *decoded_size)
Definition: write_msft.c:1036
static void write_default_value(msft_typelib_t *typelib, type_t *type, expr_t *expr, int *out)
Definition: write_msft.c:1196

Referenced by add_dispinterface_typeinfo(), add_interface_typeinfo(), and add_module_typeinfo().

◆ add_impl_type()

static void add_impl_type ( msft_typeinfo_t typeinfo,
type_t ref,
importinfo_t importinfo 
)
static

Definition at line 1864 of file write_msft.c.

1865{
1866 if(importinfo) {
1867 alloc_importinfo(typeinfo->typelib, importinfo);
1868 typeinfo->typeinfo->datatype1 = importinfo->offset+1;
1869 }else {
1870 if(ref->typelib_idx == -1)
1872 if(ref->typelib_idx == -1)
1873 error("add_impl_type: unable to add inherited interface\n");
1874
1875 typeinfo->typeinfo->datatype1 = typeinfo->typelib->typelib_typeinfo_offsets[ref->typelib_idx];
1876 }
1877
1878 typeinfo->typeinfo->cImplTypes++;
1879}
#define error(str)
Definition: mkdosfs.c:1605
static void alloc_importinfo(msft_typelib_t *typelib, importinfo_t *importinfo)
Definition: write_msft.c:673

Referenced by add_dispinterface_typeinfo(), and add_interface_typeinfo().

◆ add_interface_typeinfo()

static void add_interface_typeinfo ( msft_typelib_t typelib,
type_t interface 
)
static

Definition at line 2138 of file write_msft.c.

2139{
2140 int idx = 0;
2141 const statement_t *stmt_func;
2142 type_t *ref;
2143 msft_typeinfo_t *msft_typeinfo;
2144 importinfo_t *ref_importinfo = NULL;
2145 int num_parents = 0, num_funcs = 0;
2146 type_t *inherit;
2147 const type_t *derived;
2148
2149 if (-1 < interface->typelib_idx)
2150 return;
2151
2152 if (!interface->details.iface)
2153 {
2154 error( "interface %s is referenced but not defined\n", interface->name );
2155 return;
2156 }
2157
2158 if (is_attr(interface->attrs, ATTR_DISPINTERFACE)) {
2160 return;
2161 }
2162
2163 /* midl adds the parent interface first, unless the parent itself
2164 has no parent (i.e. it stops before IUnknown). */
2165
2167
2168 if(inherit) {
2169 ref_importinfo = find_importinfo(typelib, inherit->name);
2170
2171 if(!ref_importinfo && type_iface_get_inherit(inherit) &&
2172 inherit->typelib_idx == -1)
2174 }
2175
2176 /* check typelib_idx again, it could have been added while resolving the parent interface */
2177 if (-1 < interface->typelib_idx)
2178 return;
2179
2180 interface->typelib_idx = typelib->typelib_header.nrtypeinfos;
2182 msft_typeinfo->typeinfo->size = pointer_size;
2183 msft_typeinfo->typeinfo->typekind |= 0x0200;
2184 msft_typeinfo->typeinfo->typekind |= pointer_size << 11;
2185
2187 if (derived->name && !strcmp(derived->name, "IDispatch"))
2188 msft_typeinfo->typeinfo->flags |= 0x1000; /* TYPEFLAG_FDISPATCHABLE */
2189
2192 ref_importinfo);
2193
2194 /* count the number of inherited interfaces and non-local functions */
2195 for(ref = inherit; ref; ref = type_iface_get_inherit(ref)) {
2196 num_parents++;
2198 var_t *func = stmt_func->u.var;
2199 if (!is_local(func->attrs)) num_funcs++;
2200 }
2201 }
2202 msft_typeinfo->typeinfo->datatype2 = num_funcs << 16 | num_parents;
2203 msft_typeinfo->typeinfo->cbSizeVft = num_funcs * pointer_size;
2204
2206 var_t *func = stmt_func->u.var;
2207 if(add_func_desc(msft_typeinfo, func, idx))
2208 idx++;
2209 }
2210
2212 {
2213 typelib->typelib->reg_ifaces = xrealloc(typelib->typelib->reg_ifaces,
2214 (typelib->typelib->reg_iface_count + 1) * sizeof(interface));
2215 typelib->typelib->reg_ifaces[typelib->typelib->reg_iface_count++] = interface;
2216 }
2217}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define interface
Definition: basetyps.h:61
char * name
Definition: compiler.c:66
@ ATTR_OLEAUTOMATION
Definition: widltypes.h:148
@ ATTR_DUAL
Definition: widltypes.h:106
@ ATTR_DISPINTERFACE
Definition: widltypes.h:103
static void add_dispinterface_typeinfo(msft_typelib_t *typelib, type_t *dispinterface)
Definition: write_msft.c:2057

Referenced by add_coclass_typeinfo(), add_dispinterface_typeinfo(), add_impl_type(), add_interface_typeinfo(), add_type_typeinfo(), and encode_type().

◆ add_module_typeinfo()

static void add_module_typeinfo ( msft_typelib_t typelib,
type_t module 
)
static

Definition at line 2407 of file write_msft.c.

2408{
2409 int idx = 0;
2410 const statement_t *stmt;
2411 msft_typeinfo_t *msft_typeinfo;
2412
2413 if (-1 < module->typelib_idx)
2414 return;
2415
2416 module->typelib_idx = typelib->typelib_header.nrtypeinfos;
2417 msft_typeinfo = create_msft_typeinfo(typelib, TKIND_MODULE, module->name, module->attrs);
2418 msft_typeinfo->typeinfo->typekind |= 0x0a00;
2419
2420 STATEMENTS_FOR_EACH_FUNC( stmt, module->details.module->stmts ) {
2421 var_t *func = stmt->u.var;
2422 if(add_func_desc(msft_typeinfo, func, idx))
2423 idx++;
2424 }
2425
2426 msft_typeinfo->typeinfo->size = idx;
2427}
IMAGEHLP_MODULEW64 module

Referenced by add_entry().

◆ add_structure_typeinfo()

static void add_structure_typeinfo ( msft_typelib_t typelib,
type_t structure 
)
static

Definition at line 2219 of file write_msft.c.

2220{
2222 int idx = 0;
2223 var_t *cur;
2224 msft_typeinfo_t *msft_typeinfo;
2225
2226 if (-1 < structure->typelib_idx)
2227 return;
2228
2229 if (!structure->name)
2230 structure->name = gen_name();
2231
2232 structure->typelib_idx = typelib->typelib_header.nrtypeinfos;
2233 msft_typeinfo = create_msft_typeinfo(typelib, TKIND_RECORD, structure->name, structure->attrs);
2234 msft_typeinfo->typeinfo->size = 0;
2235
2236 if (type_get_type(structure) == TYPE_STRUCT)
2237 fields = type_struct_get_fields(structure);
2238 else
2240
2241 if (fields)
2242 {
2244 add_var_desc(msft_typeinfo, idx++, cur);
2245 }
2246}
const char * fields[10]
Definition: parser.c:313
static enum type_type type_get_type(const type_t *type)
Definition: typetree.h:113
static var_list_t * type_struct_get_fields(const type_t *type)
Definition: typetree.h:132
static var_list_t * type_encapsulated_union_get_fields(const type_t *type)
Definition: typetree.h:177
char * gen_name(void)
@ TYPE_STRUCT
Definition: widltypes.h:481
@ TKIND_RECORD
Definition: widltypes.h:235

Referenced by add_type_typeinfo(), and encode_type().

◆ add_type_typeinfo()

static void add_type_typeinfo ( msft_typelib_t typelib,
type_t type 
)
static

Definition at line 2429 of file write_msft.c.

2430{
2431 switch (type_get_type(type)) {
2432 case TYPE_INTERFACE:
2434 break;
2435 case TYPE_STRUCT:
2438 break;
2439 case TYPE_ENUM:
2441 break;
2442 case TYPE_UNION:
2444 break;
2445 case TYPE_COCLASS:
2447 break;
2448 case TYPE_BASIC:
2449 case TYPE_POINTER:
2450 case TYPE_ARRAY:
2451 break;
2452 default:
2453 error("add_entry: unhandled type 0x%x for %s\n",
2454 type_get_type(type), type->name);
2455 break;
2456 }
2457}
@ TYPE_ENUM
Definition: widltypes.h:480
@ TYPE_BASIC
Definition: widltypes.h:479
@ TYPE_UNION
Definition: widltypes.h:483
@ TYPE_POINTER
Definition: widltypes.h:489
@ TYPE_ENCAPSULATED_UNION
Definition: widltypes.h:482
@ TYPE_COCLASS
Definition: widltypes.h:486
@ TYPE_INTERFACE
Definition: widltypes.h:488
@ TYPE_ARRAY
Definition: widltypes.h:490
static void add_enum_typeinfo(msft_typelib_t *typelib, type_t *enumeration)
Definition: write_msft.c:2248
static void add_structure_typeinfo(msft_typelib_t *typelib, type_t *structure)
Definition: write_msft.c:2219
static void add_coclass_typeinfo(msft_typelib_t *typelib, type_t *cls)
Definition: write_msft.c:2323
static void add_union_typeinfo(msft_typelib_t *typelib, type_t *tunion)
Definition: write_msft.c:2266

Referenced by add_entry().

◆ add_typedef_typeinfo()

static void add_typedef_typeinfo ( msft_typelib_t typelib,
type_t dispinterface 
)
static

Definition at line 2287 of file write_msft.c.

2288{
2289 msft_typeinfo_t *msft_typeinfo = NULL;
2290 int datatype1, datatype2, duplicate = 0;
2291 unsigned int size, alignment = 0;
2292 type_t *type;
2293
2294 if (-1 < tdef->typelib_idx)
2295 return;
2296
2298
2299 if (!type->name || strcmp(tdef->name, type->name) != 0)
2300 {
2301 tdef->typelib_idx = typelib->typelib_header.nrtypeinfos;
2302 msft_typeinfo = create_msft_typeinfo(typelib, TKIND_ALIAS, tdef->name, tdef->attrs);
2303 }
2304 else
2305 duplicate = 1;
2306
2307 encode_type(typelib, get_type_vt(type), type, &datatype1, &datatype2);
2309
2310 if (msft_typeinfo)
2311 {
2312 msft_typeinfo->typeinfo->datatype1 = datatype1;
2313 msft_typeinfo->typeinfo->size = size;
2314 msft_typeinfo->typeinfo->datatype2 = datatype2;
2315 msft_typeinfo->typeinfo->typekind |= (alignment << 11 | alignment << 6);
2316 }
2317
2318 /* avoid adding duplicate type definitions */
2319 if (duplicate)
2320 tdef->typelib_idx = type->typelib_idx;
2321}
_Check_return_ _Ret_maybenull_ _In_ size_t alignment
Definition: align.cpp:48
GLsizeiptr size
Definition: glext.h:5919
unsigned short get_type_vt(type_t *t)
Definition: typelib.c:124
unsigned int type_memsize_and_alignment(const type_t *t, unsigned int *align)
Definition: typegen.c:2124
@ TKIND_ALIAS
Definition: widltypes.h:240
static int encode_type(msft_typelib_t *typelib, int vt, type_t *type, int *encoded_type, int *decoded_size)
Definition: write_msft.c:767

Referenced by add_entry(), and encode_type().

◆ add_union_typeinfo()

static void add_union_typeinfo ( msft_typelib_t typelib,
type_t tunion 
)
static

Definition at line 2266 of file write_msft.c.

2267{
2268 int idx = 0;
2269 var_t *cur;
2270 msft_typeinfo_t *msft_typeinfo;
2271
2272 if (-1 < tunion->typelib_idx)
2273 return;
2274
2275 if (!tunion->name)
2276 tunion->name = gen_name();
2277
2278 tunion->typelib_idx = typelib->typelib_header.nrtypeinfos;
2279 msft_typeinfo = create_msft_typeinfo(typelib, TKIND_UNION, tunion->name, tunion->attrs);
2280 msft_typeinfo->typeinfo->size = 0;
2281
2282 if (type_union_get_cases(tunion))
2284 add_var_desc(msft_typeinfo, idx++, cur);
2285}
static var_list_t * type_union_get_cases(const type_t *type)
Definition: typetree.h:184
@ TKIND_UNION
Definition: widltypes.h:241

Referenced by add_type_typeinfo(), and encode_type().

◆ add_var_desc()

static void add_var_desc ( msft_typeinfo_t typeinfo,
unsigned int  index,
var_t var 
)
static

Definition at line 1661 of file write_msft.c.

1662{
1663 int offset, id;
1664 unsigned int typedata_size;
1665 int extra_attr = 0;
1666 int *typedata;
1667 unsigned int var_datawidth, var_alignment = 0;
1668 int var_type_size, var_kind = 0 /* VAR_PERINSTANCE */;
1669 int alignment;
1670 int varflags = 0;
1671 const attr_t *attr;
1672 unsigned char *namedata;
1673 int var_num = (typeinfo->typeinfo->cElement >> 16) & 0xffff;
1674 int var_custdata_offset = -1;
1675
1676 if (!var->name)
1677 var->name = gen_name();
1678
1679 chat("add_var_desc(%d, %s)\n", index, var->name);
1680
1681 id = 0x40000000 + index;
1682
1683 if (var->attrs) LIST_FOR_EACH_ENTRY( attr, var->attrs, const attr_t, entry ) {
1684 expr_t *expr = attr->u.pval;
1685 switch(attr->type) {
1686 case ATTR_BINDABLE:
1687 varflags |= 0x04; /* VARFLAG_FBINDABLE */
1688 break;
1689 case ATTR_CUSTOM:
1690 extra_attr = max(extra_attr,4);
1691 set_custdata_attr(typeinfo->typelib, attr->u.pval, &var_custdata_offset);
1692 break;
1693 case ATTR_DEFAULTBIND:
1694 varflags |= 0x20; /* VARFLAG_FDEFAULTBIND */
1695 break;
1697 varflags |= 0x100; /* VARFLAG_FDEFAULTCOLLELEM */
1698 break;
1699 case ATTR_DISPLAYBIND:
1700 varflags |= 0x10; /* VARFLAG_FDISPLAYBIND */
1701 break;
1702 case ATTR_HIDDEN:
1703 varflags |= 0x40; /* VARFLAG_FHIDDEN */
1704 break;
1705 case ATTR_ID:
1706 id = expr->cval;
1707 break;
1708 case ATTR_IMMEDIATEBIND:
1709 varflags |= 0x1000; /* VARFLAG_FIMMEDIATEBIND */
1710 break;
1711 case ATTR_NONBROWSABLE:
1712 varflags |= 0x400; /* VARFLAG_FNONBROWSABLE */
1713 break;
1714 case ATTR_READONLY:
1715 varflags |= 0x01; /* VARFLAG_FREADONLY */
1716 break;
1717 /* FIXME: VARFLAG_FREPLACEABLE */
1718 case ATTR_REQUESTEDIT:
1719 varflags |= 0x08; /* VARFLAG_FREQUESTEDIT */
1720 break;
1721 case ATTR_RESTRICTED:
1722 varflags |= 0x80; /* VARFLAG_FRESTRICTED */
1723 break;
1724 case ATTR_SOURCE:
1725 varflags |= 0x02; /* VARFLAG_FSOURCE */
1726 break;
1727 case ATTR_UIDEFAULT:
1728 varflags |= 0x0200; /* VARFLAG_FUIDEFAULT */
1729 break;
1730 default:
1731 break;
1732 }
1733 }
1734
1735 /* allocate type data space for us */
1736 typedata_size = 0x14 + extra_attr * sizeof(int);
1737
1738 if (!typeinfo->var_data) {
1739 typeinfo->var_data = xmalloc(0x100);
1740 typeinfo->var_data_allocated = 0x100;
1741 typeinfo->var_data[0] = 0;
1742 }
1743
1744 if(typeinfo->var_data[0] + typedata_size + sizeof(int) > typeinfo->var_data_allocated) {
1745 typeinfo->var_data_allocated = max(typeinfo->var_data_allocated * 2,
1746 typeinfo->var_data[0] + typedata_size + sizeof(int));
1747 typeinfo->var_data = xrealloc(typeinfo->var_data, typeinfo->var_data_allocated);
1748 }
1749
1750 offset = typeinfo->var_data[0];
1751 typeinfo->var_data[0] += typedata_size;
1752 typedata = typeinfo->var_data + (offset >> 2) + 1;
1753
1754 /* fill out the basic type information */
1755 typedata[0] = typedata_size | (index << 16);
1756 typedata[2] = varflags;
1757 typedata[3] = (36 /*sizeof(VARDESC)*/ << 16) | 0;
1758
1759 if(typeinfo->vars_allocated == 0) {
1760 typeinfo->vars_allocated = 10;
1761 typeinfo->var_indices = xmalloc(typeinfo->vars_allocated * sizeof(int));
1762 typeinfo->var_names = xmalloc(typeinfo->vars_allocated * sizeof(int));
1763 typeinfo->var_offsets = xmalloc(typeinfo->vars_allocated * sizeof(int));
1764 }
1765 if(typeinfo->vars_allocated == var_num) {
1766 typeinfo->vars_allocated *= 2;
1767 typeinfo->var_indices = xrealloc(typeinfo->var_indices, typeinfo->vars_allocated * sizeof(int));
1768 typeinfo->var_names = xrealloc(typeinfo->var_names, typeinfo->vars_allocated * sizeof(int));
1769 typeinfo->var_offsets = xrealloc(typeinfo->var_offsets, typeinfo->vars_allocated * sizeof(int));
1770 }
1771 /* update the index data */
1772 typeinfo->var_indices[var_num] = id;
1773 typeinfo->var_names[var_num] = -1;
1774 typeinfo->var_offsets[var_num] = offset;
1775
1776 /* figure out type widths and whatnot */
1777 var_datawidth = type_memsize_and_alignment(var->declspec.type, &var_alignment);
1778 encode_var(typeinfo->typelib, var->declspec.type, var, &typedata[1], &var_type_size);
1779
1780 /* pad out starting position to data width */
1781 typeinfo->datawidth += var_alignment - 1;
1782 typeinfo->datawidth &= ~(var_alignment - 1);
1783
1784 switch(typeinfo->typekind) {
1785 case TKIND_ENUM:
1786 write_int_value(typeinfo->typelib, &typedata[4], VT_I4, var->eval->cval);
1787 var_kind = 2; /* VAR_CONST */
1788 var_type_size += 16; /* sizeof(VARIANT) */
1789 typeinfo->datawidth = var_datawidth;
1790 break;
1791 case TKIND_RECORD:
1792 typedata[4] = typeinfo->datawidth;
1793 typeinfo->datawidth += var_datawidth;
1794 break;
1795 case TKIND_UNION:
1796 typedata[4] = 0;
1797 typeinfo->datawidth = max(typeinfo->datawidth, var_datawidth);
1798 break;
1799 case TKIND_DISPATCH:
1800 var_kind = 3; /* VAR_DISPATCH */
1801 typedata[4] = 0;
1802 typeinfo->datawidth = pointer_size;
1803 break;
1804 default:
1805 error("add_var_desc: unhandled type kind %d\n", typeinfo->typekind);
1806 break;
1807 }
1808
1809 /* add type description size to total required allocation */
1810 typedata[3] += var_type_size << 16 | var_kind;
1811
1812 switch(extra_attr) {
1813 case 5: typedata[9] = -1 /*help_string_context*/;
1814 case 4: typedata[8] = var_custdata_offset;
1815 case 3: typedata[7] = -1;
1816 case 2: typedata[6] = -1 /*help_string_offset*/;
1817 case 1: typedata[5] = -1 /*help_context*/;
1818 case 0:
1819 break;
1820 default:
1821 warning("unknown number of optional attrs\n");
1822 }
1823
1824 /* fix type alignment */
1825 alignment = (typeinfo->typeinfo->typekind >> 11) & 0x1f;
1826 if (alignment < var_alignment) {
1827 alignment = var_alignment;
1828 typeinfo->typeinfo->typekind &= ~0xffc0;
1829 typeinfo->typeinfo->typekind |= alignment << 11 | alignment << 6;
1830 }
1831
1832 /* ??? */
1833 if (!typeinfo->typeinfo->res2) typeinfo->typeinfo->res2 = 0x1a;
1834 if ((index == 0) || (index == 1) || (index == 2) || (index == 4) || (index == 9)) {
1835 typeinfo->typeinfo->res2 <<= 1;
1836 }
1837
1838 /* ??? */
1839 if (typeinfo->typeinfo->res3 == -1) typeinfo->typeinfo->res3 = 0;
1840 typeinfo->typeinfo->res3 += 0x2c;
1841
1842 /* increment the number of variable elements */
1843 typeinfo->typeinfo->cElement += 0x10000;
1844
1845 /* pad data width to alignment */
1846 typeinfo->typeinfo->size = (typeinfo->datawidth + (alignment - 1)) & ~(alignment - 1);
1847
1848 offset = ctl2_alloc_name(typeinfo->typelib, var->name);
1849
1850 namedata = typeinfo->typelib->typelib_segment_data[MSFT_SEG_NAME] + offset;
1851 if (*((int *)namedata) == -1) {
1852 *((int *)namedata) = typeinfo->typelib->typelib_typeinfo_offsets[typeinfo->typeinfo->typekind >> 16];
1853 if(typeinfo->typekind != TKIND_DISPATCH)
1854 namedata[9] |= 0x10;
1855 } else
1856 namedata[9] &= ~0x10;
1857
1858 if (typeinfo->typekind == TKIND_ENUM) {
1859 namedata[9] |= 0x20;
1860 }
1861 typeinfo->var_names[var_num] = offset;
1862}
@ VT_I4
Definition: compat.h:2298
@ ATTR_READONLY
Definition: widltypes.h:165
static void write_int_value(msft_typelib_t *typelib, int *out, int vt, int value)
Definition: write_msft.c:1165

Referenced by add_dispinterface_typeinfo(), add_enum_typeinfo(), add_structure_typeinfo(), and add_union_typeinfo().

◆ alloc_importfile()

static int alloc_importfile ( msft_typelib_t typelib,
int  guidoffset,
int  major_version,
int  minor_version,
const char filename 
)
static

Definition at line 638 of file write_msft.c.

644{
645 int length;
646 int offset;
647 MSFT_ImpFile *importfile;
648 char *encoded_string;
649
650 length = ctl2_encode_string(filename, &encoded_string);
651
652 encoded_string[0] <<= 2;
653 encoded_string[0] |= 1;
654
655 for (offset = 0; offset < typelib->typelib_segdir[MSFT_SEG_IMPORTFILES].length;
656 offset += (((typelib->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xd] << 8) |
657 typelib->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset + 0xc]) >> 2) + 0xc) {
658 if (!memcmp(encoded_string, typelib->typelib_segment_data[MSFT_SEG_IMPORTFILES] + offset + 0xc, length)) return offset;
659 }
660
662
663 importfile = (MSFT_ImpFile *)&typelib->typelib_segment_data[MSFT_SEG_IMPORTFILES][offset];
664 importfile->guid = guidoffset;
665 importfile->lcid = typelib->typelib_header.lcid2;
666 importfile->version = major_version | (minor_version << 16);
667 memcpy(&importfile->filename, encoded_string, length);
668 free(encoded_string);
669
670 return offset;
671}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define free
Definition: debug_ros.c:5
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
const char * filename
Definition: ioapi.h:137
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
char filename[0]
Definition: write_msft.c:72
static int ctl2_encode_string(const char *string, char **result)
Definition: write_msft.c:325

Referenced by add_dispatch(), and alloc_importinfo().

◆ alloc_importinfo()

static void alloc_importinfo ( msft_typelib_t typelib,
importinfo_t importinfo 
)
static

Definition at line 673 of file write_msft.c.

674{
675 importlib_t *importlib = importinfo->importlib;
676
677 chat("alloc_importinfo: %s\n", importinfo->name);
678
679 if(!importlib->allocated) {
681 int guid_idx;
682
683 chat("allocating importlib %s\n", importlib->name);
684
685 importlib->allocated = -1;
686
687 memcpy(&guid.guid, &importlib->guid, sizeof(guid.guid));
688 guid.hreftype = 2;
689
690 guid_idx = ctl2_alloc_guid(typelib, &guid);
691
692 importlib->offset = alloc_importfile(typelib, guid_idx, importlib->version & 0xffff,
693 importlib->version >> 16, importlib->name);
694 }
695
696 if(importinfo->offset == -1 || !(importinfo->flags & MSFT_IMPINFO_OFFSET_IS_GUID)) {
697 MSFT_ImpInfo impinfo;
698
699 impinfo.flags = importinfo->flags;
700 impinfo.oImpFile = importlib->offset;
701
702 if(importinfo->flags & MSFT_IMPINFO_OFFSET_IS_GUID) {
704
705 guid.hreftype = 0;
706 memcpy(&guid.guid, &importinfo->guid, sizeof(guid.guid));
707
708 impinfo.oGuid = ctl2_alloc_guid(typelib, &guid);
709
710 importinfo->offset = alloc_msft_importinfo(typelib, &impinfo);
711
712 typelib->typelib_segment_data[MSFT_SEG_GUID][impinfo.oGuid+sizeof(guid.guid)]
713 = importinfo->offset+1;
714
715 if(!strcmp(importinfo->name, "IDispatch"))
716 typelib->typelib_header.dispatchpos = importinfo->offset+1;
717 }else {
718 impinfo.oGuid = importinfo->id;
719 importinfo->offset = alloc_msft_importinfo(typelib, &impinfo);
720 }
721 }
722}
GUID guid
Definition: version.c:147
importlib("stdole2.tlb")
char * name
Definition: widltypes.h:589
importlib_t * importlib
Definition: widltypes.h:591
struct uuid guid
Definition: widltypes.h:585

Referenced by add_impl_type(), and encode_type().

◆ alloc_msft_importinfo()

static int alloc_msft_importinfo ( msft_typelib_t typelib,
MSFT_ImpInfo impinfo 
)
static

Definition at line 602 of file write_msft.c.

605{
606 int offset;
607 MSFT_ImpInfo *impinfo_space;
608
609 for (offset = 0;
610 offset < typelib->typelib_segdir[MSFT_SEG_IMPORTINFO].length;
611 offset += sizeof(MSFT_ImpInfo)) {
612 if (!memcmp(&(typelib->typelib_segment_data[MSFT_SEG_IMPORTINFO][offset]),
613 impinfo, sizeof(MSFT_ImpInfo))) {
614 return offset;
615 }
616 }
617
618 impinfo->flags |= typelib->typelib_header.nimpinfos++;
619
621
622 impinfo_space = (void *)(typelib->typelib_segment_data[MSFT_SEG_IMPORTINFO] + offset);
623 *impinfo_space = *impinfo;
624
625 return offset;
626}
struct tagMSFT_ImpInfo MSFT_ImpInfo

Referenced by add_dispatch(), and alloc_importinfo().

◆ create_msft_typeinfo()

static msft_typeinfo_t * create_msft_typeinfo ( msft_typelib_t typelib,
enum type_kind  kind,
const char name,
const attr_list_t attrs 
)
static

Definition at line 1881 of file write_msft.c.

1883{
1884 const attr_t *attr;
1885 msft_typeinfo_t *msft_typeinfo;
1886 int nameoffset;
1887 int typeinfo_offset;
1889 MSFT_GuidEntry guidentry;
1890
1891 chat("create_msft_typeinfo: name %s kind %d index %d\n", name, kind, typelib->typelib_header.nrtypeinfos);
1892
1893 msft_typeinfo = xmalloc(sizeof(*msft_typeinfo));
1894 memset( msft_typeinfo, 0, sizeof(*msft_typeinfo) );
1895
1896 msft_typeinfo->typelib = typelib;
1897
1898 nameoffset = ctl2_alloc_name(typelib, name);
1899 typeinfo_offset = ctl2_alloc_typeinfo(typelib, nameoffset);
1900 typeinfo = (MSFT_TypeInfoBase *)&typelib->typelib_segment_data[MSFT_SEG_TYPEINFO][typeinfo_offset];
1901
1902 typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset + 9] = 0x38;
1903 *((int *)&typelib->typelib_segment_data[MSFT_SEG_NAME][nameoffset]) = typeinfo_offset;
1904
1905 msft_typeinfo->typekind = kind;
1906 msft_typeinfo->typeinfo = typeinfo;
1907
1908 typeinfo->typekind |= kind | 0x20;
1909
1910 if(kind == TKIND_COCLASS)
1911 typeinfo->flags |= 0x2; /* TYPEFLAG_FCANCREATE */
1912
1913 if (attrs) LIST_FOR_EACH_ENTRY( attr, attrs, const attr_t, entry ) {
1914 switch(attr->type) {
1915 case ATTR_AGGREGATABLE:
1916 if (kind == TKIND_COCLASS)
1917 typeinfo->flags |= 0x400; /* TYPEFLAG_FAGGREGATABLE */
1918 break;
1919
1920 case ATTR_APPOBJECT:
1921 if (kind == TKIND_COCLASS)
1922 typeinfo->flags |= 0x1; /* TYPEFLAG_FAPPOBJECT */
1923 break;
1924
1925 case ATTR_CONTROL:
1926 if (kind == TKIND_COCLASS)
1927 typeinfo->flags |= 0x20; /* TYPEFLAG_FCONTROL */
1928 break;
1929 case ATTR_CUSTOM:
1930 set_custdata_attr(typelib, attr->u.pval, &typeinfo->oCustData);
1931 break;
1932 case ATTR_DLLNAME:
1933 {
1934 int offset = ctl2_alloc_string(typelib, attr->u.pval);
1935 typeinfo->datatype1 = offset;
1936 break;
1937 }
1938
1939 case ATTR_DUAL:
1940 /* FIXME: check interface is compatible */
1941 typeinfo->typekind = (typeinfo->typekind & ~0xff) | 0x34;
1942 typeinfo->flags |= 0x140; /* TYPEFLAG_FDUAL | TYPEFLAG_FOLEAUTOMATION */
1943 break;
1944
1945 case ATTR_HELPCONTEXT:
1946 {
1947 expr_t *expr = (expr_t*)attr->u.pval;
1948 typeinfo->helpcontext = expr->cval;
1949 break;
1950 }
1951 case ATTR_HELPSTRING:
1952 {
1953 int offset = ctl2_alloc_string(typelib, attr->u.pval);
1954 if (offset == -1) break;
1955 typeinfo->docstringoffs = offset;
1956 break;
1957 }
1959 {
1960 expr_t *expr = (expr_t*)attr->u.pval;
1961 typeinfo->helpstringcontext = expr->cval;
1962 break;
1963 }
1964 case ATTR_HIDDEN:
1965 typeinfo->flags |= 0x10; /* TYPEFLAG_FHIDDEN */
1966 break;
1967
1968 case ATTR_LICENSED:
1969 typeinfo->flags |= 0x04; /* TYPEFLAG_FLICENSED */
1970 break;
1971
1972 case ATTR_NONCREATABLE:
1973 typeinfo->flags &= ~0x2; /* TYPEFLAG_FCANCREATE */
1974 break;
1975
1976 case ATTR_NONEXTENSIBLE:
1977 typeinfo->flags |= 0x80; /* TYPEFLAG_FNONEXTENSIBLE */
1978 break;
1979
1980 case ATTR_OLEAUTOMATION:
1981 typeinfo->flags |= 0x100; /* TYPEFLAG_FOLEAUTOMATION */
1982 break;
1983
1984 /* FIXME: TYPEFLAG_FPREDCLID */
1985
1986 case ATTR_PROXY:
1987 typeinfo->flags |= 0x4000; /* TYPEFLAG_FPROXY */
1988 break;
1989
1990 /* FIXME: TYPEFLAG_FREPLACEABLE */
1991
1992 case ATTR_RESTRICTED:
1993 typeinfo->flags |= 0x200; /* TYPEFLAG_FRESTRICTED */
1994 break;
1995
1996 case ATTR_UUID:
1997 guidentry.guid = *(struct uuid *)attr->u.pval;
1998 guidentry.hreftype = typelib->typelib_typeinfo_offsets[typeinfo->typekind >> 16];
1999 guidentry.next_hash = -1;
2000 typeinfo->posguid = ctl2_alloc_guid(typelib, &guidentry);
2001#if 0
2002 if (IsEqualIID(guid, &IID_IDispatch)) {
2003 typelib->typelib_header.dispatchpos = typelib->typelib_typeinfo_offsets[typeinfo->typekind >> 16];
2004 }
2005#endif
2006 break;
2007
2008 case ATTR_VERSION:
2009 typeinfo->version = attr->u.ival;
2010 break;
2011
2012 default:
2013 break;
2014 }
2015 }
2016
2017 if (typelib->last_typeinfo) typelib->last_typeinfo->next_typeinfo = msft_typeinfo;
2018 typelib->last_typeinfo = msft_typeinfo;
2019 if (!typelib->typeinfos) typelib->typeinfos = msft_typeinfo;
2020
2021
2022 return msft_typeinfo;
2023}
const GUID IID_IDispatch
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define memset(x, y, z)
Definition: compat.h:39
msft_typelib_t * typelib
Definition: write_msft.c:96
Definition: name.c:39
@ ATTR_APPOBJECT
Definition: widltypes.h:77
@ ATTR_DLLNAME
Definition: widltypes.h:105
@ ATTR_UUID
Definition: widltypes.h:182
@ ATTR_NONEXTENSIBLE
Definition: widltypes.h:143
@ ATTR_PROXY
Definition: widltypes.h:162
@ ATTR_VERSION
Definition: widltypes.h:185
@ ATTR_CONTROL
Definition: widltypes.h:92
@ ATTR_LICENSED
Definition: widltypes.h:135
@ ATTR_NONCREATABLE
Definition: widltypes.h:142
@ ATTR_AGGREGATABLE
Definition: widltypes.h:74
static int ctl2_alloc_typeinfo(msft_typelib_t *typelib, int nameoffset)
Definition: write_msft.c:418

Referenced by add_coclass_typeinfo(), add_dispinterface_typeinfo(), add_enum_typeinfo(), add_interface_typeinfo(), add_module_typeinfo(), add_structure_typeinfo(), add_typedef_typeinfo(), and add_union_typeinfo().

◆ create_msft_typelib()

int create_msft_typelib ( typelib_t typelib)

Definition at line 2755 of file write_msft.c.

2756{
2757 msft_typelib_t *msft;
2758 int failed = 0;
2759 const statement_t *stmt;
2760 const attr_t *attr;
2762 unsigned int version = 7 << 24 | 555; /* 7.00.0555 */
2763 static const struct uuid midl_time_guid = {0xde77ba63,0x517c,0x11d1,{0xa2,0xda,0x00,0x00,0xf8,0x77,0x3c,0xe9}};
2764 static const struct uuid midl_version_guid = {0xde77ba64,0x517c,0x11d1,{0xa2,0xda,0x00,0x00,0xf8,0x77,0x3c,0xe9}};
2765 static const struct uuid midl_info_guid = {0xde77ba65,0x517c,0x11d1,{0xa2,0xda,0x00,0x00,0xf8,0x77,0x3c,0xe9}};
2766 char info_string[128];
2767
2768 msft = xmalloc(sizeof(*msft));
2769 memset(msft, 0, sizeof(*msft));
2770 msft->typelib = typelib;
2771
2772 ctl2_init_header(msft);
2773 ctl2_init_segdir(msft);
2774
2776
2777 /*
2778 * The following two calls return an offset or -1 if out of memory. We
2779 * specifically need an offset of 0, however, so...
2780 */
2781 if (ctl2_alloc_segment(msft, MSFT_SEG_GUIDHASH, 0x80, 0x80)) { failed = 1; }
2782 if (ctl2_alloc_segment(msft, MSFT_SEG_NAMEHASH, 0x200, 0x200)) { failed = 1; }
2783
2784 if(failed)
2785 {
2786 free(msft);
2787 return 0;
2788 }
2789
2792
2793 memset(msft->typelib_guidhash_segment, 0xff, 0x80);
2794 memset(msft->typelib_namehash_segment, 0xff, 0x200);
2795
2796 set_lib_flags(msft);
2797 set_lcid(msft);
2798 set_help_file_name(msft);
2799 set_doc_string(msft);
2800 set_guid(msft);
2801 set_version(msft);
2802 set_name(msft);
2803 set_help_context(msft);
2804 set_help_string_dll(msft);
2806
2807 if (typelib->attrs) LIST_FOR_EACH_ENTRY( attr, typelib->attrs, const attr_t, entry ) {
2808 switch(attr->type) {
2809 case ATTR_CUSTOM:
2811 break;
2812 default:
2813 break;
2814 }
2815 }
2816
2817 /* midl adds three sets of custom data to the library:
2818 * - 2147483647 (INT_MAX, previously the current Unix time)
2819 * - midl's version number
2820 * - a string representation of those
2821 */
2822 cur_time = 2147483647;
2823 snprintf(info_string, sizeof(info_string), "Created by WIDL version %s at %s", PACKAGE_VERSION, asctime(gmtime(&cur_time)));
2824 set_custdata(msft, &midl_info_guid, VT_BSTR, info_string, &msft->typelib_header.CustomDataOffset);
2825 set_custdata(msft, &midl_time_guid, VT_UI4, &cur_time, &msft->typelib_header.CustomDataOffset);
2826 set_custdata(msft, &midl_version_guid, VT_UI4, &version, &msft->typelib_header.CustomDataOffset);
2827
2828 if (typelib->stmts)
2829 LIST_FOR_EACH_ENTRY( stmt, typelib->stmts, const statement_t, entry )
2830 add_entry(msft, stmt);
2831
2832 save_all_changes(msft);
2833 free(msft);
2834 return 1;
2835}
time_t cur_time
@ VT_BSTR
Definition: compat.h:2303
@ VT_UI4
Definition: compat.h:2313
static const WCHAR version[]
Definition: asmname.c:66
__kernel_time_t time_t
Definition: linux.h:252
_Check_return_ _CRTIMP char *__cdecl asctime(_In_ const struct tm *_Tm)
_CRTIMP struct tm *__cdecl gmtime(const time_t *_Time)
Definition: time.h:415
typelib_t * typelib
Definition: write_msft.c:77
int * typelib_namehash_segment
Definition: write_msft.c:85
MSFT_Header typelib_header
Definition: write_msft.c:78
unsigned char * typelib_segment_data[MSFT_SEG_MAX]
Definition: write_msft.c:80
int * typelib_guidhash_segment
Definition: write_msft.c:86
INT varflags
Definition: typelib.h:65
INT CustomDataOffset
Definition: typelib.h:79
@ SYS_WIN32
Definition: widltypes.h:647
@ SYS_WIN64
Definition: widltypes.h:649
#define snprintf
Definition: wintirpc.h:48
static void set_help_string_context(msft_typelib_t *typelib)
Definition: write_msft.c:2574
static void set_doc_string(msft_typelib_t *typelib)
Definition: write_msft.c:2527
static void add_entry(msft_typelib_t *typelib, const statement_t *stmt)
Definition: write_msft.c:2459
static void set_lcid(msft_typelib_t *typelib)
Definition: write_msft.c:2580
static void set_name(msft_typelib_t *typelib)
Definition: write_msft.c:2498
static void set_custdata(msft_typelib_t *typelib, const struct uuid *guid, int vt, const void *value, int *offset)
Definition: write_msft.c:1258
static void set_version(msft_typelib_t *typelib)
Definition: write_msft.c:2508
static void set_lib_flags(msft_typelib_t *typelib)
Definition: write_msft.c:2590
static void ctl2_init_segdir(msft_typelib_t *typelib)
Definition: write_msft.c:162
static void set_help_context(msft_typelib_t *typelib)
Definition: write_msft.c:2553
static void set_guid(msft_typelib_t *typelib)
Definition: write_msft.c:2513
static void set_help_string_dll(msft_typelib_t *typelib)
Definition: write_msft.c:2559
static void ctl2_init_header(msft_typelib_t *typelib)
Definition: write_msft.c:131
static void save_all_changes(msft_typelib_t *typelib)
Definition: write_msft.c:2688
static void set_help_file_name(msft_typelib_t *typelib)
Definition: write_msft.c:2538

Referenced by write_typelib_regscript().

◆ ctl2_alloc_guid()

static int ctl2_alloc_guid ( msft_typelib_t typelib,
MSFT_GuidEntry guid 
)
static

Definition at line 471 of file write_msft.c.

474{
475 int offset;
476 MSFT_GuidEntry *guid_space;
477 int hash_key;
478
479 chat("adding uuid {%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n",
480 guid->guid.Data1, guid->guid.Data2, guid->guid.Data3,
481 guid->guid.Data4[0], guid->guid.Data4[1], guid->guid.Data4[2], guid->guid.Data4[3],
482 guid->guid.Data4[4], guid->guid.Data4[5], guid->guid.Data4[6], guid->guid.Data4[7]);
483
484 hash_key = ctl2_hash_guid(&guid->guid);
485
486 offset = ctl2_find_guid(typelib, hash_key, &guid->guid);
487 if (offset != -1)
488 {
489 if (is_warning_enabled(2368))
490 warning("duplicate uuid {%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n",
491 guid->guid.Data1, guid->guid.Data2, guid->guid.Data3,
492 guid->guid.Data4[0], guid->guid.Data4[1], guid->guid.Data4[2], guid->guid.Data4[3],
493 guid->guid.Data4[4], guid->guid.Data4[5], guid->guid.Data4[6], guid->guid.Data4[7]);
494 return -1;
495 }
496
498
499 guid_space = (void *)(typelib->typelib_segment_data[MSFT_SEG_GUID] + offset);
500 *guid_space = *guid;
501
502 guid_space->next_hash = typelib->typelib_guidhash_segment[hash_key];
503 typelib->typelib_guidhash_segment[hash_key] = offset;
504
505 return offset;
506}
int is_warning_enabled(int warning)

Referenced by add_dispatch(), alloc_importinfo(), create_msft_typeinfo(), set_custdata(), and set_guid().

◆ ctl2_alloc_name()

static int ctl2_alloc_name ( msft_typelib_t typelib,
const char name 
)
static

Definition at line 519 of file write_msft.c.

522{
523 int length;
524 int offset;
526 char *encoded_name;
527
528 length = ctl2_encode_name(typelib, name, &encoded_name);
529
530 offset = ctl2_find_name(typelib, encoded_name);
531 if (offset != -1)
532 {
533 free(encoded_name);
534 return offset;
535 }
536
538
539 name_space = (void *)(typelib->typelib_segment_data[MSFT_SEG_NAME] + offset);
540 name_space->hreftype = -1;
541 name_space->next_hash = -1;
542 memcpy(&name_space->namelen, encoded_name, length);
543
544 if (typelib->typelib_namehash_segment[encoded_name[2] & 0x7f] != -1)
545 name_space->next_hash = typelib->typelib_namehash_segment[encoded_name[2] & 0x7f];
546
547 typelib->typelib_namehash_segment[encoded_name[2] & 0x7f] = offset;
548
549 typelib->typelib_header.nametablecount += 1;
550 typelib->typelib_header.nametablechars += *encoded_name;
551
552 free(encoded_name);
553 return offset;
554}
static int ctl2_find_name(msft_typelib_t *typelib, char *name)
Definition: write_msft.c:242
static int ctl2_encode_name(msft_typelib_t *typelib, const char *name, char **result)
Definition: write_msft.c:280

Referenced by add_func_desc(), add_var_desc(), create_msft_typeinfo(), and set_name().

◆ ctl2_alloc_segment()

static int ctl2_alloc_segment ( msft_typelib_t typelib,
enum MSFT_segment_index  segment,
int  size,
int  block_size 
)
static

Definition at line 365 of file write_msft.c.

370{
371 int offset;
372
373 if(!typelib->typelib_segment_data[segment]) {
374 if (!block_size) block_size = 0x2000;
375
376 typelib->typelib_segment_block_length[segment] = block_size;
377 typelib->typelib_segment_data[segment] = xmalloc(block_size);
378 if (!typelib->typelib_segment_data[segment]) return -1;
379 memset(typelib->typelib_segment_data[segment], 0x57, block_size);
380 }
381
382 while ((typelib->typelib_segdir[segment].length + size) > typelib->typelib_segment_block_length[segment]) {
383 unsigned char *block;
384
385 block_size = typelib->typelib_segment_block_length[segment];
386 block = xrealloc(typelib->typelib_segment_data[segment], block_size << 1);
387
388 if (segment == MSFT_SEG_TYPEINFO) {
389 /* TypeInfos have a direct pointer to their memory space, so we have to fix them up. */
391
392 for (typeinfo = typelib->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
393 typeinfo->typeinfo = (void *)&block[((unsigned char *)typeinfo->typeinfo) - typelib->typelib_segment_data[segment]];
394 }
395 }
396
398 typelib->typelib_segment_block_length[segment] = block_size << 1;
399 typelib->typelib_segment_data[segment] = block;
400 }
401
402 offset = typelib->typelib_segdir[segment].length;
403 typelib->typelib_segdir[segment].length += size;
404
405 return offset;
406}
static DWORD block_size(DWORD block)
Definition: jsutils.c:66
static unsigned int block
Definition: xmlmemory.c:101

Referenced by add_coclass_typeinfo(), alloc_importfile(), alloc_msft_importinfo(), create_msft_typelib(), ctl2_alloc_guid(), ctl2_alloc_name(), ctl2_alloc_string(), ctl2_alloc_typeinfo(), encode_type(), encode_var(), set_custdata(), write_int_value(), and write_string_value().

◆ ctl2_alloc_string()

static int ctl2_alloc_string ( msft_typelib_t typelib,
const char string 
)
static

Definition at line 566 of file write_msft.c.

569{
570 int length;
571 int offset;
572 unsigned char *string_space;
573 char *encoded_string;
574
575 length = ctl2_encode_string(string, &encoded_string);
576
577 for (offset = 0; offset < typelib->typelib_segdir[MSFT_SEG_STRING].length;
578 offset += (((typelib->typelib_segment_data[MSFT_SEG_STRING][offset + 1] << 8) |
579 typelib->typelib_segment_data[MSFT_SEG_STRING][offset + 0]) + 5) & ~3) {
580 if (!memcmp(encoded_string, typelib->typelib_segment_data[MSFT_SEG_STRING] + offset, length)) return offset;
581 }
582
584
585 string_space = typelib->typelib_segment_data[MSFT_SEG_STRING] + offset;
586 memcpy(string_space, encoded_string, length);
587 free(encoded_string);
588
589 return offset;
590}

Referenced by add_func_desc(), create_msft_typeinfo(), set_doc_string(), set_help_file_name(), and set_help_string_dll().

◆ ctl2_alloc_typeinfo()

static int ctl2_alloc_typeinfo ( msft_typelib_t typelib,
int  nameoffset 
)
static

Definition at line 418 of file write_msft.c.

421{
422 int offset;
424
426
427 typelib->typelib_typeinfo_offsets[typelib->typelib_header.nrtypeinfos++] = offset;
428
429 typeinfo = (void *)(typelib->typelib_segment_data[MSFT_SEG_TYPEINFO] + offset);
430
431 typeinfo->typekind = (typelib->typelib_header.nrtypeinfos - 1) << 16;
432 typeinfo->memoffset = -1; /* should be EOF if no elements */
433 typeinfo->res2 = 0;
434 typeinfo->res3 = -1;
435 typeinfo->res4 = 3;
436 typeinfo->res5 = 0;
437 typeinfo->cElement = 0;
438 typeinfo->res7 = 0;
439 typeinfo->res8 = 0;
440 typeinfo->res9 = 0;
441 typeinfo->resA = 0;
442 typeinfo->posguid = -1;
443 typeinfo->flags = 0;
444 typeinfo->NameOffset = nameoffset;
445 typeinfo->version = 0;
446 typeinfo->docstringoffs = -1;
447 typeinfo->helpstringcontext = 0;
448 typeinfo->helpcontext = 0;
449 typeinfo->oCustData = -1;
450 typeinfo->cbSizeVft = 0;
451 typeinfo->cImplTypes = 0;
452 typeinfo->size = 0;
453 typeinfo->datatype1 = -1;
454 typeinfo->datatype2 = 0;
455 typeinfo->res18 = 0;
456 typeinfo->res19 = -1;
457
458 return offset;
459}

Referenced by create_msft_typeinfo().

◆ ctl2_encode_name()

static int ctl2_encode_name ( msft_typelib_t typelib,
const char name,
char **  result 
)
static

Definition at line 280 of file write_msft.c.

284{
285 char *converted_name;
286 size_t length, size;
287 int offset;
288 int value;
289
290 length = strlen(name);
291 size = (length + 7) & ~3;
292 converted_name = xmalloc(size + 1);
293 memcpy(converted_name + 4, name, length);
294 converted_name[length + 4] = 0;
295
296 value = lhash_val_of_name_sys(typelib->typelib_header.varflags & 0x0f, typelib->typelib_header.lcid, converted_name + 4);
297
298 converted_name[0] = length & 0xff;
299 converted_name[1] = length >> 8;
300 converted_name[2] = value;
301 converted_name[3] = value >> 8;
302
303 for (offset = (4 - length) & 3; offset; offset--) converted_name[length + offset + 3] = 0x57;
304
305 *result = converted_name;
306
307 return size;
308}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLuint64EXT * result
Definition: glext.h:11304
unsigned int lhash_val_of_name_sys(syskind_t skind, int lcid, const char *lpStr)
Definition: hash.c:511
Definition: pdh_main.c:96

Referenced by ctl2_alloc_name().

◆ ctl2_encode_string()

static int ctl2_encode_string ( const char string,
char **  result 
)
static

Definition at line 325 of file write_msft.c.

328{
329 char *converted_string;
330 size_t length, size;
331 int offset;
332
333 length = strlen(string);
334 size = (length + 5) & ~3;
335 if (length < 3) size += 4;
336 converted_string = xmalloc(size);
337 memcpy(converted_string + 2, string, length);
338 converted_string[0] = length & 0xff;
339 converted_string[1] = (length >> 8) & 0xff;
340
341 if(length < 3) { /* strings of this length are padded with up to 8 bytes incl the 2 byte length */
342 for(offset = 0; offset < 4; offset++)
343 converted_string[length + offset + 2] = 0x57;
344 length += 4;
345 }
346 for (offset = (4 - (length + 2)) & 3; offset; offset--) converted_string[length + offset + 1] = 0x57;
347
348 *result = converted_string;
349 return size;
350}

Referenced by alloc_importfile(), and ctl2_alloc_string().

◆ ctl2_finalize_segment()

static int ctl2_finalize_segment ( msft_typelib_t typelib,
int  filepos,
int  segment 
)
static

Definition at line 2636 of file write_msft.c.

2637{
2638 if (typelib->typelib_segdir[segment].length) {
2639 typelib->typelib_segdir[segment].offset = filepos;
2640 } else {
2641 typelib->typelib_segdir[segment].offset = -1;
2642 }
2643
2644 return typelib->typelib_segdir[segment].length;
2645}

Referenced by save_all_changes().

◆ ctl2_finalize_typeinfos()

static void ctl2_finalize_typeinfos ( msft_typelib_t typelib,
int  filesize 
)
static

Definition at line 2621 of file write_msft.c.

2622{
2624
2625 for (typeinfo = typelib->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
2626 typeinfo->typeinfo->memoffset = filesize;
2627 if (typeinfo->func_data)
2628 filesize += typeinfo->func_data[0] + ((typeinfo->typeinfo->cElement & 0xffff) * 12);
2629 if (typeinfo->var_data)
2630 filesize += typeinfo->var_data[0] + (((typeinfo->typeinfo->cElement >> 16) & 0xffff) * 12);
2631 if (typeinfo->func_data || typeinfo->var_data)
2632 filesize += 4;
2633 }
2634}

Referenced by save_all_changes().

◆ ctl2_find_guid()

static int ctl2_find_guid ( msft_typelib_t typelib,
int  hash_key,
const struct uuid guid 
)
static

Definition at line 209 of file write_msft.c.

213{
214 int offset;
215 MSFT_GuidEntry *guidentry;
216
217 offset = typelib->typelib_guidhash_segment[hash_key];
218 while (offset != -1) {
219 guidentry = (MSFT_GuidEntry *)&typelib->typelib_segment_data[MSFT_SEG_GUID][offset];
220
221 if (!memcmp(guidentry, guid, sizeof(*guid))) return offset;
222
223 offset = guidentry->next_hash;
224 }
225
226 return offset;
227}
if(dx< 0)
Definition: linetemp.h:194

Referenced by add_dispatch(), ctl2_alloc_guid(), and set_custdata().

◆ ctl2_find_name()

static int ctl2_find_name ( msft_typelib_t typelib,
char name 
)
static

Definition at line 242 of file write_msft.c.

245{
246 int offset;
247 int *namestruct;
248
249 offset = typelib->typelib_namehash_segment[name[2] & 0x7f];
250 while (offset != -1) {
251 namestruct = (int *)&typelib->typelib_segment_data[MSFT_SEG_NAME][offset];
252
253 if (!((namestruct[2] ^ *((int *)name)) & 0xffff00ff)) {
254 /* hash codes and lengths match, final test */
255 if (!strncasecmp(name+4, (void *)(namestruct+3), name[0])) break;
256 }
257
258 /* move to next item in hash bucket */
259 offset = namestruct[1];
260 }
261
262 return offset;
263}
#define strncasecmp
Definition: fake.h:10

Referenced by ctl2_alloc_name().

◆ ctl2_hash_guid()

static int ctl2_hash_guid ( const struct uuid guid)
static

Definition at line 187 of file write_msft.c.

188{
189 int hash;
190 int i;
191
192 hash = 0;
193 for (i = 0; i < 8; i ++) {
194 hash ^= ((const short *)guid)[i];
195 }
196
197 return hash & 0x1f;
198}
Definition: _hash_fun.h:40

Referenced by add_dispatch(), ctl2_alloc_guid(), and set_custdata().

◆ ctl2_init_header()

static void ctl2_init_header ( msft_typelib_t typelib)
static

Definition at line 131 of file write_msft.c.

133{
134 typelib->typelib_header.magic1 = 0x5446534d;
135 typelib->typelib_header.magic2 = 0x00010002;
136 typelib->typelib_header.posguid = -1;
137 typelib->typelib_header.lcid = 0x0409;
138 typelib->typelib_header.lcid2 = 0x0;
139 typelib->typelib_header.varflags = 0x40;
140 typelib->typelib_header.version = 0;
141 typelib->typelib_header.flags = 0;
142 typelib->typelib_header.nrtypeinfos = 0;
143 typelib->typelib_header.helpstring = -1;
144 typelib->typelib_header.helpstringcontext = 0;
145 typelib->typelib_header.helpcontext = 0;
146 typelib->typelib_header.nametablecount = 0;
147 typelib->typelib_header.nametablechars = 0;
148 typelib->typelib_header.NameOffset = -1;
149 typelib->typelib_header.helpfile = -1;
150 typelib->typelib_header.CustomDataOffset = -1;
151 typelib->typelib_header.res44 = 0x20;
152 typelib->typelib_header.res48 = 0x80;
153 typelib->typelib_header.dispatchpos = -1;
154 typelib->typelib_header.nimpinfos = 0;
155}

Referenced by create_msft_typelib().

◆ ctl2_init_segdir()

static void ctl2_init_segdir ( msft_typelib_t typelib)
static

Definition at line 162 of file write_msft.c.

164{
165 int i;
166 MSFT_pSeg *segdir;
167
168 segdir = &typelib->typelib_segdir[MSFT_SEG_TYPEINFO];
169
170 for (i = 0; i < MSFT_SEG_MAX; i++) {
171 segdir[i].offset = -1;
172 segdir[i].length = 0;
173 segdir[i].res08 = -1;
174 segdir[i].res0c = 0x0f;
175 }
176}
INT res08
Definition: typelib.h:91
INT offset
Definition: typelib.h:89
INT res0c
Definition: typelib.h:92
INT length
Definition: typelib.h:90

Referenced by create_msft_typelib().

◆ ctl2_write_segment()

static void ctl2_write_segment ( msft_typelib_t typelib,
int  segment 
)
static

Definition at line 2615 of file write_msft.c.

2616{
2617 if (typelib->typelib_segment_data[segment])
2618 put_data(typelib->typelib_segment_data[segment], typelib->typelib_segdir[segment].length);
2619}
static void put_data(const void *data, size_t size)
Definition: tools.h:798

Referenced by save_all_changes().

◆ ctl2_write_typeinfos()

static void ctl2_write_typeinfos ( msft_typelib_t typelib)
static

Definition at line 2648 of file write_msft.c.

2649{
2651 int typedata_size;
2652
2653 for (typeinfo = typelib->typeinfos; typeinfo; typeinfo = typeinfo->next_typeinfo) {
2654 if (!typeinfo->func_data && !typeinfo->var_data) continue;
2655 typedata_size = 0;
2656 if (typeinfo->func_data)
2657 typedata_size = typeinfo->func_data[0];
2658 if (typeinfo->var_data)
2659 typedata_size += typeinfo->var_data[0];
2660 put_data(&typedata_size, sizeof(int));
2661 if (typeinfo->func_data)
2662 put_data(typeinfo->func_data + 1, typeinfo->func_data[0]);
2663 if (typeinfo->var_data)
2664 put_data(typeinfo->var_data + 1, typeinfo->var_data[0]);
2665 if (typeinfo->func_indices)
2666 put_data(typeinfo->func_indices, (typeinfo->typeinfo->cElement & 0xffff) * 4);
2667 if (typeinfo->var_indices)
2668 put_data(typeinfo->var_indices, (typeinfo->typeinfo->cElement >> 16) * 4);
2669 if (typeinfo->func_names)
2670 put_data(typeinfo->func_names, (typeinfo->typeinfo->cElement & 0xffff) * 4);
2671 if (typeinfo->var_names)
2672 put_data(typeinfo->var_names, (typeinfo->typeinfo->cElement >> 16) * 4);
2673 if (typeinfo->func_offsets)
2674 put_data(typeinfo->func_offsets, (typeinfo->typeinfo->cElement & 0xffff) * 4);
2675 if (typeinfo->var_offsets) {
2676 int add = 0, i, offset;
2677 if(typeinfo->func_data)
2678 add = typeinfo->func_data[0];
2679 for(i = 0; i < (typeinfo->typeinfo->cElement >> 16); i++) {
2680 offset = typeinfo->var_offsets[i];
2681 offset += add;
2682 put_data(&offset, 4);
2683 }
2684 }
2685 }
2686}
__forceinline bool __cdecl add(big_integer &x, uint32_t const value)

Referenced by save_all_changes().

◆ dump_type()

static void dump_type ( type_t t)
static

Definition at line 1031 of file write_msft.c.

1032{
1033 chat("dump_type: %p name %s type %d attrs %p\n", t, t->name, type_get_type(t), t->attrs);
1034}
GLdouble GLdouble t
Definition: gl.h:2047

Referenced by encode_var().

◆ encode_type()

static int encode_type ( msft_typelib_t typelib,
int  vt,
type_t type,
int encoded_type,
int decoded_size 
)
static

Definition at line 767 of file write_msft.c.

773{
774 int default_type;
775 int scratch;
776 int typeoffset;
777 int *typedata;
778 int target_type;
779 int child_size = 0;
780
781 chat("encode_type vt %d type %p\n", vt, type);
782
783 default_type = 0x80000000 | (vt << 16) | vt;
784 if (!decoded_size) decoded_size = &scratch;
785
786 *decoded_size = 0;
787
788 switch (vt) {
789 case VT_I1:
790 case VT_UI1:
791 *encoded_type = default_type;
792 break;
793
794 case VT_INT:
795 *encoded_type = 0x80000000 | (VT_I4 << 16) | VT_INT;
796 break;
797
798 case VT_UINT:
799 *encoded_type = 0x80000000 | (VT_UI4 << 16) | VT_UINT;
800 break;
801
802 case VT_UI2:
803 case VT_I2:
804 case VT_BOOL:
805 *encoded_type = default_type;
806 break;
807
808 case VT_I4:
809 case VT_UI4:
810 case VT_R4:
811 case VT_ERROR:
812 case VT_HRESULT:
813 *encoded_type = default_type;
814 break;
815
816 case VT_R8:
817 case VT_I8:
818 case VT_UI8:
819 *encoded_type = default_type;
820 break;
821
822 case VT_CY:
823 case VT_DATE:
824 *encoded_type = default_type;
825 break;
826
827 case VT_DECIMAL:
828 *encoded_type = default_type;
829 break;
830
831 case VT_VOID:
832 *encoded_type = 0x80000000 | (VT_EMPTY << 16) | vt;
833 break;
834
835 case VT_UNKNOWN:
836 case VT_DISPATCH:
837 case VT_BSTR:
838 *encoded_type = default_type;
839 break;
840
841 case VT_VARIANT:
842 *encoded_type = default_type;
843 break;
844
845 case VT_LPSTR:
846 case VT_LPWSTR:
847 *encoded_type = 0xfffe0000 | vt;
848 break;
849
850 case VT_PTR:
851 {
852 int next_vt;
853 for(next_vt = 0; is_ptr(type); type = type_pointer_get_ref_type(type)) {
855 if (next_vt != 0)
856 break;
857 }
858 /* if no type found then it must be void */
859 if (next_vt == 0)
860 next_vt = VT_VOID;
861
863 &target_type, &child_size);
864 /* these types already have an implicit pointer, so we don't need to
865 * add another */
866 if(next_vt == VT_DISPATCH || next_vt == VT_UNKNOWN) {
867 chat("encode_type: skipping ptr\n");
868 *encoded_type = target_type;
869 *decoded_size = child_size;
870 break;
871 }
872
873 for (typeoffset = 0; typeoffset < typelib->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
874 typedata = (void *)&typelib->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
875 if (((typedata[0] & 0xffff) == VT_PTR) && (typedata[1] == target_type)) break;
876 }
877
878 if (typeoffset == typelib->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
879 int mix_field;
880
881 if (target_type & 0x80000000) {
882 mix_field = ((target_type >> 16) & 0x3fff) | VT_BYREF;
883 } else {
884 typedata = (void *)&typelib->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
885 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
886 }
887
888 typeoffset = ctl2_alloc_segment(typelib, MSFT_SEG_TYPEDESC, 8, 0);
889 typedata = (void *)&typelib->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
890
891 typedata[0] = (mix_field << 16) | VT_PTR;
892 typedata[1] = target_type;
893 }
894
895 *encoded_type = typeoffset;
896
897 *decoded_size = 8 /*sizeof(TYPEDESC)*/ + child_size;
898 break;
899 }
900
901 case VT_SAFEARRAY:
902 {
904 int next_vt = get_type_vt(element_type);
905
907 &target_type, &child_size);
908
909 for (typeoffset = 0; typeoffset < typelib->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
910 typedata = (void *)&typelib->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
911 if (((typedata[0] & 0xffff) == VT_SAFEARRAY) && (typedata[1] == target_type)) break;
912 }
913
914 if (typeoffset == typelib->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
915 int mix_field;
916
917 if (target_type & 0x80000000) {
918 mix_field = ((target_type >> 16) & VT_TYPEMASK) | VT_ARRAY;
919 } else {
920 typedata = (void *)&typelib->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
921 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
922 }
923
924 typeoffset = ctl2_alloc_segment(typelib, MSFT_SEG_TYPEDESC, 8, 0);
925 typedata = (void *)&typelib->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
926
927 typedata[0] = (mix_field << 16) | VT_SAFEARRAY;
928 typedata[1] = target_type;
929 }
930
931 *encoded_type = typeoffset;
932
933 *decoded_size = 8 /*sizeof(TYPEDESC)*/ + child_size;
934 break;
935 }
936
937 case VT_USERDEFINED:
938 {
939 importinfo_t *importinfo;
940 int typeinfo_offset;
941
942 if (type->typelib_idx > -1)
943 {
944 chat("encode_type: VT_USERDEFINED - found already defined type %s at %d\n",
945 type->name, type->typelib_idx);
946 typeinfo_offset = typelib->typelib_typeinfo_offsets[type->typelib_idx];
947 }
948 else if ((importinfo = find_importinfo(typelib, type->name)))
949 {
950 chat("encode_type: VT_USERDEFINED - found imported type %s in %s\n",
951 type->name, importinfo->importlib->name);
952 alloc_importinfo(typelib, importinfo);
953 typeinfo_offset = importinfo->offset | 0x1;
954 }
955 else
956 {
957 /* Typedefs without the [public] attribute aren't included in the
958 * typelib, unless the aliasee is an anonymous UDT or the typedef
959 * is wire-marshalled. In the latter case the wire-marshal type,
960 * which may be a non-public alias, is used instead. */
961 while (type_is_alias(type))
962 {
963 if (is_attr(type->attrs, ATTR_WIREMARSHAL))
964 {
966 break;
967 }
968 else if (!is_attr(type->attrs, ATTR_PUBLIC))
970 else
971 break;
972 }
973
974 chat("encode_type: VT_USERDEFINED - adding new type %s, real type %d\n",
975 type->name, type_get_type(type));
976
978 {
979 case TYPE_STRUCT:
982 break;
983 case TYPE_INTERFACE:
985 break;
986 case TYPE_ENUM:
988 break;
989 case TYPE_UNION:
991 break;
992 case TYPE_COCLASS:
994 break;
995 case TYPE_ALIAS:
997 break;
998 default:
999 error("encode_type: VT_USERDEFINED - unhandled type %d\n",
1001 }
1002
1003 typeinfo_offset = typelib->typelib_typeinfo_offsets[type->typelib_idx];
1004 }
1005 for (typeoffset = 0; typeoffset < typelib->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
1006 typedata = (void *)&typelib->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1007 if ((typedata[0] == ((0x7fff << 16) | VT_USERDEFINED)) && (typedata[1] == typeinfo_offset)) break;
1008 }
1009
1010 if (typeoffset == typelib->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
1011 typeoffset = ctl2_alloc_segment(typelib, MSFT_SEG_TYPEDESC, 8, 0);
1012 typedata = (void *)&typelib->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1013
1014 typedata[0] = (0x7fff << 16) | VT_USERDEFINED;
1015 typedata[1] = typeinfo_offset;
1016 }
1017
1018 *encoded_type = typeoffset;
1019 break;
1020 }
1021
1022 default:
1023 error("encode_type: unrecognized type %d.\n", vt);
1024 *encoded_type = default_type;
1025 break;
1026 }
1027
1028 return 0;
1029}
@ VT_UI8
Definition: compat.h:2315
@ VT_VOID
Definition: compat.h:2318
@ VT_INT
Definition: compat.h:2316
@ VT_LPSTR
Definition: compat.h:2324
@ VT_R4
Definition: compat.h:2299
@ VT_UNKNOWN
Definition: compat.h:2308
@ VT_TYPEMASK
Definition: compat.h:2346
@ VT_BYREF
Definition: compat.h:2342
@ VT_PTR
Definition: compat.h:2320
@ VT_UI2
Definition: compat.h:2312
@ VT_DECIMAL
Definition: compat.h:2309
@ VT_ERROR
Definition: compat.h:2305
@ VT_ARRAY
Definition: compat.h:2341
@ VT_SAFEARRAY
Definition: compat.h:2321
@ VT_LPWSTR
Definition: compat.h:2325
@ VT_R8
Definition: compat.h:2300
@ VT_CY
Definition: compat.h:2301
@ VT_VARIANT
Definition: compat.h:2307
@ VT_I8
Definition: compat.h:2314
@ VT_I1
Definition: compat.h:2310
@ VT_USERDEFINED
Definition: compat.h:2323
@ VT_HRESULT
Definition: compat.h:2319
@ VT_DATE
Definition: compat.h:2302
@ VT_BOOL
Definition: compat.h:2306
@ VT_I2
Definition: compat.h:2297
@ VT_UINT
Definition: compat.h:2317
@ VT_EMPTY
Definition: compat.h:2295
@ VT_DISPATCH
Definition: compat.h:2304
@ VT_UI1
Definition: compat.h:2311
static REFPROPVARIANT PROPVAR_CHANGE_FLAGS VARTYPE vt
Definition: suminfo.c:91
static const char * target_type(DWORD dwType)
Definition: mixer.c:95
void * get_attrp(const attr_list_t *list, enum attr_type attr_type)
Definition: attribute.c:87
static int is_ptr(const type_t *t)
Definition: header.h:55
char * name
Definition: widltypes.h:596
static type_t * type_array_get_element_type(const type_t *type)
Definition: typetree.h:345
static type_t * type_pointer_get_ref_type(const type_t *type)
Definition: typetree.h:424
static int type_is_alias(const type_t *type)
Definition: typetree.h:357
@ TYPE_ALIAS
Definition: widltypes.h:484
@ ATTR_WIREMARSHAL
Definition: widltypes.h:187
static enum type_type type_get_type_detect_alias(const type_t *type)
Definition: widltypes.h:679

Referenced by add_typedef_typeinfo(), encode_type(), and encode_var().

◆ encode_var()

static int encode_var ( msft_typelib_t typelib,
type_t type,
var_t var,
int encoded_type,
int decoded_size 
)
static

Definition at line 1036 of file write_msft.c.

1042{
1043 int typeoffset;
1044 int *typedata;
1045 int target_type;
1046 int child_size;
1047 int vt;
1048 int scratch;
1049
1050 if (!decoded_size) decoded_size = &scratch;
1051 *decoded_size = 0;
1052
1053 chat("encode_var: var %p type %p type->name %s\n",
1054 var, type, type->name ? type->name : "NULL");
1055
1057 int num_dims, arrayoffset;
1058 type_t *atype;
1059 int *arraydata;
1060
1061 num_dims = 0;
1062 for (atype = type;
1063 is_array(atype) && !type_array_is_decl_as_ptr(atype);
1064 atype = type_array_get_element_type(atype))
1065 ++num_dims;
1066
1067 chat("array with %d dimensions\n", num_dims);
1069 arrayoffset = ctl2_alloc_segment(typelib, MSFT_SEG_ARRAYDESC, (2 + 2 * num_dims) * sizeof(int), 0);
1070 arraydata = (void *)&typelib->typelib_segment_data[MSFT_SEG_ARRAYDESC][arrayoffset];
1071
1072 arraydata[0] = target_type;
1073 arraydata[1] = num_dims;
1074 arraydata[1] |= ((num_dims * 2 * sizeof(int)) << 16);
1075
1076 arraydata += 2;
1077 for (atype = type;
1078 is_array(atype) && !type_array_is_decl_as_ptr(atype);
1079 atype = type_array_get_element_type(atype))
1080 {
1081 arraydata[0] = type_array_get_dim(atype);
1082 arraydata[1] = 0;
1083 arraydata += 2;
1084 }
1085
1086 typeoffset = ctl2_alloc_segment(typelib, MSFT_SEG_TYPEDESC, 8, 0);
1087 typedata = (void *)&typelib->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1088
1089 typedata[0] = (0x7ffe << 16) | VT_CARRAY;
1090 typedata[1] = arrayoffset;
1091
1092 *encoded_type = typeoffset;
1093 *decoded_size = 20 /*sizeof(ARRAYDESC)*/ + (num_dims - 1) * 8 /*sizeof(SAFEARRAYBOUND)*/;
1094 return 0;
1095 }
1096
1097 vt = get_type_vt(type);
1098 if (vt == VT_PTR) {
1099 type_t *ref = is_ptr(type) ?
1101 int skip_ptr = encode_var(typelib, ref, var, &target_type, &child_size);
1102
1103 if(skip_ptr == 2) {
1104 chat("encode_var: skipping ptr\n");
1105 *encoded_type = target_type;
1106 *decoded_size = child_size;
1107 return 0;
1108 }
1109
1110 for (typeoffset = 0; typeoffset < typelib->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
1111 typedata = (void *)&typelib->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1112 if (((typedata[0] & 0xffff) == VT_PTR) && (typedata[1] == target_type)) break;
1113 }
1114
1115 if (typeoffset == typelib->typelib_segdir[MSFT_SEG_TYPEDESC].length) {
1116 int mix_field;
1117
1118 if (target_type & 0x80000000) {
1119 mix_field = ((target_type >> 16) & 0x3fff) | VT_BYREF;
1120 } else if (get_type_vt(ref) == VT_SAFEARRAY) {
1122 mix_field = get_type_vt(element_type) | VT_ARRAY | VT_BYREF;
1123 } else {
1124 typedata = (void *)&typelib->typelib_segment_data[MSFT_SEG_TYPEDESC][target_type];
1125 mix_field = ((typedata[0] >> 16) == 0x7fff)? 0x7fff: 0x7ffe;
1126 }
1127
1128 typeoffset = ctl2_alloc_segment(typelib, MSFT_SEG_TYPEDESC, 8, 0);
1129 typedata = (void *)&typelib->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
1130
1131 typedata[0] = (mix_field << 16) | VT_PTR;
1132 typedata[1] = target_type;
1133 }
1134
1135 *encoded_type = typeoffset;
1136
1137 *decoded_size = 8 /*sizeof(TYPEDESC)*/ + child_size;
1138 return 0;
1139 }
1140
1141 dump_type(type);
1142
1143 encode_type(typelib, vt, type, encoded_type, decoded_size);
1144 /* these types already have an implicit pointer, so we don't need to
1145 * add another */
1146 if(vt == VT_DISPATCH || vt == VT_UNKNOWN) return 2;
1147 return 0;
1148}
@ VT_CARRAY
Definition: compat.h:2322
static int is_array(const type_t *t)
Definition: header.h:60
static int type_array_is_decl_as_ptr(const type_t *type)
Definition: typetree.h:350
static unsigned int type_array_get_dim(const type_t *type)
Definition: typetree.h:303
static void dump_type(type_t *t)
Definition: write_msft.c:1031

Referenced by add_func_desc(), add_var_desc(), and encode_var().

◆ find_importinfo()

static importinfo_t * find_importinfo ( msft_typelib_t typelib,
const char name 
)
static

Definition at line 724 of file write_msft.c.

725{
727 int i;
728
729 chat("search importlib %s\n", name);
730
731 if(!name)
732 return NULL;
733
734 LIST_FOR_EACH_ENTRY( importlib, &typelib->typelib->importlibs, importlib_t, entry )
735 {
736 for(i=0; i < importlib->ntypeinfos; i++) {
737 if(!strcmp(name, importlib->importinfos[i].name)) {
738 chat("Found %s in importlib.\n", name);
739 return importlib->importinfos+i;
740 }
741 }
742 }
743
744 return NULL;
745}

Referenced by add_dispinterface_typeinfo(), add_interface_typeinfo(), and encode_type().

◆ get_ulong_val()

static unsigned int get_ulong_val ( unsigned int  val,
int  vt 
)
static

Definition at line 1150 of file write_msft.c.

1151{
1152 switch(vt) {
1153 case VT_I2:
1154 case VT_BOOL:
1155 case VT_UI2:
1156 return val & 0xffff;
1157 case VT_I1:
1158 case VT_UI1:
1159 return val & 0xff;
1160 }
1161
1162 return val;
1163}
GLuint GLfloat * val
Definition: glext.h:7180

Referenced by write_int_value().

◆ save_all_changes()

static void save_all_changes ( msft_typelib_t typelib)
static

Definition at line 2688 of file write_msft.c.

2689{
2690 int filepos;
2691
2692 chat("save_all_changes(%p)\n", typelib);
2693
2694 filepos = sizeof(MSFT_Header) + sizeof(MSFT_SegDir);
2695 if(typelib->typelib_header.varflags & 0x100) filepos += 4; /* helpstringdll */
2696 filepos += typelib->typelib_header.nrtypeinfos * 4;
2697
2698 filepos += ctl2_finalize_segment(typelib, filepos, MSFT_SEG_TYPEINFO);
2699 filepos += ctl2_finalize_segment(typelib, filepos, MSFT_SEG_GUIDHASH);
2700 filepos += ctl2_finalize_segment(typelib, filepos, MSFT_SEG_GUID);
2704 filepos += ctl2_finalize_segment(typelib, filepos, MSFT_SEG_NAMEHASH);
2705 filepos += ctl2_finalize_segment(typelib, filepos, MSFT_SEG_NAME);
2706 filepos += ctl2_finalize_segment(typelib, filepos, MSFT_SEG_STRING);
2707 filepos += ctl2_finalize_segment(typelib, filepos, MSFT_SEG_TYPEDESC);
2708 filepos += ctl2_finalize_segment(typelib, filepos, MSFT_SEG_ARRAYDESC);
2709 filepos += ctl2_finalize_segment(typelib, filepos, MSFT_SEG_CUSTDATA);
2711
2713
2715
2716 put_data(&typelib->typelib_header, sizeof(typelib->typelib_header));
2717 if(typelib->typelib_header.varflags & 0x100)
2718 put_data(&typelib->help_string_dll_offset, sizeof(typelib->help_string_dll_offset));
2719
2720 put_data(typelib->typelib_typeinfo_offsets, typelib->typelib_header.nrtypeinfos * 4);
2721 put_data(&typelib->typelib_segdir, sizeof(typelib->typelib_segdir));
2735
2737
2738 if (strendswith( typelib_name, ".res" )) /* create a binary resource file */
2739 {
2740 char typelib_id[13] = "#1";
2741
2742 expr_t *expr = get_attrp( typelib->typelib->attrs, ATTR_ID );
2743 if (expr)
2744 snprintf( typelib_id, sizeof(typelib_id), "#%d", expr->cval );
2745 add_output_to_resources( "TYPELIB", typelib_id );
2746 if (strendswith( typelib_name, "_t.res" )) /* add typelib registration */
2748#ifdef __REACTOS__
2750#endif
2751 }
2753}
struct tagMSFT_Header MSFT_Header
static HRESULT flush_output_buffer(mxwriter *This)
Definition: mxwriter.c:661
static int strendswith(const char *str, const char *end)
Definition: tools.h:145
static void init_output_buffer(void)
Definition: tools.h:791
void output_typelib_regscript(const typelib_t *typelib)
Definition: register.c:334
void add_output_to_resources(const char *type, const char *name)
Definition: utils.c:192
void flush_output_resources(const char *name)
Definition: utils.c:226
char * typelib_name
Definition: widl.c:122
static void ctl2_finalize_typeinfos(msft_typelib_t *typelib, int filesize)
Definition: write_msft.c:2621
static void ctl2_write_typeinfos(msft_typelib_t *typelib)
Definition: write_msft.c:2648
static void ctl2_write_segment(msft_typelib_t *typelib, int segment)
Definition: write_msft.c:2615
static int ctl2_finalize_segment(msft_typelib_t *typelib, int filepos, int segment)
Definition: write_msft.c:2636

Referenced by create_msft_typelib().

◆ set_custdata()

static void set_custdata ( msft_typelib_t typelib,
const struct uuid guid,
int  vt,
const void value,
int offset 
)
static

Definition at line 1258 of file write_msft.c.

1260{
1261 int guidoffset;
1262 int custoffset;
1263 int *custdata;
1264 int data_out;
1265 int hash_key;
1266
1267 hash_key = ctl2_hash_guid(guid);
1268 guidoffset = ctl2_find_guid(typelib, hash_key, guid);
1269 if(guidoffset == -1) {
1270 /* add GUID that was not already present */
1271 MSFT_GuidEntry guidentry;
1272 guidentry.guid = *guid;
1273
1274 guidentry.hreftype = -1;
1275 guidentry.next_hash = -1;
1276
1277 guidoffset = ctl2_alloc_guid(typelib, &guidentry);
1278 }
1279
1280 if(vt == VT_BSTR)
1281 /* TODO midl appears to share a single reference if the same string is used as custdata in multiple places */
1282 write_string_value(typelib, &data_out, value);
1283 else
1284 write_int_value(typelib, &data_out, vt, *(int*)value);
1285
1286 custoffset = ctl2_alloc_segment(typelib, MSFT_SEG_CUSTDATAGUID, 12, 0);
1287
1288 custdata = (int *)&typelib->typelib_segment_data[MSFT_SEG_CUSTDATAGUID][custoffset];
1289 custdata[0] = guidoffset;
1290 custdata[1] = data_out;
1291 custdata[2] = *offset;
1292 *offset = custoffset;
1293}
static void write_string_value(msft_typelib_t *typelib, int *out, const char *value)
Definition: write_msft.c:1181

Referenced by create_msft_typelib(), and set_custdata_attr().

◆ set_custdata_attr()

static void set_custdata_attr ( msft_typelib_t typelib,
attr_custdata_t custdata,
int offset 
)
static

Definition at line 1295 of file write_msft.c.

1296{
1297 switch(custdata->pval->type) {
1298 case EXPR_STRLIT:
1299 case EXPR_WSTRLIT:
1300 set_custdata(typelib, &custdata->id, VT_BSTR, custdata->pval->u.sval, offset);
1301 break;
1302 case EXPR_NUM:
1303 set_custdata(typelib, &custdata->id, VT_I4, &custdata->pval->u.integer.value, offset);
1304 break;
1305 default:
1306 error("custom() attribute with unknown type\n");
1307 break;
1308 }
1309}
struct uuid id
Definition: widltypes.h:377
expr_t * pval
Definition: widltypes.h:378
const char * sval
Definition: widltypes.h:365
enum expr_type type
Definition: widltypes.h:360
union _expr_t::@5356 u
struct integer integer
Definition: widltypes.h:363
@ EXPR_NUM
Definition: widltypes.h:193

Referenced by add_func_desc(), add_var_desc(), create_msft_typeinfo(), and create_msft_typelib().

◆ set_doc_string()

static void set_doc_string ( msft_typelib_t typelib)
static

Definition at line 2527 of file write_msft.c.

2528{
2529 char *str = get_attrp( typelib->typelib->attrs, ATTR_HELPSTRING );
2530
2531 if (str)
2532 {
2534 if (offset != -1) typelib->typelib_header.helpstring = offset;
2535 }
2536}
const WCHAR * str

Referenced by create_msft_typelib().

◆ set_guid()

static void set_guid ( msft_typelib_t typelib)
static

Definition at line 2513 of file write_msft.c.

2514{
2515 MSFT_GuidEntry guidentry = { {0}, -2, -1 };
2516 int offset;
2517 struct uuid *ptr = get_attrp( typelib->typelib->attrs, ATTR_UUID );
2518
2519 if (ptr) guidentry.guid = *ptr;
2520
2521 offset = ctl2_alloc_guid(typelib, &guidentry);
2522 typelib->typelib_header.posguid = offset;
2523
2524 return;
2525}
static PVOID ptr
Definition: dispmode.c:27

Referenced by create_msft_typelib().

◆ set_help_context()

static void set_help_context ( msft_typelib_t typelib)
static

Definition at line 2553 of file write_msft.c.

2554{
2555 const expr_t *expr = get_attrp( typelib->typelib->attrs, ATTR_HELPCONTEXT );
2556 if (expr) typelib->typelib_header.helpcontext = expr->cval;
2557}

Referenced by create_msft_typelib().

◆ set_help_file_name()

static void set_help_file_name ( msft_typelib_t typelib)
static

Definition at line 2538 of file write_msft.c.

2539{
2540 char *str = get_attrp( typelib->typelib->attrs, ATTR_HELPFILE );
2541
2542 if (str)
2543 {
2545 if (offset != -1)
2546 {
2547 typelib->typelib_header.helpfile = offset;
2548 typelib->typelib_header.varflags |= 0x10;
2549 }
2550 }
2551}
@ ATTR_HELPFILE
Definition: widltypes.h:120

Referenced by create_msft_typelib().

◆ set_help_string_context()

static void set_help_string_context ( msft_typelib_t typelib)
static

Definition at line 2574 of file write_msft.c.

2575{
2576 const expr_t *expr = get_attrp( typelib->typelib->attrs, ATTR_HELPSTRINGCONTEXT );
2577 if (expr) typelib->typelib_header.helpstringcontext = expr->cval;
2578}

Referenced by create_msft_typelib().

◆ set_help_string_dll()

static void set_help_string_dll ( msft_typelib_t typelib)
static

Definition at line 2559 of file write_msft.c.

2560{
2561 char *str = get_attrp( typelib->typelib->attrs, ATTR_HELPSTRINGDLL );
2562
2563 if (str)
2564 {
2566 if (offset != -1)
2567 {
2568 typelib->help_string_dll_offset = offset;
2569 typelib->typelib_header.varflags |= 0x100;
2570 }
2571 }
2572}
@ ATTR_HELPSTRINGDLL
Definition: widltypes.h:123

Referenced by create_msft_typelib().

◆ set_lcid()

static void set_lcid ( msft_typelib_t typelib)
static

Definition at line 2580 of file write_msft.c.

2581{
2582 const expr_t *lcid_expr = get_attrp( typelib->typelib->attrs, ATTR_LIBLCID );
2583 if(lcid_expr)
2584 {
2585 typelib->typelib_header.lcid = lcid_expr->cval;
2586 typelib->typelib_header.lcid2 = lcid_expr->cval;
2587 }
2588}
int cval
Definition: widltypes.h:371
@ ATTR_LIBLCID
Definition: widltypes.h:134

Referenced by create_msft_typelib().

◆ set_lib_flags()

static void set_lib_flags ( msft_typelib_t typelib)
static

Definition at line 2590 of file write_msft.c.

2591{
2592 const attr_t *attr;
2593
2594 typelib->typelib_header.flags = 0;
2595 if (!typelib->typelib->attrs) return;
2596 LIST_FOR_EACH_ENTRY( attr, typelib->typelib->attrs, const attr_t, entry )
2597 {
2598 switch(attr->type) {
2599 case ATTR_CONTROL:
2600 typelib->typelib_header.flags |= 0x02; /* LIBFLAG_FCONTROL */
2601 break;
2602 case ATTR_HIDDEN:
2603 typelib->typelib_header.flags |= 0x04; /* LIBFLAG_FHIDDEN */
2604 break;
2605 case ATTR_RESTRICTED:
2606 typelib->typelib_header.flags |= 0x01; /* LIBFLAG_FRESTRICTED */
2607 break;
2608 default:
2609 break;
2610 }
2611 }
2612 return;
2613}

Referenced by create_msft_typelib().

◆ set_name()

static void set_name ( msft_typelib_t typelib)
static

Definition at line 2498 of file write_msft.c.

2499{
2500 int offset;
2501
2502 offset = ctl2_alloc_name(typelib, typelib->typelib->name);
2503 if (offset == -1) return;
2504 typelib->typelib_header.NameOffset = offset;
2505 return;
2506}

Referenced by create_msft_typelib(), and ft_property_do().

◆ set_version()

static void set_version ( msft_typelib_t typelib)
static

Definition at line 2508 of file write_msft.c.

2509{
2510 typelib->typelib_header.version = get_attrv( typelib->typelib->attrs, ATTR_VERSION );
2511}
unsigned int get_attrv(const attr_list_t *list, enum attr_type attr_type)
Definition: attribute.c:78

Referenced by create_msft_typelib().

◆ write_default_value()

static void write_default_value ( msft_typelib_t typelib,
type_t type,
expr_t expr,
int out 
)
static

Definition at line 1196 of file write_msft.c.

1197{
1198 int vt;
1199
1200 if (expr->type == EXPR_STRLIT || expr->type == EXPR_WSTRLIT) {
1201 vt = get_type_vt(type);
1202 if (vt != VT_BSTR && vt != VT_VARIANT)
1203 error("string default value applied to non-string type\n");
1204 chat("default value '%s'\n", expr->u.sval);
1206 return;
1207 }
1208
1209 if (type_get_type(type) == TYPE_ENUM) {
1210 vt = VT_I4;
1211 } else if (is_ptr(type)) {
1213 if (vt == VT_USERDEFINED)
1214 vt = VT_I4;
1215 if (expr->cval)
1216 warning("non-null pointer default value\n");
1217 } else {
1218 vt = get_type_vt(type);
1219 switch(vt) {
1220 case VT_I2:
1221 case VT_I4:
1222 case VT_R4:
1223 case VT_BOOL:
1224 case VT_I1:
1225 case VT_UI1:
1226 case VT_UI2:
1227 case VT_UI4:
1228 case VT_INT:
1229 case VT_UINT:
1230 case VT_HRESULT:
1231 break;
1232 case VT_USERDEFINED:
1233 vt = VT_I4;
1234 break;
1235 case VT_VARIANT: {
1236 switch (expr->type) {
1237 case EXPR_DOUBLE:
1238 vt = VT_R4;
1239 break;
1240 case EXPR_NUM:
1241 vt = VT_I4;
1242 break;
1243 default:
1244 warning("can't write default VT_VARIANT value for expression type %d.\n", expr->type);
1245 return;
1246 }
1247 break;
1248 }
1249 default:
1250 warning("can't write value of type %d yet\n", vt);
1251 return;
1252 }
1253 }
1254
1255 write_int_value(typelib, out, vt, expr->cval);
1256}
@ EXPR_DOUBLE
Definition: parse.h:28
LPCWSTR sval
Definition: query.h:93
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383

Referenced by add_func_desc().

◆ write_int_value()

static void write_int_value ( msft_typelib_t typelib,
int out,
int  vt,
int  value 
)
static

Definition at line 1165 of file write_msft.c.

1166{
1167 const unsigned int lv = get_ulong_val(value, vt);
1168 if ((lv & 0x3ffffff) == lv) {
1169 *out = 0x80000000;
1170 *out |= vt << 26;
1171 *out |= lv;
1172 } else {
1174 *((unsigned short *)&typelib->typelib_segment_data[MSFT_SEG_CUSTDATA][offset]) = vt;
1175 memcpy(&typelib->typelib_segment_data[MSFT_SEG_CUSTDATA][offset+2], &value, 4);
1176 *((unsigned short *)&typelib->typelib_segment_data[MSFT_SEG_CUSTDATA][offset+6]) = 0x5757;
1177 *out = offset;
1178 }
1179}
static unsigned int get_ulong_val(unsigned int val, int vt)
Definition: write_msft.c:1150

Referenced by add_var_desc(), set_custdata(), and write_default_value().

◆ write_string_value()

static void write_string_value ( msft_typelib_t typelib,
int out,
const char value 
)
static

Definition at line 1181 of file write_msft.c.

1182{
1183 int len = strlen(value), seg_len = (len + 6 + 3) & ~0x3;
1185 *((unsigned short *)&typelib->typelib_segment_data[MSFT_SEG_CUSTDATA][offset]) = VT_BSTR;
1186 memcpy(&typelib->typelib_segment_data[MSFT_SEG_CUSTDATA][offset+2], &len, sizeof(len));
1187 memcpy(&typelib->typelib_segment_data[MSFT_SEG_CUSTDATA][offset+6], value, len);
1188 len += 6;
1189 while(len < seg_len) {
1190 *((char *)&typelib->typelib_segment_data[MSFT_SEG_CUSTDATA][offset+len]) = 0x57;
1191 len++;
1192 }
1193 *out = offset;
1194}
GLenum GLsizei len
Definition: glext.h:6722

Referenced by set_custdata(), and write_default_value().