1
0
mirror of https://github.com/golang/go synced 2024-11-18 08:44:43 -07:00

cmd/compile: move Node.Pack to Node.Name.Pack

$ sizeof -p cmd/compile/internal/gc Node
Node 232
$

Change-Id: I4be025f4ec11f882f24ae7582821d36d3b122b77
Reviewed-on: https://go-review.googlesource.com/10526
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Russ Cox 2015-05-26 23:08:39 -04:00
parent cb20146097
commit 140ef3c59a
8 changed files with 37 additions and 13 deletions

View File

@ -432,6 +432,7 @@ func typeinit() {
Types[TUNSAFEPTR] = t Types[TUNSAFEPTR] = t
t.Sym = Pkglookup("Pointer", unsafepkg) t.Sym = Pkglookup("Pointer", unsafepkg)
t.Sym.Def = typenod(t) t.Sym.Def = typenod(t)
t.Sym.Def.Name = new(Name)
dowidth(Types[TUNSAFEPTR]) dowidth(Types[TUNSAFEPTR])
@ -654,6 +655,7 @@ func typeinit() {
dowidth(t) dowidth(t)
Types[etype] = t Types[etype] = t
s1.Def = typenod(t) s1.Def = typenod(t)
s1.Def.Name = new(Name)
} }
Array_array = int(Rnd(0, int64(Widthptr))) Array_array = int(Rnd(0, int64(Widthptr)))

View File

@ -174,6 +174,10 @@ func declare(n *Node, ctxt uint8) {
return return
} }
if n.Name == nil {
// named OLITERAL needs Name; most OLITERALs don't.
n.Name = new(Name)
}
n.Lineno = int32(parserline()) n.Lineno = int32(parserline())
s := n.Sym s := n.Sym

View File

@ -416,6 +416,7 @@ func pkgtype(s *Sym) *Type {
t := typ(TFORW) t := typ(TFORW)
t.Sym = s t.Sym = s
s.Def = typenod(t) s.Def = typenod(t)
s.Def.Name = new(Name)
} }
if s.Def.Type == nil { if s.Def.Type == nil {

View File

@ -1221,8 +1221,8 @@ name:
sym %prec NotParen sym %prec NotParen
{ {
$$ = oldname($1); $$ = oldname($1);
if $$.Pack != nil { if $$.Name != nil && $$.Name.Pack != nil {
$$.Pack.Used = true; $$.Name.Pack.Used = true;
} }
} }
@ -1687,8 +1687,8 @@ packname:
$$ = $1; $$ = $1;
n = oldname($1); n = oldname($1);
if n.Pack != nil { if n.Name != nil && n.Name.Pack != nil {
n.Pack.Used = true; n.Name.Pack.Used = true;
} }
} }
| LNAME '.' sym | LNAME '.' sym

View File

