| 1 |
/** |
| 2 |
* Defines the `Dsymbol` representing a `static assert()`. |
| 3 |
* |
| 4 |
* Specification: $(LINK2 https://dlang.org/spec/version.html#static-assert, Static Assert) |
| 5 |
* |
| 6 |
* Copyright: Copyright (C) 1999-2025 by The D Language Foundation, All Rights Reserved |
| 7 |
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright) |
| 8 |
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) |
| 9 |
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/compiler/src/dmd/staticassert.d, _staticassert.d) |
| 10 |
* Documentation: https://dlang.org/phobos/dmd_staticassert.html |
| 11 |
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/staticassert.d |
| 12 |
*/ |
| 13 |
|
| 14 |
module dmd.staticassert; |
| 15 |
|
| 16 |
import dmd.arraytypes; |
| 17 |
import dmd.dsymbol; |
| 18 |
import dmd.expression; |
| 19 |
import dmd.location; |
| 20 |
import dmd.id; |
| 21 |
import dmd.identifier; |
| 22 |
import dmd.visitor; |
| 23 |
|
| 24 |
/*********************************************************** |
| 25 |
*/ |
| 26 |
extern (C++) final class StaticAssert : Dsymbol |
| 27 |
{ |
| 28 |
Expression exp; |
| 29 |
Expressions* msgs; |
| 30 |
|
| 31 |
extern (D) this(Loc loc, Expression exp, Expression msg) |
| 32 |
{ |
| 33 |
super(DSYM.staticAssert, loc, Id.empty); |
| 34 |
this.exp = exp; |
| 35 |
this.msgs = new Expressions(1); |
| 36 |
(*this.msgs)[0] = msg; |
| 37 |
} |
| 38 |
|
| 39 |
extern (D) this(Loc loc, Expression exp, Expressions* msgs) |
| 40 |
{ |
| 41 |
super(DSYM.staticAssert, loc, Id.empty); |
| 42 |
this.exp = exp; |
| 43 |
this.msgs = msgs; |
| 44 |
} |
| 45 |
|
| 46 |
override StaticAssert syntaxCopy(Dsymbol s) |
| 47 |
{ |
| 48 |
assert(!s); |
| 49 |
return new StaticAssert(loc, exp.syntaxCopy(), msgs ? Expression.arraySyntaxCopy(msgs) : null); |
| 50 |
} |
| 51 |
|
| 52 |
override const(char)* kind() const |
| 53 |
{ |
| 54 |
return "static assert"; |
| 55 |
} |
| 56 |
|
| 57 |
override void accept(Visitor v) |
| 58 |
{ |
| 59 |
v.visit(this); |
| 60 |
} |
| 61 |
} |