0
|
1 module dmd.StorageClassDeclaration;
|
|
2
|
|
3 import dmd.AttribDeclaration;
|
|
4 import dmd.Array;
|
|
5 import dmd.TOK;
|
|
6 import dmd.Token;
|
|
7 import dmd.Scope;
|
|
8 import dmd.Dsymbol;
|
|
9 import dmd.OutBuffer;
|
|
10 import dmd.HdrGenState;
|
|
11 import dmd.STC;
|
|
12
|
|
13 class StorageClassDeclaration: AttribDeclaration
|
|
14 {
|
|
15 STC stc;
|
|
16
|
|
17 this(STC stc, Array decl)
|
|
18 {
|
|
19 super(decl);
|
|
20
|
|
21 this.stc = stc;
|
|
22 }
|
|
23
|
72
|
24 override Dsymbol syntaxCopy(Dsymbol s)
|
0
|
25 {
|
51
|
26 StorageClassDeclaration scd;
|
|
27
|
|
28 assert(!s);
|
|
29 scd = new StorageClassDeclaration(stc, Dsymbol.arraySyntaxCopy(decl));
|
|
30 return scd;
|
0
|
31 }
|
|
32
|
72
|
33 override void setScope(Scope sc)
|
0
|
34 {
|
|
35 if (decl)
|
|
36 {
|
|
37 STC scstc = sc.stc;
|
|
38
|
|
39 /* These sets of storage classes are mutually exclusive,
|
|
40 * so choose the innermost or most recent one.
|
|
41 */
|
|
42 if (stc & (STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCextern | STC.STCmanifest))
|
|
43 scstc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCextern | STC.STCmanifest);
|
|
44 if (stc & (STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCtls | STC.STCmanifest | STC.STCgshared))
|
|
45 scstc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCtls | STC.STCmanifest | STC.STCgshared);
|
|
46 if (stc & (STC.STCconst | STC.STCimmutable | STC.STCmanifest))
|
|
47 scstc &= ~(STC.STCconst | STC.STCimmutable | STC.STCmanifest);
|
|
48 if (stc & (STC.STCgshared | STC.STCshared | STC.STCtls))
|
|
49 scstc &= ~(STC.STCgshared | STC.STCshared | STC.STCtls);
|
|
50 scstc |= stc;
|
|
51
|
|
52 setScopeNewSc(sc, scstc, sc.linkage, sc.protection, sc.explicitProtection, sc.structalign);
|
|
53 }
|
|
54 }
|
|
55
|
72
|
56 override void semantic(Scope sc)
|
0
|
57 {
|
|
58 if (decl)
|
|
59 {
|
|
60 STC scstc = sc.stc;
|
|
61
|
|
62 /* These sets of storage classes are mutually exclusive,
|
|
63 * so choose the innermost or most recent one.
|
|
64 */
|
|
65 if (stc & (STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCextern | STC.STCmanifest))
|
|
66 scstc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCextern | STC.STCmanifest);
|
|
67 if (stc & (STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCtls | STC.STCmanifest | STC.STCgshared))
|
|
68 scstc &= ~(STC.STCauto | STC.STCscope | STC.STCstatic | STC.STCtls | STC.STCmanifest | STC.STCgshared);
|
|
69 if (stc & (STC.STCconst | STC.STCimmutable | STC.STCmanifest))
|
|
70 scstc &= ~(STC.STCconst | STC.STCimmutable | STC.STCmanifest);
|
|
71 if (stc & (STC.STCgshared | STC.STCshared | STC.STCtls))
|
|
72 scstc &= ~(STC.STCgshared | STC.STCshared | STC.STCtls);
|
|
73 scstc |= stc;
|
|
74
|
|
75 semanticNewSc(sc, scstc, sc.linkage, sc.protection, sc.explicitProtection, sc.structalign);
|
|
76 }
|
|
77 }
|
|
78
|
72
|
79 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
0
|
80 {
|
|
81 assert(false);
|
|
82 }
|
|
83
|
|
84 static void stcToCBuffer(OutBuffer buf, int stc)
|
|
85 {
|
|
86 struct SCstring
|
|
87 {
|
|
88 int stc;
|
|
89 TOK tok;
|
|
90 };
|
|
91
|
|
92 static SCstring[] table =
|
|
93 [
|
|
94 { STCauto, TOKauto },
|
|
95 { STCscope, TOKscope },
|
|
96 { STCstatic, TOKstatic },
|
|
97 { STCextern, TOKextern },
|
|
98 { STCconst, TOKconst },
|
|
99 { STCfinal, TOKfinal },
|
|
100 { STCabstract, TOKabstract },
|
|
101 { STCsynchronized, TOKsynchronized },
|
|
102 { STCdeprecated, TOKdeprecated },
|
|
103 { STCoverride, TOKoverride },
|
|
104 { STClazy, TOKlazy },
|
|
105 { STCalias, TOKalias },
|
|
106 { STCout, TOKout },
|
|
107 { STCin, TOKin },
|
|
108 /// version (DMDV2) {
|
|
109 /// { STCimmutable, TOKimmutable },
|
|
110 /// { STCshared, TOKshared },
|
|
111 /// { STCnothrow, TOKnothrow },
|
|
112 /// { STCpure, TOKpure },
|
|
113 /// { STCref, TOKref },
|
|
114 /// { STCtls, TOKtls },
|
|
115 /// { STCgshared, TOKgshared },
|
|
116 /// }
|
|
117 ];
|
|
118
|
|
119 for (int i = 0; i < table.length; i++)
|
|
120 {
|
|
121 if (stc & table[i].stc)
|
|
122 {
|
|
123 buf.writestring(Token.toChars(table[i].tok));
|
|
124 buf.writeByte(' ');
|
|
125 }
|
|
126 }
|
|
127 }
|
72
|
128 }
|