]> Cypherpunks repositories - gostls13.git/commitdiff
go/internal/gccgoimporter: adjust to std repo libraries (fix build)
authorRobert Griesemer <gri@golang.org>
Tue, 16 Jun 2015 23:47:45 +0000 (16:47 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 17 Jun 2015 23:03:57 +0000 (23:03 +0000)
Change-Id: Ia9cbe3bfaa3e66c93d568d8beeed624b113d51a2
Reviewed-on: https://go-review.googlesource.com/11152
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/go/build/deps_test.go
src/go/internal/gccgoimporter/gccgoinstallation.go
src/go/internal/gccgoimporter/gccgoinstallation_test.go
src/go/internal/gccgoimporter/importer.go
src/go/internal/gccgoimporter/importer_test.go
src/go/internal/gccgoimporter/parser.go
src/go/internal/gccgoimporter/parser_test.go

index 187e9d1bb536efb2679372423a6756e72e90e61f..de29b56f6dec3560acb2812171075ed7ee19fe13 100644 (file)
@@ -126,7 +126,7 @@ var pkgDeps = map[string][]string{
        // Operating system access.
        "syscall":       {"L0", "unicode/utf16"},
        "time":          {"L0", "syscall", "internal/syscall/windows/registry"},
-       "os":            {"L1", "os", "syscall", "time", "internal/syscall/windows"},
+       "os":            {"L1", "os", "syscall", "time", "internal/syscall/windows", "C"},
        "path/filepath": {"L2", "os", "syscall"},
        "io/ioutil":     {"L2", "os", "path/filepath", "time"},
        "os/exec":       {"L2", "os", "path/filepath", "syscall"},
@@ -343,8 +343,9 @@ var pkgDeps = map[string][]string{
        "debug/plan9obj":                    {"encoding/binary", "errors", "fmt", "io", "os"},
        "go/constant":                       {"fmt", "go/token", "math/big", "strconv"},
        "go/format":                         {"bytes", "fmt", "go/ast", "go/parser", "go/printer", "go/token", "internal/format", "io"},
-       "go/importer":                       {"go/internal/gcimporter", "go/types", "io", "runtime"},
+       "go/importer":                       {"go/internal/gcimporter", "go/internal/gccgoimporter", "go/types", "io", "runtime"},
        "go/internal/gcimporter":            {"bufio", "errors", "fmt", "go/build", "go/constant", "go/token", "go/types", "io", "os", "path/filepath", "strconv", "strings", "text/scanner"},
+       "go/internal/gccgoimporter":         {"bufio", "bytes", "debug/elf", "errors", "fmt", "go/constant", "go/token", "go/types", "io", "os", "os/exec", "path/filepath", "strconv", "strings", "text/scanner"},
        "go/types":                          {"bytes", "container/heap", "fmt", "go/ast", "go/constant", "go/parser", "go/token", "io", "math", "path", "sort", "strconv", "strings", "sync", "unicode"},
        "image/internal/imageutil":          {"image"},
        "internal/format":                   {"bytes", "go/ast", "go/parser", "go/printer", "go/token", "strings"},
index 1c56cf5a5bdec9d2ffcb5853d3580bc7a0bf199f..622dfc8b69642d30ffc73af80223ef19715a7860 100644 (file)
@@ -6,12 +6,11 @@ package gccgoimporter
 
 import (
        "bufio"
+       "go/types"
        "os"
        "os/exec"
        "path/filepath"
        "strings"
-
-       "golang.org/x/tools/go/types"
 )
 
 // Information about a specific installation of gccgo.
@@ -90,6 +89,6 @@ func (inst *GccgoInstallation) SearchPaths() (paths []string) {
 
 // Return an importer that searches incpaths followed by the gcc installation's
 // built-in search paths and the current directory.
-func (inst *GccgoInstallation) GetImporter(incpaths []string, initmap map[*types.Package]InitData) types.Importer {
+func (inst *GccgoInstallation) GetImporter(incpaths []string, initmap map[*types.Package]InitData) Importer {
        return GetImporter(append(append(incpaths, inst.SearchPaths()...), "."), initmap)
 }
index 9ab928dce343d9986a2fc9722979c855bea5d265..d9adcecab7c8c9f7d6db686781113f12e8cb0f30 100644 (file)
@@ -2,13 +2,16 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// Exclude plan9 for now due to test failure with TestGoxImporter.
+// TODO(gri) eliminate this build tag
+// +build !plan9
+
 package gccgoimporter
 
 import (
+       "go/types"
        "runtime"
        "testing"
-
-       "golang.org/x/tools/go/types"
 )
 
 var importablePackages = [...]string{
index 59576cad29d0bcffaebfaf05ccea580842e83158..feb9849eefe90c747973059165ba0ad53174db66 100644 (file)
@@ -3,21 +3,18 @@
 // license that can be found in the LICENSE file.
 
 // Package gccgoimporter implements Import for gccgo-generated object files.
-package gccgoimporter // import "golang.org/x/tools/go/gccgoimporter"
+package gccgoimporter // import "go/internal/gccgoimporter"
 
 import (
        "bytes"
        "debug/elf"
        "fmt"
+       "go/types"
        "io"
-       "io/ioutil"
        "os"
        "os/exec"
        "path/filepath"
        "strings"
-
-       "golang.org/x/tools/go/importer"
-       "golang.org/x/tools/go/types"
 )
 
 // A PackageInit describes an imported package that needs initialization.
@@ -132,7 +129,16 @@ func openExportFile(fpath string) (reader io.ReadSeeker, closer io.Closer, err e
        return
 }
 
-func GetImporter(searchpaths []string, initmap map[*types.Package]InitData) types.Importer {
+// An Importer resolves import paths to Packages. The imports map records
+// packages already known, indexed by package path.
+// An importer must determine the canonical package path and check imports
+// to see if it is already present in the map. If so, the Importer can return
+// the map entry. Otherwise, the importer must load the package data for the
+// given path into a new *Package, record it in imports map, and return the
+// package.
+type Importer func(imports map[string]*types.Package, path string) (*types.Package, error)
+
+func GetImporter(searchpaths []string, initmap map[*types.Package]InitData) Importer {
        return func(imports map[string]*types.Package, pkgpath string) (pkg *types.Package, err error) {
                if pkgpath == "unsafe" {
                        return types.Unsafe, nil
@@ -170,25 +176,26 @@ func GetImporter(searchpaths []string, initmap map[*types.Package]InitData) type
                                initmap[pkg] = p.initdata
                        }
 
-               case goimporterMagic:
-                       var data []byte
-                       data, err = ioutil.ReadAll(reader)
-                       if err != nil {
-                               return
-                       }
-                       var n int
-                       n, pkg, err = importer.ImportData(imports, data)
-                       if err != nil {
-                               return
-                       }
-
-                       if initmap != nil {
-                               suffixreader := bytes.NewReader(data[n:])
-                               var p parser
-                               p.init(fpath, suffixreader, nil)
-                               p.parseInitData()
-                               initmap[pkg] = p.initdata
-                       }
+               // Excluded for now: Standard gccgo doesn't support this import format currently.
+               // case goimporterMagic:
+               //      var data []byte
+               //      data, err = ioutil.ReadAll(reader)
+               //      if err != nil {
+               //              return
+               //      }
+               //      var n int
+               //      n, pkg, err = importer.ImportData(imports, data)
+               //      if err != nil {
+               //              return
+               //      }
+
+               //      if initmap != nil {
+               //              suffixreader := bytes.NewReader(data[n:])
+               //              var p parser
+               //              p.init(fpath, suffixreader, nil)
+               //              p.parseInitData()
+               //              initmap[pkg] = p.initdata
+               //      }
 
                default:
                        err = fmt.Errorf("unrecognized magic string: %q", string(magic[:]))
index c7adb459b8cf83950ca356d03412003e8de38a3d..ce0dfb99efa670b373e186cb209de440aba1eefa 100644 (file)
@@ -2,17 +2,21 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// Exclude plan9 for now due to test failure with TestGoxImporter.
+// TODO(gri) eliminate this build tag
+// +build !plan9
+
 package gccgoimporter
 
 import (
+       "go/types"
+       "internal/testenv"
        "io/ioutil"
        "os"
        "os/exec"
        "path/filepath"
        "runtime"
        "testing"
-
-       "golang.org/x/tools/go/types"
 )
 
 type importerTest struct {
@@ -20,7 +24,7 @@ type importerTest struct {
        wantinits                    []string
 }
 
-func runImporterTest(t *testing.T, imp types.Importer, initmap map[*types.Package]InitData, test *importerTest) {
+func runImporterTest(t *testing.T, imp Importer, initmap map[*types.Package]InitData, test *importerTest) {
        pkg, err := imp(make(map[string]*types.Package), test.pkgpath)
        if err != nil {
                t.Error(err)
@@ -100,6 +104,8 @@ var importerTests = [...]importerTest{
 }
 
 func TestGoxImporter(t *testing.T) {
+       testenv.MustHaveGoBuild(t)
+
        initmap := make(map[*types.Package]InitData)
        imp := GetImporter([]string{"testdata"}, initmap)
 
@@ -109,6 +115,8 @@ func TestGoxImporter(t *testing.T) {
 }
 
 func TestObjImporter(t *testing.T) {
+       testenv.MustHaveGoBuild(t)
+
        // This test relies on gccgo being around, which it most likely will be if we
        // were compiled with gccgo.
        if runtime.Compiler != "gccgo" {
index 5bd1858fb357f0d3513b93d84dadb0d2c6b13c11..e985de5a6788e2052ed4755aba33d131773dd2d1 100644 (file)
@@ -8,14 +8,13 @@ import (
        "bytes"
        "errors"
        "fmt"
+       "go/constant"
        "go/token"
+       "go/types"
        "io"
        "strconv"
        "strings"
        "text/scanner"
-
-       "golang.org/x/tools/go/exact"
-       "golang.org/x/tools/go/types"
 )
 
 type parser struct {
@@ -248,11 +247,11 @@ func (p *parser) parseVar(pkg *types.Package) *types.Var {
 
 // ConstValue     = string | "false" | "true" | ["-"] (int ["'"] | FloatOrComplex) .
 // FloatOrComplex = float ["i" | ("+"|"-") float "i"] .
-func (p *parser) parseConstValue() (val exact.Value, typ types.Type) {
+func (p *parser) parseConstValue() (val constant.Value, typ types.Type) {
        switch p.tok {
        case scanner.String:
                str := p.parseString()
-               val = exact.MakeString(str)
+               val = constant.MakeString(str)
                typ = types.Typ[types.UntypedString]
                return
 
@@ -268,7 +267,7 @@ func (p *parser) parseConstValue() (val exact.Value, typ types.Type) {
                }
 
                p.next()
-               val = exact.MakeBool(b)
+               val = constant.MakeBool(b)
                typ = types.Typ[types.UntypedBool]
                return
        }
@@ -281,7 +280,7 @@ func (p *parser) parseConstValue() (val exact.Value, typ types.Type) {
 
        switch p.tok {
        case scanner.Int:
-               val = exact.MakeFromLiteral(sign+p.lit, token.INT)
+               val = constant.MakeFromLiteral(sign+p.lit, token.INT, 0)
                if val == nil {
                        p.error("could not parse integer literal")
                }
@@ -314,7 +313,7 @@ func (p *parser) parseConstValue() (val exact.Value, typ types.Type) {
                        re = "0"
 
                default:
-                       val = exact.MakeFromLiteral(re, token.FLOAT)
+                       val = constant.MakeFromLiteral(re, token.FLOAT, 0)
                        if val == nil {
                                p.error("could not parse float literal")
                        }
@@ -323,15 +322,15 @@ func (p *parser) parseConstValue() (val exact.Value, typ types.Type) {
                }
 
                p.expectKeyword("i")
-               reval := exact.MakeFromLiteral(re, token.FLOAT)
+               reval := constant.MakeFromLiteral(re, token.FLOAT, 0)
                if reval == nil {
                        p.error("could not parse real component of complex literal")
                }
-               imval := exact.MakeFromLiteral(im+"i", token.IMAG)
+               imval := constant.MakeFromLiteral(im+"i", token.IMAG, 0)
                if imval == nil {
                        p.error("could not parse imag component of complex literal")
                }
-               val = exact.BinaryOp(reval, token.ADD, imval)
+               val = constant.BinaryOp(reval, token.ADD, imval)
                typ = types.Typ[types.UntypedComplex]
 
        default:
index 1f0f12a2f863301f5dbdbc7ec00ff5887aa807b3..b96486f20adce1cf3082ab7cc0fa3eaf24091b8f 100644 (file)
@@ -6,11 +6,10 @@ package gccgoimporter
 
 import (
        "bytes"
+       "go/types"
        "strings"
        "testing"
        "text/scanner"
-
-       "golang.org/x/tools/go/types"
 )
 
 var typeParserTests = []struct {