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

Side by Side Diff: src/cmd/cgo/gcc.go

Issue 5336041: code review 5336041: cgo: print error instead of panic on undeclared enums/s... (Closed)
Patch Set: diff -r 84def2047f20 https://go.googlecode.com/hg/ Created 13 years, 5 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:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Annotate Ref in Prog with C types by parsing gcc debug output. 5 // Annotate Ref in Prog with C types by parsing gcc debug output.
6 // Conversion of debug output to Go types. 6 // Conversion of debug output to Go types.
7 7
8 package main 8 package main
9 9
10 import ( 10 import (
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 } 570 }
571 if e.Tag != dwarf.TagCompileUnit { 571 if e.Tag != dwarf.TagCompileUnit {
572 r.SkipChildren() 572 r.SkipChildren()
573 } 573 }
574 } 574 }
575 575
576 // Record types and typedef information. 576 // Record types and typedef information.
577 var conv typeConv 577 var conv typeConv
578 conv.Init(p.PtrSize) 578 conv.Init(p.PtrSize)
579 for i, n := range names { 579 for i, n := range names {
580 if types[i] == nil {
581 continue
582 }
580 f, fok := types[i].(*dwarf.FuncType) 583 f, fok := types[i].(*dwarf.FuncType)
581 if n.Kind != "type" && fok { 584 if n.Kind != "type" && fok {
582 n.Kind = "func" 585 n.Kind = "func"
583 n.FuncType = conv.FuncType(f) 586 n.FuncType = conv.FuncType(f)
584 } else { 587 } else {
585 n.Type = conv.Type(types[i]) 588 n.Type = conv.Type(types[i])
586 if enums[i] != 0 && n.Type.EnumValues != nil { 589 if enums[i] != 0 && n.Type.EnumValues != nil {
587 k := fmt.Sprintf("__cgo_enum__%d", i) 590 k := fmt.Sprintf("__cgo_enum__%d", i)
588 n.Kind = "const" 591 n.Kind = "const"
589 n.Const = strconv.Itoa64(n.Type.EnumValues[k]) 592 n.Const = strconv.Itoa64(n.Type.EnumValues[k])
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 // Okay - might be new(T) 660 // Okay - might be new(T)
658 expr = r.Name.Type.Go 661 expr = r.Name.Type.Go
659 } 662 }
660 if r.Name.Kind == "var" { 663 if r.Name.Kind == "var" {
661 expr = &ast.StarExpr{X: expr} 664 expr = &ast.StarExpr{X: expr}
662 } 665 }
663 666
664 case "type": 667 case "type":
665 if r.Name.Kind != "type" { 668 if r.Name.Kind != "type" {
666 error_(r.Pos(), "expression C.%s used as type", r.Name.Go) 669 error_(r.Pos(), "expression C.%s used as type", r.Name.Go)
670 } else if r.Name.Type == nil {
671 // Use of C.enum_x, C.struct_x or C.union_x with out C definition.
672 // GCC won't raise an error when using pointers to such unknown types.
673 error_(r.Pos(), "type C.%s: undefined C type '%s '", r.Name.Go, r.Name.C)
667 } else { 674 } else {
668 expr = r.Name.Type.Go 675 expr = r.Name.Type.Go
669 } 676 }
670 default: 677 default:
671 if r.Name.Kind == "func" { 678 if r.Name.Kind == "func" {
672 error_(r.Pos(), "must call C.%s", r.Name.Go) 679 error_(r.Pos(), "must call C.%s", r.Name.Go)
673 } 680 }
674 } 681 }
675 *r.Expr = expr 682 *r.Expr = expr
676 } 683 }
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 off = dt.ByteSize 1373 off = dt.ByteSize
1367 } 1374 }
1368 if off != dt.ByteSize { 1375 if off != dt.ByteSize {
1369 fatalf("struct size calculation error") 1376 fatalf("struct size calculation error")
1370 } 1377 }
1371 buf.WriteString("}") 1378 buf.WriteString("}")
1372 csyntax = buf.String() 1379 csyntax = buf.String()
1373 expr = &ast.StructType{Fields: &ast.FieldList{List: fld}} 1380 expr = &ast.StructType{Fields: &ast.FieldList{List: fld}}
1374 return 1381 return
1375 } 1382 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

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