1
0
mirror of https://github.com/golang/go synced 2024-11-22 20:04:47 -07:00

[dev.typeparams] cmd/compile: simplify import* functions

CL 280634 remove Sym.Importdef, so ipkg in importsym is not used
anymore. So we can remove it from importsym and all other import*
functions, which just call importsym internally.

Change-Id: I15b9d11c4445dbe40982f7ff2a33a2116705e790
Reviewed-on: https://go-review.googlesource.com/c/go/+/329573
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Cuong Manh Le 2021-06-20 21:33:54 +07:00
parent e57da8e53c
commit 844c076359
3 changed files with 20 additions and 20 deletions

View File

@ -15,22 +15,22 @@ import (
// importalias declares symbol s as an imported type alias with type t. // importalias declares symbol s as an imported type alias with type t.
// ipkg is the package being imported // ipkg is the package being imported
func importalias(ipkg *types.Pkg, pos src.XPos, s *types.Sym, t *types.Type) *ir.Name { func importalias(pos src.XPos, s *types.Sym, t *types.Type) *ir.Name {
return importobj(ipkg, pos, s, ir.OTYPE, ir.PEXTERN, t) return importobj(pos, s, ir.OTYPE, ir.PEXTERN, t)
} }
// importconst declares symbol s as an imported constant with type t and value val. // importconst declares symbol s as an imported constant with type t and value val.
// ipkg is the package being imported // ipkg is the package being imported
func importconst(ipkg *types.Pkg, pos src.XPos, s *types.Sym, t *types.Type, val constant.Value) *ir.Name { func importconst(pos src.XPos, s *types.Sym, t *types.Type, val constant.Value) *ir.Name {
n := importobj(ipkg, pos, s, ir.OLITERAL, ir.PEXTERN, t) n := importobj(pos, s, ir.OLITERAL, ir.PEXTERN, t)
n.SetVal(val) n.SetVal(val)
return n return n
} }
// importfunc declares symbol s as an imported function with type t. // importfunc declares symbol s as an imported function with type t.
// ipkg is the package being imported // ipkg is the package being imported
func importfunc(ipkg *types.Pkg, pos src.XPos, s *types.Sym, t *types.Type) *ir.Name { func importfunc(pos src.XPos, s *types.Sym, t *types.Type) *ir.Name {
n := importobj(ipkg, pos, s, ir.ONAME, ir.PFUNC, t) n := importobj(pos, s, ir.ONAME, ir.PFUNC, t)
n.Func = ir.NewFunc(pos) n.Func = ir.NewFunc(pos)
n.Func.Nname = n n.Func.Nname = n
return n return n
@ -38,8 +38,8 @@ func importfunc(ipkg *types.Pkg, pos src.XPos, s *types.Sym, t *types.Type) *ir.
// importobj declares symbol s as an imported object representable by op. // importobj declares symbol s as an imported object representable by op.
// ipkg is the package being imported // ipkg is the package being imported
func importobj(ipkg *types.Pkg, pos src.XPos, s *types.Sym, op ir.Op, ctxt ir.Class, t *types.Type) *ir.Name { func importobj(pos src.XPos, s *types.Sym, op ir.Op, ctxt ir.Class, t *types.Type) *ir.Name {
n := importsym(ipkg, pos, s, op, ctxt) n := importsym(pos, s, op, ctxt)
n.SetType(t) n.SetType(t)
if ctxt == ir.PFUNC { if ctxt == ir.PFUNC {
n.Sym().SetFunc(true) n.Sym().SetFunc(true)
@ -47,7 +47,7 @@ func importobj(ipkg *types.Pkg, pos src.XPos, s *types.Sym, op ir.Op, ctxt ir.Cl
return n return n
} }
func importsym(ipkg *types.Pkg, pos src.XPos, s *types.Sym, op ir.Op, ctxt ir.Class) *ir.Name { func importsym(pos src.XPos, s *types.Sym, op ir.Op, ctxt ir.Class) *ir.Name {
if n := s.PkgDef(); n != nil { if n := s.PkgDef(); n != nil {
base.Fatalf("importsym of symbol that already exists: %v", n) base.Fatalf("importsym of symbol that already exists: %v", n)
} }
@ -61,14 +61,14 @@ func importsym(ipkg *types.Pkg, pos src.XPos, s *types.Sym, op ir.Op, ctxt ir.Cl
// importtype returns the named type declared by symbol s. // importtype returns the named type declared by symbol s.
// If no such type has been declared yet, a forward declaration is returned. // If no such type has been declared yet, a forward declaration is returned.
// ipkg is the package being imported // ipkg is the package being imported
func importtype(ipkg *types.Pkg, pos src.XPos, s *types.Sym) *ir.Name { func importtype(pos src.XPos, s *types.Sym) *ir.Name {
n := importsym(ipkg, pos, s, ir.OTYPE, ir.PEXTERN) n := importsym(pos, s, ir.OTYPE, ir.PEXTERN)
n.SetType(types.NewNamed(n)) n.SetType(types.NewNamed(n))
return n return n
} }
// importvar declares symbol s as an imported variable with type t. // importvar declares symbol s as an imported variable with type t.
// ipkg is the package being imported // ipkg is the package being imported
func importvar(ipkg *types.Pkg, pos src.XPos, s *types.Sym, t *types.Type) *ir.Name { func importvar(pos src.XPos, s *types.Sym, t *types.Type) *ir.Name {
return importobj(ipkg, pos, s, ir.ONAME, ir.PEXTERN, t) return importobj(pos, s, ir.ONAME, ir.PEXTERN, t)
} }

View File

@ -294,13 +294,13 @@ func (r *importReader) doDecl(sym *types.Sym) *ir.Name {
case 'A': case 'A':
typ := r.typ() typ := r.typ()
return importalias(r.p.ipkg, pos, sym, typ) return importalias(pos, sym, typ)
case 'C': case 'C':
typ := r.typ() typ := r.typ()
val := r.value(typ) val := r.value(typ)
n := importconst(r.p.ipkg, pos, sym, typ, val) n := importconst(pos, sym, typ, val)
r.constExt(n) r.constExt(n)
return n return n
@ -311,7 +311,7 @@ func (r *importReader) doDecl(sym *types.Sym) *ir.Name {
} }
typ := r.signature(nil, tparams) typ := r.signature(nil, tparams)
n := importfunc(r.p.ipkg, pos, sym, typ) n := importfunc(pos, sym, typ)
r.funcExt(n) r.funcExt(n)
return n return n
@ -323,7 +323,7 @@ func (r *importReader) doDecl(sym *types.Sym) *ir.Name {
// Types can be recursive. We need to setup a stub // Types can be recursive. We need to setup a stub
// declaration before recursing. // declaration before recursing.
n := importtype(r.p.ipkg, pos, sym) n := importtype(pos, sym)
t := n.Type() t := n.Type()
if rparams != nil { if rparams != nil {
t.SetRParams(rparams) t.SetRParams(rparams)
@ -401,7 +401,7 @@ func (r *importReader) doDecl(sym *types.Sym) *ir.Name {
case 'V': case 'V':
typ := r.typ() typ := r.typ()
n := importvar(r.p.ipkg, pos, sym, typ) n := importvar(pos, sym, typ)
r.varExt(n) r.varExt(n)
return n return n

View File

@ -75,9 +75,9 @@ func InitRuntime() {
typ := typs[d.typ] typ := typs[d.typ]
switch d.tag { switch d.tag {
case funcTag: case funcTag:
importfunc(ir.Pkgs.Runtime, src.NoXPos, sym, typ) importfunc(src.NoXPos, sym, typ)
case varTag: case varTag:
importvar(ir.Pkgs.Runtime, src.NoXPos, sym, typ) importvar(src.NoXPos, sym, typ)
default: default:
base.Fatalf("unhandled declaration tag %v", d.tag) base.Fatalf("unhandled declaration tag %v", d.tag)
} }