1 2 /* Compiler implementation of the D programming language 3 * Copyright (C) 1999-2019 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 "globals.h" 14 #include "visitor.h" 15 16 class Expression; 17 class Identifier; 18 struct OutBuffer; 19 class Module; 20 struct Scope; 21 class ScopeDsymbol; 22 class DebugCondition; 23 class ForeachStatement; 24 class ForeachRangeStatement; 25 26 int findCondition(Strings *ids, Identifier *ident); 27 28 class Condition 29 { 30 public: 31 Loc loc; 32 // 0: not computed yet 33 // 1: include 34 // 2: do not include 35 int inc; 36 37 Condition(Loc loc); 38 39 virtual Condition *syntaxCopy() = 0; 40 virtual int include(Scope *sc, ScopeDsymbol *sds) = 0; isDebugCondition()41 virtual DebugCondition *isDebugCondition() { return NULL; } isVersionCondition()42 virtual VersionCondition *isVersionCondition() { return NULL; } accept(Visitor * v)43 virtual void accept(Visitor *v) { v->visit(this); } 44 }; 45 46 class StaticForeach 47 { 48 public: 49 Loc loc; 50 51 ForeachStatement *aggrfe; 52 ForeachRangeStatement *rangefe; 53 54 bool needExpansion; 55 56 StaticForeach(Loc loc, ForeachStatement *aggrfe, ForeachRangeStatement *rangefe); 57 StaticForeach *syntaxCopy(); 58 }; 59 60 void staticForeachPrepare(StaticForeach *sfe, Scope *sc); 61 bool staticForeachReady(StaticForeach *sfe); 62 63 class DVCondition : public Condition 64 { 65 public: 66 unsigned level; 67 Identifier *ident; 68 Module *mod; 69 70 DVCondition(Module *mod, unsigned level, Identifier *ident); 71 72 Condition *syntaxCopy(); accept(Visitor * v)73 void accept(Visitor *v) { v->visit(this); } 74 }; 75 76 class DebugCondition : public DVCondition 77 { 78 public: 79 static void setGlobalLevel(unsigned level); 80 static void addGlobalIdent(const char *ident); 81 82 DebugCondition(Module *mod, unsigned level, Identifier *ident); 83 84 int include(Scope *sc, ScopeDsymbol *sds); 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 setGlobalLevel(unsigned level); 93 static void addGlobalIdent(const char *ident); 94 static void addPredefinedGlobalIdent(const char *ident); 95 96 VersionCondition(Module *mod, unsigned level, Identifier *ident); 97 98 int include(Scope *sc, ScopeDsymbol *sds); isVersionCondition()99 VersionCondition *isVersionCondition() { return this; } accept(Visitor * v)100 void accept(Visitor *v) { v->visit(this); } 101 }; 102 103 class StaticIfCondition : public Condition 104 { 105 public: 106 Expression *exp; 107 108 StaticIfCondition(Loc loc, Expression *exp); 109 Condition *syntaxCopy(); 110 int include(Scope *sc, ScopeDsymbol *sds); accept(Visitor * v)111 void accept(Visitor *v) { v->visit(this); } 112 }; 113