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