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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.VersionCondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 96
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.DVCondition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Module;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.String;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Util : error;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import std.string : startsWith;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 // for findCondition
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import core.stdc.string;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import std.stdio;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
26 bool findCondition(Vector!(string) ids, Identifier ident)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 if (ids !is null) {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
29 foreach (id; ids)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 if (id == ident.toChars()) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 class VersionCondition : DVCondition
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 static void setGlobalLevel(uint level)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 global.params.versionlevel = level;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 }
178
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
48
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 static void checkPredefined(Loc loc, string ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 {
96
acd69f84627e further work
Trass3r
parents: 72
diff changeset
51 version (DMDV2)
acd69f84627e further work
Trass3r
parents: 72
diff changeset
52 {
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
53 enum string[] reserved = [
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 "DigitalMars", "X86", "X86_64",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 "Windows", "Win32", "Win64",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 "linux",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 /* Although Posix is predefined by D1, disallowing its
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 * redefinition breaks makefiles and older builds.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 "Posix",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 "D_NET",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 "OSX", "FreeBSD",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 "Solaris",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 "LittleEndian", "BigEndian",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 "all",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 "none",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 ];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 } else {
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
69 enum string[] reserved = [
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 "DigitalMars", "X86", "X86_64",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 "Windows", "Win32", "Win64",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 "linux",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 "OSX", "FreeBSD",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 "Solaris",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 "LittleEndian", "BigEndian",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 "all",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 "none",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 ];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 foreach (reservedIdent; reserved)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 if (ident == reservedIdent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 if (ident.startsWith("D_")) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 goto Lerror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 Lerror:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 error(loc, "version identifier '%s' is reserved and cannot be set", ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 }
178
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
95
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 static void addGlobalIdent(string ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 checkPredefined(Loc(0), ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 addPredefinedGlobalIdent(ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 }
178
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
101
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 static void addPredefinedGlobalIdent(string ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
104 global.params.versionids.push(ident); ///
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 this(Module mod, uint level, Identifier ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
109 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 super(mod, level, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
113 override final bool include(Scope sc, ScopeDsymbol s)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 //printf("VersionCondition::include() level = %d, versionlevel = %d\n", level, global.params.versionlevel);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 //if (ident) printf("\tident = '%s'\n", ident->toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 if (inc == 0) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 inc = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 if (ident !is null) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 if (findCondition(mod.versionids, ident)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 inc = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 } else if (findCondition(global.params.versionids, ident)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 inc = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 } else {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
125 mod.versionidsNot.push(ident.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 } else if (level <= global.params.versionlevel || level <= mod.versionlevel) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 inc = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 return (inc == 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 }
178
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
134
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
135 override final void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 if (ident !is null) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 buf.printf("version (%s)", ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 buf.printf("version (%u)", level);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
143 }