Allow returning something of type void in a function that returns void
[delight/core.git] / dmd2 / version.c
blob18cc461a0d203dfcdb4d2716784b5bb588648d2a
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.
10 #include <stdio.h>
11 #include <assert.h>
13 #include "root.h"
15 #include "identifier.h"
16 #include "dsymbol.h"
17 #include "cond.h"
18 #include "version.h"
19 #include "module.h"
21 /* ================================================== */
23 /* DebugSymbol's happen for statements like:
24 * debug = identifier;
25 * debug = integer;
28 DebugSymbol::DebugSymbol(Loc loc, Identifier *ident)
29 : Dsymbol(ident)
31 this->loc = loc;
34 DebugSymbol::DebugSymbol(Loc loc, unsigned level)
35 : Dsymbol()
37 this->level = level;
38 this->loc = loc;
41 Dsymbol *DebugSymbol::syntaxCopy(Dsymbol *s)
43 assert(!s);
44 DebugSymbol *ds = new DebugSymbol(loc, ident);
45 ds->level = level;
46 return ds;
49 int DebugSymbol::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
51 //printf("DebugSymbol::addMember('%s') %s\n", sd->toChars(), toChars());
52 Module *m;
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)
59 if (!m)
60 error("declaration must be at module level");
61 else
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());
70 else
72 if (!m)
73 error("level declaration must be at module level");
74 else
75 m->debuglevel = level;
77 return 0;
80 void DebugSymbol::semantic(Scope *sc)
82 //printf("DebugSymbol::semantic() %s\n", toChars());
85 void DebugSymbol::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
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();
96 char *DebugSymbol::kind()
98 return "debug";
101 /* ================================================== */
103 /* VersionSymbol's happen for statements like:
104 * version = identifier;
105 * version = integer;
108 VersionSymbol::VersionSymbol(Loc loc, Identifier *ident)
109 : Dsymbol(ident)
111 this->loc = loc;
114 VersionSymbol::VersionSymbol(Loc loc, unsigned level)
115 : Dsymbol()
117 this->level = level;
118 this->loc = loc;
121 Dsymbol *VersionSymbol::syntaxCopy(Dsymbol *s)
123 assert(!s);
124 VersionSymbol *ds = new VersionSymbol(loc, ident);
125 ds->level = level;
126 return ds;
129 int VersionSymbol::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
131 //printf("VersionSymbol::addMember('%s') %s\n", sd->toChars(), toChars());
132 Module *m;
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)
139 VersionCondition::checkPredefined(loc, ident->toChars());
140 if (!m)
141 error("declaration must be at module level");
142 else
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());
151 else
153 if (!m)
154 error("level declaration must be at module level");
155 else
156 m->versionlevel = level;
158 return 0;
161 void VersionSymbol::semantic(Scope *sc)
165 void VersionSymbol::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
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();
176 char *VersionSymbol::kind()
178 return "version";