Cope with Main not being a class.
[delight/core.git] / dmd2 / staticassert.c
blob97e3a42be8fed663c213ebef60c44156f529094c
2 // Copyright (c) 1999-2007 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 <string.h>
12 #include <assert.h>
14 #include "dsymbol.h"
15 #include "staticassert.h"
16 #include "expression.h"
17 #include "id.h"
18 #include "hdrgen.h"
20 /********************************* AttribDeclaration ****************************/
22 StaticAssert::StaticAssert(Loc loc, Expression *exp, Expression *msg)
23 : Dsymbol(Id::empty)
25 this->loc = loc;
26 this->exp = exp;
27 this->msg = msg;
30 Dsymbol *StaticAssert::syntaxCopy(Dsymbol *s)
32 StaticAssert *sa;
34 assert(!s);
35 sa = new StaticAssert(loc, exp->syntaxCopy(), msg ? msg->syntaxCopy() : NULL);
36 return sa;
39 int StaticAssert::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
41 return 0; // we didn't add anything
44 void StaticAssert::semantic(Scope *sc)
48 void StaticAssert::semantic2(Scope *sc)
50 Expression *e;
52 //printf("StaticAssert::semantic2() %s\n", toChars());
53 e = exp->semantic(sc);
54 e = e->optimize(WANTvalue | WANTinterpret);
55 if (e->isBool(FALSE))
57 if (msg)
58 { HdrGenState hgs;
59 OutBuffer buf;
61 msg = msg->semantic(sc);
62 msg = msg->optimize(WANTvalue | WANTinterpret);
63 hgs.console = 1;
64 msg->toCBuffer(&buf, &hgs);
65 error("%s", buf.toChars());
67 else
68 error("is false");
69 if (!global.gag)
70 fatal();
72 else if (!e->isBool(TRUE))
74 error("(%s) is not evaluatable at compile time", exp->toChars());
78 int StaticAssert::oneMember(Dsymbol **ps)
80 //printf("StaticAssert::oneMember())\n");
81 *ps = NULL;
82 return TRUE;
85 void StaticAssert::inlineScan()
89 void StaticAssert::toObjFile(int multiobj)
93 char *StaticAssert::kind()
95 return "static assert";
98 void StaticAssert::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
100 buf->writestring(kind());
101 buf->writeByte('(');
102 exp->toCBuffer(buf, hgs);
103 if (msg)
105 buf->writeByte(',');
106 msg->toCBuffer(buf, hgs);
108 buf->writestring(");");
109 buf->writenl();