annotate dmd/AggregateDeclaration.d @ 187:b0d41ff5e0df

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