@ -2182,6 +2182,7 @@ func lexinit() {
s1.Lexical = LNAME s1.Lexical = LNAME
s1.Def = typenod(t) s1.Def = typenod(t)
s1.Def.Name = new(Name)
continue continue
} }
@ -2207,11 +2208,13 @@ func lexinit() {
s = Pkglookup("true", builtinpkg) s = Pkglookup("true", builtinpkg)
s.Def = Nodbool(true) s.Def = Nodbool(true)
s.Def.Sym = Lookup("true") s.Def.Sym = Lookup("true")
s.Def.Name = new(Name)
s.Def.Type = idealbool s.Def.Type = idealbool
s = Pkglookup("false", builtinpkg) s = Pkglookup("false", builtinpkg)
s.Def = Nodbool(false) s.Def = Nodbool(false)
s.Def.Sym = Lookup("false") s.Def.Sym = Lookup("false")
s.Def.Name = new(Name)
s.Def.Type = idealbool s.Def.Type = idealbool
s = Lookup("_") s = Lookup("_")
@ -2235,6 +2238,7 @@ func lexinit() {
v.U = new(NilVal) v.U = new(NilVal)
s.Def = nodlit(v) s.Def = nodlit(v)
s.Def.Sym = s s.Def.Sym = s
s.Def.Name = new(Name)
} }
func lexinit1() { func lexinit1() {
@ -2282,6 +2286,7 @@ func lexinit1() {
bytetype.Sym = s1 bytetype.Sym = s1
s1.Lexical = LNAME s1.Lexical = LNAME
s1.Def = typenod(bytetype) s1.Def = typenod(bytetype)
s1.Def.Name = new(Name)
// rune alias // rune alias
s = Lookup("rune") s = Lookup("rune")
@ -2292,6 +2297,7 @@ func lexinit1() {
runetype.Sym = s1 runetype.Sym = s1
s1.Lexical = LNAME s1.Lexical = LNAME
s1.Def = typenod(runetype) s1.Def = typenod(runetype)
s1.Def.Name = new(Name)
} }
func lexfini() { func lexfini() {
@ -2311,6 +2317,7 @@ func lexfini() {
etype = syms[i].etype etype = syms[i].etype
if etype != Txxx && (etype != TANY || Debug['A'] != 0) && s.Def == nil { if etype != Txxx && (etype != TANY || Debug['A'] != 0) && s.Def == nil {
s.Def = typenod(Types[etype]) s.Def = typenod(Types[etype])
s.Def.Name = new(Name)
s.Origpkg = builtinpkg s.Origpkg = builtinpkg
} }
@ -2328,6 +2335,7 @@ func lexfini() {
s = Lookup(Thearch.Typedefs[i].Name) s = Lookup(Thearch.Typedefs[i].Name)
if s.Def == nil { if s.Def == nil {
s.Def = typenod(Types[Thearch.Typedefs[i].Etype]) s.Def = typenod(Types[Thearch.Typedefs[i].Etype])
s.Def.Name = new(Name)
s.Origpkg = builtinpkg s.Origpkg = builtinpkg
} }
} }
@ -2338,18 +2346,21 @@ func lexfini() {
if s.Def == nil { if s.Def == nil {
s.Def = typenod(bytetype) s.Def = typenod(bytetype)
s.Def.Name = new(Name)
s.Origpkg = builtinpkg s.Origpkg = builtinpkg
} }
s = Lookup("error") s = Lookup("error")
if s.Def == nil { if s.Def == nil {
s.Def = typenod(errortype) s.Def = typenod(errortype)
s.Def.Name = new(Name)
s.Origpkg = builtinpkg s.Origpkg = builtinpkg
} }
s = Lookup("rune") s = Lookup("rune")
if s.Def == nil { if s.Def == nil {
s.Def = typenod(runetype) s.Def = typenod(runetype)
s.Def.Name = new(Name)
s.Origpkg = builtinpkg s.Origpkg = builtinpkg
} }
@ -2359,6 +2370,7 @@ func lexfini() {
v.U = new(NilVal) v.U = new(NilVal)
s.Def = nodlit(v) s.Def = nodlit(v)
s.Def.Sym = s s.Def.Sym = s
s.Def.Name = new(Name)
s.Origpkg = builtinpkg s.Origpkg = builtinpkg
} }
@ -2373,6 +2385,7 @@ func lexfini() {
if s.Def == nil { if s.Def == nil {
s.Def = Nodbool(true) s.Def = Nodbool(true)
s.Def.Sym = s s.Def.Sym = s
s.Def.Name = new(Name)
s.Origpkg = builtinpkg s.Origpkg = builtinpkg
} }
@ -2380,6 +2393,7 @@ func lexfini() {
if s.Def == nil { if s.Def == nil {
s.Def = Nodbool(false) s.Def = Nodbool(false)
s.Def.Sym = s s.Def.Sym = s
s.Def.Name = new(Name)
s.Origpkg = builtinpkg s.Origpkg = builtinpkg
} }
@ -2572,9 +2586,9 @@ func mkpackage(pkgname string) {
if s.Def.Sym != s { if s.Def.Sym != s {
// throw away top-level name left over // throw away top-level name left over
// from previous import . "x" // from previous import . "x"
if s.Def.Pack != nil && !s.Def.Pack.Used && nsyntaxerrors == 0 { if s.Def.Name != nil && s.Def.Name.Pack != nil && !s.Def.Name.Pack.Used && nsyntaxerrors == 0 {
pkgnotused(int(s.Def.Pack.Lineno), s.Def.Pack.Pkg.Path, "") pkgnotused(int(s.Def.Name.Pack.Lineno), s.Def.Name.Pack.Pkg.Path, "")
s.Def.Pack.Used = true s.Def.Name.Pack.Used = true
} }
s.Def = nil s.Def = nil

View File

@ -331,7 +331,10 @@ func importdot(opkg *Pkg, pack *Node) {
s1.Def = s.Def s1.Def = s.Def
s1.Block = s.Block s1.Block = s.Block
s1.Def.Pack = pack if s1.Def.Name == nil {
Dump("s1def", s1.Def)
}
s1.Def.Name.Pack = pack
s1.Origpkg = opkg s1.Origpkg = opkg
n++ n++
} }

View File

@ -30,7 +30,6 @@ type Node struct {
// ONAME // ONAME
Name *Name Name *Name
Pack *Node // real package for import . names
Curfn *Node // function for local variables Curfn *Node // function for local variables
Param *Param Param *Param
@ -94,6 +93,7 @@ type Node struct {
// Name holds Node fields used only by ONAME nodes. // Name holds Node fields used only by ONAME nodes.
type Name struct { type Name struct {
Pack *Node // real package for import . names
Heapaddr *Node // temp holding heap address of param Heapaddr *Node // temp holding heap address of param
Inlvar *Node // ONAME substitute while inlining Inlvar *Node // ONAME substitute while inlining
Defn *Node // initializing assignment Defn *Node // initializing assignment

View File

@ -2390,8 +2390,8 @@ yydefault:
//line go.y:1222 //line go.y:1222
{ {
yyVAL.node = oldname(yyDollar[1].sym) yyVAL.node = oldname(yyDollar[1].sym)
if yyVAL.node.Pack != nil { if yyVAL.node.Name != nil && yyVAL.node.Name.Pack != nil {
yyVAL.node.Pack.Used = true yyVAL.node.Name.Pack.Used = true
} }
} }
case 164: case 164:
@ -2846,8 +2846,8 @@ yydefault:
yyVAL.sym = yyDollar[1].sym yyVAL.sym = yyDollar[1].sym
n = oldname(yyDollar[1].sym) n = oldname(yyDollar[1].sym)
if n.Pack != nil { if n.Name != nil && n.Name.Pack != nil {
n.Pack.Used = true n.Name.Pack.Used = true
} }
} }
case 237: case 237: