annotate dmd/Scope.d @ 114:e28b18c23469

added a module dmd.common for commonly used stuff it currently holds code for consistency checking of predefined versions also added a VisualD project file
author Trass3r
date Wed, 01 Sep 2010 18:21:58 +0200
parents ee670dd808a8
children 010eb8f0e18d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 83
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Module;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.LabelStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.SwitchStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.TryFinallyStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.TemplateInstance;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.ForeachStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.LINK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.PROT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.AnonymousAggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.ClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.DocComment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.DsymbolTable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.CSX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29
83
ee670dd808a8 malloc -> GC.malloc change, plus compilation issues fixed (always check before commiting stuff!!!)
korDen
parents: 82
diff changeset
30 import core.memory;
ee670dd808a8 malloc -> GC.malloc change, plus compilation issues fixed (always check before commiting stuff!!!)
korDen
parents: 82
diff changeset
31
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 enum SCOPE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 SCOPEctor = 1, // constructor type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 SCOPEstaticif = 2, // inside static if
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 SCOPEfree = 4, // is on free list
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 class Scope
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 Scope enclosing; // enclosing Scope
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 Module module_; // Root module
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 ScopeDsymbol scopesym; // current symbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 ScopeDsymbol sd; // if in static if, and declaring new symbols,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 // sd gets the addMember()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 FuncDeclaration func; // function we are in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 Dsymbol parent; // parent to use
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 LabelStatement slabel; // enclosing labelled statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 SwitchStatement sw; // enclosing switch statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 TryFinallyStatement tf; // enclosing try finally statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 TemplateInstance tinst; // enclosing template instance
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 Statement sbreak; // enclosing statement that supports "break"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 Statement scontinue; // enclosing statement that supports "continue"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 ForeachStatement fes; // if nested function for ForeachStatement, this is it
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 uint offset; // next offset to use in aggregate
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 int inunion; // we're processing members of a union
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 int incontract; // we're inside contract code
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 int nofree; // set if shouldn't free it
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 int noctor; // set if constructor calls aren't allowed
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 int intypeof; // in typeof(exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 int parameterSpecialization; // if in template parameter specialization
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 int noaccesscheck; // don't do access checks
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 int mustsemantic; // cannot defer semantic()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 uint callSuper; // primitive flow analysis for constructors
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 ///#define CSXthis_ctor 1 // called this()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 ///#define CSXsuper_ctor 2 // called super()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 ///#define CSXthis 4 // referenced this
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 ///#define CSXsuper 8 // referenced super
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 ///#define CSXlabel 0x10 // seen a label
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 ///#define CSXreturn 0x20 // seen a return statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 ///#define CSXany_ctor 0x40 // either this() or super() was called
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 uint structalign; // alignment for struct members
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 LINK linkage = LINK.LINKd; // linkage for external functions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 PROT protection = PROT.PROTpublic; // protection for class members
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 int explicitProtection; // set if in an explicit protection attribute
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 STC stc; // storage class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 SCOPE flags;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 AnonymousAggregateDeclaration anonAgg; // for temporary analysis
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 DocComment lastdc; // documentation comment for last symbol at this scope
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 uint lastoffset; // offset in docbuf of where to insert next dec
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 OutBuffer docbuf; // buffer for documentation output
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 static Scope freelist;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 /// static void *operator new(size_t sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 static Scope createGlobal(Module module_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 Scope sc = new Scope();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 sc.module_ = module_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 sc.scopesym = new ScopeDsymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 sc.scopesym.symtab = new DsymbolTable();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 // Add top level package as member of this global scope
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 Dsymbol m = module_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 while (m.parent !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 m = m.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104
13
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
105 m.addMember(null, sc.scopesym, true);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 m.parent = null; // got changed by addMember()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 // Create the module scope underneath the global scope
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 sc = sc.push(module_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 sc.parent = module_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 return sc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 this()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 // Create root scope
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 //printf("Scope.Scope() %p\n", this);
21
26b9f97f6162 Added in some = new OutBuffer();'s to be on the safe side, been getting some issues with null OutBuffers.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
119 this.docbuf = new OutBuffer;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 this.structalign = global.structalign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 this(Module module_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 assert(false);
21
26b9f97f6162 Added in some = new OutBuffer();'s to be on the safe side, been getting some issues with null OutBuffers.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
126 this.docbuf = new OutBuffer;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 this(Scope enclosing)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 //printf("Scope.Scope(enclosing = %p) %p\n", enclosing, this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 assert(!(enclosing.flags & SCOPE.SCOPEfree));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 this.module_ = enclosing.module_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 this.func = enclosing.func;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 this.parent = enclosing.parent;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 23
diff changeset
136 this.scopesym = null;
43073c7c7769 updated to 2.035
Trass3r
parents: 23
diff changeset
137 this.sd = null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 this.sw = enclosing.sw;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 this.tf = enclosing.tf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 this.tinst = enclosing.tinst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 this.sbreak = enclosing.sbreak;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 this.scontinue = enclosing.scontinue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 this.fes = enclosing.fes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 this.structalign = enclosing.structalign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 this.enclosing = enclosing;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 if (enclosing.enclosing)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 assert(!(enclosing.enclosing.flags & SCOPE.SCOPEfree));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 if (this is enclosing.enclosing) /// huh?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 writef("this = %p, enclosing = %p, enclosing.enclosing = %p\n", this, enclosing, enclosing.enclosing);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 assert(this !is enclosing.enclosing);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 this.linkage = enclosing.linkage;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 this.protection = enclosing.protection;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 this.explicitProtection = enclosing.explicitProtection;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 this.stc = enclosing.stc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 this.inunion = enclosing.inunion;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 this.incontract = enclosing.incontract;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 this.noctor = enclosing.noctor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 this.noaccesscheck = enclosing.noaccesscheck;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 this.mustsemantic = enclosing.mustsemantic;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 this.intypeof = enclosing.intypeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 this.parameterSpecialization = enclosing.parameterSpecialization;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 this.callSuper = enclosing.callSuper;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 this.docbuf = enclosing.docbuf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 assert(this !is enclosing); /// huh?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 }
82
e95073e26356 fixed a hack I used as a lack of copy ctor in D
korDen
parents: 79
diff changeset
171
e95073e26356 fixed a hack I used as a lack of copy ctor in D
korDen
parents: 79
diff changeset
172 Scope clone()
e95073e26356 fixed a hack I used as a lack of copy ctor in D
korDen
parents: 79
diff changeset
173 {
e95073e26356 fixed a hack I used as a lack of copy ctor in D
korDen
parents: 79
diff changeset
174 // similar code is used in Type.clone()
e95073e26356 fixed a hack I used as a lack of copy ctor in D
korDen
parents: 79
diff changeset
175 // TODO: move to Util or something...
e95073e26356 fixed a hack I used as a lack of copy ctor in D
korDen
parents: 79
diff changeset
176 size_t size = __traits(classInstanceSize, typeof(this));
83
ee670dd808a8 malloc -> GC.malloc change, plus compilation issues fixed (always check before commiting stuff!!!)
korDen
parents: 82
diff changeset
177 void* mem = GC.malloc(size);
ee670dd808a8 malloc -> GC.malloc change, plus compilation issues fixed (always check before commiting stuff!!!)
korDen
parents: 82
diff changeset
178 memcpy(mem, cast(void*)this, size);
82
e95073e26356 fixed a hack I used as a lack of copy ctor in D
korDen
parents: 79
diff changeset
179
e95073e26356 fixed a hack I used as a lack of copy ctor in D
korDen
parents: 79
diff changeset
180 return cast(typeof(this))mem;
e95073e26356 fixed a hack I used as a lack of copy ctor in D
korDen
parents: 79
diff changeset
181 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 Scope push()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 //printf("Scope.push()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 Scope s = new Scope(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 assert(this !is s); /// huh?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 Scope push(ScopeDsymbol ss)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 //printf("Scope.push(%s)\n", ss.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 Scope s = push();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 s.scopesym = ss;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 Scope pop()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 //printf("Scope.pop() %p nofree = %d\n", this, nofree);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 Scope enc = enclosing;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 if (enclosing)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 enclosing.callSuper |= callSuper;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 if (!nofree)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 enclosing = freelist;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 freelist = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 flags |= SCOPE.SCOPEfree;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 return enc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 void mergeCallSuper(Loc loc, uint cs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 // This does a primitive flow analysis to support the restrictions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 // regarding when and how constructors can appear.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 // It merges the results of two paths.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 // The two paths are callSuper and cs; the result is merged into callSuper.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 if (cs != callSuper)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 int a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 int b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 callSuper |= cs & (CSX.CSXany_ctor | CSX.CSXlabel);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 if (cs & CSX.CSXreturn)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 else if (callSuper & CSX.CSXreturn)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 callSuper = cs | (callSuper & (CSX.CSXany_ctor | CSX.CSXlabel));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 a = (cs & (CSX.CSXthis_ctor | CSX.CSXsuper_ctor)) != 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 b = (callSuper & (CSX.CSXthis_ctor | CSX.CSXsuper_ctor)) != 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 if (a != b)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 error(loc, "one path skips constructor");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 callSuper |= cs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 Dsymbol search(Loc loc, Identifier ident, Dsymbol* pscopesym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 Dsymbol s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 Scope sc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 //printf("Scope.search(%p, '%s')\n", this, ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 if (ident is Id.empty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 // Look for module scope
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 for (sc = this; sc; sc = sc.enclosing)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 assert(sc != sc.enclosing);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 if (sc.scopesym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 s = sc.scopesym.isModule();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 //printf("\tfound %s.%s\n", s.parent ? s.parent.toChars() : "", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 if (pscopesym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 *pscopesym = sc.scopesym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 for (sc = this; sc; sc = sc.enclosing)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 assert(sc != sc.enclosing);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 if (sc.scopesym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 //printf("\tlooking in scopesym '%s', kind = '%s'\n", sc.scopesym.toChars(), sc.scopesym.kind());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 s = sc.scopesym.search(loc, ident, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 if ((global.params.warnings ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 global.params.Dversion > 1) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 ident == Id.length &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 sc.scopesym.isArrayScopeSymbol() &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 sc.enclosing &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 sc.enclosing.search(loc, ident, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 warning(s.loc, "array 'length' hides other 'length' name in outer scope");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 //printf("\tfound %s.%s, kind = '%s'\n", s.parent ? s.parent.toChars() : "", s.toChars(), s.kind());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 if (pscopesym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 *pscopesym = sc.scopesym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 Dsymbol insert(Dsymbol s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 for (Scope sc = this; sc; sc = sc.enclosing)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 //printf("\tsc = %p\n", sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 if (sc.scopesym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 //printf("\t\tsc.scopesym = %p\n", sc.scopesym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 if (!sc.scopesym.symtab)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 sc.scopesym.symtab = new DsymbolTable();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317
79
43073c7c7769 updated to 2.035
Trass3r
parents: 23
diff changeset
318 return sc.scopesym.symtabInsert(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 ClassDeclaration getClassScope()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 /********************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 * Search enclosing scopes for ClassDeclaration.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 AggregateDeclaration getStructClassScope()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 for (Scope sc = this; sc; sc = sc.enclosing)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 AggregateDeclaration ad;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 if (sc.scopesym)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 ad = sc.scopesym.isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 if (ad)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 return ad;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 ad = sc.scopesym.isStructDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 if (ad)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 return ad;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 void setNoFree()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 //int i = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 //printf("Scope.setNoFree(this = %p)\n", this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 for (Scope sc = this; sc; sc = sc.enclosing)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 //printf("\tsc = %p\n", sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 sc.nofree = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 assert(!(flags & SCOPE.SCOPEfree));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 //assert(sc != sc.enclosing);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 //assert(!sc.enclosing || sc != sc.enclosing.enclosing);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 //if (++i == 10)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 //assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 }
21
26b9f97f6162 Added in some = new OutBuffer();'s to be on the safe side, been getting some issues with null OutBuffers.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
373 }