Mercurial > projects > ddmd
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 |
rev | line source |
---|---|
0 | 1 module dmd.StorageClassDeclaration; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.AttribDeclaration; |
5 import dmd.Array; | |
6 import dmd.TOK; | |
7 import dmd.Token; | |
8 import dmd.Scope; | |
9 import dmd.Dsymbol; | |
10 import dmd.OutBuffer; | |
11 import dmd.HdrGenState; | |
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 | 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 | 18 class StorageClassDeclaration: AttribDeclaration |
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 | 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 | 25 { |
178 | 26 register(); |
0 | 27 super(decl); |
28 | |
29 this.stc = stc; | |
30 } | |
31 | |
72 | 32 override Dsymbol syntaxCopy(Dsymbol s) |
0 | 33 { |
51 | 34 StorageClassDeclaration scd; |
35 | |
36 assert(!s); | |
37 scd = new StorageClassDeclaration(stc, Dsymbol.arraySyntaxCopy(decl)); | |
38 return scd; | |
0 | 39 } |
40 | |
72 | 41 override void setScope(Scope sc) |
0 | 42 { |
43 if (decl) | |
44 { | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
45 StorageClass scstc = sc.stc; |
0 | 46 |
47 /* These sets of storage classes are mutually exclusive, | |
48 * so choose the innermost or most recent one. | |
49 */ | |
50 if (stc & (STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCextern | STC.STCmanifest)) | |
51 scstc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCextern | STC.STCmanifest); | |
52 if (stc & (STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCtls | STC.STCmanifest | STC.STCgshared)) | |
53 scstc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCtls | STC.STCmanifest | STC.STCgshared); | |
54 if (stc & (STC.STCconst | STC.STCimmutable | STC.STCmanifest)) | |
55 scstc &= ~(STC.STCconst | STC.STCimmutable | STC.STCmanifest); | |
56 if (stc & (STC.STCgshared | STC.STCshared | STC.STCtls)) | |
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 | 60 scstc |= stc; |
61 | |
62 setScopeNewSc(sc, scstc, sc.linkage, sc.protection, sc.explicitProtection, sc.structalign); | |
63 } | |
64 } | |
65 | |
72 | 66 override void semantic(Scope sc) |
0 | 67 { |
68 if (decl) | |
69 { | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
70 StorageClass scstc = sc.stc; |
0 | 71 |
72 /* These sets of storage classes are mutually exclusive, | |
73 * so choose the innermost or most recent one. | |
74 */ | |
75 if (stc & (STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCextern | STC.STCmanifest)) | |
76 scstc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCextern | STC.STCmanifest); | |
77 if (stc & (STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCtls | STC.STCmanifest | STC.STCgshared)) | |
78 scstc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCtls | STC.STCmanifest | STC.STCgshared); | |
79 if (stc & (STC.STCconst | STC.STCimmutable | STC.STCmanifest)) | |
80 scstc &= ~(STC.STCconst | STC.STCimmutable | STC.STCmanifest); | |
81 if (stc & (STC.STCgshared | STC.STCshared | STC.STCtls)) | |
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 | 85 scstc |= stc; |
86 | |
87 semanticNewSc(sc, scstc, sc.linkage, sc.protection, sc.explicitProtection, sc.structalign); | |
88 } | |
89 } | |
90 | |
72 | 91 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 92 { |
93 assert(false); | |
94 } | |
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 | 97 { |
98 struct SCstring | |
99 { | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
100 StorageClass stc; |
0 | 101 TOK tok; |
102 }; | |
103 | |
170 | 104 enum SCstring[] table = |
0 | 105 [ |
106 { STCauto, TOKauto }, | |
107 { STCscope, TOKscope }, | |
108 { STCstatic, TOKstatic }, | |
109 { STCextern, TOKextern }, | |
110 { STCconst, TOKconst }, | |
111 { STCfinal, TOKfinal }, | |
112 { STCabstract, TOKabstract }, | |
113 { STCsynchronized, TOKsynchronized }, | |
114 { STCdeprecated, TOKdeprecated }, | |
115 { STCoverride, TOKoverride }, | |
116 { STClazy, TOKlazy }, | |
117 { STCalias, TOKalias }, | |
118 { STCout, TOKout }, | |
119 { STCin, TOKin }, | |
179 | 120 ///version (DMDV2) { |
121 { STCimmutable, TOKimmutable }, | |
122 { STCshared, TOKshared }, | |
123 { STCnothrow, TOKnothrow }, | |
124 { STCpure, TOKpure }, | |
125 { STCref, TOKref }, | |
126 { STCtls, TOKtls }, | |
127 { STCgshared, TOKgshared }, | |
128 { STCproperty, TOKat }, | |
129 { STCsafe, TOKat }, | |
130 { STCtrusted, TOKat }, | |
131 { STCdisable, TOKat }, | |
132 ///} | |
0 | 133 ]; |
134 | |
135 for (int i = 0; i < table.length; i++) | |
136 { | |
137 if (stc & table[i].stc) | |
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 | 149 else if (stc & STCdisable) |
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 | 157 buf.writeByte(' '); |
158 } | |
159 } | |
160 } | |
72 | 161 } |