mirror of
https://github.com/golang/go
synced 2024-11-18 18:24:48 -07:00
cmd/compile: deduplicate importtype and (*importer).importtype
Change-Id: I7bfb0e5e71fc26448b0d5d3801cd6e50c8b48f5d Reviewed-on: https://go-review.googlesource.com/29078 Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
36b32911bd
commit
b11c79fd07
@ -388,10 +388,7 @@ func (p *importer) newtyp(etype EType) *Type {
|
|||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is like the function importtype but it delays the
|
// importtype declares that pt, an imported named type, has underlying type t.
|
||||||
// type identity check for types that have been seen already.
|
|
||||||
// importer.importtype and importtype and (export.go) need to
|
|
||||||
// remain in sync.
|
|
||||||
func (p *importer) importtype(pt, t *Type) {
|
func (p *importer) importtype(pt, t *Type) {
|
||||||
// override declaration in unsafe.go for Pointer.
|
// override declaration in unsafe.go for Pointer.
|
||||||
// there is no way in Go code to define unsafe.Pointer
|
// there is no way in Go code to define unsafe.Pointer
|
||||||
@ -409,10 +406,14 @@ func (p *importer) importtype(pt, t *Type) {
|
|||||||
declare(n, PEXTERN)
|
declare(n, PEXTERN)
|
||||||
checkwidth(pt)
|
checkwidth(pt)
|
||||||
} else {
|
} else {
|
||||||
// pt.Orig and t must be identical. Since t may not be
|
// pt.Orig and t must be identical.
|
||||||
// fully set up yet, collect the types and verify identity
|
if p.trackAllTypes {
|
||||||
// later.
|
// If we track all types, t may not be fully set up yet.
|
||||||
p.cmpList = append(p.cmpList, struct{ pt, t *Type }{pt, t})
|
// Collect the types and verify identity later.
|
||||||
|
p.cmpList = append(p.cmpList, struct{ pt, t *Type }{pt, t})
|
||||||
|
} else if !Eqtype(pt.Orig, t) {
|
||||||
|
Yyerror("inconsistent definition for type %v during import\n\t%L (in %q)\n\t%L (in %q)", pt.Sym, pt, pt.Sym.Importdef.Path, t, importpkg.Path)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if Debug['E'] != 0 {
|
if Debug['E'] != 0 {
|
||||||
@ -442,13 +443,7 @@ func (p *importer) typ() *Type {
|
|||||||
// read underlying type
|
// read underlying type
|
||||||
// parser.go:hidden_type
|
// parser.go:hidden_type
|
||||||
t0 := p.typ()
|
t0 := p.typ()
|
||||||
if p.trackAllTypes {
|
p.importtype(t, t0)
|
||||||
// If we track all types, we cannot check equality of previously
|
|
||||||
// imported types until later. Use customized version of importtype.
|
|
||||||
p.importtype(t, t0)
|
|
||||||
} else {
|
|
||||||
importtype(t, t0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// interfaces don't have associated methods
|
// interfaces don't have associated methods
|
||||||
if t0.IsInterface() {
|
if t0.IsInterface() {
|
||||||
|
@ -344,32 +344,6 @@ func importvar(s *Sym, t *Type) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// importtype and importer.importtype (bimport.go) need to remain in sync.
|
|
||||||
func importtype(pt *Type, t *Type) {
|
|
||||||
// override declaration in unsafe.go for Pointer.
|
|
||||||
// there is no way in Go code to define unsafe.Pointer
|
|
||||||
// so we have to supply it.
|
|
||||||
if incannedimport != 0 && importpkg.Name == "unsafe" && pt.Nod.Sym.Name == "Pointer" {
|
|
||||||
t = Types[TUNSAFEPTR]
|
|
||||||
}
|
|
||||||
|
|
||||||
if pt.Etype == TFORW {
|
|
||||||
n := pt.Nod
|
|
||||||
copytype(pt.Nod, t)
|
|
||||||
pt.Nod = n // unzero nod
|
|
||||||
pt.Sym.Importdef = importpkg
|
|
||||||
pt.Sym.Lastlineno = lineno
|
|
||||||
declare(n, PEXTERN)
|
|
||||||
checkwidth(pt)
|
|
||||||
} else if !Eqtype(pt.Orig, t) {
|
|
||||||
Yyerror("inconsistent definition for type %v during import\n\t%L (in %q)\n\t%L (in %q)", pt.Sym, pt, pt.Sym.Importdef.Path, t, importpkg.Path)
|
|
||||||
}
|
|
||||||
|
|
||||||
if Debug['E'] != 0 {
|
|
||||||
fmt.Printf("import type %v %L\n", pt, t)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func dumpasmhdr() {
|
func dumpasmhdr() {
|
||||||
b, err := bio.Create(asmhdr)
|
b, err := bio.Create(asmhdr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user