Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:40

0001 /*=============================================================================
0002     Boost.Wave: A Standard compliant C++ preprocessor library
0003 
0004     http://www.boost.org/
0005 
0006     Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
0007     Software License, Version 1.0. (See accompanying file
0008     LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 =============================================================================*/
0010 
0011 #if !defined(BOOST_CPP_IFBLOCK_HPP_D4676B36_00C5_41F4_BC9F_9CBBAE3B8006_INCLUDED)
0012 #define BOOST_CPP_IFBLOCK_HPP_D4676B36_00C5_41F4_BC9F_9CBBAE3B8006_INCLUDED
0013 
0014 #include <stack>
0015 #include <boost/wave/wave_config.hpp>
0016 
0017 // this must occur after all of the includes and before any code appears
0018 #ifdef BOOST_HAS_ABI_HEADERS
0019 #include BOOST_ABI_PREFIX
0020 #endif
0021 
0022 ///////////////////////////////////////////////////////////////////////////////
0023 namespace boost {
0024 namespace wave {
0025 namespace util {
0026 
0027 ///////////////////////////////////////////////////////////////////////////////
0028 // the class if_blocks handles recursive conditional compilation contexts
0029 class if_block
0030 {
0031 public:
0032     if_block() :
0033         status(true), some_part_status(true),
0034         enclosing_status(true), is_in_else(false)
0035     {
0036     }
0037     if_block(bool status_, bool enclosing_status_) :
0038         status(status_),
0039         some_part_status(status_),
0040         enclosing_status(enclosing_status_),
0041         is_in_else(false)
0042     {
0043     }
0044 
0045     void set_status(bool status_)
0046     {
0047         status = status_;
0048         if (status_)
0049             some_part_status = true;
0050     }
0051     bool get_status() const { return status; }
0052     bool get_some_part_status() const { return some_part_status; }
0053     bool get_enclosing_status() const { return enclosing_status; }
0054     bool get_in_else() const { return is_in_else; }
0055     void set_in_else() { is_in_else = true; }
0056 
0057 private:
0058    bool status;             // Current block is true
0059    bool some_part_status;   // One of the preceding or current #if/#elif was true
0060    bool enclosing_status;   // Enclosing #if block is true
0061    bool is_in_else;         // Inside the #else part
0062 };
0063 
0064 ///////////////////////////////////////////////////////////////////////////////
0065 // stack of conditional compilation contexts
0066 class if_block_stack
0067 :   private std::stack<if_block>
0068 {
0069 public:
0070     typedef std::stack<if_block>::size_type size_type;
0071 
0072     void enter_if_block(bool new_status)
0073     {
0074         // If enclosing block is false, then this block is also false
0075         bool enclosing_status = get_status();
0076         this->push (value_type (new_status && enclosing_status, enclosing_status));
0077     }
0078     bool enter_elif_block(bool new_status)
0079     {
0080         if (!is_inside_ifpart())
0081             return false;       // #elif without matching #if
0082 
0083         if (get_enclosing_status()) {
0084             if (get_status()) {
0085                 // entered a (false) #elif block from a true block
0086                 this->top().set_status(false);
0087             }
0088             else if (new_status && !this->top().get_some_part_status()) {
0089                 // Entered true #elif block and no previous block was true
0090                 this->top().set_status(new_status);
0091             }
0092         }
0093         return true;
0094     }
0095     bool enter_else_block()
0096     {
0097         if (!is_inside_ifpart())
0098             return false;       // #else without matching #if
0099 
0100         if (get_enclosing_status()) {
0101             if (!this->top().get_some_part_status()) {
0102                 // Entered (true) #else block and no previous block was true
0103                 this->top().set_status(true);
0104             }
0105             else if (get_status()) {
0106                 // Entered (false) #else block from true block
0107                 this->top().set_status(false);
0108             }
0109 
0110             // Set else flag
0111             this->top().set_in_else();
0112         }
0113         return true;
0114     }
0115     bool exit_if_block()
0116     {
0117         if (0 == this->size())
0118             return false;   // #endif without matching #if
0119 
0120         this->pop();
0121         return true;
0122     }
0123 
0124     // return, whether the top (innermost) condition is true or false
0125     bool get_status() const
0126     {
0127         return 0 == this->size() || this->top().get_status();
0128     }
0129     bool get_some_part_status() const
0130     {
0131         return 0 == this->size() || this->top().get_some_part_status();
0132     }
0133     bool get_enclosing_status() const
0134     {
0135         return 0 == this->size() || this->top().get_enclosing_status();
0136     }
0137 
0138     size_type get_if_block_depth() const { return this->size(); }
0139 
0140 protected:
0141     bool is_inside_ifpart() const
0142     {
0143         return 0 != this->size() && !this->top().get_in_else();
0144     }
0145     bool is_inside_elsepart() const
0146     {
0147         return 0 != this->size() && this->top().get_in_else();
0148     }
0149 };
0150 
0151 ///////////////////////////////////////////////////////////////////////////////
0152 }   // namespace util
0153 }   // namespace wave
0154 }   // namespace boost
0155 
0156 // the suffix header occurs after all of the code
0157 #ifdef BOOST_HAS_ABI_HEADERS
0158 #include BOOST_ABI_SUFFIX
0159 #endif
0160 
0161 #endif // !defined(BOOST_CPP_IFBLOCK_HPP_D4676B36_00C5_41F4_BC9F_9CBBAE3B8006_INCLUDED)