Mercurial > projects > ldc
comparison dmd/version.c @ 1:c53b6e3fe49a trunk
[svn r5] Initial commit. Most things are very rough.
author | lindquist |
---|---|
date | Sat, 01 Sep 2007 21:43:27 +0200 |
parents | |
children | aaade6ded589 |
comparison
equal
deleted
inserted
replaced
0:a9e71648e74d | 1:c53b6e3fe49a |
---|---|
1 | |
2 // Copyright (c) 1999-2005 by Digital Mars | |
3 // All Rights Reserved | |
4 // written by Walter Bright | |
5 // http://www.digitalmars.com | |
6 // License for redistribution is by either the Artistic License | |
7 // in artistic.txt, or the GNU General Public License in gnu.txt. | |
8 // See the included readme.txt for details. | |
9 | |
10 #include <stdio.h> | |
11 #include <assert.h> | |
12 | |
13 #include "root.h" | |
14 | |
15 #include "identifier.h" | |
16 #include "dsymbol.h" | |
17 #include "cond.h" | |
18 #include "version.h" | |
19 #include "module.h" | |
20 | |
21 /* ================================================== */ | |
22 | |
23 /* DebugSymbol's happen for statements like: | |
24 * debug = identifier; | |
25 * debug = integer; | |
26 */ | |
27 | |
28 DebugSymbol::DebugSymbol(Loc loc, Identifier *ident) | |
29 : Dsymbol(ident) | |
30 { | |
31 this->loc = loc; | |
32 } | |
33 | |
34 DebugSymbol::DebugSymbol(Loc loc, unsigned level) | |
35 : Dsymbol() | |
36 { | |
37 this->level = level; | |
38 this->loc = loc; | |
39 } | |
40 | |
41 Dsymbol *DebugSymbol::syntaxCopy(Dsymbol *s) | |
42 { | |
43 assert(!s); | |
44 DebugSymbol *ds = new DebugSymbol(loc, ident); | |
45 ds->level = level; | |
46 return ds; | |
47 } | |
48 | |
49 int DebugSymbol::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) | |
50 { | |
51 //printf("DebugSymbol::addMember('%s') %s\n", sd->toChars(), toChars()); | |
52 Module *m; | |
53 | |
54 // Do not add the member to the symbol table, | |
55 // just make sure subsequent debug declarations work. | |
56 m = sd->isModule(); | |
57 if (ident) | |
58 { | |
59 if (!m) | |
60 error("declaration must be at module level"); | |
61 else | |
62 { | |
63 if (findCondition(m->debugidsNot, ident)) | |
64 error("defined after use"); | |
65 if (!m->debugids) | |
66 m->debugids = new Array(); | |
67 m->debugids->push(ident->toChars()); | |
68 } | |
69 } | |
70 else | |
71 { | |
72 if (!m) | |
73 error("level declaration must be at module level"); | |
74 else | |
75 m->debuglevel = level; | |
76 } | |
77 return 0; | |
78 } | |
79 | |
80 void DebugSymbol::semantic(Scope *sc) | |
81 { | |
82 //printf("DebugSymbol::semantic() %s\n", toChars()); | |
83 } | |
84 | |
85 void DebugSymbol::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
86 { | |
87 buf->writestring("debug = "); | |
88 if (ident) | |
89 buf->writestring(ident->toChars()); | |
90 else | |
91 buf->printf("%u", level); | |
92 buf->writestring(";"); | |
93 buf->writenl(); | |
94 } | |
95 | |
96 char *DebugSymbol::kind() | |
97 { | |
98 return "debug"; | |
99 } | |
100 | |
101 /* ================================================== */ | |
102 | |
103 /* VersionSymbol's happen for statements like: | |
104 * version = identifier; | |
105 * version = integer; | |
106 */ | |
107 | |
108 VersionSymbol::VersionSymbol(Loc loc, Identifier *ident) | |
109 : Dsymbol(ident) | |
110 { | |
111 this->loc = loc; | |
112 } | |
113 | |
114 VersionSymbol::VersionSymbol(Loc loc, unsigned level) | |
115 : Dsymbol() | |
116 { | |
117 this->level = level; | |
118 this->loc = loc; | |
119 } | |
120 | |
121 Dsymbol *VersionSymbol::syntaxCopy(Dsymbol *s) | |
122 { | |
123 assert(!s); | |
124 VersionSymbol *ds = new VersionSymbol(loc, ident); | |
125 ds->level = level; | |
126 return ds; | |
127 } | |
128 | |
129 int VersionSymbol::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) | |
130 { | |
131 //printf("VersionSymbol::addMember('%s') %s\n", sd->toChars(), toChars()); | |
132 Module *m; | |
133 | |
134 // Do not add the member to the symbol table, | |
135 // just make sure subsequent debug declarations work. | |
136 m = sd->isModule(); | |
137 if (ident) | |
138 { | |
139 VersionCondition::checkPredefined(loc, ident->toChars()); | |
140 if (!m) | |
141 error("declaration must be at module level"); | |
142 else | |
143 { | |
144 if (findCondition(m->versionidsNot, ident)) | |
145 error("defined after use"); | |
146 if (!m->versionids) | |
147 m->versionids = new Array(); | |
148 m->versionids->push(ident->toChars()); | |
149 } | |
150 } | |
151 else | |
152 { | |
153 if (!m) | |
154 error("level declaration must be at module level"); | |
155 else | |
156 m->versionlevel = level; | |
157 } | |
158 return 0; | |
159 } | |
160 | |
161 void VersionSymbol::semantic(Scope *sc) | |
162 { | |
163 } | |
164 | |
165 void VersionSymbol::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
166 { | |
167 buf->writestring("version = "); | |
168 if (ident) | |
169 buf->writestring(ident->toChars()); | |
170 else | |
171 buf->printf("%u", level); | |
172 buf->writestring(";"); | |
173 buf->writenl(); | |
174 } | |
175 | |
176 char *VersionSymbol::kind() | |
177 { | |
178 return "version"; | |
179 } | |
180 | |
181 |