896490373863eba2bbdafb13e2a5fe3874440792
9 typedef struct _struct_member
13 struct _struct_member
* next
;
18 struct_member
* member_list
;
20 struct _type
* type_value
;
27 unsigned int default_sign
;
28 struct_type
* struct_desc
;
31 static struct_type struct_types
[255];
33 static int next_struct_slot_free
= 0;
34 static struct_type
* current_struct
;
36 static type types
[255] = {
38 {"boolean", BOOLEAN_TYPE
, UNSIGNED_TYPE_OPTION
},
39 {"byte", BYTE_TYPE
, 0},
40 {"char", CHAR_TYPE
, UNSIGNED_TYPE_OPTION
},
41 {"double", DOUBLE_TYPE
, 0},
42 {"error_status_t", ERROR_STATUS_TYPE
, UNSIGNED_TYPE_OPTION
},
43 {"float", FLOAT_TYPE
, 0},
44 {"handle_t", HANDLE_TYPE
, 0},
45 {"hyper", HYPER_TYPE
, SIGNED_TYPE_OPTION
},
46 {"int", INT_TYPE
, SIGNED_TYPE_OPTION
},
47 {"__int32", INT32_TYPE
, SIGNED_TYPE_OPTION
},
48 {"__int3264", INT32OR64_TYPE
, SIGNED_TYPE_OPTION
},
49 {"__int64", INT64_TYPE
, SIGNED_TYPE_OPTION
},
50 {"long", LONG_TYPE
, SIGNED_TYPE_OPTION
},
51 {"short", SHORT_TYPE
, SIGNED_TYPE_OPTION
},
52 {"small", SMALL_TYPE
, SIGNED_TYPE_OPTION
},
53 {"void", VOID_TYPE
, 0},
54 {"wchar_t", WCHAR_TYPE
, UNSIGNED_TYPE_OPTION
},
58 static int next_free_slot
= 18;
60 unsigned int struct_to_type(char* tag
)
64 for (i
= 0; i
< next_struct_slot_free
; i
++)
66 if (strcmp(tag
, struct_types
[i
].tag
) == 0)
68 return(struct_types
[i
].type_value
->value
);
74 void start_struct(char* tag
)
81 sprintf(tag
, "__unnamed_struct%d", next_struct_slot_free
);
84 name
= malloc(strlen("struct ") + strlen(tag
) + 1);
85 strcpy(name
, "struct ");
88 struct_types
[next_struct_slot_free
].tag
= strdup(tag
);
89 struct_types
[next_struct_slot_free
].member_list
= NULL
;
90 current_struct
= &struct_types
[next_struct_slot_free
];
92 types
[next_free_slot
].name
= name
;
93 types
[next_free_slot
].value
= next_free_slot
<< 8;
94 types
[next_free_slot
].default_sign
= 0;
95 types
[next_free_slot
].struct_desc
=
96 &struct_types
[next_struct_slot_free
];
98 struct_types
[next_struct_slot_free
].type_value
= &types
[next_free_slot
];
100 next_struct_slot_free
++;
104 void add_struct_member(char* name
, unsigned int type
)
106 struct_member
* member
;
108 member
= malloc(sizeof(struct_member
));
110 member
->name
= strdup(name
);
111 member
->value
= type
;
112 member
->next
= current_struct
->member_list
;
113 current_struct
->member_list
= member
;
116 unsigned int end_struct(void)
121 printf("Defining struct %s {\n", current_struct
->tag
);
123 cur
= current_struct
->member_list
;
126 print_type(cur
->value
);
127 printf(" %s\n", cur
->name
);
133 n
= current_struct
->type_value
->value
;
134 current_struct
= NULL
;
138 void add_typedef(char* name
, int type
)
140 printf("Adding typedef %s to ", name
);
144 types
[next_free_slot
].name
= strdup(name
);
145 types
[next_free_slot
].value
= type
;
146 types
[next_free_slot
].default_sign
= 0;
150 void print_type(int tval
)
154 for (i
= 1; i
< next_free_slot
; i
++)
156 if ((tval
& BASE_TYPE_MASK
) == types
[i
].value
)
158 if (tval
& UNSIGNED_TYPE_OPTION
)
162 if (tval
& SIGNED_TYPE_OPTION
)
166 printf("%s", types
[i
].name
);
167 if (tval
& POINTER_TYPE_OPTION
)
174 printf("unknown type");
177 int token_to_type(char* token
)
181 for (i
= 1; i
< next_free_slot
; i
++)
183 if (strcmp(types
[i
].name
, token
) == 0)
185 return(types
[i
].value
);