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 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 virtual Condition *syntaxCopy() = 0; 39 virtual int include(Scope *sc) = 0; isDebugCondition()40 virtual DebugCondition *isDebugCondition() { return NULL; } isVersionCondition()41 virtual VersionCondition *isVersionCondition() { return NULL; } accept(Visitor * v)42 void accept(Visitor *v) { v->visit(this); } 43 }; 44 45 class StaticForeach 46 { 47 public: 48 Loc loc; 49 50 ForeachStatement *aggrfe; 51 ForeachRangeStatement *rangefe; 52 53 bool needExpansion; 54 55 StaticForeach *syntaxCopy(); 56 }; 57 58 class DVCondition : public Condition 59 { 60 public: 61 unsigned level; 62 Identifier *ident; 63 Module *mod; 64 65 DVCondition *syntaxCopy(); accept(Visitor * v)66 void accept(Visitor *v) { v->visit(this); } 67 }; 68 69 class DebugCondition : public DVCondition 70 { 71 public: 72 static void addGlobalIdent(const char *ident); 73 74 int include(Scope *sc); isDebugCondition()75 DebugCondition *isDebugCondition() { return this; } accept(Visitor * v)76 void accept(Visitor *v) { v->visit(this); } 77 }; 78 79 class VersionCondition : public DVCondition 80 { 81 public: 82 static void addGlobalIdent(const char *ident); 83 static void addPredefinedGlobalIdent(const char *ident); 84 85 int include(Scope *sc); isVersionCondition()86 VersionCondition *isVersionCondition() { return this; } accept(Visitor * v)87 void accept(Visitor *v) { v->visit(this); } 88 }; 89 90 class StaticIfCondition : public Condition 91 { 92 public: 93 Expression *exp; 94 95 StaticIfCondition *syntaxCopy(); 96 int include(Scope *sc); accept(Visitor * v)97 void accept(Visitor *v) { v->visit(this); } 98 }; 99