]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/d/dmd/staticassert.c
2 /* Compiler implementation of the D programming language
3 * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved
4 * written by Walter Bright
5 * http://www.digitalmars.com
6 * Distributed under the Boost Software License, Version 1.0.
7 * http://www.boost.org/LICENSE_1_0.txt
8 * https://github.com/D-Programming-Language/dmd/blob/master/src/staticassert.c
17 #include "staticassert.h"
18 #include "expression.h"
22 #include "declaration.h"
24 Expression
*semantic(Expression
*e
, Scope
*sc
);
25 bool evalStaticCondition(Scope
*sc
, Expression
*exp
, Expression
*e
, bool &errors
);
27 /********************************* AttribDeclaration ****************************/
29 StaticAssert::StaticAssert(Loc loc
, Expression
*exp
, Expression
*msg
)
37 Dsymbol
*StaticAssert::syntaxCopy(Dsymbol
*s
)
40 return new StaticAssert(loc
, exp
->syntaxCopy(), msg
? msg
->syntaxCopy() : NULL
);
43 void StaticAssert::addMember(Scope
*, ScopeDsymbol
*)
45 // we didn't add anything
48 void StaticAssert::semantic(Scope
*)
52 void StaticAssert::semantic2(Scope
*sc
)
54 //printf("StaticAssert::semantic2() %s\n", toChars());
55 ScopeDsymbol
*sds
= new ScopeDsymbol();
61 bool result
= evalStaticCondition(sc
, exp
, exp
, errors
);
65 errorSupplemental(loc
, "while evaluating: static assert(%s)", exp
->toChars());
72 msg
= ::semantic(msg
, sc
);
73 msg
= resolveProperties(sc
, msg
);
75 msg
= msg
->ctfeInterpret();
76 if (StringExp
* se
= msg
->toStringExp())
78 // same with pragma(msg)
80 error("\"%.*s\"", (int)se
->len
, (char *)se
->string
);
83 error("%s", msg
->toChars());
86 error("(%s) is false", exp
->toChars());
88 sc
->tinst
->printInstantiationTrace();
94 bool StaticAssert::oneMember(Dsymbol
**ps
, Identifier
*)
96 //printf("StaticAssert::oneMember())\n");
101 const char *StaticAssert::kind()
103 return "static assert";