Mercurial > projects > ddmd
annotate dmd/VersionCondition.d @ 192:eb38fdcb3e62 default tip
updated to compile with dmd2.062
author | korDen |
---|---|
date | Sat, 02 Mar 2013 01:25:52 -0800 |
parents | b0d41ff5e0df |
children |
rev | line source |
---|---|
0 | 1 module dmd.VersionCondition; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.DVCondition; |
5 import dmd.Loc; | |
6 import dmd.Module; | |
7 import dmd.Scope; | |
8 import dmd.ScopeDsymbol; | |
9 import dmd.OutBuffer; | |
10 import dmd.HdrGenState; | |
11 import dmd.Identifier; | |
12 import dmd.Global; | |
13 import dmd.String; | |
14 import dmd.Util : error; | |
15 | |
16 import std.string : startsWith; | |
17 | |
18 // for findCondition | |
19 import dmd.Array; | |
20 import core.stdc.string; | |
21 | |
22 import std.stdio; | |
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 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
|
25 |
178 | 26 bool findCondition(Vector!(string) ids, Identifier ident) |
0 | 27 { |
28 if (ids !is null) { | |
178 | 29 foreach (id; ids) |
0 | 30 { |
31 if (id == ident.toChars()) { | |
32 return true; | |
33 } | |
34 } | |
35 } | |
36 | |
37 return false; | |
38 } | |
39 | |
40 class VersionCondition : DVCondition | |
41 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
42 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
|
43 |
0 | 44 static void setGlobalLevel(uint level) |
45 { | |
46 global.params.versionlevel = level; | |
47 } | |
178 | 48 |
0 | 49 static void checkPredefined(Loc loc, string ident) |
50 { | |
96 | 51 version (DMDV2) |
52 { | |
174 | 53 enum string[] reserved = [ |
0 | 54 "DigitalMars", "X86", "X86_64", |
55 "Windows", "Win32", "Win64", | |
56 "linux", | |
57 /* Although Posix is predefined by D1, disallowing its | |
58 * redefinition breaks makefiles and older builds. | |
59 */ | |
60 "Posix", | |
61 "D_NET", | |
62 "OSX", "FreeBSD", | |
63 "Solaris", | |
64 "LittleEndian", "BigEndian", | |
65 "all", | |
66 "none", | |
67 ]; | |
68 } else { | |
174 | 69 enum string[] reserved = [ |
0 | 70 "DigitalMars", "X86", "X86_64", |
71 "Windows", "Win32", "Win64", | |
72 "linux", | |
73 "OSX", "FreeBSD", | |
74 "Solaris", | |
75 "LittleEndian", "BigEndian", | |
76 "all", | |
77 "none", | |
78 ]; | |
79 } | |
80 foreach (reservedIdent; reserved) | |
81 { | |
82 if (ident == reservedIdent) | |
83 goto Lerror; | |
84 } | |
85 | |
86 if (ident.startsWith("D_")) { | |
87 goto Lerror; | |
88 } | |
89 | |
90 return; | |
91 | |
92 Lerror: | |
93 error(loc, "version identifier '%s' is reserved and cannot be set", ident); | |
94 } | |
178 | 95 |
0 | 96 static void addGlobalIdent(string ident) |
97 { | |
98 checkPredefined(Loc(0), ident); | |
99 addPredefinedGlobalIdent(ident); | |
100 } | |
178 | 101 |
0 | 102 static void addPredefinedGlobalIdent(string ident) |
103 { | |
178 | 104 global.params.versionids.push(ident); /// |
0 | 105 } |
106 | |
107 this(Module mod, uint level, Identifier ident) | |
108 { | |
178 | 109 register(); |
0 | 110 super(mod, level, ident); |
111 } | |
112 | |
72 | 113 override final bool include(Scope sc, ScopeDsymbol s) |
0 | 114 { |
115 //printf("VersionCondition::include() level = %d, versionlevel = %d\n", level, global.params.versionlevel); | |
116 //if (ident) printf("\tident = '%s'\n", ident->toChars()); | |
117 if (inc == 0) { | |
118 inc = 2; | |
119 if (ident !is null) { | |
120 if (findCondition(mod.versionids, ident)) { | |
121 inc = 1; | |
122 } else if (findCondition(global.params.versionids, ident)) { | |
123 inc = 1; | |
124 } else { | |
178 | 125 mod.versionidsNot.push(ident.toChars()); |
0 | 126 } |
127 } else if (level <= global.params.versionlevel || level <= mod.versionlevel) { | |
128 inc = 1; | |
129 } | |
130 } | |
131 | |
132 return (inc == 1); | |
133 } | |
178 | 134 |
72 | 135 override final void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 136 { |
137 if (ident !is null) { | |
138 buf.printf("version (%s)", ident.toChars()); | |
139 } else { | |
140 buf.printf("version (%u)", level); | |
141 } | |
142 } | |
72 | 143 } |