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 {
|
|
26 super(ident);
|
|
27 this.loc = loc;
|
|
28 }
|
|
29
|
|
30 this(Loc loc, uint level)
|
|
31 {
|
|
32 super();
|
|
33
|
|
34 this.level = level;
|
|
35 this.loc = loc;
|
|
36 }
|
|
37
|
72
|
38 override Dsymbol syntaxCopy(Dsymbol s)
|
0
|
39 {
|
129
|
40 assert(!s);
|
|
41 VersionSymbol ds = new VersionSymbol(loc, ident);
|
|
42 ds.level = level;
|
|
43 return ds;
|
0
|
44 }
|
|
45
|
72
|
46 override bool addMember(Scope sc, ScopeDsymbol s, bool memnum)
|
0
|
47 {
|
|
48 //printf("VersionSymbol::addMember('%s') %s\n", sd->toChars(), toChars());
|
|
49
|
|
50 // Do not add the member to the symbol table,
|
|
51 // just make sure subsequent debug declarations work.
|
|
52 Module m = s.isModule();
|
|
53 if (ident)
|
|
54 {
|
|
55 VersionCondition.checkPredefined(loc, ident.toChars());
|
|
56 if (!m)
|
|
57 error("declaration must be at module level");
|
|
58 else
|
|
59 {
|
|
60 if (findCondition(m.versionidsNot, ident))
|
|
61 error("defined after use");
|
|
62 if (!m.versionids)
|
|
63 m.versionids = new Array();
|
|
64 m.versionids.push(cast(void*)new String(ident.toChars()));
|
|
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 }
|
|
77
|
72
|
78 override void semantic(Scope sc)
|
0
|
79 {
|
|
80 }
|
|
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 }
|
|
92
|
72
|
93 override string kind()
|
0
|
94 {
|
129
|
95 return "version";
|
0
|
96 }
|
72
|
97 }
|