1  
       2  /* Compiler implementation of the D programming language
       3   * Copyright (C) 1999-2023 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 NULL; }
      43      virtual VersionCondition *isVersionCondition() { return NULL; }
      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      StaticForeach *syntaxCopy();
      58  };
      59  
      60  class DVCondition : public Condition
      61  {
      62  public:
      63      unsigned level;
      64      Identifier *ident;
      65      Module *mod;
      66  
      67      DVCondition *syntaxCopy() override final;
      68      void accept(Visitor *v) override { v->visit(this); }
      69  };
      70  
      71  class DebugCondition final : public DVCondition
      72  {
      73  public:
      74      static void addGlobalIdent(const char *ident);
      75  
      76      int include(Scope *sc) override;
      77      DebugCondition *isDebugCondition() override { return this; }
      78      void accept(Visitor *v) override { v->visit(this); }
      79  };
      80  
      81  class VersionCondition final : public DVCondition
      82  {
      83  public:
      84      static void addGlobalIdent(const char *ident);
      85      static void addPredefinedGlobalIdent(const char *ident);
      86  
      87      int include(Scope *sc) override;
      88      VersionCondition *isVersionCondition() override { return this; }
      89      void accept(Visitor *v) override { v->visit(this); }
      90  };
      91  
      92  class StaticIfCondition final : public Condition
      93  {
      94  public:
      95      Expression *exp;
      96  
      97      StaticIfCondition *syntaxCopy() override;
      98      int include(Scope *sc) override;
      99      void accept(Visitor *v) override { v->visit(this); }
     100  };