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-2023 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/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/src/dmd/staticassert.d 12 */ 13 14 module dmd.staticassert; 15 16 import dmd.arraytypes; 17 import dmd.dscope; 18 import dmd.dsymbol; 19 import dmd.expression; 20 import dmd.globals; 21 import dmd.location; 22 import dmd.id; 23 import dmd.identifier; 24 import dmd.mtype; 25 import dmd.visitor; 26 27 /*********************************************************** 28 */ 29 extern (C++) final class StaticAssert : Dsymbol 30 { 31 Expression exp; 32 Expressions* msgs; 33 34 extern (D) this(const ref Loc loc, Expression exp, Expression msg) 35 { 36 super(loc, Id.empty); 37 this.exp = exp; 38 this.msgs = new Expressions(1); 39 (*this.msgs)[0] = msg; 40 } 41 42 extern (D) this(const ref Loc loc, Expression exp, Expressions* msgs) 43 { 44 super(loc, Id.empty); 45 this.exp = exp; 46 this.msgs = msgs; 47 } 48 49 override StaticAssert syntaxCopy(Dsymbol s) 50 { 51 assert(!s); 52 return new StaticAssert(loc, exp.syntaxCopy(), msgs ? Expression.arraySyntaxCopy(msgs) : null); 53 } 54 55 override void addMember(Scope* sc, ScopeDsymbol sds) 56 { 57 // we didn't add anything 58 } 59 60 override bool oneMember(Dsymbol* ps, Identifier ident) 61 { 62 //printf("StaticAssert::oneMember())\n"); 63 *ps = null; 64 return true; 65 } 66 67 override const(char)* kind() const 68 { 69 return "static assert"; 70 } 71 72 override inout(StaticAssert) isStaticAssert() inout 73 { 74 return this; 75 } 76 77 override void accept(Visitor v) 78 { 79 v.visit(this); 80 } 81 }