Mercurial > projects > ddmd
annotate dmd/StorageClassDeclaration.d @ 178:e3afd1303184
Many small bugs fixed
Made all classes derive from TObject to detect memory leaks (functionality is disabled for now)
Began work on overriding backend memory allocations (to avoid memory leaks)
author | korDen |
---|---|
date | Sun, 17 Oct 2010 07:42:00 +0400 |
parents | 96c0fff6897d |
children | cd48cb899aee |
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 }, | |
116 /// version (DMDV2) { | |
117 /// { STCimmutable, TOKimmutable }, | |
118 /// { STCshared, TOKshared }, | |
119 /// { STCnothrow, TOKnothrow }, | |
120 /// { STCpure, TOKpure }, | |
121 /// { STCref, TOKref }, | |
122 /// { STCtls, TOKtls }, | |
123 /// { STCgshared, TOKgshared }, | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
124 /// { STCproperty, TOKat }, |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
125 /// { STCsafe, TOKat }, |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
126 /// { STCtrusted, TOKat }, |
0 | 127 /// } |
128 ]; | |
129 | |
130 for (int i = 0; i < table.length; i++) | |
131 { | |
132 if (stc & table[i].stc) | |
133 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
134 enum TOK tok = table[i].tok; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
135 if (tok == TOKat) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
136 { Identifier id; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
137 |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
138 if (stc & STCproperty) |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
139 id = Id.property; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
140 else if (stc & STCsafe) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
141 id = Id.safe; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
142 else if (stc & STCtrusted) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
143 id = Id.trusted; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
144 else |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
145 assert(0); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
146 buf.writestring(id.toChars()); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
147 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
148 else |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
149 buf.writestring(Token.toChars(tok)); |
0 | 150 buf.writeByte(' '); |
151 } | |
152 } | |
153 } | |
72 | 154 } |