diff --git a/ChangeLog b/ChangeLog index d0d1d6d..c903eb7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,27 @@ TODO (known issues): - Fix the trigraph backslash problem in the re2c (C/C++ and IDL) scanners, if there is the end of the (internal) buffer just in between a '??/' and a '\n'. +Sun Mar 28 12:55:59 WEDT 2004 +Version 1.1.4 +- Fixed a problem, where the first returned token was lost, whenever a + --forceinclude file was given. +- Adjusted the Wave driver and the other samples to use the new program_options + library syntax (V1.1.x only). + +Mon Mar 1 19:14:21 WEST 2004 +Version 1.1.2 +Version 1.0.4 +- Fixed a problem, which does not report an error, if in a #define statement in + between a macro name and its replacement list were no whitespace given. +- Fixed a bug, which generated an unexpected exception of the $ character in the + input. +- Macro definitions, which differ by whitespace only (one definition contains + whitespace at a certain position, the other definition does not) are correctly + reported as a warning now. +- Fixed a problem, where different formal argument names during macro + redefinition were not flagged as a warning. +- A wide character string used in a #line directive wasn't flagged as an error. + Sun Feb 29 19:10:14 WEST 2004 Used the test suite distributed with the mcpp V2.4 preprocessor to fix a bunch of mostly minor issues: diff --git a/include/boost/wave/grammars/cpp_chlit_grammar.hpp b/include/boost/wave/grammars/cpp_chlit_grammar.hpp index 907a187..fb6e410 100644 --- a/include/boost/wave/grammars/cpp_chlit_grammar.hpp +++ b/include/boost/wave/grammars/cpp_chlit_grammar.hpp @@ -147,11 +147,8 @@ struct chlit_grammar : [ self.value = impl::compose(self.value, val('\\')) ] - | ch_p('x') >> hex_p - [ - self.value = impl::compose(self.value, arg1) - ] - | uint_parser() + | ch_p('x') + >> uint_parser() [ self.value = impl::compose(self.value, arg1) ] @@ -165,9 +162,13 @@ struct chlit_grammar : [ self.value = impl::compose(self.value, arg1) ] + | uint_parser() + [ + self.value = impl::compose(self.value, arg1) + ] ) ) - | eps_p(anychar_p - ch_p('\'')) >> anychar_p + | ~eps_p(ch_p('\'')) >> anychar_p [ self.value = impl::compose(self.value, arg1) ] diff --git a/include/boost/wave/grammars/cpp_defined_grammar.hpp b/include/boost/wave/grammars/cpp_defined_grammar.hpp index 67bef17..e7e13f4 100644 --- a/include/boost/wave/grammars/cpp_defined_grammar.hpp +++ b/include/boost/wave/grammars/cpp_defined_grammar.hpp @@ -12,8 +12,8 @@ #if !defined(CPP_DEFINED_GRAMMAR_HPP_F48287B2_DC67_40A8_B4A1_800EFBD67869_INCLUDED) #define CPP_DEFINED_GRAMMAR_HPP_F48287B2_DC67_40A8_B4A1_800EFBD67869_INCLUDED +#include #include -#include #include #if SPIRIT_VERSION >= 0x1700 #include diff --git a/include/boost/wave/grammars/cpp_expression_grammar.hpp b/include/boost/wave/grammars/cpp_expression_grammar.hpp index 195f12e..c5eaab1 100644 --- a/include/boost/wave/grammars/cpp_expression_grammar.hpp +++ b/include/boost/wave/grammars/cpp_expression_grammar.hpp @@ -12,8 +12,8 @@ #if !defined(CPP_EXPRESSION_GRAMMAR_HPP_099CD1A4_A6C0_44BE_8F24_0B00F5BE5674_INCLUDED) #define CPP_EXPRESSION_GRAMMAR_HPP_099CD1A4_A6C0_44BE_8F24_0B00F5BE5674_INCLUDED +#include #include -#include #include #include #if SPIRIT_VERSION >= 0x1700 @@ -91,7 +91,8 @@ namespace impl { }; template - boost::wave::grammars::closures::closure_value operator()(TokenT const &token) const + boost::wave::grammars::closures::closure_value + operator()(TokenT const &token) const { typedef boost::wave::grammars::closures::closure_value return_t; bool is_unsigned = false; @@ -117,7 +118,8 @@ namespace impl { }; template - boost::wave::grammars::closures::closure_value operator()(TokenT const &token) const + boost::wave::grammars::closures::closure_value + operator()(TokenT const &token) const { typedef boost::wave::grammars::closures::closure_value return_t; return return_t(chlit_grammar_gen::evaluate(token)); @@ -139,8 +141,8 @@ namespace impl { }; template - boost::wave::grammars::closures::closure_value operator()( - CondT const &cond, Arg1T &val1, Arg2T const &val2) const + boost::wave::grammars::closures::closure_value + operator()(CondT const &cond, Arg1T &val1, Arg2T const &val2) const { typedef boost::wave::grammars::closures::closure_value return_t; return return_t(val1.handle_questionmark(cond, val2)); @@ -176,6 +178,7 @@ struct expression_grammar : typedef boost::spirit::rule simple_rule_t; simple_rule_t pp_expression; + rule_t const_exp; rule_t logical_or_exp, logical_and_exp; rule_t inclusive_or_exp, exclusive_or_exp, and_exp; @@ -291,8 +294,8 @@ struct expression_grammar : >> and_exp [ exclusive_or_exp.val = - static_cast_(exclusive_or_exp.val) - ^ static_cast_(arg1) + static_cast_(exclusive_or_exp.val) + ^ static_cast_(arg1) ] ) ; @@ -303,8 +306,8 @@ struct expression_grammar : >> cmp_equality [ and_exp.val = - static_cast_(and_exp.val) - & static_cast_(arg1) + static_cast_(and_exp.val) + & static_cast_(arg1) ] ) ; @@ -401,8 +404,8 @@ struct expression_grammar : >> unary_exp [ multiply_exp.val = - static_cast_(multiply_exp.val) - % static_cast_(arg1) + static_cast_(multiply_exp.val) + % static_cast_(arg1) ] ) ; @@ -579,7 +582,7 @@ struct expression_grammar : BOOST_SPIRIT_DEBUG_TRACE_RULE(constant, TRACE_CPP_EXPR_GRAMMAR); BOOST_SPIRIT_DEBUG_TRACE_RULE(const_exp_subrule, TRACE_CPP_EXPR_GRAMMAR); - BOOST_SPIRIT_DEBUG_TRACE_RULE(const_exp, TRACE_CPP_EXPR_GRAMMAR); + BOOST_SPIRIT_DEBUG_TRACE_RULE(const_exp_nocalc, TRACE_CPP_EXPR_GRAMMAR); BOOST_SPIRIT_DEBUG_TRACE_RULE(logical_or_exp_nocalc, TRACE_CPP_EXPR_GRAMMAR); BOOST_SPIRIT_DEBUG_TRACE_RULE(logical_and_exp_nocalc, TRACE_CPP_EXPR_GRAMMAR); BOOST_SPIRIT_DEBUG_TRACE_RULE(inclusive_or_exp_nocalc, TRACE_CPP_EXPR_GRAMMAR); diff --git a/include/boost/wave/trace_policies.hpp b/include/boost/wave/trace_policies.hpp index 5924d06..4a89691 100644 --- a/include/boost/wave/trace_policies.hpp +++ b/include/boost/wave/trace_policies.hpp @@ -27,8 +27,7 @@ namespace trace_policies { enum trace_flags { trace_nothing = 0, // disable tracing trace_macros = 1, // enable macro tracing - trace_includes = 2, // enable include file tracing - trace_timer = 3 // enable timer tracing + trace_includes = 2 // enable include file tracing }; /////////////////////////////////////////////////////////////////////////////// diff --git a/include/boost/wave/util/flex_string.hpp b/include/boost/wave/util/flex_string.hpp index b439628..b27d10e 100644 --- a/include/boost/wave/util/flex_string.hpp +++ b/include/boost/wave/util/flex_string.hpp @@ -65,13 +65,13 @@ class StoragePolicy */ #include +#include #include #include #include #include #include -#include #include #include #include @@ -284,7 +284,7 @@ private: void Init(size_type size, size_type capacity) { - assert(size <= capacity); + BOOST_ASSERT(size <= capacity); if (capacity == 0) { pData_ = const_cast(&emptyString_); @@ -353,7 +353,7 @@ public: ~SimpleStringStorage() { - assert(begin() <= end()); + BOOST_ASSERT(begin() <= end()); if (pData_ != &emptyString_) free(pData_); } @@ -520,7 +520,7 @@ class AllocatorStringStorage : public A void Init(size_type size, size_type cap) { - assert(size <= cap); + BOOST_ASSERT(size <= cap); if (cap == 0) { @@ -763,7 +763,7 @@ public: // protected: void reserve(size_type res_arg) { - assert(res_arg < max_size()); + BOOST_ASSERT(res_arg < max_size()); base::reserve(res_arg + 1); } @@ -850,14 +850,14 @@ private: Storage& GetStorage() { - assert(buf_[maxSmallString] == magic); + BOOST_ASSERT(buf_[maxSmallString] == magic); Storage* p = reinterpret_cast(&buf_[0]); return *p; } const Storage& GetStorage() const { - assert(buf_[maxSmallString] == magic); + BOOST_ASSERT(buf_[maxSmallString] == magic); const Storage *p = reinterpret_cast(&buf_[0]); return *p; } @@ -919,12 +919,9 @@ public: SmallStringOpt& operator=(const SmallStringOpt& rhs) { - if (&rhs != this) - { - reserve(rhs.size()); - resize(0, 0); - append(rhs.data(), rhs.size()); - } + reserve(rhs.size()); + resize(0, 0); + append(rhs.data(), rhs.size()); return *this; } @@ -959,7 +956,7 @@ public: size_type size() const { - assert(!Small() || maxSmallString >= buf_[maxSmallString]); + BOOST_ASSERT(!Small() || maxSmallString >= buf_[maxSmallString]); return Small() ? maxSmallString - buf_[maxSmallString] : GetStorage().size(); @@ -987,7 +984,7 @@ public: { GetStorage().reserve(res_arg); } - assert(capacity() >= res_arg); + BOOST_ASSERT(capacity() >= res_arg); } void append(const value_type* s, size_type sz) @@ -1005,7 +1002,7 @@ public: if (maxSmallString < neededCapacity) { // need to change storage strategy - allocator_type alloc; + allocator_type alloc; Storage temp(alloc); temp.reserve(neededCapacity); temp.append(buf_, maxSmallString - buf_[maxSmallString]); @@ -1071,8 +1068,8 @@ public: else { // Big string resized to small string - // 11-17=2001: bug fix in the assertion below - assert(capacity() > n); + // 11-17=2001: bug fix in the BOOST_ASSERTion below + BOOST_ASSERT(capacity() > n); SmallStringOpt newObj(data(), n, get_allocator()); newObj.swap(*this); } @@ -1168,21 +1165,21 @@ private: RefCountType GetRefs() const { const Storage& d = Data(); - assert(d.size() > 0); - assert(static_cast(*d.begin()) != 0); + BOOST_ASSERT(d.size() > 0); + BOOST_ASSERT(static_cast(*d.begin()) != 0); return *d.begin(); } RefCountType& Refs() { Storage& d = Data(); - assert(d.size() > 0); + BOOST_ASSERT(d.size() > 0); return reinterpret_cast(*d.begin()); } void MakeUnique() const { - assert(GetRefs() >= 1); + BOOST_ASSERT(GetRefs() >= 1); if (GetRefs() == 1) return; union @@ -1211,7 +1208,7 @@ public: new(buf_) Storage(s.Data(), flex_string_details::Shallow()); ++Refs(); } - assert(Data().size() > 0); + BOOST_ASSERT(Data().size() > 0); } CowString(const allocator_type& a) @@ -1238,26 +1235,39 @@ public: CowString& operator=(const CowString& rhs) { - CowString(rhs).swap(*this); +// CowString(rhs).swap(*this); + if (--Refs() == 0) Data().~Storage(); + if (rhs.GetRefs() == std::numeric_limits::max()) + { + // must make a brand new copy + new(buf_) Storage(rhs.Data()); // non shallow + Refs() = 1; + } + else + { + new(buf_) Storage(rhs.Data(), flex_string_details::Shallow()); + ++Refs(); + } + BOOST_ASSERT(Data().size() > 0); return *this; } ~CowString() { - assert(Data().size() > 0); + BOOST_ASSERT(Data().size() > 0); if (--Refs() == 0) Data().~Storage(); } iterator begin() { - assert(Data().size() > 0); + BOOST_ASSERT(Data().size() > 0); MakeUnique(); return Data().begin() + 1; } const_iterator begin() const { - assert(Data().size() > 0); + BOOST_ASSERT(Data().size() > 0); return Data().begin() + 1; } @@ -1274,25 +1284,25 @@ public: size_type size() const { - assert(Data().size() > 0); + BOOST_ASSERT(Data().size() > 0); return Data().size() - 1; } size_type max_size() const { - assert(Data().max_size() > 0); + BOOST_ASSERT(Data().max_size() > 0); return Data().max_size() - 1; } size_type capacity() const { - assert(Data().capacity() > 0); + BOOST_ASSERT(Data().capacity() > 0); return Data().capacity() - 1; } void resize(size_type n, E c) { - assert(Data().size() > 0); + BOOST_ASSERT(Data().size() > 0); MakeUnique(); Data().resize(n + 1, c); } @@ -1328,13 +1338,13 @@ public: const E* c_str() const { - assert(Data().size() > 0); + BOOST_ASSERT(Data().size() > 0); return Data().c_str() + 1; } const E* data() const { - assert(Data().size() > 0); + BOOST_ASSERT(Data().size() > 0); return Data().data() + 1; } @@ -1363,7 +1373,7 @@ class flex_string : private Storage #else template static inline void Enforce(bool condition, Exception*, const char* msg) - { assert(condition && msg); } + { BOOST_ASSERT(condition && msg); } #endif // defined(THROW_ON_ENFORCE) bool Sane() const @@ -1383,11 +1393,11 @@ class flex_string : private Storage { Invariant(const flex_string& s) : s_(s) { - assert(s_.Sane()); + BOOST_ASSERT(s_.Sane()); } ~Invariant() { - assert(s_.Sane()); + BOOST_ASSERT(s_.Sane()); } private: const flex_string& s_; @@ -1777,7 +1787,7 @@ public: // d2 > s1 if (le(d2, s2)) { - assert(aliased); + BOOST_ASSERT(aliased); pod_move(s1, d2, d1); pod_move(d2 + delta, s2 + delta, d1 + (d2 - s1)); } @@ -1881,7 +1891,7 @@ private: flex_string& ReplaceImpl(iterator i1, iterator i2, InputIterator b, InputIterator e, Selector<0>) { - assert(false); + BOOST_ASSERT(false); return *this; } diff --git a/include/boost/wave/util/functor_input.hpp b/include/boost/wave/util/functor_input.hpp index 1071a0a..a80ba77 100644 --- a/include/boost/wave/util/functor_input.hpp +++ b/include/boost/wave/util/functor_input.hpp @@ -106,6 +106,7 @@ struct functor_input { { BOOST_SPIRIT_ASSERT(0 != data); data->curtok = (data->ftor)(); + data->was_initialized = true; } bool input_at_eof() const diff --git a/include/boost/wave/wave_config.hpp b/include/boost/wave/wave_config.hpp index 6350746..d58fa74 100644 --- a/include/boost/wave/wave_config.hpp +++ b/include/boost/wave/wave_config.hpp @@ -16,6 +16,7 @@ #include #include +#include /////////////////////////////////////////////////////////////////////////////// // Decide, whether to implement macro scopes (#scope/#endscope), variadics, @@ -153,16 +154,36 @@ // names inside a file_position template class // #if !defined(BOOST_WAVE_STRINGTYPE) -#define BOOST_WAVE_STRINGTYPE boost::wave::util::flex_string< \ - char, std::char_traits, std::allocator, \ - boost::wave::util::CowString< \ - boost::wave::util::AllocatorStringStorage > \ - > \ - /**/ +// use the following, if you have a fast std::allocator +#define BOOST_WAVE_STRINGTYPE boost::wave::util::flex_string< \ + char, std::char_traits, std::allocator, \ + boost::wave::util::CowString \ + > \ + > \ + /**/ + +//#define BOOST_WAVE_STRINGTYPE boost::wave::util::flex_string< \ +// char, std::char_traits, boost::fast_pool_allocator, \ +// boost::wave::util::CowString \ +// > \ +// > \ +// > \ +// /**/ + // This include is needed for the flex_string class used in the // BOOST_WAVE_STRINGTYPE above. #include + +// This include is needed for the boost::fast_allocator class used in the +// BOOST_WAVE_STRINGTYPE above. +// Configure Boost.Pool thread support (for now: no thread support at all) +#define BOOST_NO_MT +#include + #endif /////////////////////////////////////////////////////////////////////////////// @@ -172,7 +193,7 @@ //#define BOOST_SPIRIT_DEBUG /////////////////////////////////////////////////////////////////////////////// -// debug flags for the pp-iterator library, possible flags: +// debug flags for the Wave library, possible flags: #define BOOST_SPIRIT_DEBUG_FLAGS_CPP_GRAMMAR 0x0001 #define BOOST_SPIRIT_DEBUG_FLAGS_TIME_CONVERSION 0x0002 #define BOOST_SPIRIT_DEBUG_FLAGS_CPP_EXPR_GRAMMAR 0x0004 @@ -252,9 +273,10 @@ #endif /////////////////////////////////////////////////////////////////////////////// -// configure Boost.Pool thread support -// (for now: no thread support at all) +// configure Boost.Pool thread support (for now: no thread support at all) +#if !defined(BOOST_NO_MT) #define BOOST_NO_MT +#endif // !defined(BOOST_NO_MT) /////////////////////////////////////////////////////////////////////////////// // Auto library naming diff --git a/include/boost/wave/wave_version.hpp b/include/boost/wave/wave_version.hpp index dcffd88..d569dd9 100644 --- a/include/boost/wave/wave_version.hpp +++ b/include/boost/wave/wave_version.hpp @@ -14,14 +14,14 @@ #if !defined(WAVE_VERSION_H_9D79ABDB_AC54_4C0A_89B1_F70A2DCFE21E_INCLUDED) #define WAVE_VERSION_H_9D79ABDB_AC54_4C0A_89B1_F70A2DCFE21E_INCLUDED -// BOOST_WAVE_VERSION & 0x00FF is the sub-minor version -// BOOST_WAVE_VERSION & 0x0F00 is the minor version -// BOOST_WAVE_VERSION & 0xF000 is the major version -#define BOOST_WAVE_VERSION 0x1102 +// BOOST_WAVE_VERSION & 0x0000FF is the sub-minor version +// BOOST_WAVE_VERSION & 0x00FF00 is the minor version +// BOOST_WAVE_VERSION & 0xFF0000 is the major version +#define BOOST_WAVE_VERSION 0x010104 // The following defines contain the same information as above #define BOOST_WAVE_VERSION_MAJOR 1 #define BOOST_WAVE_VERSION_MINOR 1 -#define BOOST_WAVE_VERSION_SUBMINOR 2 +#define BOOST_WAVE_VERSION_SUBMINOR 4 #endif // !defined(WAVE_VERSION_H_9D79ABDB_AC54_4C0A_89B1_F70A2DCFE21E_INCLUDED) diff --git a/samples/list_includes/list_includes.cpp b/samples/list_includes/list_includes.cpp index c75c483..29819c6 100644 --- a/samples/list_includes/list_includes.cpp +++ b/samples/list_includes/list_includes.cpp @@ -65,6 +65,19 @@ using std::istreambuf_iterator; namespace po = boost::program_options; +/////////////////////////////////////////////////////////////////////////////// +namespace cmd_line_util { + + // predicate to extract all positional arguments from the command line + struct is_argument { + bool operator()(po::option const &opt) + { + return (opt.position_key == -1) ? true : false; + } + }; +/////////////////////////////////////////////////////////////////////////////// +} + /////////////////////////////////////////////////////////////////////////////// // print the current version @@ -120,17 +133,15 @@ struct trace_include_files /////////////////////////////////////////////////////////////////////////////// // -int do_actual_work ( - po::options_and_arguments const opts, po::variables_map const &vm, - vector const &pathes, vector const &syspathes) +int +do_actual_work(vector const &arguments, po::variables_map const &vm) { // current file position is saved for exception handling boost::wave::util::file_position_t current_position; try { - vector const &arguments = opts.arguments(); - vector::const_iterator lastfile = arguments.end(); - + // list the included files for all arguments given + vector::const_iterator lastfile = arguments.end(); for (vector::const_iterator file_it = arguments.begin(); file_it != lastfile; ++file_it) { @@ -168,9 +179,11 @@ boost::wave::util::file_position_t current_position; context_t ctx (instring.begin(), instring.end(), (*file_it).c_str(), trace); // add include directories to the include path - if (vm.count("path")) { - vector::const_iterator end = pathes.end(); - for (vector::const_iterator cit = pathes.begin(); + if (vm.count("include")) { + vector const &paths = + vm["include"].as >(); + vector::const_iterator end = paths.end(); + for (vector::const_iterator cit = paths.begin(); cit != end; ++cit) { ctx.add_include_path((*cit).c_str()); @@ -178,9 +191,11 @@ boost::wave::util::file_position_t current_position; } // add system include directories to the include path - if (vm.count("syspath")) { - vector::const_iterator end = syspathes.end(); - for (vector::const_iterator cit = syspathes.begin(); + if (vm.count("sysinclude")) { + vector const &syspaths = + vm["sysinclude"].as >(); + vector::const_iterator end = syspaths.end(); + for (vector::const_iterator cit = syspaths.begin(); cit != end; ++cit) { ctx.add_sysinclude_path((*cit).c_str()); @@ -237,23 +252,24 @@ main (int argc, char const *argv[]) { try { // analyze the command line options and arguments - vector pathes; vector syspathes; po::options_description desc("Usage: list_includes [options] file ..."); desc.add_options() - ("help,h", "", "print out program usage (this message)") - ("version,v", "", "print the version number") - ("path,I", po::parameter >("dir", &pathes), + ("help,h", "print out program usage (this message)") + ("version,v", "print the version number") + ("include,I", po::value >(), "specify additional include directory") - ("syspath,S", po::parameter >("dir", &syspathes), + ("sysinclude,S", po::value >(), "specify additional system include directory") ; - po::options_and_arguments opts = po::parse_command_line(argc, argv, desc); + po::parsed_options opts = po::parse_command_line(argc, argv, desc); po::variables_map vm; - po::store(opts, vm, desc); + po::store(opts, vm); + po::notify(vm); + if (vm.count("help")) { cout << desc << endl; return 1; @@ -263,15 +279,21 @@ main (int argc, char const *argv[]) return print_version(); } + // extract the arguments from the parsed command line + vector arguments; + + std::remove_copy_if(opts.options.begin(), opts.options.end(), + inserter(arguments, arguments.end()), cmd_line_util::is_argument()); + // if there is no input file given, then exit - if (0 == opts.arguments().size()) { + if (0 == arguments.size() || 0 == arguments[0].value.size()) { cerr << "list_includes: No input file given. " << "Use --help to get a hint." << endl; return 5; } // iterate over all given input files - return do_actual_work(opts, vm, pathes, syspathes); + return do_actual_work(arguments[0].value , vm); } catch (std::exception &e) { cout << "list_includes: exception caught: " << e.what() << endl; diff --git a/samples/quick_start/quick_start.cpp b/samples/quick_start/quick_start.cpp index 4f82909..6a4b955 100644 --- a/samples/quick_start/quick_start.cpp +++ b/samples/quick_start/quick_start.cpp @@ -36,6 +36,7 @@ int main(int argc, char *argv[]) boost::wave::util::file_position_t current_position; try { + // Open and read in the specified input file. std::ifstream instream(argv[1]); std::string instring; @@ -55,19 +56,22 @@ boost::wave::util::file_position_t current_position; // be used by the Wave library. typedef boost::wave::cpplexer::lex_iterator lex_iterator_t; - // This is the resulting context type to use. + // This is the resulting context type to use. The first template parameter + // should match the iterator type to be used during construction of the + // corresponding context object (see below). typedef boost::wave::context context_t; // The preprocessor iterator shouldn't be constructed directly. It is // to be generated through a wave::context<> object. This wave:context<> - // object is additionally to be used to initialize and define different - // parameters of the actual preprocessing. + // object is to be used additionally to initialize and define different + // parameters of the actual preprocessing (not done here). + // // The preprocessing of the input stream is done on the fly behind the // scenes during iteration over the context_t::iterator_t stream. context_t ctx (instring.begin(), instring.end(), argv[1]); - // analyze the actual file + // analyze the input file context_t::iterator_t first = ctx.begin(); context_t::iterator_t last = ctx.end(); diff --git a/samples/waveidl/idl.cpp b/samples/waveidl/idl.cpp index 464cc31..3120e85 100644 --- a/samples/waveidl/idl.cpp +++ b/samples/waveidl/idl.cpp @@ -123,7 +123,7 @@ namespace cmd_line_util { return pair(); } - // class, which keeps include file information from the command line + // class, which keeps include file information read from the command line class include_paths { public: include_paths() : seen_separator(false) {} @@ -159,14 +159,6 @@ namespace cmd_line_util { } }; - // Workaround for a problem in the program_options library: all options - // stored in a variables_map, which have an assigned validator function - // need an extraction operator. - std::istream& operator>>(std::istream& is, include_paths& p) - { - return is; - } - // Read all options from a given config file, parse and add them to the // given variables_map void read_config_file_options(string const &filename, @@ -205,20 +197,40 @@ namespace cmd_line_util { } } + // predicate to extract all positional arguments from the command line + struct is_argument { + bool operator()(po::option const &opt) + { + return (opt.position_key == -1) ? true : false; + } + }; + /////////////////////////////////////////////////////////////////////////////// } +/////////////////////////////////////////////////////////////////////////////// +// +// Special validator overload, which allows to handle the -I- syntax for +// switching the semantics of an -I option. +// +/////////////////////////////////////////////////////////////////////////////// +void +po::validator::operator()( + boost::any &v, std::vector const &s) +{ + cmd_line_util::include_paths::validate(v, s); +} + /////////////////////////////////////////////////////////////////////////////// // do the actual preprocessing -int do_actual_work (po::options_and_arguments const opts, - po::variables_map const &vm) +int +do_actual_work (std::string file_name, po::variables_map const &vm) { // current file position is saved for exception handling boost::wave::util::file_position_t current_position; try { // process the given file - string file_name(opts.arguments().front()); ifstream instream(file_name.c_str()); string instring; @@ -256,8 +268,8 @@ boost::wave::util::file_position_t current_position; // add include directories to the system include search paths if (vm.count("sysinclude")) { - vector syspaths = vm["sysinclude"].as >(); - + vector const &syspaths = + vm["sysinclude"].as >(); vector::const_iterator end = syspaths.end(); for (vector::const_iterator cit = syspaths.begin(); cit != end; ++cit) @@ -293,7 +305,7 @@ boost::wave::util::file_position_t current_position; // add additional defined macros if (vm.count("define")) { - vector macros = vm["define"].as >(); + vector const ¯os = vm["define"].as >(); vector::const_iterator end = macros.end(); for (vector::const_iterator cit = macros.begin(); cit != end; ++cit) @@ -304,7 +316,8 @@ boost::wave::util::file_position_t current_position; // add additional predefined macros if (vm.count("predefine")) { - vector predefmacros = vm["predefine"].as >(); + vector const &predefmacros = + vm["predefine"].as >(); vector::const_iterator end = predefmacros.end(); for (vector::const_iterator cit = predefmacros.begin(); cit != end; ++cit) @@ -315,7 +328,8 @@ boost::wave::util::file_position_t current_position; // undefine specified macros if (vm.count("undefine")) { - vector undefmacros = vm["undefine"].as >(); + vector const &undefmacros = + vm["undefine"].as >(); vector::const_iterator end = undefmacros.end(); for (vector::const_iterator cit = undefmacros.begin(); cit != end; ++cit) @@ -411,16 +425,15 @@ main (int argc, char const *argv[]) { try { // analyze the command line options and arguments - vector cfg_files; // declare the options allowed from the command line only po::options_description desc_cmdline ("Options allowed on the command line only"); desc_cmdline.add_options() - ("help,h", "", "print out program usage (this message)") - ("version,v", "", "print the version number") - ("copyright,c", "", "print out the copyright statement") - ("config-file", po::parameter("filepath", &cfg_files), + ("help,h", "print out program usage (this message)") + ("version,v", "print the version number") + ("copyright,c", "print out the copyright statement") + ("config-file", po::value >(), "specify a config file (alternatively: @filepath)") ; @@ -428,36 +441,34 @@ main (int argc, char const *argv[]) po::options_description desc_generic ("Options allowed additionally in a config file"); desc_generic.add_options() - ("output,o", "path", "specify a file to use for output instead of stdout") - ("include,I", "path", "specify an additional include directory"). - validator(&cmd_line_util::include_paths::validate) - ("sysinclude,S", po::parameter >("syspath"), + ("output,o", "specify a file to use for output instead of stdout") + ("include,I", po::value()->composing(), + "specify an additional include directory") + ("sysinclude,S", po::value >()->composing(), "specify an additional system include directory") - ("define,D", po::parameter >("macro[=[value]]"), - "specify a macro to define") - ("predefine,P", po::parameter >("macro[=[value]]"), - "specify a macro to predefine") - ("undefine,U", po::parameter >("macro"), + ("define,D", po::value >()->composing(), + "specify a macro to define (as macro[=[value]])") + ("predefine,P", po::value >()->composing(), + "specify a macro to predefine (as macro[=[value]])") + ("undefine,U", po::value >()->composing(), "specify a macro to undefine") ; // combine the options for the different usage schemes po::options_description desc_overall_cmdline; - - desc_overall_cmdline.add(desc_cmdline); - desc_overall_cmdline.add(desc_generic); - po::options_description desc_overall_cfgfile; + desc_overall_cmdline.add(desc_cmdline).add(desc_generic); desc_overall_cfgfile.add(desc_generic); // parse command line and store results - po::options_and_arguments opts = po::parse_command_line(argc, argv, + po::parsed_options opts = po::parse_command_line(argc, argv, desc_overall_cmdline, 0, cmd_line_util::at_option_parser); po::variables_map vm; - po::store(opts, vm, desc_overall_cmdline); - + po::store(opts, vm); + po::notify(vm); + // Try to find a waveidl.cfg in the same directory as the executable was // started from. If this exists, treat it as a wave config file fs::path filename(argv[0], fs::native); @@ -469,6 +480,8 @@ main (int argc, char const *argv[]) // if there is specified at least one config file, parse it and add the // options to the main variables_map if (vm.count("config-file")) { + vector const &cfg_files = + vm["config-file"].as >(); vector::const_iterator end = cfg_files.end(); for (vector::const_iterator cit = cfg_files.begin(); cit != end; ++cit) @@ -484,8 +497,7 @@ main (int argc, char const *argv[]) po::options_description desc_help ( "Usage: waveidl [options] [@config-file(s)] file"); - desc_help.add(desc_cmdline); - desc_help.add(desc_generic); + desc_help.add(desc_cmdline).add(desc_generic); cout << desc_help << endl; return 1; } @@ -498,15 +510,21 @@ main (int argc, char const *argv[]) return print_copyright(); } + // extract the arguments from the parsed command line + vector arguments; + + std::remove_copy_if(opts.options.begin(), opts.options.end(), + inserter(arguments, arguments.end()), cmd_line_util::is_argument()); + // if there is no input file given, then exit - if (0 == opts.arguments().size()) { + if (0 == arguments.size() || 0 == arguments[0].value.size()) { cerr << "waveidl: no input file given, " << "use --help to get a hint." << endl; return 5; } // preprocess the given input file - return do_actual_work(opts, vm); + return do_actual_work(arguments[0].value[0], vm); } catch (std::exception &e) { cout << "waveidl: exception caught: " << e.what() << endl; diff --git a/samples/waveidl/idl_config.hpp b/samples/waveidl/idl_config.hpp index 850c069..c33f238 100644 --- a/samples/waveidl/idl_config.hpp +++ b/samples/waveidl/idl_config.hpp @@ -99,14 +99,16 @@ // Define the string type to be used to store the token values and the file // names inside a file_position template class // - -// use the following, if you have a fast std::allocator #define BOOST_WAVE_STRINGTYPE boost::wave::util::flex_string< \ char, std::char_traits, std::allocator, \ - boost::wave::util::CowString< \ - boost::wave::util::AllocatorStringStorage > \ + boost::wave::util::CowString< \ + boost::wave::util::AllocatorStringStorage \ + > \ > \ /**/ + +// This include is needed for the flex_string class used in the +// BOOST_WAVE_STRINGTYPE above. #include /////////////////////////////////////////////////////////////////////////////// @@ -191,6 +193,10 @@ // #define BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION 1 +/////////////////////////////////////////////////////////////////////////////// +// configure Boost.Pool thread support (for now: no thread support at all) +#define BOOST_NO_MT + /////////////////////////////////////////////////////////////////////////////// // MSVC specific #pragma's #if defined(BOOST_MSVC) diff --git a/src/cpplexer/re2clex/cpp.re.cpp b/src/cpplexer/re2clex/cpp.re.cpp index ec254f7..d6d94dd 100644 --- a/src/cpplexer/re2clex/cpp.re.cpp +++ b/src/cpplexer/re2clex/cpp.re.cpp @@ -1,4 +1,4 @@ -/* Generated by re2c 0.5 on Sat Feb 28 15:06:01 2004 */ +/* Generated by re2c 0.5 on Thu Mar 18 10:53:27 2004 */ #line 1 "c:\\Cvs\\spirit\\wave\\boost\\libs\\wave\\src\\cpplexer\\re2clex\\cpp.re" /*============================================================================= Wave: A Standard compliant C++ preprocessor library diff --git a/tool/cpp.cpp b/tool/cpp.cpp index bfcc253..94dc3a5 100644 --- a/tool/cpp.cpp +++ b/tool/cpp.cpp @@ -18,6 +18,7 @@ // It is available here: http://boost-sandbox.sourceforge.net/program_options. // #include +#include #include #include @@ -97,7 +98,7 @@ int print_version() // print the copyright statement int print_copyright() { -char const *copyright[] = { + char const *copyright[] = { "", "Wave: A Standard conformant C++ preprocessor", "Copyright (c) 2001-2004 Hartmut Kaiser", @@ -128,7 +129,7 @@ namespace cmd_line_util { return pair(); } - // class, which keeps include file information from the command line + // class, which keeps include file information read from the command line class include_paths { public: include_paths() : seen_separator(false) {} @@ -164,14 +165,6 @@ namespace cmd_line_util { } }; - // Workaround for a problem in the program_options library: all options - // stored in a variables_map, which have an assigned validator function - // need an extraction operator. - std::istream& operator>>(std::istream& is, include_paths& p) - { - return is; - } - // Read all options from a given config file, parse and add them to the // given variables_map void read_config_file_options(string const &filename, @@ -204,15 +197,35 @@ namespace cmd_line_util { } if (options.size() > 0) { - po::options_and_arguments oa = po::parse_command_line(options, desc); - - po::store(oa, vm, desc); + po::store(po::command_line_parser(options).options(desc).run(), vm); + po::notify(vm); } } + // predicate to extract all positional arguments from the command line + struct is_argument { + bool operator()(po::option const &opt) + { + return (opt.position_key == -1) ? true : false; + } + }; + /////////////////////////////////////////////////////////////////////////////// } +/////////////////////////////////////////////////////////////////////////////// +// +// Special validator overload, which allows to handle the -I- syntax for +// switching the semantics of an -I option. +// +/////////////////////////////////////////////////////////////////////////////// +void +po::validator::operator()( + boost::any &v, std::vector const &s) +{ + cmd_line_util::include_paths::validate(v, s); +} + /////////////////////////////////////////////////////////////////////////////// namespace { @@ -243,15 +256,14 @@ namespace { /////////////////////////////////////////////////////////////////////////////// // do the actual preprocessing -int do_actual_work (po::options_and_arguments const opts, - po::variables_map const &vm) +int +do_actual_work (std::string file_name, po::variables_map const &vm) { // current file position is saved for exception handling boost::wave::util::file_position_t current_position; try { // process the given file - string file_name(opts.arguments().front()); ifstream instream(file_name.c_str()); string instring; @@ -381,7 +393,7 @@ boost::wave::util::file_position_t current_position; // add additional defined macros if (vm.count("define")) { - vector macros = vm["define"].as >(); + vector const ¯os = vm["define"].as >(); vector::const_iterator end = macros.end(); for (vector::const_iterator cit = macros.begin(); cit != end; ++cit) @@ -392,7 +404,8 @@ boost::wave::util::file_position_t current_position; // add additional predefined macros if (vm.count("predefine")) { - vector predefmacros = vm["predefine"].as >(); + vector const &predefmacros = + vm["predefine"].as >(); vector::const_iterator end = predefmacros.end(); for (vector::const_iterator cit = predefmacros.begin(); cit != end; ++cit) @@ -403,7 +416,8 @@ boost::wave::util::file_position_t current_position; // undefine specified macros if (vm.count("undefine")) { - vector undefmacros = vm["undefine"].as >(); + vector const &undefmacros = + vm["undefine"].as >(); vector::const_iterator end = undefmacros.end(); for (vector::const_iterator cit = undefmacros.begin(); cit != end; ++cit) @@ -452,7 +466,8 @@ boost::wave::util::file_position_t current_position; // add the filenames to force as include files in _reverse_ order // the second parameter 'is_last' for the force_include function should // be set to true for the last (first given) file. - vector force = vm["forceinclude"].as >(); + vector const &force = + vm["forceinclude"].as >(); vector::const_reverse_iterator rend = force.rend(); for (vector::const_reverse_iterator cit = force.rbegin(); cit != rend; /**/) @@ -526,16 +541,15 @@ main (int argc, char const *argv[]) { try { // analyze the command line options and arguments - vector cfg_files; // declare the options allowed from the command line only po::options_description desc_cmdline ("Options allowed on the command line only"); desc_cmdline.add_options() - ("help,h", "", "print out program usage (this message)") - ("version,v", "", "print the version number") - ("copyright,c", "", "print out the copyright statement") - ("config-file", po::parameter("filepath", &cfg_files), + ("help,h", "print out program usage (this message)") + ("version,v", "print the version number") + ("copyright,c", "print out the copyright statement") + ("config-file", po::value >(), "specify a config file (alternatively: @filepath)") ; @@ -543,55 +557,52 @@ main (int argc, char const *argv[]) po::options_description desc_generic ("Options allowed additionally in a config file"); desc_generic.add_options() - ("output,o", "path", "specify a file to use for output instead of stdout") - ("include,I", "path", "specify an additional include directory"). - validator(&cmd_line_util::include_paths::validate) - ("sysinclude,S", po::parameter >("syspath"), + ("output,o", "specify a file to use for output instead of stdout") + ("include,I", po::value()->composing(), + "specify an additional include directory") + ("sysinclude,S", po::value >()->composing(), "specify an additional system include directory") - ("forceinclude,F", po::parameter >("file"), + ("forceinclude,F", po::value >()->composing(), "force inclusion of the given file") - ("define,D", po::parameter >("macro[=[value]]"), - "specify a macro to define") - ("predefine,P", po::parameter >("macro[=[value]]"), - "specify a macro to predefine") - ("undefine,U", po::parameter >("macro"), + ("define,D", po::value >()->composing(), + "specify a macro to define (as macro[=[value]])") + ("predefine,P", po::value >()->composing(), + "specify a macro to predefine (as macro[=[value]])") + ("undefine,U", po::value >()->composing(), "specify a macro to undefine") - ("nesting,n", po::parameter("depth"), + ("nesting,n", po::value(), "specify a new maximal include nesting depth") ; po::options_description desc_ext ("Extended options (allowed everywhere)"); desc_ext.add_options() - ("traceto,t", "path", "output trace info to a file [path] or to stderr [-]") - ("timer", "", "output overall elapsed computing time to stderr") + ("traceto,t", po::value(), + "output trace info to a file [path] or to stderr [-]") + ("timer", "output overall elapsed computing time to stderr") #if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0 - ("variadics", "", "enable certain C99 extensions in C++ mode") - ("c99", "", "enable C99 mode (implies --variadics)") + ("variadics", "enable certain C99 extensions in C++ mode") + ("c99", "enable C99 mode (implies --variadics)") #endif #if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0 - ("c++0x", "", "enable C++0x support (implies --variadics)") + ("c++0x", "enable C++0x support (implies --variadics)") #endif ; // combine the options for the different usage schemes po::options_description desc_overall_cmdline; - - desc_overall_cmdline.add(desc_cmdline); - desc_overall_cmdline.add(desc_generic); - desc_overall_cmdline.add(desc_ext); - po::options_description desc_overall_cfgfile; - desc_overall_cfgfile.add(desc_generic); - desc_overall_cfgfile.add(desc_ext); + desc_overall_cmdline.add(desc_cmdline).add(desc_generic).add(desc_ext); + desc_overall_cfgfile.add(desc_generic).add(desc_ext); // parse command line and store results - po::options_and_arguments opts = po::parse_command_line(argc, argv, - desc_overall_cmdline, 0, cmd_line_util::at_option_parser); + po::parsed_options opts(po::parse_command_line(argc, argv, + desc_overall_cmdline, 0, cmd_line_util::at_option_parser)); po::variables_map vm; - po::store(opts, vm, desc_overall_cmdline); + po::store(opts, vm); + po::notify(vm); // Try to find a wave.cfg in the same directory as the executable was // started from. If this exists, treat it as a wave config file @@ -604,6 +615,8 @@ main (int argc, char const *argv[]) // if there is specified at least one config file, parse it and add the // options to the main variables_map if (vm.count("config-file")) { + vector const &cfg_files = + vm["config-file"].as >(); vector::const_iterator end = cfg_files.end(); for (vector::const_iterator cit = cfg_files.begin(); cit != end; ++cit) @@ -619,9 +632,7 @@ main (int argc, char const *argv[]) po::options_description desc_help ( "Usage: wave [options] [@config-file(s)] file"); - desc_help.add(desc_cmdline); - desc_help.add(desc_generic); - desc_help.add(desc_ext); + desc_help.add(desc_cmdline).add(desc_generic).add(desc_ext); cout << desc_help << endl; return 1; } @@ -633,16 +644,22 @@ main (int argc, char const *argv[]) if (vm.count("copyright")) { return print_copyright(); } - + + // extract the arguments from the parsed command line + vector arguments; + + std::remove_copy_if(opts.options.begin(), opts.options.end(), + inserter(arguments, arguments.end()), cmd_line_util::is_argument()); + // if there is no input file given, then exit - if (0 == opts.arguments().size()) { + if (0 == arguments.size() || 0 == arguments[0].value.size()) { cerr << "wave: no input file given, " << "use --help to get a hint." << endl; return 5; } // preprocess the given input file - return do_actual_work(opts, vm); + return do_actual_work(arguments[0].value[0], vm); } catch (std::exception &e) { cout << "wave: exception caught: " << e.what() << endl; diff --git a/tool/cpp_config.hpp b/tool/cpp_config.hpp index 8c6485e..764ec63 100644 --- a/tool/cpp_config.hpp +++ b/tool/cpp_config.hpp @@ -122,14 +122,34 @@ // // use the following, if you have a fast std::allocator -#define BOOST_WAVE_STRINGTYPE wave::util::flex_string< \ +#define BOOST_WAVE_STRINGTYPE boost::wave::util::flex_string< \ char, std::char_traits, std::allocator, \ - wave::util::CowString > \ + boost::wave::util::CowString \ + > \ > \ /**/ + +//#define BOOST_WAVE_STRINGTYPE boost::wave::util::flex_string< \ +// char, std::char_traits, boost::fast_pool_allocator, \ +// boost::wave::util::CowString \ +// > \ +// > \ +// > \ +// /**/ + +// This include is needed for the flex_string class used in the +// BOOST_WAVE_STRINGTYPE above. #include +// This include is needed for the boost::fast_allocator class used in the +// BOOST_WAVE_STRINGTYPE above. +// Configure Boost.Pool thread support (for now: no thread support at all) +#define BOOST_NO_MT +#include + /////////////////////////////////////////////////////////////////////////////// // Uncomment the following, if you need debug output, the // BOOST_SPIRIT_DEBUG_FLAGS constants below help to fine control the amount of @@ -148,7 +168,7 @@ /**/ /////////////////////////////////////////////////////////////////////////////// -// debug flags for the pp-iterator library, possible flags (defined in +// debug flags for the Wave library, possible flags (defined in // wave_config.hpp): // // #define BOOST_SPIRIT_DEBUG_FLAGS_CPP_GRAMMAR 0x0001 @@ -159,7 +179,7 @@ // #define BOOST_SPIRIT_DEBUG_FLAGS_DEFINED_GRAMMAR 0x0020 // #define BOOST_SPIRIT_DEBUG_FLAGS_PREDEF_MACROS_GRAMMAR 0x0040 -#define BOOST_SPIRIT_DEBUG_FLAGS_CPP (\ +#define BOOST_SPIRIT_DEBUG_FLAGS_CPP ( 0 | \ /* insert the required flags from above */ \ ) \ /**/ diff --git a/tool/cpp_version.hpp b/tool/cpp_version.hpp index d279e52..8aa3d8f 100644 --- a/tool/cpp_version.hpp +++ b/tool/cpp_version.hpp @@ -17,6 +17,6 @@ #define CPP_VERSION_MAJOR BOOST_WAVE_VERSION_MAJOR #define CPP_VERSION_MINOR BOOST_WAVE_VERSION_MINOR #define CPP_VERSION_SUBMINOR BOOST_WAVE_VERSION_SUBMINOR -#define CPP_VERSION_DATE 20040228L +#define CPP_VERSION_DATE 20040325L #endif // !defined(CPP_VERSION_HPP_CE4FE67F_63F9_468D_8364_C855F89D3C5D_INCLUDED)