Mercurial > projects > ddmd
annotate dmd/StaticAssert.d @ 187:b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author | Abscissa |
---|---|
date | Tue, 07 Jun 2011 23:37:34 -0400 |
parents | e3afd1303184 |
children |
rev | line source |
---|---|
0 | 1 module dmd.StaticAssert; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Dsymbol; |
5 import dmd.Expression; | |
6 import dmd.OutBuffer; | |
7 import dmd.HdrGenState; | |
8 import dmd.ScopeDsymbol; | |
9 import dmd.Loc; | |
10 import dmd.Scope; | |
11 import dmd.Id; | |
12 import dmd.WANT; | |
13 import dmd.Global; | |
14 import dmd.Util; | |
15 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
16 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
17 |
0 | 18 class StaticAssert : Dsymbol |
19 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
20 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
21 |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
22 Expression exp; |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
23 Expression msg; |
0 | 24 |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
25 this(Loc loc, Expression exp, Expression msg) |
0 | 26 { |
178 | 27 register(); |
0 | 28 super(Id.empty); |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
29 |
0 | 30 this.loc = loc; |
31 this.exp = exp; | |
32 this.msg = msg; | |
33 } | |
34 | |
72 | 35 override Dsymbol syntaxCopy(Dsymbol s) |
0 | 36 { |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
37 StaticAssert sa; |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
38 |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
39 assert(!s); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
40 sa = new StaticAssert(loc, exp.syntaxCopy(), msg ? msg.syntaxCopy() : null); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
41 return sa; |
0 | 42 } |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
43 |
72 | 44 override bool addMember(Scope sc, ScopeDsymbol sd, bool memnum) |
0 | 45 { |
46 return false; // we didn't add anything | |
47 } | |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
48 |
72 | 49 override void semantic(Scope sc) |
0 | 50 { |
51 } | |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
52 |
72 | 53 override void semantic2(Scope sc) |
0 | 54 { |
55 Expression e; | |
56 | |
57 //printf("StaticAssert::semantic2() %s\n", toChars()); | |
58 e = exp.semantic(sc); | |
59 e = e.optimize(WANT.WANTvalue | WANT.WANTinterpret); | |
60 if (e.isBool(false)) | |
61 { | |
62 if (msg) | |
63 { | |
64 HdrGenState hgs; | |
65 scope OutBuffer buf = new OutBuffer(); | |
66 | |
67 msg = msg.semantic(sc); | |
68 msg = msg.optimize(WANT.WANTvalue | WANT.WANTinterpret); | |
69 hgs.console = 1; | |
70 msg.toCBuffer(buf, &hgs); | |
71 error("%s", buf.toChars()); | |
72 } | |
73 else | |
74 error("(%s) is false", exp.toChars()); | |
75 | |
135 | 76 if (sc.tinst) |
0 | 77 sc.tinst.printInstantiationTrace(); |
78 | |
135 | 79 if (!global.gag) |
0 | 80 fatal(); |
81 } | |
82 else if (!e.isBool(true)) | |
83 { | |
84 error("(%s) is not evaluatable at compile time", exp.toChars()); | |
85 } | |
86 } | |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
87 |
72 | 88 override void inlineScan() |
0 | 89 { |
90 } | |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
91 |
72 | 92 override bool oneMember(Dsymbol* ps) |
0 | 93 { |
13 | 94 //printf("StaticAssert.oneMember())\n"); |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
95 *ps = null; |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
96 return true; |
0 | 97 } |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
98 |
72 | 99 override void toObjFile(int multiobj) |
0 | 100 { |
101 } | |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
102 |
72 | 103 override string kind() |
0 | 104 { |
105 return "static assert"; | |
106 } | |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
107 |
72 | 108 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 109 { |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
110 buf.writestring(kind()); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
111 buf.writeByte('('); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
112 exp.toCBuffer(buf, hgs); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
113 if (msg) |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
114 { |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
115 buf.writeByte(','); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
116 msg.toCBuffer(buf, hgs); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
117 } |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
118 buf.writestring(");"); |
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
119 buf.writenl(); |
0 | 120 } |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
121 } |