aboutsummaryrefslogtreecommitdiff
path: root/gcc/d/dmd/staticassert.d
blob: 0e959bc84af7c4c7fb770a9f18cc241c167b82d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
 * Defines the `Dsymbol` representing a `static assert()`.
 *
 * Specification: $(LINK2 https://dlang.org/spec/version.html#static-assert, Static Assert)
 *
 * Copyright:   Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved
 * Authors:     $(LINK2 https://www.digitalmars.com, Walter Bright)
 * License:     $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
 * Source:      $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/staticassert.d, _staticassert.d)
 * Documentation:  https://dlang.org/phobos/dmd_staticassert.html
 * Coverage:    https://codecov.io/gh/dlang/dmd/src/master/src/dmd/staticassert.d
 */

module dmd.staticassert;

import dmd.arraytypes;
import dmd.dsymbol;
import dmd.expression;
import dmd.location;
import dmd.id;
import dmd.identifier;
import dmd.visitor;

/***********************************************************
 */
extern (C++) final class StaticAssert : Dsymbol
{
    Expression exp;
    Expressions* msgs;

    extern (D) this(Loc loc, Expression exp, Expression msg)
    {
        super(DSYM.staticAssert, loc, Id.empty);
        this.exp = exp;
        this.msgs = new Expressions(1);
        (*this.msgs)[0] = msg;
    }

    extern (D) this(Loc loc, Expression exp, Expressions* msgs)
    {
        super(DSYM.staticAssert, loc, Id.empty);
        this.exp = exp;
        this.msgs = msgs;
    }

    override StaticAssert syntaxCopy(Dsymbol s)
    {
        assert(!s);
        return new StaticAssert(loc, exp.syntaxCopy(), msgs ? Expression.arraySyntaxCopy(msgs) : null);
    }

    override const(char)* kind() const
    {
        return "static assert";
    }

    override void accept(Visitor v)
    {
        v.visit(this);
    }
}