Back to home page

EIC code displayed by LXR

 
 

    


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

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_MACRO_DEFINITION_HPP_D68A639E_2DA5_4E9C_8ACD_CFE6B903831E_INCLUDED)
0012 #define BOOST_MACRO_DEFINITION_HPP_D68A639E_2DA5_4E9C_8ACD_CFE6B903831E_INCLUDED
0013 
0014 #include <vector>
0015 #include <list>
0016 
0017 #include <boost/detail/atomic_count.hpp>
0018 #include <boost/intrusive_ptr.hpp>
0019 
0020 #include <boost/wave/wave_config.hpp>
0021 #if BOOST_WAVE_SERIALIZATION != 0
0022 #include <boost/serialization/serialization.hpp>
0023 #include <boost/serialization/list.hpp>
0024 #include <boost/serialization/vector.hpp>
0025 #endif
0026 
0027 #include <boost/wave/token_ids.hpp>
0028 
0029 // this must occur after all of the includes and before any code appears
0030 #ifdef BOOST_HAS_ABI_HEADERS
0031 #include BOOST_ABI_PREFIX
0032 #endif
0033 
0034 ///////////////////////////////////////////////////////////////////////////////
0035 namespace boost {
0036 namespace wave {
0037 namespace util {
0038 
0039 ///////////////////////////////////////////////////////////////////////////////
0040 //
0041 //  macro_definition
0042 //
0043 //      This class containes all infos for a defined macro.
0044 //
0045 ///////////////////////////////////////////////////////////////////////////////
0046 template <typename TokenT, typename ContainerT>
0047 struct macro_definition {
0048 
0049     typedef std::vector<TokenT> parameter_container_type;
0050     typedef ContainerT          definition_container_type;
0051 
0052     typedef typename parameter_container_type::const_iterator
0053         const_parameter_iterator_t;
0054     typedef typename definition_container_type::const_iterator
0055         const_definition_iterator_t;
0056 
0057     macro_definition(TokenT const &token_, bool has_parameters,
0058             bool is_predefined_, long uid_)
0059     :   macroname(token_), uid(uid_), is_functionlike(has_parameters),
0060         replaced_parameters(false), is_available_for_replacement(true),
0061         is_predefined(is_predefined_)
0062 #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
0063         , has_ellipsis(false)
0064 #endif
0065         , use_count(0)
0066     {
0067     }
0068     // generated copy constructor
0069     // generated destructor
0070     // generated assignment operator
0071 
0072     // Replace all occurrences of the parameters throughout the macrodefinition
0073     // with special parameter tokens to simplify later macro replacement.
0074     // Additionally mark all occurrences of the macro name itself throughout
0075     // the macro definition
0076     template<typename ContextT>
0077     void replace_parameters(ContextT const & ctx)
0078     {
0079         using namespace boost::wave;
0080 
0081         if (!replaced_parameters) {
0082             typename definition_container_type::iterator end = macrodefinition.end();
0083             typename definition_container_type::iterator it = macrodefinition.begin();
0084 
0085             for (/**/; it != end; ++it) {
0086                 token_id id = *it;
0087 
0088                 if (T_IDENTIFIER == id ||
0089                     IS_CATEGORY(id, KeywordTokenType) ||
0090                     IS_EXTCATEGORY(id, OperatorTokenType|AltExtTokenType) ||
0091                     IS_CATEGORY(id, OperatorTokenType))
0092                 {
0093                 // may be a parameter to replace
0094                     const_parameter_iterator_t cend = macroparameters.end();
0095                     const_parameter_iterator_t cit = macroparameters.begin();
0096                     for (typename parameter_container_type::size_type i = 0;
0097                         cit != cend; ++cit, ++i)
0098                     {
0099                         if ((*it).get_value() == (*cit).get_value()) {
0100                             (*it).set_token_id(token_id(T_PARAMETERBASE+i));
0101                             break;
0102                         }
0103 #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
0104                         else if (need_variadics(ctx.get_language()) &&
0105                             T_ELLIPSIS == token_id(*cit) &&
0106                             "__VA_ARGS__" == (*it).get_value())
0107                         {
0108                         // __VA_ARGS__ requires special handling
0109                             (*it).set_token_id(token_id(T_EXTPARAMETERBASE+i));
0110                             break;
0111                         }
0112 #if BOOST_WAVE_SUPPORT_VA_OPT != 0
0113                         else if (need_va_opt(ctx.get_language()) &&
0114                             T_ELLIPSIS == token_id(*cit) &&
0115                             "__VA_OPT__" == (*it).get_value())
0116                         {
0117                         // __VA_OPT__ also requires related special handling
0118                             (*it).set_token_id(token_id(T_OPTPARAMETERBASE+i));
0119                             break;
0120                         }
0121 #endif
0122 #endif
0123                     }
0124                 }
0125             }
0126 
0127 #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
0128             // we need to know, if the last of the formal arguments is an ellipsis
0129             if (macroparameters.size() > 0 &&
0130                 T_ELLIPSIS == token_id(macroparameters.back()))
0131             {
0132                 has_ellipsis = true;
0133             }
0134 #endif
0135             replaced_parameters = true;     // do it only once
0136         }
0137     }
0138 
0139     TokenT macroname;                       // macro name
0140     parameter_container_type macroparameters;  // formal parameters
0141     definition_container_type macrodefinition; // macro definition token sequence
0142     long uid;                               // unique id of this macro
0143     bool is_functionlike;
0144     bool replaced_parameters;
0145     bool is_available_for_replacement;
0146     bool is_predefined;
0147 #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
0148     bool has_ellipsis;
0149 #endif
0150     boost::detail::atomic_count use_count;
0151 
0152 #if BOOST_WAVE_SERIALIZATION != 0
0153     // default constructor is needed for serialization only
0154     macro_definition()
0155     :   uid(0), is_functionlike(false), replaced_parameters(false),
0156         is_available_for_replacement(false), is_predefined(false)
0157 #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
0158       , has_ellipsis(false)
0159 #endif
0160       , use_count(0)
0161     {}
0162 
0163 private:
0164     friend class boost::serialization::access;
0165     template<typename Archive>
0166     void serialize(Archive &ar, const unsigned int version)
0167     {
0168         using namespace boost::serialization;
0169         ar & make_nvp("name", macroname);
0170         ar & make_nvp("parameters", macroparameters);
0171         ar & make_nvp("definition", macrodefinition);
0172         ar & make_nvp("uid", uid);
0173         ar & make_nvp("is_functionlike", is_functionlike);
0174         ar & make_nvp("has_replaced_parameters", replaced_parameters);
0175         ar & make_nvp("is_available_for_replacement", is_available_for_replacement);
0176         ar & make_nvp("is_predefined", is_predefined);
0177 #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
0178         ar & make_nvp("has_ellipsis", has_ellipsis);
0179 #endif
0180     }
0181 #endif
0182 };
0183 
0184 #if BOOST_WAVE_SERIALIZATION == 0
0185 ///////////////////////////////////////////////////////////////////////////////
0186 template <typename TokenT, typename ContainerT>
0187 inline void
0188 intrusive_ptr_add_ref(macro_definition<TokenT, ContainerT>* p)
0189 {
0190     ++p->use_count;
0191 }
0192 
0193 template <typename TokenT, typename ContainerT>
0194 inline void
0195 intrusive_ptr_release(macro_definition<TokenT, ContainerT>* p)
0196 {
0197     if (--p->use_count == 0)
0198         delete p;
0199 }
0200 #endif
0201 
0202 ///////////////////////////////////////////////////////////////////////////////
0203 }   // namespace util
0204 }   // namespace wave
0205 }   // namespace boost
0206 
0207 // the suffix header occurs after all of the code
0208 #ifdef BOOST_HAS_ABI_HEADERS
0209 #include BOOST_ABI_SUFFIX
0210 #endif
0211 
0212 #endif // !defined(BOOST_MACRO_DEFINITION_HPP_D68A639E_2DA5_4E9C_8ACD_CFE6B903831E_INCLUDED)