Don't export position info for now. Enabled/disabled with a flag.
The importer recognizes the chosen format automatically.

Change-Id: I055818eb9dba50cc97f40eb92220258a1ddbfbec
Reviewed-on: https://go-review.googlesource.com/22427
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Robert Griesemer 2016-04-25 13:02:21 -07:00
parent 477d3b98e5
commit 487c81ee33
2 changed files with 38 additions and 6 deletions

View File

@ -37,6 +37,14 @@ import (
// (suspected) format errors, and whenever a change is made to the format.
const debugFormat = false // default: false
// If posInfoFormat is set, position information (file, lineno) is written
// for each exported object, including methods and struct fields. Currently
// disabled because it may lead to different object files depending on which
// directory they are built under, which causes tests checking for hermetic
// builds to fail (e.g. TestCgoConsistentResults for cmd/go).
// TODO(gri) determine what to do here.
const posInfoFormat = false
// If trace is set, debugging output is printed to std out.
const trace = false // default: false
@ -77,6 +85,9 @@ func BExportData(fset *token.FileSet, pkg *types.Package) []byte {
}
p.rawByte(format)
// posInfo exported or not?
p.bool(posInfoFormat)
// --- generic export data ---
if trace {
@ -200,6 +211,10 @@ func (p *exporter) obj(obj types.Object) {
}
func (p *exporter) pos(obj types.Object) {
if !posInfoFormat {
return
}
var file string
var line int
if p.fset != nil {
@ -563,6 +578,20 @@ func valueToRat(x constant.Value) *big.Rat {
return new(big.Rat).SetInt(new(big.Int).SetBytes(bytes))
}
func (p *exporter) bool(b bool) bool {
if trace {
p.tracef("[")
defer p.tracef("= %v] ", b)
}
x := 0
if b {
x = 1
}
p.int(x)
return b
}
// ----------------------------------------------------------------------------
// Low-level encoders

View File

@ -6,10 +6,6 @@
// This file is a copy of $GOROOT/src/go/internal/gcimporter/bimport.go, tagged for go1.5.
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gcimporter
import (
@ -35,8 +31,9 @@ type importer struct {
typList []types.Type // in order of appearance
// position encoding
prevFile string
prevLine int
posInfoFormat bool
prevFile string
prevLine int
// debugging support
debugFormat bool
@ -65,6 +62,8 @@ func BImportData(imports map[string]*types.Package, data []byte, path string) (i
return p.read, nil, fmt.Errorf("invalid encoding format in export data: got %q; want 'c' or 'd'", format)
}
p.posInfoFormat = p.int() != 0
// --- generic export data ---
if v := p.string(); v != "v0" {
@ -202,6 +201,10 @@ func (p *importer) obj(tag int) {
}
func (p *importer) pos() {
if !p.posInfoFormat {
return
}
file := p.prevFile
line := p.prevLine