main: rework preprocessor invocation
[cparser] / wrappergen / write_compoundsizes.c
1 #include "type_t.h"
2 #include "ast_t.h"
3 #include "entity_t.h"
4 #include "attribute_t.h"
5 #include "write_compoundsizes.h"
6
7 void write_compoundsizes(FILE *output, const translation_unit_t *unit)
8 {
9         for (const entity_t *entity = unit->scope.entities;
10                  entity != NULL; entity = entity->base.next) {
11                 if (entity->kind != ENTITY_TYPEDEF)
12                         continue;
13
14                 type_t *type = skip_typeref(entity->typedefe.type);
15                 if (!is_type_compound(type))
16                         continue;
17
18                 /* see if we have the required attributes */
19                 const compound_t *compound = type->compound.compound;
20                 bool        had_dllexport = false;
21                 const char *string        = NULL;
22                 for (const attribute_t *attrib = compound->attributes;
23                      attrib != NULL; attrib = attrib->next) {
24                     if (attrib->kind == ATTRIBUTE_GNU_DLLEXPORT)
25                                 had_dllexport = true;
26                         if (attrib->kind == ATTRIBUTE_GNU_DEPRECATED) {
27                                 const attribute_argument_t *argument = attrib->a.arguments;
28                                 assert(argument != NULL && argument->kind == ATTRIBUTE_ARGUMENT_EXPRESSION);
29                                 const expression_t *expr = argument->v.expression;
30                                 assert(expr->kind == EXPR_STRING_LITERAL);
31                                 string = expr->string_literal.value.begin;
32                         }
33                 }
34
35                 if (had_dllexport && string != NULL) {
36                         fprintf(output, "%s %u\n", string, get_type_size(type));
37                 }
38         }
39 }