From bee5d0dd77b83cbdd4f8fc89a42994361ce12fc3 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Thu, 24 Mar 2011 21:24:24 +0000 Subject: [PATCH] Quickbook: Small cleanups. Mostly avoiding warnings, and removing unnecessary includes. [SVN r70526] --- src/Jamfile.v2 | 2 + src/actions.cpp | 133 +++++++++++++++++++++------------------ src/actions.hpp | 21 +------ src/actions_class.hpp | 5 +- src/code_snippet.cpp | 9 ++- src/doc_info_actions.cpp | 1 + src/doc_info_grammar.cpp | 10 +-- src/fwd.hpp | 3 + src/main_grammar.cpp | 1 - src/parsers.hpp | 7 ++- src/quickbook.cpp | 9 ++- src/rule_store.hpp | 5 +- src/values.cpp | 2 +- src/values.hpp | 22 +++++-- 14 files changed, 126 insertions(+), 104 deletions(-) diff --git a/src/Jamfile.v2 b/src/Jamfile.v2 index 0e29632..e7ead94 100644 --- a/src/Jamfile.v2 +++ b/src/Jamfile.v2 @@ -14,6 +14,8 @@ project quickbook darwin:300 gcc:-g0 darwin:-g0 + all + msvc:/wd4709 ; lib shell32 ; diff --git a/src/actions.cpp b/src/actions.cpp index ca6dff4..f4b2d7e 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -10,15 +10,15 @@ =============================================================================*/ #include #include -#include #include #include #include +#include #include #include -#include #include #include +#include #include "quickbook.hpp" #include "actions.hpp" #include "utils.hpp" @@ -558,12 +558,12 @@ namespace quickbook detail::print_space(*first++, out.get()); } - void pre_escape_back::operator()(iterator first, iterator last) const + void pre_escape_back::operator()(iterator, iterator) const { escape_actions.phrase.push(); // save the stream } - void post_escape_back::operator()(iterator first, iterator last) const + void post_escape_back::operator()(iterator, iterator) const { escape_actions.output_pre(escape_actions.phrase); out << escape_actions.phrase.str(); @@ -897,59 +897,72 @@ namespace quickbook namespace { - iterator find_bracket_end(iterator begin, iterator const& end) - { - unsigned int depth = 1; - - while(depth > 0) { - char const* search_chars = "[]\\"; - begin = std::find_first_of(begin, end, search_chars, search_chars + 3); - if(begin == end) return begin; - - if(*begin == '\\') - { - if(++begin == end) return begin; - ++begin; - } - else - { - depth += (*begin == '[') ? 1 : -1; - ++begin; - } - } - - return begin; - } - - iterator find_first_seperator(iterator const& begin, iterator const& end) + iterator find_first_seperator(iterator begin, iterator end) { if(qbk_version_n < 105) { - char const* whitespace = " \t\r\n"; - return std::find_first_of(begin, end, whitespace, whitespace + 4); - } - else { - iterator pos = begin; - - while(true) + for(;begin != end; ++begin) { - char const* search_chars = " \t\r\n\\["; - pos = std::find_first_of(pos, end, search_chars, search_chars + 6); - if(pos == end) return pos; - - switch(*pos) + switch(*begin) { - case '[': - pos = find_bracket_end(++pos, end); - break; - case '\\': - if(++pos == end) return pos; - ++pos; - break; + case ' ': + case '\t': + case '\n': + case '\r': + return begin; default: - return pos; + break; } } } + else { + unsigned int depth = 0; + + for(;begin != end; ++begin) + { + switch(*begin) + { + case '[': + ++depth; + break; + case '\\': + if(++begin == end) return begin; + break; + case ']': + if (depth > 0) --depth; + break; + case ' ': + case '\t': + case '\n': + case '\r': + if (depth == 0) return begin; + default: + break; + } + } + } + + return begin; + } + + std::pair find_seperator(iterator begin, iterator end) + { + iterator first = begin = find_first_seperator(begin, end); + + for(;begin != end; ++begin) + { + switch(*begin) + { + case ' ': + case '\t': + case '\n': + case '\r': + break; + default: + return std::make_pair(first, begin); + } + } + + return std::make_pair(first, begin); } bool break_arguments( @@ -980,17 +993,15 @@ namespace quickbook iterator begin(body.content.begin(), body.position); iterator end(body.content.end()); - iterator l_pos = find_first_seperator(begin, end); - if (l_pos == end) - break; - char const* whitespace = " \t\r\n"; - char const* whitespace_end = whitespace + 4; - iterator r_pos = l_pos; - while(r_pos != end && std::find(whitespace, whitespace_end, *r_pos) != whitespace_end) ++r_pos; - if (r_pos == end) - break; - template_body second(std::string(r_pos, end), body.filename, r_pos.get_position(), false); - body.content = std::string(begin, l_pos); + std::pair pos = + find_seperator(begin, end); + if (pos.second == end) break; + template_body second( + std::string(pos.second, end), + body.filename, + pos.second.get_position(), + false); + body.content = std::string(begin, pos.first); args.push_back(second); } } @@ -1834,7 +1845,7 @@ namespace quickbook return (*this)(first, last, value::default_tag); } - void collector_to_value_action::operator()(iterator first, iterator last) const + void collector_to_value_action::operator()(iterator, iterator) const { if(!actions.output_pre(output)) return; diff --git a/src/actions.hpp b/src/actions.hpp index f47aaf4..a2a34c7 100644 --- a/src/actions.hpp +++ b/src/actions.hpp @@ -10,32 +10,19 @@ #if !defined(BOOST_SPIRIT_QUICKBOOK_ACTIONS_HPP) #define BOOST_SPIRIT_QUICKBOOK_ACTIONS_HPP -#include #include #include -#include -#include -#include #include -#include -#include +#include #include "fwd.hpp" -#include "collector.hpp" #include "template_stack.hpp" #include "utils.hpp" #include "values.hpp" #include "scoped.hpp" -#ifdef BOOST_MSVC -// disable copy/assignment could not be generated, unreferenced formal params -#pragma warning (push) -#pragma warning(disable : 4511 4512 4100) -#endif - namespace quickbook { namespace cl = boost::spirit::classic; - namespace fs = boost::filesystem; extern unsigned qbk_version_n; // qbk_major_version * 100 + qbk_minor_version @@ -125,7 +112,7 @@ namespace quickbook : actions(actions) {} void operator()() const; - void operator()(iterator first, iterator last) const { (*this)(); } + void operator()(iterator, iterator) const { (*this)(); } quickbook::actions& actions; }; @@ -441,8 +428,4 @@ namespace quickbook }; } -#ifdef BOOST_MSVC -#pragma warning (pop) -#endif - #endif // BOOST_SPIRIT_QUICKBOOK_ACTIONS_HPP diff --git a/src/actions_class.hpp b/src/actions_class.hpp index ae7f227..fe580cf 100644 --- a/src/actions_class.hpp +++ b/src/actions_class.hpp @@ -10,11 +10,12 @@ #if !defined(BOOST_SPIRIT_ACTIONS_CLASS_HPP) #define BOOST_SPIRIT_ACTIONS_CLASS_HPP +#include +#include #include "actions.hpp" #include "parsers.hpp" #include "values_parse.hpp" -#include -#include +#include "collector.hpp" namespace quickbook { diff --git a/src/code_snippet.cpp b/src/code_snippet.cpp index 10a3dab..4391299 100644 --- a/src/code_snippet.cpp +++ b/src/code_snippet.cpp @@ -7,6 +7,7 @@ http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ +#include #include #include #include @@ -307,9 +308,7 @@ namespace quickbook iterator first(code.begin()); iterator last(code.end()); - size_t fname_len = file.size(); - bool is_python = fname_len >= 3 - && file[--fname_len]=='y' && file[--fname_len]=='p' && file[--fname_len]=='.'; + bool is_python = extension == ".py"; code_snippet_actions a(storage, file, doc_id, is_python ? "[python]" : "[c++]"); // TODO: Should I check that parse succeeded? if(is_python) { @@ -398,14 +397,14 @@ namespace quickbook } } - void code_snippet_actions::start_snippet(iterator first, iterator last) + void code_snippet_actions::start_snippet(iterator, iterator) { append_code(); snippet_stack.push(snippet_data(id, callout_id)); id.clear(); } - void code_snippet_actions::end_snippet(iterator first, iterator last) + void code_snippet_actions::end_snippet(iterator first, iterator) { // TODO: Error? if(snippet_stack.empty()) return; diff --git a/src/doc_info_actions.cpp b/src/doc_info_actions.cpp index a7c6214..2d7939e 100644 --- a/src/doc_info_actions.cpp +++ b/src/doc_info_actions.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "quickbook.hpp" #include "utils.hpp" #include "input_path.hpp" diff --git a/src/doc_info_grammar.cpp b/src/doc_info_grammar.cpp index ceb8107..8eac383 100644 --- a/src/doc_info_grammar.cpp +++ b/src/doc_info_grammar.cpp @@ -8,10 +8,8 @@ http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ -#include "grammar_impl.hpp" -#include "actions_class.hpp" -#include "doc_info_tags.hpp" -#include "phrase_tags.hpp" +#include +#include #include #include #include @@ -19,6 +17,10 @@ #include #include #include +#include "grammar_impl.hpp" +#include "actions_class.hpp" +#include "doc_info_tags.hpp" +#include "phrase_tags.hpp" namespace quickbook { diff --git a/src/fwd.hpp b/src/fwd.hpp index 1e0926e..60d246d 100644 --- a/src/fwd.hpp +++ b/src/fwd.hpp @@ -17,8 +17,11 @@ namespace quickbook { struct actions; struct quickbook_grammar; + struct collector; typedef position_iterator iterator; + + inline void ignore_variable(void const*) {} } #endif diff --git a/src/main_grammar.cpp b/src/main_grammar.cpp index 377bd3e..2ebe04b 100644 --- a/src/main_grammar.cpp +++ b/src/main_grammar.cpp @@ -186,7 +186,6 @@ namespace quickbook ) >> local.process_element() [ actions.values.list(ph::var(local.info.tag)) - [ cl::lazy_p(*ph::var(local.info.rule)) >> space >> ']' diff --git a/src/parsers.hpp b/src/parsers.hpp index 152771e..cd3a061 100644 --- a/src/parsers.hpp +++ b/src/parsers.hpp @@ -176,7 +176,7 @@ namespace quickbook { { typedef phoenix::tuple<> tuple; return scoped_parser_gen(impl_, tuple()); - }; + } template scoped_parser_gen > @@ -184,7 +184,7 @@ namespace quickbook { { typedef phoenix::tuple tuple; return scoped_parser_gen(impl_, tuple(x1)); - }; + } template scoped_parser_gen > @@ -192,7 +192,7 @@ namespace quickbook { { typedef phoenix::tuple tuple; return scoped_parser_gen(impl_, tuple(x1, x2)); - }; + } Impl impl_; }; @@ -252,4 +252,5 @@ namespace quickbook { lookback_gen const lookback = lookback_gen(); } + #endif // BOOST_QUICKBOOK_SCOPED_BLOCK_HPP diff --git a/src/quickbook.cpp b/src/quickbook.cpp index d7fa8ef..6c9dc1e 100644 --- a/src/quickbook.cpp +++ b/src/quickbook.cpp @@ -110,8 +110,10 @@ namespace quickbook } static int - parse_document(fs::path const& filein_, fs::path const& xinclude_base, - string_stream& out, bool ignore_docinfo = false) + parse_document( + fs::path const& filein_, + fs::path const& xinclude_base, + string_stream& out) { actions actor(filein_, xinclude_base, out); @@ -248,6 +250,9 @@ main(int argc, char* argv[]) bool pretty_print = true; #if QUICKBOOK_WIDE_PATHS + quickbook::ignore_variable(&argc); + quickbook::ignore_variable(&argv); + int wide_argc; LPWSTR* wide_argv = CommandLineToArgvW(GetCommandLineW(), &wide_argc); if (!wide_argv) diff --git a/src/rule_store.hpp b/src/rule_store.hpp index d9aa6c6..29d3466 100644 --- a/src/rule_store.hpp +++ b/src/rule_store.hpp @@ -15,7 +15,7 @@ #define BOOST_SPIRIT_QUICKBOOK_RULE_STORE_HPP #include -#include +#include #include namespace quickbook @@ -34,7 +34,8 @@ namespace quickbook scoped_void() : ptr_(0), del_(0) {} scoped_void(scoped_void const& src) : ptr_(0), del_(0) { - BOOST_ASSERT(!src.ptr_); + ignore_variable(&src); + assert(!src.ptr_); } ~scoped_void() { if(ptr_) del_(ptr_); diff --git a/src/values.cpp b/src/values.cpp index e17b320..9c2a439 100644 --- a/src/values.cpp +++ b/src/values.cpp @@ -693,7 +693,7 @@ namespace quickbook value_node* pos = head_; boost::intrusive_ptr new_node; - while(true) { + for(;;) { if(pos == &value_nil_impl::instance) return this; new_node = pos->store(); diff --git a/src/values.hpp b/src/values.hpp index 4e11750..0b060ec 100644 --- a/src/values.hpp +++ b/src/values.hpp @@ -305,7 +305,6 @@ namespace quickbook value::iterator* ptr_; }; - typedef iterator const_iterator; typedef iterator::reference reference; @@ -323,13 +322,13 @@ namespace quickbook reference consume() { - assert(check()); + assert_check(); return *pos_++; } reference consume(value::tag_type t) { - assert(check(t)); + assert_check(t); return *pos_++; } @@ -365,12 +364,27 @@ namespace quickbook void finish() const { - assert(pos_ == end_); + if (pos_ != end_) + throw value_error("Not all values handled."); } iterator begin() { return iterator(&pos_); } iterator end() { return iterator(&end_); } private: + + void assert_check() const + { + if (pos_ == end_) + throw value_error("Attempt to read past end of value list."); + } + + void assert_check(value::tag_type t) const + { + assert_check(); + if (t != pos_->get_tag()) + throw value_error("Incorrect value tag."); + } + value list_; value::iterator pos_, end_; };