aboutsummaryrefslogtreecommitdiff
path: root/gcc/d/dmd/cond.h
blob: 45094d14991f7d7d8ab35bce5c45370ab8613e21 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

/* Compiler implementation of the D programming language
 * Copyright (C) 1999-2023 by The D Language Foundation, All Rights Reserved
 * written by Walter Bright
 * https://www.digitalmars.com
 * Distributed under the Boost Software License, Version 1.0.
 * https://www.boost.org/LICENSE_1_0.txt
 * https://github.com/dlang/dmd/blob/master/src/dmd/cond.h
 */

#pragma once

#include "ast_node.h"
#include "globals.h"
#include "visitor.h"

class Expression;
class Identifier;
class Module;
struct Scope;
class DebugCondition;
class ForeachStatement;
class ForeachRangeStatement;

enum Include
{
    INCLUDEnotComputed, /// not computed yet
    INCLUDEyes,         /// include the conditional code
    INCLUDEno           /// do not include the conditional code
};

class Condition : public ASTNode
{
public:
    Loc loc;
    Include inc;

    DYNCAST dyncast() const override final { return DYNCAST_CONDITION; }

    virtual Condition *syntaxCopy() = 0;
    virtual int include(Scope *sc) = 0;
    virtual DebugCondition *isDebugCondition() { return NULL; }
    virtual VersionCondition *isVersionCondition() { return NULL; }
    void accept(Visitor *v) override { v->visit(this); }
};

class StaticForeach final : public RootObject
{
public:
    Loc loc;

    ForeachStatement *aggrfe;
    ForeachRangeStatement *rangefe;

    d_bool needExpansion;

    StaticForeach *syntaxCopy();
};

class DVCondition : public Condition
{
public:
    unsigned level;
    Identifier *ident;
    Module *mod;

    DVCondition *syntaxCopy() override final;
    void accept(Visitor *v) override { v->visit(this); }
};

class DebugCondition final : public DVCondition
{
public:
    static void addGlobalIdent(const char *ident);

    int include(Scope *sc) override;
    DebugCondition *isDebugCondition() override { return this; }
    void accept(Visitor *v) override { v->visit(this); }
};

class VersionCondition final : public DVCondition
{
public:
    static void addGlobalIdent(const char *ident);
    static void addPredefinedGlobalIdent(const char *ident);

    int include(Scope *sc) override;
    VersionCondition *isVersionCondition() override { return this; }
    void accept(Visitor *v) override { v->visit(this); }
};

class StaticIfCondition final : public Condition
{
public:
    Expression *exp;

    StaticIfCondition *syntaxCopy() override;
    int include(Scope *sc) override;
    void accept(Visitor *v) override { v->visit(this); }
};