1
0
mirror of https://github.com/golang/go synced 2024-11-18 08:54:45 -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
t.Sym = Pkglookup("Pointer", unsafepkg)
t.Sym.Def = typenod(t)
t.Sym.Def.Name = new(Name)
dowidth(Types[TUNSAFEPTR])
@ -654,6 +655,7 @@ func typeinit() {
dowidth(t)
Types[etype] = t
s1.Def = typenod(t)
s1.Def.Name = new(Name)
}
Array_array = int(Rnd(0, int64(Widthptr)))

View File

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

View File

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

View File

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

View File

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

View File

@ -331,7 +331,10 @@ func importdot(opkg *Pkg, pack *Node) {
s1.Def = s.Def
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
n++
}

View File

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

View File

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