Commit 5b8bcf23 authored by Russ Cox's avatar Russ Cox

godefs: better handling of enums

Fixes #432.

R=r, r2
CC=golang-dev
https://golang.org/cl/3869043
parent 9f178edf
...@@ -373,6 +373,8 @@ Continue: ...@@ -373,6 +373,8 @@ Continue:
prefix = prefixlen(t); prefix = prefixlen(t);
for(j=0; j<t->nf; j++) { for(j=0; j<t->nf; j++) {
f = &t->f[j]; f = &t->f[j];
if(f->type->kind == 0)
continue;
// padding // padding
if(t->kind == Struct || lang == &go) { if(t->kind == Struct || lang == &go) {
if(f->offset%8 != 0 || f->size%8 != 0) { if(f->offset%8 != 0 || f->size%8 != 0) {
......
...@@ -363,13 +363,22 @@ parsedef(char **pp, char *name) ...@@ -363,13 +363,22 @@ parsedef(char **pp, char *name)
return nil; return nil;
} }
while(f->type->kind == Typedef)
f->type = f->type->type;
if(f->type->kind == 0 && f->size <= 64 && (f->size&(f->size-1)) == 0) {
// unknown type but <= 64 bits and bit size is a power of two.
// could be enum - make Uint64 and then let it reduce
tt = emalloc(sizeof *tt);
*tt = *f->type;
f->type = tt;
tt->kind = Uint64;
}
// rewrite // rewrite
// uint32 x : 8; // uint32 x : 8;
// into // into
// uint8 x; // uint8 x;
// hooray for bitfields. // hooray for bitfields.
while(f->type->kind == Typedef)
f->type = f->type->type;
while(Int16 <= f->type->kind && f->type->kind <= Uint64 && kindsize[f->type->kind] > f->size) { while(Int16 <= f->type->kind && f->type->kind <= Uint64 && kindsize[f->type->kind] > f->size) {
tt = emalloc(sizeof *tt); tt = emalloc(sizeof *tt);
*tt = *f->type; *tt = *f->type;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment