Commit 289e2829 authored by Robert Griesemer's avatar Robert Griesemer

go/internal/gccgoimporter: adjust to std repo libraries (fix build)

Change-Id: Ia9cbe3bfaa3e66c93d568d8beeed624b113d51a2
Reviewed-on: https://go-review.googlesource.com/11152Reviewed-by: default avatarAlan Donovan <adonovan@google.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent f6ae5f96
...@@ -126,7 +126,7 @@ var pkgDeps = map[string][]string{ ...@@ -126,7 +126,7 @@ var pkgDeps = map[string][]string{
// Operating system access. // Operating system access.
"syscall": {"L0", "unicode/utf16"}, "syscall": {"L0", "unicode/utf16"},
"time": {"L0", "syscall", "internal/syscall/windows/registry"}, "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"}, "path/filepath": {"L2", "os", "syscall"},
"io/ioutil": {"L2", "os", "path/filepath", "time"}, "io/ioutil": {"L2", "os", "path/filepath", "time"},
"os/exec": {"L2", "os", "path/filepath", "syscall"}, "os/exec": {"L2", "os", "path/filepath", "syscall"},
...@@ -343,8 +343,9 @@ var pkgDeps = map[string][]string{ ...@@ -343,8 +343,9 @@ var pkgDeps = map[string][]string{
"debug/plan9obj": {"encoding/binary", "errors", "fmt", "io", "os"}, "debug/plan9obj": {"encoding/binary", "errors", "fmt", "io", "os"},
"go/constant": {"fmt", "go/token", "math/big", "strconv"}, "go/constant": {"fmt", "go/token", "math/big", "strconv"},
"go/format": {"bytes", "fmt", "go/ast", "go/parser", "go/printer", "go/token", "internal/format", "io"}, "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/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"}, "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"}, "image/internal/imageutil": {"image"},
"internal/format": {"bytes", "go/ast", "go/parser", "go/printer", "go/token", "strings"}, "internal/format": {"bytes", "go/ast", "go/parser", "go/printer", "go/token", "strings"},
......
...@@ -6,12 +6,11 @@ package gccgoimporter ...@@ -6,12 +6,11 @@ package gccgoimporter
import ( import (
"bufio" "bufio"
"go/types"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strings" "strings"
"golang.org/x/tools/go/types"
) )
// Information about a specific installation of gccgo. // Information about a specific installation of gccgo.
...@@ -90,6 +89,6 @@ func (inst *GccgoInstallation) SearchPaths() (paths []string) { ...@@ -90,6 +89,6 @@ func (inst *GccgoInstallation) SearchPaths() (paths []string) {
// Return an importer that searches incpaths followed by the gcc installation's // Return an importer that searches incpaths followed by the gcc installation's
// built-in search paths and the current directory. // 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) return GetImporter(append(append(incpaths, inst.SearchPaths()...), "."), initmap)
} }
...@@ -2,13 +2,16 @@ ...@@ -2,13 +2,16 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // 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 package gccgoimporter
import ( import (
"go/types"
"runtime" "runtime"
"testing" "testing"
"golang.org/x/tools/go/types"
) )
var importablePackages = [...]string{ var importablePackages = [...]string{
......
...@@ -3,21 +3,18 @@ ...@@ -3,21 +3,18 @@
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// Package gccgoimporter implements Import for gccgo-generated object files. // 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 ( import (
"bytes" "bytes"
"debug/elf" "debug/elf"
"fmt" "fmt"
"go/types"
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strings" "strings"
"golang.org/x/tools/go/importer"
"golang.org/x/tools/go/types"
) )
// A PackageInit describes an imported package that needs initialization. // 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 ...@@ -132,7 +129,16 @@ func openExportFile(fpath string) (reader io.ReadSeeker, closer io.Closer, err e
return 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) { return func(imports map[string]*types.Package, pkgpath string) (pkg *types.Package, err error) {
if pkgpath == "unsafe" { if pkgpath == "unsafe" {
return types.Unsafe, nil return types.Unsafe, nil
...@@ -170,25 +176,26 @@ func GetImporter(searchpaths []string, initmap map[*types.Package]InitData) type ...@@ -170,25 +176,26 @@ func GetImporter(searchpaths []string, initmap map[*types.Package]InitData) type
initmap[pkg] = p.initdata initmap[pkg] = p.initdata
} }
case goimporterMagic: // Excluded for now: Standard gccgo doesn't support this import format currently.
var data []byte // case goimporterMagic:
data, err = ioutil.ReadAll(reader) // var data []byte
if err != nil { // data, err = ioutil.ReadAll(reader)
return // if err != nil {
} // return
var n int // }
n, pkg, err = importer.ImportData(imports, data) // var n int
if err != nil { // n, pkg, err = importer.ImportData(imports, data)
return // if err != nil {
} // return
// }
if initmap != nil {
suffixreader := bytes.NewReader(data[n:]) // if initmap != nil {
var p parser // suffixreader := bytes.NewReader(data[n:])
p.init(fpath, suffixreader, nil) // var p parser
p.parseInitData() // p.init(fpath, suffixreader, nil)
initmap[pkg] = p.initdata // p.parseInitData()
} // initmap[pkg] = p.initdata
// }
default: default:
err = fmt.Errorf("unrecognized magic string: %q", string(magic[:])) err = fmt.Errorf("unrecognized magic string: %q", string(magic[:]))
......
...@@ -2,17 +2,21 @@ ...@@ -2,17 +2,21 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // 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 package gccgoimporter
import ( import (
"go/types"
"internal/testenv"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime" "runtime"
"testing" "testing"
"golang.org/x/tools/go/types"
) )
type importerTest struct { type importerTest struct {
...@@ -20,7 +24,7 @@ type importerTest struct { ...@@ -20,7 +24,7 @@ type importerTest struct {
wantinits []string 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) pkg, err := imp(make(map[string]*types.Package), test.pkgpath)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
...@@ -100,6 +104,8 @@ var importerTests = [...]importerTest{ ...@@ -100,6 +104,8 @@ var importerTests = [...]importerTest{
} }
func TestGoxImporter(t *testing.T) { func TestGoxImporter(t *testing.T) {
testenv.MustHaveGoBuild(t)
initmap := make(map[*types.Package]InitData) initmap := make(map[*types.Package]InitData)
imp := GetImporter([]string{"testdata"}, initmap) imp := GetImporter([]string{"testdata"}, initmap)
...@@ -109,6 +115,8 @@ func TestGoxImporter(t *testing.T) { ...@@ -109,6 +115,8 @@ func TestGoxImporter(t *testing.T) {
} }
func TestObjImporter(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 // This test relies on gccgo being around, which it most likely will be if we
// were compiled with gccgo. // were compiled with gccgo.
if runtime.Compiler != "gccgo" { if runtime.Compiler != "gccgo" {
......
...@@ -8,14 +8,13 @@ import ( ...@@ -8,14 +8,13 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"go/constant"
"go/token" "go/token"
"go/types"
"io" "io"
"strconv" "strconv"
"strings" "strings"
"text/scanner" "text/scanner"
"golang.org/x/tools/go/exact"
"golang.org/x/tools/go/types"
) )
type parser struct { type parser struct {
...@@ -248,11 +247,11 @@ func (p *parser) parseVar(pkg *types.Package) *types.Var { ...@@ -248,11 +247,11 @@ func (p *parser) parseVar(pkg *types.Package) *types.Var {
// ConstValue = string | "false" | "true" | ["-"] (int ["'"] | FloatOrComplex) . // ConstValue = string | "false" | "true" | ["-"] (int ["'"] | FloatOrComplex) .
// FloatOrComplex = float ["i" | ("+"|"-") float "i"] . // 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 { switch p.tok {
case scanner.String: case scanner.String:
str := p.parseString() str := p.parseString()
val = exact.MakeString(str) val = constant.MakeString(str)
typ = types.Typ[types.UntypedString] typ = types.Typ[types.UntypedString]
return return
...@@ -268,7 +267,7 @@ func (p *parser) parseConstValue() (val exact.Value, typ types.Type) { ...@@ -268,7 +267,7 @@ func (p *parser) parseConstValue() (val exact.Value, typ types.Type) {
} }
p.next() p.next()
val = exact.MakeBool(b) val = constant.MakeBool(b)
typ = types.Typ[types.UntypedBool] typ = types.Typ[types.UntypedBool]
return return
} }
...@@ -281,7 +280,7 @@ func (p *parser) parseConstValue() (val exact.Value, typ types.Type) { ...@@ -281,7 +280,7 @@ func (p *parser) parseConstValue() (val exact.Value, typ types.Type) {
switch p.tok { switch p.tok {
case scanner.Int: case scanner.Int:
val = exact.MakeFromLiteral(sign+p.lit, token.INT) val = constant.MakeFromLiteral(sign+p.lit, token.INT, 0)
if val == nil { if val == nil {
p.error("could not parse integer literal") p.error("could not parse integer literal")
} }
...@@ -314,7 +313,7 @@ func (p *parser) parseConstValue() (val exact.Value, typ types.Type) { ...@@ -314,7 +313,7 @@ func (p *parser) parseConstValue() (val exact.Value, typ types.Type) {
re = "0" re = "0"
default: default:
val = exact.MakeFromLiteral(re, token.FLOAT) val = constant.MakeFromLiteral(re, token.FLOAT, 0)
if val == nil { if val == nil {
p.error("could not parse float literal") p.error("could not parse float literal")
} }
...@@ -323,15 +322,15 @@ func (p *parser) parseConstValue() (val exact.Value, typ types.Type) { ...@@ -323,15 +322,15 @@ func (p *parser) parseConstValue() (val exact.Value, typ types.Type) {
} }
p.expectKeyword("i") p.expectKeyword("i")
reval := exact.MakeFromLiteral(re, token.FLOAT) reval := constant.MakeFromLiteral(re, token.FLOAT, 0)
if reval == nil { if reval == nil {
p.error("could not parse real component of complex literal") 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 { if imval == nil {
p.error("could not parse imag component of complex literal") 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] typ = types.Typ[types.UntypedComplex]
default: default:
......
...@@ -6,11 +6,10 @@ package gccgoimporter ...@@ -6,11 +6,10 @@ package gccgoimporter
import ( import (
"bytes" "bytes"
"go/types"
"strings" "strings"
"testing" "testing"
"text/scanner" "text/scanner"
"golang.org/x/tools/go/types"
) )
var typeParserTests = []struct { var typeParserTests = []struct {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment