Mercurial > projects > ldc
annotate dmd/staticassert.c @ 650:aa6a0b7968f7
Added test case for bug #100
Removed dubious check for not emitting static private global in other modules without access. This should be handled properly somewhere else, it's causing unresolved global errors for stuff that should work (in MiniD)
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Sun, 05 Oct 2008 17:28:15 +0200 |
parents | d4e95db0e62b |
children | 8026319762be |
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 |
22 /********************************* AttribDeclaration ****************************/ | |
23 | |
24 StaticAssert::StaticAssert(Loc loc, Expression *exp, Expression *msg) | |
25 : Dsymbol(Id::empty) | |
26 { | |
27 this->loc = loc; | |
28 this->exp = exp; | |
29 this->msg = msg; | |
30 } | |
31 | |
32 Dsymbol *StaticAssert::syntaxCopy(Dsymbol *s) | |
33 { | |
34 StaticAssert *sa; | |
35 | |
36 assert(!s); | |
37 sa = new StaticAssert(loc, exp->syntaxCopy(), msg ? msg->syntaxCopy() : NULL); | |
38 return sa; | |
39 } | |
40 | |
41 int StaticAssert::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) | |
42 { | |
43 return 0; // we didn't add anything | |
44 } | |
45 | |
46 void StaticAssert::semantic(Scope *sc) | |
47 { | |
48 } | |
49 | |
50 void StaticAssert::semantic2(Scope *sc) | |
51 { | |
52 Expression *e; | |
53 | |
19 | 54 //printf("StaticAssert::semantic2() %s\n", toChars()); |
1 | 55 e = exp->semantic(sc); |
56 e = e->optimize(WANTvalue | WANTinterpret); | |
57 if (e->isBool(FALSE)) | |
58 { | |
59 if (msg) | |
60 { HdrGenState hgs; | |
61 OutBuffer buf; | |
62 | |
63 msg = msg->semantic(sc); | |
64 msg = msg->optimize(WANTvalue | WANTinterpret); | |
65 hgs.console = 1; | |
66 msg->toCBuffer(&buf, &hgs); | |
67 error("%s", buf.toChars()); | |
68 } | |
69 else | |
70 error("is false"); | |
561
d4e95db0e62b
Introducing template instantiation traces for static asserts and errors within templates.
Christian Kamm <kamm incasoftware de>
parents:
336
diff
changeset
|
71 if(sc->tinst) |
d4e95db0e62b
Introducing template instantiation traces for static asserts and errors within templates.
Christian Kamm <kamm incasoftware de>
parents:
336
diff
changeset
|
72 sc->tinst->printInstantiationTrace(); |
1 | 73 if (!global.gag) |
74 fatal(); | |
75 } | |
76 else if (!e->isBool(TRUE)) | |
77 { | |
78 error("(%s) is not evaluatable at compile time", exp->toChars()); | |
79 } | |
80 } | |
81 | |
82 int StaticAssert::oneMember(Dsymbol **ps) | |
83 { | |
84 //printf("StaticAssert::oneMember())\n"); | |
85 *ps = NULL; | |
86 return TRUE; | |
87 } | |
88 | |
89 void StaticAssert::inlineScan() | |
90 { | |
91 } | |
92 | |
336 | 93 void StaticAssert::toObjFile(int multiobj) |
1 | 94 { |
95 } | |
96 | |
336 | 97 const char *StaticAssert::kind() |
1 | 98 { |
99 return "static assert"; | |
100 } | |
101 | |
102 void StaticAssert::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
103 { | |
104 buf->writestring(kind()); | |
105 buf->writeByte('('); | |
106 exp->toCBuffer(buf, hgs); | |
107 if (msg) | |
108 { | |
109 buf->writeByte(','); | |
110 msg->toCBuffer(buf, hgs); | |
111 } | |
112 buf->writestring(");"); | |
113 buf->writenl(); | |
114 } |