0
|
1 module dmd.VersionSymbol;
|
|
2
|
114
|
3 import dmd.common;
|
0
|
4 import dmd.Dsymbol;
|
|
5 import dmd.Loc;
|
|
6 import dmd.Identifier;
|
|
7 import dmd.Module;
|
|
8 import dmd.Array;
|
|
9 import dmd.VersionCondition;
|
|
10 import dmd.Scope;
|
|
11 import dmd.ScopeDsymbol;
|
|
12 import dmd.HdrGenState;
|
|
13 import dmd.String;
|
|
14 import dmd.OutBuffer;
|
|
15
|
129
|
16 /* VersionSymbol's happen for statements like:
|
|
17 * version = identifier;
|
|
18 * version = integer;
|
|
19 */
|
0
|
20 class VersionSymbol : Dsymbol
|
|
21 {
|
|
22 uint level;
|
|
23
|
|
24 this(Loc loc, Identifier ident)
|
|
25 {
|
178
|
26 register();
|
0
|
27 super(ident);
|
|
28 this.loc = loc;
|
|
29 }
|
178
|
30
|
0
|
31 this(Loc loc, uint level)
|
|
32 {
|
178
|
33 register();
|
0
|
34 super();
|
|
35
|
|
36 this.level = level;
|
|
37 this.loc = loc;
|
|
38 }
|
178
|
39
|
72
|
40 override Dsymbol syntaxCopy(Dsymbol s)
|
0
|
41 {
|
129
|
42 assert(!s);
|
|
43 VersionSymbol ds = new VersionSymbol(loc, ident);
|
|
44 ds.level = level;
|
|
45 return ds;
|
0
|
46 }
|
178
|
47
|
72
|
48 override bool addMember(Scope sc, ScopeDsymbol s, bool memnum)
|
0
|
49 {
|
|
50 //printf("VersionSymbol::addMember('%s') %s\n", sd->toChars(), toChars());
|
|
51
|
|
52 // Do not add the member to the symbol table,
|
|
53 // just make sure subsequent debug declarations work.
|
|
54 Module m = s.isModule();
|
|
55 if (ident)
|
|
56 {
|
|
57 VersionCondition.checkPredefined(loc, ident.toChars());
|
|
58 if (!m)
|
|
59 error("declaration must be at module level");
|
|
60 else
|
|
61 {
|
|
62 if (findCondition(m.versionidsNot, ident))
|
|
63 error("defined after use");
|
178
|
64 m.versionids.push(ident.toChars());
|
0
|
65 }
|
|
66 }
|
|
67 else
|
|
68 {
|
|
69 if (!m)
|
|
70 error("level declaration must be at module level");
|
|
71 else
|
|
72 m.versionlevel = level;
|
|
73 }
|
|
74
|
|
75 return false;
|
|
76 }
|
178
|
77
|
72
|
78 override void semantic(Scope sc)
|
0
|
79 {
|
|
80 }
|
178
|
81
|
72
|
82 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
0
|
83 {
|
129
|
84 buf.writestring("version = ");
|
|
85 if (ident)
|
|
86 buf.writestring(ident.toChars());
|
|
87 else
|
|
88 buf.printf("%u", level);
|
|
89 buf.writestring(";");
|
|
90 buf.writenl();
|
0
|
91 }
|
178
|
92
|
72
|
93 override string kind()
|
0
|
94 {
|
129
|
95 return "version";
|
0
|
96 }
|
72
|
97 }
|