1
2
3
4
5 package types
6
7 import (
8 "cmd/compile/internal/base"
9 "cmd/internal/src"
10 )
11
12
13
14 var blockgen int32 = 1
15 var Block int32 = 1
16
17
18
19 type dsym struct {
20 sym *Sym
21 def Object
22 block int32
23 lastlineno src.XPos
24 }
25
26
27
28 var dclstack []dsym
29
30
31
32 func Pushdcl(s *Sym) {
33 dclstack = append(dclstack, dsym{
34 sym: s,
35 def: s.Def,
36 block: s.Block,
37 lastlineno: s.Lastlineno,
38 })
39 }
40
41
42
43 func Popdcl() {
44 for i := len(dclstack); i > 0; i-- {
45 d := &dclstack[i-1]
46 s := d.sym
47 if s == nil {
48
49 Block = d.block
50 dclstack = dclstack[:i-1]
51 return
52 }
53
54 s.Def = d.def
55 s.Block = d.block
56 s.Lastlineno = d.lastlineno
57
58
59 d.sym = nil
60 d.def = nil
61 }
62 base.Fatalf("popdcl: no stack mark")
63 }
64
65
66 func Markdcl() {
67 dclstack = append(dclstack, dsym{
68 sym: nil,
69 block: Block,
70 })
71 blockgen++
72 Block = blockgen
73 }
74
75 func isDclstackValid() bool {
76 for _, d := range dclstack {
77 if d.sym == nil {
78 return false
79 }
80 }
81 return true
82 }
83
84
85 func (s *Sym) PkgDef() Object {
86 return *s.pkgDefPtr()
87 }
88
89
90 func (s *Sym) SetPkgDef(n Object) {
91 *s.pkgDefPtr() = n
92 }
93
94 func (s *Sym) pkgDefPtr() *Object {
95
96
97 for i := range dclstack {
98 d := &dclstack[i]
99 if s == d.sym {
100 return &d.def
101 }
102 }
103
104
105
106 return &s.Def
107 }
108
109 func CheckDclstack() {
110 if !isDclstackValid() {
111 base.Fatalf("mark left on the dclstack")
112 }
113 }
114
View as plain text