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