annotate dmd/AggregateDeclaration.d @ 178:e3afd1303184

Many small bugs fixed Made all classes derive from TObject to detect memory leaks (functionality is disabled for now) Began work on overriding backend memory allocations (to avoid memory leaks)
author korDen
date Sun, 17 Oct 2010 07:42:00 +0400
parents fa9a71a9f5a8
children b0d41ff5e0df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 96
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.ExpStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.AddrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.CastExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.DotVarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.TypeStruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.StructDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Declaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.TypeClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.ThisExp;
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
18 import dmd.Global;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.PROT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.DotIdExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.CallExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.DtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.Lexer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.InvariantDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.NewDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.DeleteDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.CtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.Identifier;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
36 import dmd.Json;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.ClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.BaseClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 import dmd.backend.Classsym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 import dmd.backend.LIST;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 import dmd.backend.SC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 import dmd.backend.FL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 import dmd.backend.SFL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 import dmd.codegen.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 /****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 * Determine if scope sc has package level access to s.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 bool hasPackageAccess(Scope sc, Dsymbol s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 printf("hasPackageAccess(s = '%s', sc = '%p')\n", s.toChars(), sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 for (; s; s = s.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 if (s.isPackage() && !s.isModule())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 printf("\tthis is in package '%s'\n", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 if (s && s == sc.module_.parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 printf("\ts is in same package as sc\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 printf("\tno package access\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 /********************************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 * Helper function for ClassDeclaration.accessCheck()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 * 0 no access
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 * 1 access
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 bool accessCheckX(Dsymbol smember, Dsymbol sfunc, AggregateDeclaration dthis, AggregateDeclaration cdscope)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 assert(dthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 writef("accessCheckX for %s.%s in function %s() in scope %s\n", dthis.toChars(), smember.toChars(), sfunc ? sfunc.toChars() : "null", cdscope ? cdscope.toChars() : "null");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 if (dthis.hasPrivateAccess(sfunc) || dthis.isFriendOf(cdscope))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 if (smember.toParent() == dthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 ClassDeclaration cdthis = dthis.isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 if (cdthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 {
125
767a01c2a272 BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
113 foreach (b; cdthis.baseclasses)
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
114 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 PROT access = b.base.getAccess(smember);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 if (access >= PROT.PROTprotected || accessCheckX(smember, sfunc, b.base, cdscope))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 if (smember.toParent() != dthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 ClassDeclaration cdthis = dthis.isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 if (cdthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 {
125
767a01c2a272 BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
130 foreach (b; cdthis.baseclasses)
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
131 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 if (accessCheckX(smember, sfunc, b.base, cdscope))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 class AggregateDeclaration : ScopeDsymbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 Type type;
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
145 StorageClass storage_class;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 PROT protection = PROT.PROTpublic;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 Type handle; // 'this' type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 uint structsize; // size of struct
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 uint alignsize; // size of struct for alignment purposes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 uint structalign; // struct member alignment in effect
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 int hasUnions; // set if aggregate has overlapping fields
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
152 VarDeclarations fields; // VarDeclaration fields
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 uint sizeok; // set when structsize contains valid data
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 // 0: no size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 // 1: size is correct
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 // 2: cannot determine size; fwd referenced
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 bool isdeprecated; // true if deprecated
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
158
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 125
diff changeset
159 version (DMDV2) {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 bool isnested; // true if is nested
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 VarDeclaration vthis; // 'this' parameter if this aggregate is nested
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 125
diff changeset
162 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 // Special member functions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 InvariantDeclaration inv; // invariant
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 NewDeclaration aggNew; // allocator
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 DeleteDeclaration aggDelete; // deallocator
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 //CtorDeclaration *ctor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 Dsymbol ctor; // CtorDeclaration or TemplateDeclaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 CtorDeclaration defaultCtor; // default constructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 Dsymbol aliasthis; // forward unresolved lookups to aliasthis
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 FuncDeclarations dtors; // Array of destructors
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 FuncDeclaration dtor; // aggregate destructor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 version (IN_GCC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 Array methods; // flat list of all methods for debug information
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 this(Loc loc, Identifier id)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 176
diff changeset
184 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 super(id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 this.loc = loc;
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
187
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
188 fields = new VarDeclarations(); ///
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 dtors = new FuncDeclarations();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 16
diff changeset
192 override void semantic2(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 //printf("AggregateDeclaration.semantic2(%s)\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 if (scope_ && members)
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
196 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 error("has forward references");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 if (members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 sc = sc.push(this);
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
203 foreach(Dsymbol s; members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 s.semantic2(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 16
diff changeset
209 override void semantic3(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 //printf("AggregateDeclaration.semantic3(%s)\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 if (members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 sc = sc.push(this);
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
215 foreach(Dsymbol s; members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 s.semantic3(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 16
diff changeset
221 override void inlineScan()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 //printf("AggregateDeclaration.inlineScan(%s)\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 if (members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 {
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
226 foreach(Dsymbol s; members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 //printf("inline scan aggregate symbol '%s'\n", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 s.inlineScan();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 }
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
233
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 16
diff changeset
234 override uint size(Loc loc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 //printf("AggregateDeclaration.size() = %d\n", structsize);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 if (!members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 error(loc, "unknown size");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 if (sizeok != 1)
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
241 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 error(loc, "no size yet for forward reference");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 //*(char*)0=0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 return structsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 }
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
248
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 /****************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 * Do byte or word alignment as necessary.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 * Align sizes of 0, as we may not know array sizes yet.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 static void alignmember(uint salign, uint size, uint* poffset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 //printf("salign = %d, size = %d, offset = %d\n",salign,size,offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 if (salign > 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 assert(size != 3);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 int sa = size;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 if (sa == 0 || salign < sa)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 sa = salign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 *poffset = (*poffset + sa - 1) & ~(sa - 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 //printf("result = %d\n",offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 }
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
266
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 16
diff changeset
267 override Type getType()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 return type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 }
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
271
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 void addField(Scope sc, VarDeclaration v)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 uint memsize; // size of member
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 uint memalignsize; // size of member for alignment purposes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 uint xalign; // alignment boundaries
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 //printf("AggregateDeclaration.addField('%s') %s\n", v.toChars(), toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 assert(!(v.storage_class & (STC.STCstatic | STC.STCextern | STC.STCparameter | STC.STCtls)));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 // Check for forward referenced types which will fail the size() call
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 Type t = v.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 if (v.storage_class & STC.STCref)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 { // References are the size of a pointer
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
285 t = global.tvoidptr;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 if (t.ty == TY.Tstruct /*&& isStructDeclaration()*/)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 { TypeStruct ts = cast(TypeStruct)t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 if (ts.sym == this)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 error("cannot have field %s with same struct type", v.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 if (ts.sym.sizeok != 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 sizeok = 2; // cannot finish; flag as forward referenced
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 if (t.ty == TY.Tident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 sizeok = 2; // cannot finish; flag as forward referenced
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 memsize = cast(uint)t.size(loc); ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 memalignsize = t.alignsize();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 xalign = t.memalign(sc.structalign);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 alignmember(xalign, memalignsize, &sc.offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 v.offset = sc.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 sc.offset += memsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 if (sc.offset > structsize)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 structsize = sc.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 if (sc.structalign < memalignsize)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 memalignsize = sc.structalign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 if (alignsize < memalignsize)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 alignsize = memalignsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 //printf("\talignsize = %d\n", alignsize);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 v.storage_class |= STC.STCfield;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 //printf(" addField '%s' to '%s' at offset %d, size = %d\n", v.toChars(), toChars(), v.offset, memsize);
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
324 fields.push(v);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 }
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
326
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 16
diff changeset
327 override bool isDeprecated() // is aggregate deprecated?
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 return isdeprecated;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 * Create inclusive destructor for struct/class by aggregating
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 * all the destructors in dtors[] with the destructors for
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 * all the members.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 * Note the close similarity with StructDeclaration.buildPostBlit(),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 * and the ordering changes (runs backward instead of forwards).
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 FuncDeclaration buildDtor(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 //printf("AggregateDeclaration.buildDtor() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 Expression e = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
344 version (DMDV2)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
345 {
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 79
diff changeset
346 foreach (size_t i, VarDeclaration v; fields)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 assert(v && v.storage_class & STC.STCfield);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 if (v.storage_class & STC.STCref)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 Type tv = v.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 size_t dim = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 while (tv.ty == TY.Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 { TypeSArray ta = cast(TypeSArray)tv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 dim *= (cast(TypeSArray)tv).dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 tv = tv.nextOf().toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 if (tv.ty == TY.Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 { TypeStruct ts = cast(TypeStruct)tv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 StructDeclaration sd = ts.sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 if (sd.dtor)
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
362 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 Expression ex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 // this.v
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 ex = new ThisExp(Loc(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 ex = new DotVarExp(Loc(0), ex, v, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 if (dim == 1)
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
370 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 // this.v.dtor()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 ex = new DotVarExp(Loc(0), ex, sd.dtor, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 ex = new CallExp(Loc(0), ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 // Typeinfo.destroy(cast(void*)&this.v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 Expression ea = new AddrExp(Loc(0), ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 ea = new CastExp(Loc(0), ea, Type.tvoid.pointerTo());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 Expression et = v.type.getTypeInfo(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 et = new DotIdExp(Loc(0), et, Id.destroy);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 ex = new CallExp(Loc(0), et, ea);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 e = Expression.combine(ex, e); // combine in reverse order
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 /* Build our own "destructor" which executes e
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 if (e)
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
394 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 //printf("Building __fieldDtor()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 DtorDeclaration dd = new DtorDeclaration(Loc(0), Loc(0), Lexer.idPool("__fieldDtor"));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 dd.fbody = new ExpStatement(Loc(0), e);
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
398 dtors.shift(dd);
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
399 members.push(dd);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 dd.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 switch (dtors.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 case 1:
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
410 return cast(FuncDeclaration)dtors[0];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 e = null;
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
414 foreach(FuncDeclaration fd; dtors)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 Expression ex = new ThisExp(Loc(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 ex = new DotVarExp(Loc(0), ex, fd, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 ex = new CallExp(Loc(0), ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 e = Expression.combine(ex, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 }
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
421 auto dd = new DtorDeclaration(Loc(0), Loc(0), Lexer.idPool("__aggrDtor"));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 dd.fbody = new ExpStatement(Loc(0), e);
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
423 members.push(dd);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 dd.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 return dd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 /****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 * Returns true if there's an extra member which is the 'this'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 * pointer to the enclosing context (enclosing aggregate or function)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 bool isNested()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 return isnested;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 16
diff changeset
438 override void emitComment(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 }
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
442
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
443 override void toJsonBuffer(OutBuffer buf)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
444 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
445 //writef("AggregateDeclaration.toJsonBuffer()\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
446 buf.writestring("{\n");
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
447
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
448 JsonProperty(buf, Pname, toChars());
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
449 JsonProperty(buf, Pkind, kind());
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
450 if (comment)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
451 JsonProperty(buf, Pcomment, comment);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
452 if (loc.linnum)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
453 JsonProperty(buf, Pline, loc.linnum);
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
454
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
455 ClassDeclaration cd = isClassDeclaration();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
456 if (cd)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
457 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
458 if (cd.baseClass)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
459 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
460 JsonProperty(buf, "base", cd.baseClass.toChars());
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
461 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
462 if (cd.interfaces_dim)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
463 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
464 JsonString(buf, "interfaces");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
465 buf.writestring(" : [\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
466 size_t offset = buf.offset;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
467 for (int i = 0; i < cd.interfaces_dim; i++)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
468 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
469 BaseClass b = cd.interfaces[i];
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
470 if (offset != buf.offset)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
471 {
96
acd69f84627e further work
Trass3r
parents: 89
diff changeset
472 buf.writestring(",\n");
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
473 offset = buf.offset;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
474 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
475 JsonString(buf, b.base.toChars());
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
476 }
96
acd69f84627e further work
Trass3r
parents: 89
diff changeset
477 JsonRemoveComma(buf);
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
478 buf.writestring("],\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
479 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
480 }
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
481
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
482 JsonString(buf, Pmembers);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
483 buf.writestring(" : [\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
484 size_t offset = buf.offset;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
485 foreach (Dsymbol s; members)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
486 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
487 if (offset != buf.offset)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
488 {
96
acd69f84627e further work
Trass3r
parents: 89
diff changeset
489 buf.writestring(",\n");
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
490 offset = buf.offset;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
491 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
492 s.toJsonBuffer(buf);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
493 }
96
acd69f84627e further work
Trass3r
parents: 89
diff changeset
494 JsonRemoveComma(buf);
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
495 buf.writestring("]\n");
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
496
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
497 buf.writestring("}\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
498 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
499
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 16
diff changeset
500 override void toDocBuffer(OutBuffer buf)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 // For access checking
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 PROT getAccess(Dsymbol smember) // determine access to smember
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 /****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 * Determine if this is the same or friend of cd.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 bool isFriendOf(AggregateDeclaration cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 printf("AggregateDeclaration.isFriendOf(this = '%s', cd = '%s')\n", toChars(), cd ? cd.toChars() : "null");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 if (this is cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 // Friends if both are in the same module
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 //if (toParent() == cd.toParent())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 if (cd && getModule() == cd.getModule())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 printf("\tin same module\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 printf("\tnot friend\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 }
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
537
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 /**********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 * Determine if smember has access to private members of this declaration.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 bool hasPrivateAccess(Dsymbol smember) // does smember have private access to members of this class?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 if (smember)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 AggregateDeclaration cd = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 Dsymbol smemberparent = smember.toParent();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 if (smemberparent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 cd = smemberparent.isAggregateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 printf("AggregateDeclaration::hasPrivateAccess(class %s, member %s)\n", toChars(), smember.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 if (this == cd) // smember is a member of this class
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 printf("\tyes 1\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 return true; // so we get private access
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 // If both are members of the same module, grant access
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 while (true)
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
564 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 Dsymbol sp = smember.toParent();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 if (sp.isFuncDeclaration() && smember.isFuncDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 smember = sp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 if (!cd && toParent() == smember.toParent())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 printf("\tyes 2\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 if (!cd && getModule() == smember.getModule())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581 printf("\tyes 3\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 printf("\tno\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 }
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
591
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 /*******************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 * Do access check for member of this class, this class being the
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 * type of the 'this' pointer used to access smember.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 void accessCheck(Loc loc, Scope sc, Dsymbol smember)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 bool result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 FuncDeclaration f = sc.func;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 AggregateDeclaration cdscope = sc.getStructClassScope();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 PROT access;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 printf("AggregateDeclaration.accessCheck() for %s.%s in function %s() in scope %s\n", toChars(), smember.toChars(), f ? f.toChars() : null, cdscope ? cdscope.toChars() : null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 Dsymbol smemberparent = smember.toParent();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 if (!smemberparent || !smemberparent.isAggregateDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 printf("not an aggregate member\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 return; // then it is accessible
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 // BUG: should enable this check
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 //assert(smember.parent.isBaseOf(this, null));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 if (smemberparent == this)
176
fa9a71a9f5a8 Moved all the mutable globals to Global
korDen
parents: 131
diff changeset
621 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 PROT access2 = smember.prot();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624 result = access2 >= PROT.PROTpublic ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625 hasPrivateAccess(f) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 isFriendOf(cdscope) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 (access2 == PROT.PROTpackage && hasPackageAccess(sc, this));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 printf("result1 = %d\n", result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633 else if ((access = this.getAccess(smember)) >= PROT.PROTpublic)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 result = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637 printf("result2 = %d\n", result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 else if (access == PROT.PROTpackage && hasPackageAccess(sc, this))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 result = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 printf("result3 = %d\n", result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 result = accessCheckX(smember, f, this, cdscope);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 printf("result4 = %d\n", result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 if (!result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 error(loc, "member %s is not accessible", smember.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 halt();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 16
diff changeset
661 override PROT prot()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666 // Back end
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 Symbol* stag; // tag symbol for debug data
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668 Symbol* sinit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 Symbol* toInitializer()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 Classsym* stag;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 if (!sinit)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 stag = fake_classsym(Id.ClassInfo);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 s = toSymbolX("__init", SC.SCextern, stag.Stype, "Z");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 s.Sfl = FL.FLextern;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 s.Sflags |= SFL.SFLnodebug;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 slist_add(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 sinit = s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685 return sinit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 16
diff changeset
688 override AggregateDeclaration isAggregateDeclaration() { return this; }
16
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
689 }