Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(540)

Delta Between Two Patch Sets: src/cmd/godefs/main.c

Issue 4564043: code review 4564043: godefs: do not assume forward type references are enums (Closed)
Left Patch Set: diff -r 798775ed7ee3 https://go.googlecode.com/hg/ Created 13 years, 10 months ago
Right Patch Set: diff -r 3bbbb59986c7 https://go.googlecode.com/hg/ Created 13 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/cmd/godefs/a.h ('k') | src/cmd/godefs/stabs.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // Godefs takes as input a host-compilable C file that includes 5 // Godefs takes as input a host-compilable C file that includes
6 // standard system headers. From that input file, it generates 6 // standard system headers. From that input file, it generates
7 // a standalone (no #includes) C or Go file containing equivalent 7 // a standalone (no #includes) C or Go file containing equivalent
8 // definitions. 8 // definitions.
9 // 9 //
10 // The input C file is expected to define new types and enumerated 10 // The input C file is expected to define new types and enumerated
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 170
171 void 171 void
172 waitforgcc(void) 172 waitforgcc(void)
173 { 173 {
174 waitpid(); 174 waitpid();
175 } 175 }
176 176
177 void 177 void
178 main(int argc, char **argv) 178 main(int argc, char **argv)
179 { 179 {
180 » int p[2], pid, i, j, k, n, off, npad, prefix; 180 » int p[2], pid, i, j, n, off, npad, prefix;
181 char **av, *q, *r, *tofree, *name; 181 char **av, *q, *r, *tofree, *name;
182 char nambuf[100]; 182 char nambuf[100];
183 Biobuf *bin, *bout; 183 Biobuf *bin, *bout;
184 Type *t, *tt; 184 Type *t, *tt;
185 Field *f; 185 Field *f;
186 int orig_output_fd; 186 int orig_output_fd;
187 187
188 quotefmtinstall(); 188 quotefmtinstall();
189 189
190 oargc = argc; 190 oargc = argc;
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 Bprint(bout, lang->structbegin, name, name, name); 369 Bprint(bout, lang->structbegin, name, name, name);
370 StructBody: 370 StructBody:
371 prefix = 0; 371 prefix = 0;
372 if(lang == &go) 372 if(lang == &go)
373 prefix = prefixlen(t); 373 prefix = prefixlen(t);
374 for(j=0; j<t->nf; j++) { 374 for(j=0; j<t->nf; j++) {
375 f = &t->f[j]; 375 f = &t->f[j];
376 if(f->type->kind == 0 && f->size <= 64 && (f->si ze&(f->size-1)) == 0) { 376 if(f->type->kind == 0 && f->size <= 64 && (f->si ze&(f->size-1)) == 0) {
377 // unknown type but <= 64 bits and bit s ize is a power of two. 377 // unknown type but <= 64 bits and bit s ize is a power of two.
378 // could be enum - make Uint64 and then let it reduce 378 // could be enum - make Uint64 and then let it reduce
379 » » » » » for (k = Uint64; k >= Uint8 && kindsize[ k] >= f->size; k -= 2) { 379 » » » » » tt = emalloc(sizeof *tt);
rsc 2011/06/02 14:17:29 I'm a bit confused by this loop. Maybe it is supp
380 » » » » » » tt = emalloc(sizeof *tt); 380 » » » » » *tt = *f->type;
381 » » » » » » *tt = *f->type; 381 » » » » » f->type = tt;
382 » » » » » » f->type = tt; 382 » » » » » tt->kind = Uint64;
383 » » » » » » tt->kind = k; 383 » » » » » while(tt->kind > Uint8 && kindsize[tt->k ind] > f->size)
rh 2011/06/03 02:38:25 Is this closer?
384 » » » » » } 384 » » » » » » tt->kind -= 2;
385 } 385 }
386 // padding 386 // padding
387 if(t->kind == Struct || lang == &go) { 387 if(t->kind == Struct || lang == &go) {
388 if(f->offset%8 != 0 || f->size%8 != 0) { 388 if(f->offset%8 != 0 || f->size%8 != 0) {
389 fprint(2, "ignoring bitfield %s. %s\n", t->name, f->name); 389 fprint(2, "ignoring bitfield %s. %s\n", t->name, f->name);
390 continue; 390 continue;
391 } 391 }
392 if(f->offset < off) 392 if(f->offset < off)
393 sysfatal("%s: struct fields went backward", t->name); 393 sysfatal("%s: struct fields went backward", t->name);
394 if(off < f->offset) { 394 if(off < f->offset) {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 return 0; 597 return 0;
598 if(name == nil) { 598 if(name == nil) {
599 name = f->name; 599 name = f->name;
600 len = p+1 - name; 600 len = p+1 - name;
601 } 601 }
602 else if(strncmp(f->name, name, len) != 0) 602 else if(strncmp(f->name, name, len) != 0)
603 return 0; 603 return 0;
604 } 604 }
605 return len; 605 return len;
606 } 606 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b