source: NonGTP/Boost/boost/wave/util/macro_definition.hpp @ 857

Revision 857, 5.0 KB checked in by igarcia, 18 years ago (diff)
Line 
1/*=============================================================================
2    Boost.Wave: A Standard compliant C++ preprocessor library
3
4    http://www.boost.org/
5
6    Copyright (c) 2001-2005 Hartmut Kaiser. Distributed under the Boost
7    Software License, Version 1.0. (See accompanying file
8    LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9=============================================================================*/
10
11#if !defined(MACRO_DEFINITION_HPP_D68A639E_2DA5_4E9C_8ACD_CFE6B903831E_INCLUDED)
12#define MACRO_DEFINITION_HPP_D68A639E_2DA5_4E9C_8ACD_CFE6B903831E_INCLUDED
13
14#include <vector>
15#include <list>
16
17#include <boost/wave/wave_config.hpp>
18#include <boost/wave/token_ids.hpp>
19
20///////////////////////////////////////////////////////////////////////////////
21namespace boost {
22namespace wave {
23namespace util {
24
25///////////////////////////////////////////////////////////////////////////////
26//
27//  macro_definition
28//
29//      This class containes all infos for a defined macro.
30//
31///////////////////////////////////////////////////////////////////////////////
32template <typename TokenT, typename ContainerT>
33struct macro_definition {
34
35    typedef std::vector<TokenT> parameter_container_t;
36    typedef ContainerT          definition_container_t;
37   
38    typedef typename parameter_container_t::const_iterator
39        const_parameter_iterator_t;
40    typedef typename definition_container_t::const_iterator
41        const_definition_iterator_t;
42
43    macro_definition(TokenT const &token_, bool has_parameters,
44            bool is_predefined_, long uid_)
45    :   macroname(token_), uid(uid_), is_functionlike(has_parameters),
46        replaced_parameters(false), is_available_for_replacement(true),
47        is_predefined(is_predefined_)
48#if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
49        , has_ellipsis(false)
50#endif
51    {
52    }
53    // generated copy constructor
54    // generated destructor
55    // generated assignment operator
56
57    // Replace all occurrences of the parameters throughout the macrodefinition
58    // with special parameter tokens to simplify later macro replacement.
59    // Additionally mark all occurrences of the macro name itself throughout
60    // the macro definition
61    void replace_parameters()
62    {
63        using namespace boost::wave;
64       
65        if (!replaced_parameters) {
66        typename definition_container_t::iterator end = macrodefinition.end();
67        typename definition_container_t::iterator it = macrodefinition.begin();
68
69            for (/**/; it != end; ++it) {
70            token_id id = *it;
71           
72                if (T_IDENTIFIER == id ||
73                    IS_CATEGORY(id, KeywordTokenType) ||
74                    IS_EXTCATEGORY(id, OperatorTokenType|AltExtTokenType))
75                {
76                // may be a parameter to replace
77                    const_parameter_iterator_t cend = macroparameters.end();
78                    const_parameter_iterator_t cit = macroparameters.begin();
79                    for (typename parameter_container_t::size_type i = 0;
80                        cit != cend; ++cit, ++i)
81                    {
82                        if ((*it).get_value() == (*cit).get_value()) {
83                            (*it).set_token_id(token_id(T_PARAMETERBASE+i));
84                            break;
85                        }
86#if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
87                        else if (T_ELLIPSIS == token_id(*cit) &&
88                            "__VA_ARGS__" == (*it).get_value())
89                        {
90                        // __VA_ARGS__ requires special handling
91                            (*it).set_token_id(token_id(T_EXTPARAMETERBASE+i));
92                            break;
93                        }
94#endif
95                    }
96                }
97            }
98           
99#if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
100        // we need to know, if the last of the formal arguments is an ellipsis
101            if (macroparameters.size() > 0 &&
102                T_ELLIPSIS == token_id(macroparameters.back()))
103            {
104                has_ellipsis = true;
105            }
106#endif
107            replaced_parameters = true;     // do it only once
108        }
109    }
110
111    TokenT macroname;                       // macro name
112    parameter_container_t macroparameters;  // formal parameters
113    definition_container_t macrodefinition; // macro definition token sequence
114    long uid;                               // unique id of this macro
115    bool is_functionlike;
116    bool replaced_parameters;
117    bool is_available_for_replacement;
118    bool is_predefined;
119#if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
120    bool has_ellipsis;
121#endif
122};
123
124///////////////////////////////////////////////////////////////////////////////
125}   // namespace util
126}   // namespace wave
127}   // namespace boost
128
129#endif // !defined(MACRO_DEFINITION_HPP_D68A639E_2DA5_4E9C_8ACD_CFE6B903831E_INCLUDED)
Note: See TracBrowser for help on using the repository browser.