annotate dmd/StorageClassDeclaration.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 cd48cb899aee
children a4c9de8e39b3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.StorageClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 74
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.AttribDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Token;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.STC;
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
13 import dmd.Id;
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
14 import dmd.Identifier;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
16 import dmd.DDMDExtensions;
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
17
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 class StorageClassDeclaration: AttribDeclaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
20 mixin insertMemberExtension!(typeof(this));
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
21
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
22 StorageClass stc;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
24 this(StorageClass stc, Dsymbols decl)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 170
diff changeset
26 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 super(decl);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 this.stc = stc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 51
diff changeset
32 override Dsymbol syntaxCopy(Dsymbol s)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
34 StorageClassDeclaration scd;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
35
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
36 assert(!s);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
37 scd = new StorageClassDeclaration(stc, Dsymbol.arraySyntaxCopy(decl));
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
38 return scd;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 51
diff changeset
41 override void setScope(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 if (decl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 {
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
45 StorageClass scstc = sc.stc;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 /* These sets of storage classes are mutually exclusive,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 * so choose the innermost or most recent one.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 if (stc & (STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCextern | STC.STCmanifest))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 scstc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCextern | STC.STCmanifest);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 if (stc & (STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCtls | STC.STCmanifest | STC.STCgshared))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 scstc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCtls | STC.STCmanifest | STC.STCgshared);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 if (stc & (STC.STCconst | STC.STCimmutable | STC.STCmanifest))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 scstc &= ~(STC.STCconst | STC.STCimmutable | STC.STCmanifest);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 if (stc & (STC.STCgshared | STC.STCshared | STC.STCtls))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 scstc &= ~(STC.STCgshared | STC.STCshared | STC.STCtls);
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
58 if (stc & (STCsafe | STCtrusted | STCsystem))
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
59 scstc &= ~(STCsafe | STCtrusted | STCsystem);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 scstc |= stc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 setScopeNewSc(sc, scstc, sc.linkage, sc.protection, sc.explicitProtection, sc.structalign);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 51
diff changeset
66 override void semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 if (decl)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 {
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
70 StorageClass scstc = sc.stc;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 /* These sets of storage classes are mutually exclusive,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 * so choose the innermost or most recent one.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 if (stc & (STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCextern | STC.STCmanifest))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 scstc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCextern | STC.STCmanifest);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 if (stc & (STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCtls | STC.STCmanifest | STC.STCgshared))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 scstc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCtls | STC.STCmanifest | STC.STCgshared);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 if (stc & (STC.STCconst | STC.STCimmutable | STC.STCmanifest))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 scstc &= ~(STC.STCconst | STC.STCimmutable | STC.STCmanifest);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 if (stc & (STC.STCgshared | STC.STCshared | STC.STCtls))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 scstc &= ~(STC.STCgshared | STC.STCshared | STC.STCtls);
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
83 if (stc & (STCsafe | STCtrusted | STCsystem))
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
84 scstc &= ~(STCsafe | STCtrusted | STCsystem);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 scstc |= stc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 semanticNewSc(sc, scstc, sc.linkage, sc.protection, sc.explicitProtection, sc.structalign);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 51
diff changeset
91 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
96 static void stcToCBuffer(OutBuffer buf, StorageClass stc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 struct SCstring
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 {
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
100 StorageClass stc;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 TOK tok;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 };
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103
170
96c0fff6897d more global state cleanup
korDen
parents: 131
diff changeset
104 enum SCstring[] table =
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 [
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 { STCauto, TOKauto },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 { STCscope, TOKscope },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 { STCstatic, TOKstatic },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 { STCextern, TOKextern },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 { STCconst, TOKconst },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 { STCfinal, TOKfinal },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 { STCabstract, TOKabstract },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 { STCsynchronized, TOKsynchronized },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 { STCdeprecated, TOKdeprecated },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 { STCoverride, TOKoverride },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 { STClazy, TOKlazy },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 { STCalias, TOKalias },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 { STCout, TOKout },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 { STCin, TOKin },
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
120 ///version (DMDV2) {
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
121 { STCimmutable, TOKimmutable },
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
122 { STCshared, TOKshared },
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
123 { STCnothrow, TOKnothrow },
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
124 { STCpure, TOKpure },
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
125 { STCref, TOKref },
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
126 { STCtls, TOKtls },
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
127 { STCgshared, TOKgshared },
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
128 { STCproperty, TOKat },
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
129 { STCsafe, TOKat },
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
130 { STCtrusted, TOKat },
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
131 { STCdisable, TOKat },
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
132 ///}
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 ];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 for (int i = 0; i < table.length; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 if (stc & table[i].stc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 {
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
139 enum TOK tok = table[i].tok;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
140 if (tok == TOKat)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
141 { Identifier id;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
142
131
206db751bd4c dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
143 if (stc & STCproperty)
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
144 id = Id.property;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
145 else if (stc & STCsafe)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
146 id = Id.safe;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
147 else if (stc & STCtrusted)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
148 id = Id.trusted;
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
149 else if (stc & STCdisable)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
150 id = Id.disable;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
151 else
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
152 assert(0);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
153 buf.writestring(id.toChars());
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
154 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
155 else
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
156 buf.writestring(Token.toChars(tok));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 buf.writeByte(' ');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 51
diff changeset
161 }