| 1 |
|
| 2 |
/* Compiler implementation of the D programming language |
| 3 |
* Copyright (C) 1999-2025 by The D Language Foundation, All Rights Reserved |
| 4 |
* written by Walter Bright |
| 5 |
* https://www.digitalmars.com |
| 6 |
* Distributed under the Boost Software License, Version 1.0. |
| 7 |
* https://www.boost.org/LICENSE_1_0.txt |
| 8 |
* https://github.com/dlang/dmd/blob/master/src/dmd/cond.h |
| 9 |
*/ |
| 10 |
|
| 11 |
#pragma once |
| 12 |
|
| 13 |
#include "ast_node.h" |
| 14 |
#include "globals.h" |
| 15 |
#include "visitor.h" |
| 16 |
|
| 17 |
class Expression; |
| 18 |
class Identifier; |
| 19 |
class Module; |
| 20 |
struct Scope; |
| 21 |
class DebugCondition; |
| 22 |
class ForeachStatement; |
| 23 |
class ForeachRangeStatement; |
| 24 |
|
| 25 |
enum Include |
| 26 |
{ |
| 27 |
INCLUDEnotComputed, /// not computed yet |
| 28 |
INCLUDEyes, /// include the conditional code |
| 29 |
INCLUDEno /// do not include the conditional code |
| 30 |
}; |
| 31 |
|
| 32 |
class Condition : public ASTNode |
| 33 |
{ |
| 34 |
public: |
| 35 |
Loc loc; |
| 36 |
Include inc; |
| 37 |
|
| 38 |
DYNCAST dyncast() const override final { return DYNCAST_CONDITION; } |
| 39 |
|
| 40 |
virtual Condition *syntaxCopy() = 0; |
| 41 |
virtual int include(Scope *sc) = 0; |
| 42 |
virtual DebugCondition *isDebugCondition() { return nullptr; } |
| 43 |
virtual VersionCondition *isVersionCondition() { return nullptr; } |
| 44 |
void accept(Visitor *v) override { v->visit(this); } |
| 45 |
}; |
| 46 |
|
| 47 |
class StaticForeach final : public RootObject |
| 48 |
{ |
| 49 |
public: |
| 50 |
Loc loc; |
| 51 |
|
| 52 |
ForeachStatement *aggrfe; |
| 53 |
ForeachRangeStatement *rangefe; |
| 54 |
|
| 55 |
d_bool needExpansion; |
| 56 |
}; |
| 57 |
|
| 58 |
class DVCondition : public Condition |
| 59 |
{ |
| 60 |
public: |
| 61 |
Identifier *ident; |
| 62 |
Module *mod; |
| 63 |
|
| 64 |
DVCondition *syntaxCopy() override final; |
| 65 |
void accept(Visitor *v) override { v->visit(this); } |
| 66 |
}; |
| 67 |
|
| 68 |
class DebugCondition final : public DVCondition |
| 69 |
{ |
| 70 |
public: |
| 71 |
static void addGlobalIdent(const char *ident); |
| 72 |
|
| 73 |
int include(Scope *sc) override; |
| 74 |
void accept(Visitor *v) override { v->visit(this); } |
| 75 |
}; |
| 76 |
|
| 77 |
class VersionCondition final : public DVCondition |
| 78 |
{ |
| 79 |
public: |
| 80 |
static void addGlobalIdent(const char *ident); |
| 81 |
static void addPredefinedGlobalIdent(const char *ident); |
| 82 |
|
| 83 |
int include(Scope *sc) override; |
| 84 |
void accept(Visitor *v) override { v->visit(this); } |
| 85 |
}; |
| 86 |
|
| 87 |
class StaticIfCondition final : public Condition |
| 88 |
{ |
| 89 |
public: |
| 90 |
Expression *exp; |
| 91 |
|
| 92 |
StaticIfCondition *syntaxCopy() override; |
| 93 |
int include(Scope *sc) override; |
| 94 |
void accept(Visitor *v) override { v->visit(this); } |
| 95 |
}; |