diff options
Diffstat (limited to 'libgo/go/cmd/cgo/main.go')
-rw-r--r-- | libgo/go/cmd/cgo/main.go | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/libgo/go/cmd/cgo/main.go b/libgo/go/cmd/cgo/main.go index ac102050dad..c9a44fdd166 100644 --- a/libgo/go/cmd/cgo/main.go +++ b/libgo/go/cmd/cgo/main.go @@ -17,7 +17,7 @@ import ( "go/ast" "go/printer" "go/token" - "io" + "io/ioutil" "os" "path/filepath" "reflect" @@ -88,7 +88,7 @@ type Name struct { Mangle string // name used in generated Go C string // name used in C Define string // #define expansion - Kind string // "const", "type", "var", "fpvar", "func", "not-type" + Kind string // "iconst", "uconst", "fconst", "sconst", "type", "var", "fpvar", "func", "not-type" Type *Type // the type of xxx FuncType *FuncType AddError bool @@ -100,6 +100,11 @@ func (n *Name) IsVar() bool { return n.Kind == "var" || n.Kind == "fpvar" } +// IsConst reports whether Kind is either "iconst", "uconst", "fconst" or "sconst" +func (n *Name) IsConst() bool { + return strings.HasSuffix(n.Kind, "const") +} + // A ExpFunc is an exported function, callable from C. // Such functions are identified in the Go input file // by doc comments containing the line //export ExpName @@ -274,30 +279,28 @@ func main() { // concern is other cgo wrappers for the same functions. // Use the beginning of the md5 of the input to disambiguate. h := md5.New() - for _, input := range goFiles { + fs := make([]*File, len(goFiles)) + for i, input := range goFiles { if *srcDir != "" { input = filepath.Join(*srcDir, input) } - f, err := os.Open(input) + + b, err := ioutil.ReadFile(input) if err != nil { fatalf("%s", err) } - io.Copy(h, f) - f.Close() - } - cPrefix = fmt.Sprintf("_%x", h.Sum(nil)[0:6]) - - fs := make([]*File, len(goFiles)) - for i, input := range goFiles { - if *srcDir != "" { - input = filepath.Join(*srcDir, input) + if _, err = h.Write(b); err != nil { + fatalf("%s", err) } + f := new(File) - f.ReadGo(input) + f.ParseGo(input, b) f.DiscardCgoDirectives() fs[i] = f } + cPrefix = fmt.Sprintf("_%x", h.Sum(nil)[0:6]) + if *objDir == "" { // make sure that _obj directory exists, so that we can write // all the output files there. |