Mercurial > projects > ddmd
annotate dmd/VersionSymbol.d @ 187:b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author | Abscissa |
---|---|
date | Tue, 07 Jun 2011 23:37:34 -0400 |
parents | e3afd1303184 |
children |
rev | line source |
---|---|
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 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
16 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
17 |
129 | 18 /* VersionSymbol's happen for statements like: |
19 * version = identifier; | |
20 * version = integer; | |
21 */ | |
0 | 22 class VersionSymbol : Dsymbol |
23 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
24 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
25 |
0 | 26 uint level; |
27 | |
28 this(Loc loc, Identifier ident) | |
29 { | |
178 | 30 register(); |
0 | 31 super(ident); |
32 this.loc = loc; | |
33 } | |
178 | 34 |
0 | 35 this(Loc loc, uint level) |
36 { | |
178 | 37 register(); |
0 | 38 super(); |
39 | |
40 this.level = level; | |
41 this.loc = loc; | |
42 } | |
178 | 43 |
72 | 44 override Dsymbol syntaxCopy(Dsymbol s) |
0 | 45 { |
129 | 46 assert(!s); |
47 VersionSymbol ds = new VersionSymbol(loc, ident); | |
48 ds.level = level; | |
49 return ds; | |
0 | 50 } |
178 | 51 |
72 | 52 override bool addMember(Scope sc, ScopeDsymbol s, bool memnum) |
0 | 53 { |
54 //printf("VersionSymbol::addMember('%s') %s\n", sd->toChars(), toChars()); | |
55 | |
56 // Do not add the member to the symbol table, | |
57 // just make sure subsequent debug declarations work. | |
58 Module m = s.isModule(); | |
59 if (ident) | |
60 { | |
61 VersionCondition.checkPredefined(loc, ident.toChars()); | |
62 if (!m) | |
63 error("declaration must be at module level"); | |
64 else | |
65 { | |
66 if (findCondition(m.versionidsNot, ident)) | |
67 error("defined after use"); | |
178 | 68 m.versionids.push(ident.toChars()); |
0 | 69 } |
70 } | |
71 else | |
72 { | |
73 if (!m) | |
74 error("level declaration must be at module level"); | |
75 else | |
76 m.versionlevel = level; | |
77 } | |
78 | |
79 return false; | |
80 } | |
178 | 81 |
72 | 82 override void semantic(Scope sc) |
0 | 83 { |
84 } | |
178 | 85 |
72 | 86 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 87 { |
129 | 88 buf.writestring("version = "); |
89 if (ident) | |
90 buf.writestring(ident.toChars()); | |
91 else | |
92 buf.printf("%u", level); | |
93 buf.writestring(";"); | |
94 buf.writenl(); | |
0 | 95 } |
178 | 96 |
72 | 97 override string kind() |
0 | 98 { |
129 | 99 return "version"; |
0 | 100 } |
72 | 101 } |