Mercurial > projects > ddmd
annotate dmd/StorageClassDeclaration.d @ 179:cd48cb899aee
Updated to dmd2.040
author | korDen |
---|---|
date | Sun, 17 Oct 2010 20:56:07 +0400 |
parents | e3afd1303184 |
children | b0d41ff5e0df |
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 |
16 class StorageClassDeclaration: AttribDeclaration | |
17 { | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
18 StorageClass stc; |
0 | 19 |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
20 this(StorageClass stc, Dsymbols decl) |
0 | 21 { |
178 | 22 register(); |
0 | 23 super(decl); |
24 | |
25 this.stc = stc; | |
26 } | |
27 | |
72 | 28 override Dsymbol syntaxCopy(Dsymbol s) |
0 | 29 { |
51 | 30 StorageClassDeclaration scd; |
31 | |
32 assert(!s); | |
33 scd = new StorageClassDeclaration(stc, Dsymbol.arraySyntaxCopy(decl)); | |
34 return scd; | |
0 | 35 } |
36 | |
72 | 37 override void setScope(Scope sc) |
0 | 38 { |
39 if (decl) | |
40 { | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
41 StorageClass scstc = sc.stc; |
0 | 42 |
43 /* These sets of storage classes are mutually exclusive, | |
44 * so choose the innermost or most recent one. | |
45 */ | |
46 if (stc & (STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCextern | STC.STCmanifest)) | |
47 scstc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCextern | STC.STCmanifest); | |
48 if (stc & (STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCtls | STC.STCmanifest | STC.STCgshared)) | |
49 scstc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCtls | STC.STCmanifest | STC.STCgshared); | |
50 if (stc & (STC.STCconst | STC.STCimmutable | STC.STCmanifest)) | |
51 scstc &= ~(STC.STCconst | STC.STCimmutable | STC.STCmanifest); | |
52 if (stc & (STC.STCgshared | STC.STCshared | STC.STCtls)) | |
53 scstc &= ~(STC.STCgshared | STC.STCshared | STC.STCtls); | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
54 if (stc & (STCsafe | STCtrusted | STCsystem)) |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
55 scstc &= ~(STCsafe | STCtrusted | STCsystem); |
0 | 56 scstc |= stc; |
57 | |
58 setScopeNewSc(sc, scstc, sc.linkage, sc.protection, sc.explicitProtection, sc.structalign); | |
59 } | |
60 } | |
61 | |
72 | 62 override void semantic(Scope sc) |
0 | 63 { |
64 if (decl) | |
65 { | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
66 StorageClass scstc = sc.stc; |
0 | 67 |
68 /* These sets of storage classes are mutually exclusive, | |
69 * so choose the innermost or most recent one. | |
70 */ | |
71 if (stc & (STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCextern | STC.STCmanifest)) | |
72 scstc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCextern | STC.STCmanifest); | |
73 if (stc & (STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCtls | STC.STCmanifest | STC.STCgshared)) | |
74 scstc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCtls | STC.STCmanifest | STC.STCgshared); | |
75 if (stc & (STC.STCconst | STC.STCimmutable | STC.STCmanifest)) | |
76 scstc &= ~(STC.STCconst | STC.STCimmutable | STC.STCmanifest); | |
77 if (stc & (STC.STCgshared | STC.STCshared | STC.STCtls)) | |
78 scstc &= ~(STC.STCgshared | STC.STCshared | STC.STCtls); | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
79 if (stc & (STCsafe | STCtrusted | STCsystem)) |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
80 scstc &= ~(STCsafe | STCtrusted | STCsystem); |
0 | 81 scstc |= stc; |
82 | |
83 semanticNewSc(sc, scstc, sc.linkage, sc.protection, sc.explicitProtection, sc.structalign); | |
84 } | |
85 } | |
86 | |
72 | 87 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 88 { |
89 assert(false); | |
90 } | |
91 | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
92 static void stcToCBuffer(OutBuffer buf, StorageClass stc) |
0 | 93 { |
94 struct SCstring | |
95 { | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
96 StorageClass stc; |
0 | 97 TOK tok; |
98 }; | |
99 | |
170 | 100 enum SCstring[] table = |
0 | 101 [ |
102 { STCauto, TOKauto }, | |
103 { STCscope, TOKscope }, | |
104 { STCstatic, TOKstatic }, | |
105 { STCextern, TOKextern }, | |
106 { STCconst, TOKconst }, | |
107 { STCfinal, TOKfinal }, | |
108 { STCabstract, TOKabstract }, | |
109 { STCsynchronized, TOKsynchronized }, | |
110 { STCdeprecated, TOKdeprecated }, | |
111 { STCoverride, TOKoverride }, | |
112 { STClazy, TOKlazy }, | |
113 { STCalias, TOKalias }, | |
114 { STCout, TOKout }, | |
115 { STCin, TOKin }, | |
179 | 116 ///version (DMDV2) { |
117 { STCimmutable, TOKimmutable }, | |
118 { STCshared, TOKshared }, | |
119 { STCnothrow, TOKnothrow }, | |
120 { STCpure, TOKpure }, | |
121 { STCref, TOKref }, | |
122 { STCtls, TOKtls }, | |
123 { STCgshared, TOKgshared }, | |
124 { STCproperty, TOKat }, | |
125 { STCsafe, TOKat }, | |
126 { STCtrusted, TOKat }, | |
127 { STCdisable, TOKat }, | |
128 ///} | |
0 | 129 ]; |
130 | |
131 for (int i = 0; i < table.length; i++) | |
132 { | |
133 if (stc & table[i].stc) | |
134 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
135 enum TOK tok = table[i].tok; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
136 if (tok == TOKat) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
137 { Identifier id; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
138 |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
139 if (stc & STCproperty) |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
140 id = Id.property; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
141 else if (stc & STCsafe) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
142 id = Id.safe; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
143 else if (stc & STCtrusted) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
144 id = Id.trusted; |
179 | 145 else if (stc & STCdisable) |
146 id = Id.disable; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
147 else |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
148 assert(0); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
149 buf.writestring(id.toChars()); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
150 } |
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 buf.writestring(Token.toChars(tok)); |
0 | 153 buf.writeByte(' '); |
154 } | |
155 } | |
156 } | |
72 | 157 } |