Mercurial > projects > ddmd
comparison dmd/StaticAssert.d @ 0:10317f0c89a5
Initial commit
author | korDen |
---|---|
date | Sat, 24 Oct 2009 08:42:06 +0400 |
parents | |
children | 427f8aa74d28 1628b221808d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:10317f0c89a5 |
---|---|
1 module dmd.StaticAssert; | |
2 | |
3 import dmd.Dsymbol; | |
4 import dmd.Expression; | |
5 import dmd.OutBuffer; | |
6 import dmd.HdrGenState; | |
7 import dmd.ScopeDsymbol; | |
8 import dmd.Loc; | |
9 import dmd.Scope; | |
10 import dmd.Id; | |
11 import dmd.WANT; | |
12 import dmd.Global; | |
13 import dmd.Util; | |
14 | |
15 class StaticAssert : Dsymbol | |
16 { | |
17 Expression exp; | |
18 Expression msg; | |
19 | |
20 this(Loc loc, Expression exp, Expression msg) | |
21 { | |
22 super(Id.empty); | |
23 | |
24 this.loc = loc; | |
25 this.exp = exp; | |
26 this.msg = msg; | |
27 } | |
28 | |
29 Dsymbol syntaxCopy(Dsymbol s) | |
30 { | |
31 assert(false); | |
32 } | |
33 | |
34 bool addMember(Scope sc, ScopeDsymbol sd, int memnum) | |
35 { | |
36 return false; // we didn't add anything | |
37 } | |
38 | |
39 void semantic(Scope sc) | |
40 { | |
41 } | |
42 | |
43 void semantic2(Scope sc) | |
44 { | |
45 Expression e; | |
46 | |
47 //printf("StaticAssert::semantic2() %s\n", toChars()); | |
48 e = exp.semantic(sc); | |
49 e = e.optimize(WANT.WANTvalue | WANT.WANTinterpret); | |
50 if (e.isBool(false)) | |
51 { | |
52 if (msg) | |
53 { | |
54 HdrGenState hgs; | |
55 scope OutBuffer buf = new OutBuffer(); | |
56 | |
57 msg = msg.semantic(sc); | |
58 msg = msg.optimize(WANT.WANTvalue | WANT.WANTinterpret); | |
59 hgs.console = 1; | |
60 msg.toCBuffer(buf, &hgs); | |
61 error("%s", buf.toChars()); | |
62 } | |
63 else | |
64 error("(%s) is false", exp.toChars()); | |
65 | |
66 if(sc.tinst) | |
67 sc.tinst.printInstantiationTrace(); | |
68 | |
69 if (!global.gag) { | |
70 fatal(); | |
71 } | |
72 } | |
73 else if (!e.isBool(true)) | |
74 { | |
75 error("(%s) is not evaluatable at compile time", exp.toChars()); | |
76 } | |
77 } | |
78 | |
79 void inlineScan() | |
80 { | |
81 assert(false); | |
82 } | |
83 | |
84 bool oneMember(Dsymbol* ps) | |
85 { | |
86 assert(false); | |
87 } | |
88 | |
89 void toObjFile(int multiobj) | |
90 { | |
91 assert(false); | |
92 } | |
93 | |
94 string kind() | |
95 { | |
96 return "static assert"; | |
97 } | |
98 | |
99 void toCBuffer(OutBuffer buf, HdrGenState* hgs) | |
100 { | |
101 assert(false); | |
102 } | |
103 } |