]> Cypherpunks repositories - gostls13.git/commitdiff
godefs: better handling of enums
authorRuss Cox <rsc@golang.org>
Tue, 11 Jan 2011 16:12:15 +0000 (11:12 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 11 Jan 2011 16:12:15 +0000 (11:12 -0500)
Fixes #432.

R=r, r2
CC=golang-dev
https://golang.org/cl/3869043

src/cmd/godefs/main.c
src/cmd/godefs/stabs.c

index cdecd6e8d83d3dfef84d12afe83dd7a57cc56e50..69ee1be5dbc099c9c84aebcb6bc459f034fbc341 100644 (file)
@@ -373,6 +373,8 @@ Continue:
                                prefix = prefixlen(t);
                        for(j=0; j<t->nf; j++) {
                                f = &t->f[j];
+                               if(f->type->kind == 0)
+                                       continue;
                                // padding
                                if(t->kind == Struct || lang == &go) {
                                        if(f->offset%8 != 0 || f->size%8 != 0) {
index 8d3be191344730346c01cdc3fa3742e0f404f306..1bc96d4c8c200ee8599818524abc2c96d733f193 100644 (file)
@@ -363,13 +363,22 @@ parsedef(char **pp, char *name)
                                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
                        //      uint32 x : 8;
                        // into
                        //      uint8 x;
                        // 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) {
                                tt = emalloc(sizeof *tt);
                                *tt = *f->type;