2 // Copyright (c) 1999-2007 by Digital Mars
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.
15 #include "staticassert.h"
16 #include "expression.h"
20 /********************************* AttribDeclaration ****************************/
22 StaticAssert::StaticAssert(Loc loc
, Expression
*exp
, Expression
*msg
)
30 Dsymbol
*StaticAssert::syntaxCopy(Dsymbol
*s
)
35 sa
= new StaticAssert(loc
, exp
->syntaxCopy(), msg
? msg
->syntaxCopy() : NULL
);
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
)
52 //printf("StaticAssert::semantic2() %s\n", toChars());
53 e
= exp
->semantic(sc
);
54 e
= e
->optimize(WANTvalue
| WANTinterpret
);
61 msg
= msg
->semantic(sc
);
62 msg
= msg
->optimize(WANTvalue
| WANTinterpret
);
64 msg
->toCBuffer(&buf
, &hgs
);
65 error("%s", buf
.toChars());
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");
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());
102 exp
->toCBuffer(buf
, hgs
);
106 msg
->toCBuffer(buf
, hgs
);
108 buf
->writestring(");");