Mercurial > projects > ldc
annotate dmd/staticassert.c @ 1553:f55ca8a1598c
Value::getNameStart and Value::getNameLength were removed
author | Benjamin Kramer <benny.kra@gmail.com> |
---|---|
date | Thu, 23 Jul 2009 20:34:35 +0200 |
parents | 8026319762be |
children | 1b24e9c7cc26 |
rev | line source |
---|---|
1 | 1 |
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. | |
9 | |
10 #include <stdio.h> | |
11 #include <string.h> | |
12 #include <assert.h> | |
13 | |
14 #include "dsymbol.h" | |
15 #include "staticassert.h" | |
16 #include "expression.h" | |
17 #include "id.h" | |
18 #include "hdrgen.h" | |
561
d4e95db0e62b
Introducing template instantiation traces for static asserts and errors within templates.
Christian Kamm <kamm incasoftware de>
parents:
336
diff
changeset
|
19 #include "scope.h" |
d4e95db0e62b
Introducing template instantiation traces for static asserts and errors within templates.
Christian Kamm <kamm incasoftware de>
parents:
336
diff
changeset
|
20 #include "template.h" |
1 | 21 |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
561
diff
changeset
|
22 |
1 | 23 /********************************* AttribDeclaration ****************************/ |
24 | |
25 StaticAssert::StaticAssert(Loc loc, Expression *exp, Expression *msg) | |
26 : Dsymbol(Id::empty) | |
27 { | |
28 this->loc = loc; | |
29 this->exp = exp; | |
30 this->msg = msg; | |
31 } | |
32 | |
33 Dsymbol *StaticAssert::syntaxCopy(Dsymbol *s) | |
34 { | |
35 StaticAssert *sa; | |
36 | |
37 assert(!s); | |
38 sa = new StaticAssert(loc, exp->syntaxCopy(), msg ? msg->syntaxCopy() : NULL); | |
39 return sa; | |
40 } | |
41 | |
42 int StaticAssert::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) | |
43 { | |
44 return 0; // we didn't add anything | |
45 } | |
46 | |
47 void StaticAssert::semantic(Scope *sc) | |
48 { | |
49 } | |
50 | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
561
diff
changeset
|
51 #include "scope.h" |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
561
diff
changeset
|
52 #include "template.h" |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
561
diff
changeset
|
53 #include "declaration.h" |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
561
diff
changeset
|
54 |
1 | 55 void StaticAssert::semantic2(Scope *sc) |
56 { | |
57 Expression *e; | |
58 | |
19 | 59 //printf("StaticAssert::semantic2() %s\n", toChars()); |
1 | 60 e = exp->semantic(sc); |
61 e = e->optimize(WANTvalue | WANTinterpret); | |
62 if (e->isBool(FALSE)) | |
63 { | |
64 if (msg) | |
65 { HdrGenState hgs; | |
66 OutBuffer buf; | |
67 | |
68 msg = msg->semantic(sc); | |
69 msg = msg->optimize(WANTvalue | WANTinterpret); | |
70 hgs.console = 1; | |
71 msg->toCBuffer(&buf, &hgs); | |
72 error("%s", buf.toChars()); | |
73 } | |
74 else | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
561
diff
changeset
|
75 error("(%s) is false", exp->toChars()); |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
561
diff
changeset
|
76 if(sc->tinst) |
561
d4e95db0e62b
Introducing template instantiation traces for static asserts and errors within templates.
Christian Kamm <kamm incasoftware de>
parents:
336
diff
changeset
|
77 sc->tinst->printInstantiationTrace(); |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
561
diff
changeset
|
78 if (!global.gag) { |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
561
diff
changeset
|
79 fatal(); |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
561
diff
changeset
|
80 } |
1 | 81 } |
82 else if (!e->isBool(TRUE)) | |
83 { | |
84 error("(%s) is not evaluatable at compile time", exp->toChars()); | |
85 } | |
86 } | |
87 | |
88 int StaticAssert::oneMember(Dsymbol **ps) | |
89 { | |
90 //printf("StaticAssert::oneMember())\n"); | |
91 *ps = NULL; | |
92 return TRUE; | |
93 } | |
94 | |
95 void StaticAssert::inlineScan() | |
96 { | |
97 } | |
98 | |
336 | 99 void StaticAssert::toObjFile(int multiobj) |
1 | 100 { |
101 } | |
102 | |
336 | 103 const char *StaticAssert::kind() |
1 | 104 { |
105 return "static assert"; | |
106 } | |
107 | |
108 void StaticAssert::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
109 { | |
110 buf->writestring(kind()); | |
111 buf->writeByte('('); | |
112 exp->toCBuffer(buf, hgs); | |
113 if (msg) | |
114 { | |
115 buf->writeByte(','); | |
116 msg->toCBuffer(buf, hgs); | |
117 } | |
118 buf->writestring(");"); | |
119 buf->writenl(); | |
120 } |