0
|
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
|
13
|
34 bool addMember(Scope sc, ScopeDsymbol sd, bool memnum)
|
0
|
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 {
|
13
|
86 //printf("StaticAssert.oneMember())\n");
|
|
87 *ps = null;
|
|
88 return true;
|
0
|
89 }
|
|
90
|
|
91 void toObjFile(int multiobj)
|
|
92 {
|
|
93 assert(false);
|
|
94 }
|
|
95
|
|
96 string kind()
|
|
97 {
|
|
98 return "static assert";
|
|
99 }
|
|
100
|
|
101 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
|
102 {
|
|
103 assert(false);
|
|
104 }
|
|
105 } |