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