go.tools/go.types: cleanups
- if a named type was imported before, read it again and throw it away in favor of the existing type (the old code did the same, but more circuitously) - better tag name for int64 values R=adonovan CC=golang-codereviews https://golang.org/cl/47650044
This commit is contained in:
parent
ff72a95f05
commit
a9b6519df8
|
|
@ -26,7 +26,7 @@ const (
|
|||
version = "v0"
|
||||
)
|
||||
|
||||
// Object and type tags. Must be < 0.
|
||||
// Tags. Must be < 0.
|
||||
const (
|
||||
// Packages
|
||||
packageTag = -(iota + 1)
|
||||
|
|
@ -50,7 +50,7 @@ const (
|
|||
namedTag
|
||||
|
||||
// Values
|
||||
intTag
|
||||
int64Tag
|
||||
floatTag
|
||||
fractionTag
|
||||
complexTag
|
||||
|
|
@ -181,7 +181,7 @@ func (p *exporter) value(x exact.Value) {
|
|||
p.string(exact.StringVal(x))
|
||||
case exact.Int:
|
||||
if i, ok := exact.Int64Val(x); ok {
|
||||
p.int(intTag)
|
||||
p.int(int64Tag)
|
||||
p.int64(i)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ func (p *importer) value() exact.Value {
|
|||
return exact.MakeBool(true)
|
||||
case stringTag:
|
||||
return exact.MakeString(p.string())
|
||||
case intTag:
|
||||
case int64Tag:
|
||||
return exact.MakeInt64(p.int64())
|
||||
case floatTag:
|
||||
return p.float()
|
||||
|
|
@ -282,30 +282,31 @@ func (p *importer) typ() types.Type {
|
|||
return t
|
||||
|
||||
case namedTag:
|
||||
// import type object
|
||||
// read type object
|
||||
name := p.string()
|
||||
pkg := p.pkg()
|
||||
scope := pkg.Scope()
|
||||
obj := scope.Lookup(name)
|
||||
|
||||
// if the object doesn't exist yet, create and insert it
|
||||
if obj == nil {
|
||||
new := types.NewTypeName(token.NoPos, pkg, name, nil)
|
||||
types.NewNamed(new, nil, nil)
|
||||
scope.Insert(new)
|
||||
obj = new
|
||||
obj = types.NewTypeName(token.NoPos, pkg, name, nil)
|
||||
scope.Insert(obj)
|
||||
}
|
||||
|
||||
// associate new named type with obj if it doesn't exist yet
|
||||
t0 := types.NewNamed(obj.(*types.TypeName), nil, nil)
|
||||
|
||||
// but record the existing type, if any
|
||||
t := obj.Type().(*types.Named)
|
||||
p.record(t)
|
||||
|
||||
// import underlying type
|
||||
u := p.typ()
|
||||
if t.Underlying() == nil {
|
||||
t.SetUnderlying(u)
|
||||
}
|
||||
// read underlying type
|
||||
t0.SetUnderlying(p.typ())
|
||||
|
||||
// read associated methods
|
||||
n := p.int()
|
||||
for i := 0; i < n; i++ {
|
||||
t.AddMethod(types.NewFunc(token.NoPos, pkg, p.string(), p.typ().(*types.Signature)))
|
||||
for i, n := 0, p.int(); i < n; i++ {
|
||||
t0.AddMethod(types.NewFunc(token.NoPos, pkg, p.string(), p.typ().(*types.Signature)))
|
||||
}
|
||||
|
||||
return t
|
||||
|
|
|
|||
Loading…
Reference in New Issue