diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-04-26 09:55:32 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-04-26 09:55:32 +0200 |
commit | 7b15ed9ef455b6b66c6b376898a88aef5d6a9970 (patch) | |
tree | 3ef530baa80cdf29436ba981f5783be6b4d2202b /src/cmd/cgo | |
parent | 50104cc32a498f7517a51c8dc93106c51c7a54b4 (diff) | |
download | golang-7b15ed9ef455b6b66c6b376898a88aef5d6a9970.tar.gz |
Imported Upstream version 2011.04.13upstream/2011.04.13
Diffstat (limited to 'src/cmd/cgo')
-rw-r--r-- | src/cmd/cgo/ast.go | 20 | ||||
-rw-r--r-- | src/cmd/cgo/gcc.go | 60 | ||||
-rw-r--r-- | src/cmd/cgo/main.go | 8 | ||||
-rw-r--r-- | src/cmd/cgo/out.go | 6 | ||||
-rw-r--r-- | src/cmd/cgo/util.go | 20 |
5 files changed, 58 insertions, 56 deletions
diff --git a/src/cmd/cgo/ast.go b/src/cmd/cgo/ast.go index 2eae22aed..46e33686d 100644 --- a/src/cmd/cgo/ast.go +++ b/src/cmd/cgo/ast.go @@ -30,7 +30,7 @@ func parse(name string, flags uint) *ast.File { } os.Exit(2) } - fatal("parsing %s: %s", name, err) + fatalf("parsing %s: %s", name, err) } return ast1 } @@ -180,7 +180,7 @@ func (f *File) saveExport(x interface{}, context string) { return } for _, c := range n.Doc.List { - if string(c.Text[0:9]) != "//export " { + if !strings.HasPrefix(string(c.Text), "//export ") { continue } @@ -325,26 +325,28 @@ func (f *File) walk(x interface{}, context string, visit func(*File, interface{} f.walk(n.Results, "expr", visit) case *ast.BranchStmt: case *ast.BlockStmt: - f.walk(n.List, "stmt", visit) + f.walk(n.List, context, visit) case *ast.IfStmt: f.walk(n.Init, "stmt", visit) f.walk(&n.Cond, "expr", visit) f.walk(n.Body, "stmt", visit) f.walk(n.Else, "stmt", visit) case *ast.CaseClause: - f.walk(n.Values, "expr", visit) + if context == "typeswitch" { + context = "type" + } else { + context = "expr" + } + f.walk(n.List, context, visit) f.walk(n.Body, "stmt", visit) case *ast.SwitchStmt: f.walk(n.Init, "stmt", visit) f.walk(&n.Tag, "expr", visit) - f.walk(n.Body, "stmt", visit) - case *ast.TypeCaseClause: - f.walk(n.Types, "type", visit) - f.walk(n.Body, "stmt", visit) + f.walk(n.Body, "switch", visit) case *ast.TypeSwitchStmt: f.walk(n.Init, "stmt", visit) f.walk(n.Assign, "stmt", visit) - f.walk(n.Body, "stmt", visit) + f.walk(n.Body, "typeswitch", visit) case *ast.CommClause: f.walk(n.Comm, "stmt", visit) f.walk(n.Body, "stmt", visit) diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index f7ecc9e14..ae5ca2c7d 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -79,7 +79,7 @@ NextLine: l = strings.TrimSpace(l[4:]) fields := strings.Split(l, ":", 2) if len(fields) != 2 { - fatal("%s: bad #cgo line: %s", srcfile, line) + fatalf("%s: bad #cgo line: %s", srcfile, line) } var k string @@ -97,17 +97,17 @@ NextLine: continue NextLine } default: - fatal("%s: bad #cgo option: %s", srcfile, fields[0]) + fatalf("%s: bad #cgo option: %s", srcfile, fields[0]) } if k != "CFLAGS" && k != "LDFLAGS" { - fatal("%s: unsupported #cgo option %s", srcfile, k) + fatalf("%s: unsupported #cgo option %s", srcfile, k) } v := strings.TrimSpace(fields[1]) args, err := splitQuoted(v) if err != nil { - fatal("%s: bad #cgo option %s: %s", srcfile, k, err.String()) + fatalf("%s: bad #cgo option %s: %s", srcfile, k, err.String()) } if oldv, ok := p.CgoFlags[k]; ok { p.CgoFlags[k] = oldv + " " + v @@ -317,7 +317,7 @@ func (p *Package) guessKinds(f *File) []*Name { b.WriteString("}\n") stderr := p.gccErrors(b.Bytes()) if stderr == "" { - fatal("gcc produced no output\non input:\n%s", b.Bytes()) + fatalf("gcc produced no output\non input:\n%s", b.Bytes()) } names := make([]*Name, len(toSniff)) @@ -383,7 +383,7 @@ func (p *Package) guessKinds(f *File) []*Name { error(token.NoPos, "could not determine kind of name for C.%s", n.Go) } if nerrors > 0 { - fatal("unresolved names") + fatalf("unresolved names") } return needType } @@ -422,7 +422,7 @@ func (p *Package) loadDWARF(f *File, names []*Name) { for { e, err := r.Next() if err != nil { - fatal("reading DWARF entry: %s", err) + fatalf("reading DWARF entry: %s", err) } if e == nil { break @@ -433,7 +433,7 @@ func (p *Package) loadDWARF(f *File, names []*Name) { for { e, err := r.Next() if err != nil { - fatal("reading DWARF entry: %s", err) + fatalf("reading DWARF entry: %s", err) } if e.Tag == 0 { break @@ -452,27 +452,27 @@ func (p *Package) loadDWARF(f *File, names []*Name) { name, _ := e.Val(dwarf.AttrName).(string) typOff, _ := e.Val(dwarf.AttrType).(dwarf.Offset) if name == "" || typOff == 0 { - fatal("malformed DWARF TagVariable entry") + fatalf("malformed DWARF TagVariable entry") } if !strings.HasPrefix(name, "__cgo__") { break } typ, err := d.Type(typOff) if err != nil { - fatal("loading DWARF type: %s", err) + fatalf("loading DWARF type: %s", err) } t, ok := typ.(*dwarf.PtrType) if !ok || t == nil { - fatal("internal error: %s has non-pointer type", name) + fatalf("internal error: %s has non-pointer type", name) } i, err := strconv.Atoi(name[7:]) if err != nil { - fatal("malformed __cgo__ name: %s", name) + fatalf("malformed __cgo__ name: %s", name) } if enums[i] != 0 { t, err := d.Type(enums[i]) if err != nil { - fatal("loading DWARF type: %s", err) + fatalf("loading DWARF type: %s", err) } types[i] = t } else { @@ -632,14 +632,14 @@ func (p *Package) gccDebug(stdin []byte) *dwarf.Data { if f, err = elf.Open(gccTmp); err != nil { if f, err = macho.Open(gccTmp); err != nil { if f, err = pe.Open(gccTmp); err != nil { - fatal("cannot parse gcc output %s as ELF or Mach-O or PE object", gccTmp) + fatalf("cannot parse gcc output %s as ELF or Mach-O or PE object", gccTmp) } } } d, err := f.DWARF() if err != nil { - fatal("cannot load DWARF debug information from %s: %s", gccTmp, err) + fatalf("cannot load DWARF debug information from %s: %s", gccTmp, err) } return d } @@ -807,7 +807,7 @@ func (tr *TypeRepr) Set(repr string, fargs ...interface{}) { func (c *typeConv) Type(dtype dwarf.Type) *Type { if t, ok := c.m[dtype]; ok { if t.Go == nil { - fatal("type conversion loop at %s", dtype) + fatalf("type conversion loop at %s", dtype) } return t } @@ -830,11 +830,11 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type { switch dt := dtype.(type) { default: - fatal("unexpected type: %s", dtype) + fatalf("unexpected type: %s", dtype) case *dwarf.AddrType: if t.Size != c.ptrSize { - fatal("unexpected: %d-byte address type - %s", t.Size, dtype) + fatalf("unexpected: %d-byte address type - %s", t.Size, dtype) } t.Go = c.uintptr t.Align = t.Size @@ -860,7 +860,7 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type { case *dwarf.CharType: if t.Size != 1 { - fatal("unexpected: %d-byte char type - %s", t.Size, dtype) + fatalf("unexpected: %d-byte char type - %s", t.Size, dtype) } t.Go = c.int8 t.Align = 1 @@ -880,7 +880,7 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type { } switch t.Size + int64(signed) { default: - fatal("unexpected: %d-byte enum type - %s", t.Size, dtype) + fatalf("unexpected: %d-byte enum type - %s", t.Size, dtype) case 1: t.Go = c.uint8 case 2: @@ -902,7 +902,7 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type { case *dwarf.FloatType: switch t.Size { default: - fatal("unexpected: %d-byte float type - %s", t.Size, dtype) + fatalf("unexpected: %d-byte float type - %s", t.Size, dtype) case 4: t.Go = c.float32 case 8: @@ -915,7 +915,7 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type { case *dwarf.ComplexType: switch t.Size { default: - fatal("unexpected: %d-byte complex type - %s", t.Size, dtype) + fatalf("unexpected: %d-byte complex type - %s", t.Size, dtype) case 8: t.Go = c.complex64 case 16: @@ -933,11 +933,11 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type { case *dwarf.IntType: if dt.BitSize > 0 { - fatal("unexpected: %d-bit int type - %s", dt.BitSize, dtype) + fatalf("unexpected: %d-bit int type - %s", dt.BitSize, dtype) } switch t.Size { default: - fatal("unexpected: %d-byte int type - %s", t.Size, dtype) + fatalf("unexpected: %d-byte int type - %s", t.Size, dtype) case 1: t.Go = c.int8 case 2: @@ -1022,18 +1022,18 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type { case *dwarf.UcharType: if t.Size != 1 { - fatal("unexpected: %d-byte uchar type - %s", t.Size, dtype) + fatalf("unexpected: %d-byte uchar type - %s", t.Size, dtype) } t.Go = c.uint8 t.Align = 1 case *dwarf.UintType: if dt.BitSize > 0 { - fatal("unexpected: %d-bit uint type - %s", dt.BitSize, dtype) + fatalf("unexpected: %d-bit uint type - %s", dt.BitSize, dtype) } switch t.Size { default: - fatal("unexpected: %d-byte uint type - %s", t.Size, dtype) + fatalf("unexpected: %d-byte uint type - %s", t.Size, dtype) case 1: t.Go = c.uint8 case 2: @@ -1067,7 +1067,7 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type { } if t.C.Empty() { - fatal("internal error: did not create C name for %s", dtype) + fatalf("internal error: did not create C name for %s", dtype) } return t @@ -1156,7 +1156,7 @@ func (c *typeConv) Opaque(n int64) ast.Expr { func (c *typeConv) intExpr(n int64) ast.Expr { return &ast.BasicLit{ Kind: token.INT, - Value: []byte(strconv.Itoa64(n)), + Value: strconv.Itoa64(n), } } @@ -1229,7 +1229,7 @@ func (c *typeConv) Struct(dt *dwarf.StructType) (expr *ast.StructType, csyntax s off = dt.ByteSize } if off != dt.ByteSize { - fatal("struct size calculation error") + fatalf("struct size calculation error") } buf.WriteString("}") csyntax = buf.String() diff --git a/src/cmd/cgo/main.go b/src/cmd/cgo/main.go index 2dc662de5..00ffc4506 100644 --- a/src/cmd/cgo/main.go +++ b/src/cmd/cgo/main.go @@ -177,11 +177,11 @@ func main() { arch := os.Getenv("GOARCH") if arch == "" { - fatal("$GOARCH is not set") + fatalf("$GOARCH is not set") } ptrSize := ptrSizeMap[arch] if ptrSize == 0 { - fatal("unknown $GOARCH %q", arch) + fatalf("unknown $GOARCH %q", arch) } // Clear locale variables so gcc emits English errors [sic]. @@ -203,9 +203,9 @@ func main() { // Use the beginning of the md5 of the input to disambiguate. h := md5.New() for _, input := range goFiles { - f, err := os.Open(input, os.O_RDONLY, 0) + f, err := os.Open(input) if err != nil { - fatal("%s", err) + fatalf("%s", err) } io.Copy(h, f) f.Close() diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go index 4a5fa6a73..abf8c8bc2 100644 --- a/src/cmd/cgo/out.go +++ b/src/cmd/cgo/out.go @@ -105,7 +105,7 @@ func dynimport(obj string) (syms, imports []string) { if f, err1 = elf.Open(obj); err1 != nil { if f, err2 = pe.Open(obj); err2 != nil { if f, err3 = macho.Open(obj); err3 != nil { - fatal("cannot parse %s as ELF (%v) or PE (%v) or Mach-O (%v)", obj, err1, err2, err3) + fatalf("cannot parse %s as ELF (%v) or PE (%v) or Mach-O (%v)", obj, err1, err2, err3) } isMacho = true } @@ -114,7 +114,7 @@ func dynimport(obj string) (syms, imports []string) { var err os.Error syms, err = f.ImportedSymbols() if err != nil { - fatal("cannot load dynamic symbols: %v", err) + fatalf("cannot load dynamic symbols: %v", err) } if isMacho { // remove leading _ that OS X insists on @@ -127,7 +127,7 @@ func dynimport(obj string) (syms, imports []string) { imports, err = f.ImportedLibraries() if err != nil { - fatal("cannot load dynamic imports: %v", err) + fatalf("cannot load dynamic imports: %v", err) } return diff --git a/src/cmd/cgo/util.go b/src/cmd/cgo/util.go index 59529a6d2..1ca24103e 100644 --- a/src/cmd/cgo/util.go +++ b/src/cmd/cgo/util.go @@ -18,23 +18,23 @@ import ( func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) { cmd, err := exec.LookPath(argv[0]) if err != nil { - fatal("exec %s: %s", argv[0], err) + fatalf("exec %s: %s", argv[0], err) } r0, w0, err := os.Pipe() if err != nil { - fatal("%s", err) + fatalf("%s", err) } r1, w1, err := os.Pipe() if err != nil { - fatal("%s", err) + fatalf("%s", err) } r2, w2, err := os.Pipe() if err != nil { - fatal("%s", err) + fatalf("%s", err) } - p, err := os.StartProcess(cmd, argv, os.Environ(), "", []*os.File{r0, w1, w2}) + p, err := os.StartProcess(cmd, argv, &os.ProcAttr{Files: []*os.File{r0, w1, w2}}) if err != nil { - fatal("%s", err) + fatalf("%s", err) } defer p.Release() r0.Close() @@ -58,14 +58,14 @@ func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) { w, err := p.Wait(0) if err != nil { - fatal("%s", err) + fatalf("%s", err) } ok = w.Exited() && w.ExitStatus() == 0 return } // Die with an error message. -func fatal(msg string, args ...interface{}) { +func fatalf(msg string, args ...interface{}) { fmt.Fprintf(os.Stderr, msg+"\n", args...) os.Exit(2) } @@ -95,9 +95,9 @@ func isName(s string) bool { } func creat(name string) *os.File { - f, err := os.Open(name, os.O_WRONLY|os.O_CREAT|os.O_TRUNC, 0666) + f, err := os.Create(name) if err != nil { - fatal("%s", err) + fatalf("%s", err) } return f } |