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 *syntaxCopy(); 57 }; 58 59 class DVCondition : public Condition 60 { 61 public: 62 unsigned level; 63 Identifier *ident; 64 Module *mod; 65 66 DVCondition(Module *mod, unsigned level, Identifier *ident); 67 68 Condition *syntaxCopy(); accept(Visitor * v)69 void accept(Visitor *v) { v->visit(this); } 70 }; 71 72 class DebugCondition : public DVCondition 73 { 74 public: 75 static void setGlobalLevel(unsigned level); 76 static void addGlobalIdent(const char *ident); 77 78 DebugCondition(Module *mod, unsigned level, Identifier *ident); 79 80 int include(Scope *sc, ScopeDsymbol *sds); isDebugCondition()81 DebugCondition *isDebugCondition() { return this; } accept(Visitor * v)82 void accept(Visitor *v) { v->visit(this); } 83 }; 84 85 class VersionCondition : public DVCondition 86 { 87 public: 88 static void setGlobalLevel(unsigned level); 89 static void addGlobalIdent(const char *ident); 90 static void addPredefinedGlobalIdent(const char *ident); 91 92 VersionCondition(Module *mod, unsigned level, Identifier *ident); 93 94 int include(Scope *sc, ScopeDsymbol *sds); isVersionCondition()95 VersionCondition *isVersionCondition() { return this; } accept(Visitor * v)96 void accept(Visitor *v) { v->visit(this); } 97 }; 98 99 class StaticIfCondition : public Condition 100 { 101 public: 102 Expression *exp; 103 int nest; // limit circular dependencies 104 105 StaticIfCondition(Loc loc, Expression *exp); 106 Condition *syntaxCopy(); 107 int include(Scope *sc, ScopeDsymbol *sds); accept(Visitor * v)108 void accept(Visitor *v) { v->visit(this); } 109 }; 110