1 2 /* Compiler implementation of the D programming language 3 * Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved 4 * written by Walter Bright 5 * http://www.digitalmars.com 6 * Distributed under the Boost Software License, Version 1.0. 7 * http://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 struct OutBuffer; 20 class Module; 21 struct Scope; 22 class ScopeDsymbol; 23 class DebugCondition; 24 class ForeachStatement; 25 class ForeachRangeStatement; 26 27 int findCondition(Identifiers *ids, Identifier *ident); 28 29 class Condition : public ASTNode 30 { 31 public: 32 Loc loc; 33 // 0: not computed yet 34 // 1: include 35 // 2: do not include 36 int inc; 37 38 Condition(Loc loc); 39 40 virtual Condition *syntaxCopy() = 0; 41 virtual int include(Scope *sc) = 0; isDebugCondition()42 virtual DebugCondition *isDebugCondition() { return NULL; } isVersionCondition()43 virtual VersionCondition *isVersionCondition() { return NULL; } accept(Visitor * v)44 void accept(Visitor *v) { v->visit(this); } 45 }; 46 47 class StaticForeach 48 { 49 public: 50 Loc loc; 51 52 ForeachStatement *aggrfe; 53 ForeachRangeStatement *rangefe; 54 55 bool needExpansion; 56 57 StaticForeach(Loc loc, ForeachStatement *aggrfe, ForeachRangeStatement *rangefe); 58 StaticForeach *syntaxCopy(); 59 }; 60 61 void staticForeachPrepare(StaticForeach *sfe, Scope *sc); 62 bool staticForeachReady(StaticForeach *sfe); 63 64 class DVCondition : public Condition 65 { 66 public: 67 unsigned level; 68 Identifier *ident; 69 Module *mod; 70 71 DVCondition(Module *mod, unsigned level, Identifier *ident); 72 73 Condition *syntaxCopy(); accept(Visitor * v)74 void accept(Visitor *v) { v->visit(this); } 75 }; 76 77 class DebugCondition : public DVCondition 78 { 79 public: 80 static void addGlobalIdent(const char *ident); 81 82 DebugCondition(Module *mod, unsigned level, Identifier *ident); 83 84 int include(Scope *sc); isDebugCondition()85 DebugCondition *isDebugCondition() { return this; } accept(Visitor * v)86 void accept(Visitor *v) { v->visit(this); } 87 }; 88 89 class VersionCondition : public DVCondition 90 { 91 public: 92 static void addGlobalIdent(const char *ident); 93 static void addPredefinedGlobalIdent(const char *ident); 94 95 VersionCondition(Module *mod, unsigned level, Identifier *ident); 96 97 int include(Scope *sc); isVersionCondition()98 VersionCondition *isVersionCondition() { return this; } accept(Visitor * v)99 void accept(Visitor *v) { v->visit(this); } 100 }; 101 102 class StaticIfCondition : public Condition 103 { 104 public: 105 Expression *exp; 106 107 StaticIfCondition(Loc loc, Expression *exp); 108 Condition *syntaxCopy(); 109 int include(Scope *sc); accept(Visitor * v)110 void accept(Visitor *v) { v->visit(this); } 111 }; 112