|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r70195 - in trunk/tools/quickbook: . src
From: dnljms_at_[hidden]
Date: 2011-03-19 12:24:41
Author: danieljames
Date: 2011-03-19 12:24:39 EDT (Sat, 19 Mar 2011)
New Revision: 70195
URL: http://svn.boost.org/trac/boost/changeset/70195
Log:
Quickbook: Implement int value and use for years and versions.
Hopefully will no longer need to the workaround for 64 bit gcc.
Properties modified:
trunk/tools/quickbook/ (props changed)
Text files modified:
trunk/tools/quickbook/src/actions.cpp | 8 -----
trunk/tools/quickbook/src/actions.hpp | 10 ------
trunk/tools/quickbook/src/doc_info_actions.cpp | 26 ++++++++++------
trunk/tools/quickbook/src/doc_info_grammar.cpp | 19 ++++++-----
trunk/tools/quickbook/src/doc_info_tags.hpp | 1
trunk/tools/quickbook/src/values.cpp | 63 ++++++++++++++++++++++++++++++++++++---
trunk/tools/quickbook/src/values.hpp | 10 +++++
trunk/tools/quickbook/src/values_parse.hpp | 6 +++
8 files changed, 101 insertions(+), 42 deletions(-)
Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp (original)
+++ trunk/tools/quickbook/src/actions.cpp 2011-03-19 12:24:39 EDT (Sat, 19 Mar 2011)
@@ -33,12 +33,8 @@
char const* quickbook_get_date = "__quickbook_get_date__";
char const* quickbook_get_time = "__quickbook_get_time__";
- int qbk_major_version = -1;
- int qbk_minor_version = -1;
unsigned qbk_version_n = 0; // qbk_major_version * 100 + qbk_minor_version
- void assign_qbk_version::operator()(int value) const { v_ = value; }
-
namespace {
std::string fully_qualified_id(std::string const& library_id,
std::string const& qualified_section_id,
@@ -1646,8 +1642,6 @@
// save the source mode and version info (only restored for 1.6+)
std::string source_mode = actions.source_mode;
- unsigned qbk_major_version_store = qbk_major_version;
- unsigned qbk_minor_version_store = qbk_minor_version;
unsigned qbk_version_n_store = qbk_version_n;
// scope the macros
@@ -1683,8 +1677,6 @@
{
actions.source_mode = source_mode;
- qbk_major_version = qbk_major_version_store;
- qbk_minor_version = qbk_minor_version_store;
qbk_version_n = qbk_version_n_store;
}
Modified: trunk/tools/quickbook/src/actions.hpp
==============================================================================
--- trunk/tools/quickbook/src/actions.hpp (original)
+++ trunk/tools/quickbook/src/actions.hpp 2011-03-19 12:24:39 EDT (Sat, 19 Mar 2011)
@@ -37,17 +37,7 @@
namespace cl = boost::spirit::classic;
namespace fs = boost::filesystem;
- extern int qbk_major_version;
- extern int qbk_minor_version;
extern unsigned qbk_version_n; // qbk_major_version * 100 + qbk_minor_version
-
- // This struct is used to avoid an optimization bug
- // in g++ 4.4 on 64-bit linux.
- struct assign_qbk_version {
- assign_qbk_version(int& v) : v_(v) {}
- void operator()(int value) const;
- int& v_;
- };
struct quickbook_range {
template <typename Arg>
Modified: trunk/tools/quickbook/src/doc_info_actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/doc_info_actions.cpp (original)
+++ trunk/tools/quickbook/src/doc_info_actions.cpp 2011-03-19 12:24:39 EDT (Sat, 19 Mar 2011)
@@ -11,7 +11,6 @@
#include <sstream>
#include <boost/bind.hpp>
#include <boost/algorithm/string/join.hpp>
-#include <boost/lexical_cast.hpp>
#include "quickbook.hpp"
#include "utils.hpp"
#include "input_path.hpp"
@@ -79,8 +78,8 @@
while (values.check(value::default_tag)) values.consume();
- std::vector<std::string> duplicates;
-
+ value qbk_version = values.optional_consume(doc_info_tags::qbk_version);
+
value doc_title;
if (values.check())
{
@@ -89,6 +88,8 @@
actions.doc_title_qbk = doc_title.get_quickbook();
}
+ std::vector<std::string> duplicates;
+
value id = consume_last_single(values, doc_info_attributes::id, &duplicates);
value dirname = consume_last_single(values, doc_info_attributes::dirname, &duplicates);
value last_revision = consume_last_single(values, doc_info_attributes::last_revision, &duplicates);
@@ -155,22 +156,28 @@
// Quickbook version
- if (qbk_major_version == -1)
+ int qbk_major_version, qbk_minor_version;
+
+ if (qbk_version.empty())
{
// hard code quickbook version to v1.1
qbk_major_version = 1;
qbk_minor_version = 1;
- qbk_version_n = 101;
detail::outwarn(actions.filename,1)
<< "Warning: Quickbook version undefined. "
"Version 1.1 is assumed" << std::endl;
}
else
{
- qbk_version_n = ((unsigned) qbk_major_version * 100) +
- (unsigned) qbk_minor_version;
+ value_consumer qbk_version_values(qbk_version);
+ qbk_major_version = qbk_version_values.consume().get_int();
+ qbk_minor_version = qbk_version_values.consume().get_int();
+ qbk_version_values.finish();
}
+ qbk_version_n = ((unsigned) qbk_major_version * 100) +
+ (unsigned) qbk_minor_version;
+
if (qbk_version_n == 106)
{
detail::outwarn(actions.filename,1)
@@ -283,11 +290,10 @@
while(copyright.check(doc_info_tags::copyright_year))
{
- int year_start =
- boost::lexical_cast<int>(copyright.consume().get_quickbook());
+ int year_start = copyright.consume().get_int();
int year_end =
copyright.check(doc_info_tags::copyright_year_end) ?
- boost::lexical_cast<int>(copyright.consume().get_quickbook()) :
+ copyright.consume().get_int() :
year_start;
if (year_end < year_start) {
Modified: trunk/tools/quickbook/src/doc_info_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/doc_info_grammar.cpp (original)
+++ trunk/tools/quickbook/src/doc_info_grammar.cpp 2011-03-19 12:24:39 EDT (Sat, 19 Mar 2011)
@@ -16,6 +16,7 @@
#include <boost/spirit/include/classic_loops.hpp>
#include <boost/spirit/include/classic_symbols.hpp>
#include <boost/spirit/include/classic_chset.hpp>
+#include <boost/spirit/include/classic_numerics.hpp>
#include <boost/spirit/include/phoenix1_primitives.hpp>
namespace quickbook
@@ -65,9 +66,10 @@
cl::rule<scanner>
doc_title, doc_simple, doc_phrase, doc_fallback,
doc_authors, doc_author,
- doc_copyright, doc_copyright_year, doc_copyright_holder,
+ doc_copyright, doc_copyright_holder,
doc_source_mode, doc_biblioid,
quickbook_version, char_;
+ cl::uint_parser<int, 10, 4, 4> doc_copyright_year;
cl::symbols<> doc_types;
cl::symbols<value::tag_type> doc_attributes;
std::map<value::tag_type, cl::rule<scanner>* > attribute_rules;
@@ -135,11 +137,14 @@
;
local.quickbook_version =
- "quickbook" >> hard_space
- >> ( cl::uint_p [assign_qbk_version(qbk_major_version)]
+ actions.values.list(doc_info_tags::qbk_version)
+ [ "quickbook"
+ >> hard_space
+ >> ( cl::uint_p [actions.values.entry(ph::arg1)]
>> '.'
- >> uint2_t() [assign_qbk_version(qbk_minor_version)]
+ >> uint2_t() [actions.values.entry(ph::arg1)]
)
+ ]
;
// TODO: Clear phrase afterwards?
@@ -156,8 +161,6 @@
local.attribute_rules[doc_info_attributes::last_revision] = &local.doc_simple;
local.attribute_rules[doc_info_attributes::lang] = &local.doc_simple;
- local.doc_copyright_year = cl::repeat_p(4)[cl::digit_p];
-
local.doc_copyright_holder
= *( ~cl::eps_p
( ']'
@@ -168,12 +171,12 @@
local.doc_copyright =
*( +( local.doc_copyright_year
- [actions.values.entry(ph::arg1, ph::arg2, doc_info_tags::copyright_year)]
+ [actions.values.entry(ph::arg1, doc_info_tags::copyright_year)]
>> space
>> !( '-'
>> space
>> local.doc_copyright_year
- [actions.values.entry(ph::arg1, ph::arg2, doc_info_tags::copyright_year_end)]
+ [actions.values.entry(ph::arg1, doc_info_tags::copyright_year_end)]
>> space
)
>> !cl::ch_p(',')
Modified: trunk/tools/quickbook/src/doc_info_tags.hpp
==============================================================================
--- trunk/tools/quickbook/src/doc_info_tags.hpp (original)
+++ trunk/tools/quickbook/src/doc_info_tags.hpp 2011-03-19 12:24:39 EDT (Sat, 19 Mar 2011)
@@ -14,6 +14,7 @@
namespace quickbook
{
QUICKBOOK_VALUE_TAGS(doc_info_tags, 0x400,
+ (qbk_version)
(type)
(title)
(author_surname)(author_first)
Modified: trunk/tools/quickbook/src/values.cpp
==============================================================================
--- trunk/tools/quickbook/src/values.cpp (original)
+++ trunk/tools/quickbook/src/values.cpp 2011-03-19 12:24:39 EDT (Sat, 19 Mar 2011)
@@ -9,6 +9,7 @@
#include "values.hpp"
#include <boost/intrusive_ptr.hpp>
#include <boost/current_function.hpp>
+#include <boost/lexical_cast.hpp>
#define UNDEFINED_ERROR() \
throw value_error( \
@@ -41,6 +42,7 @@
value_node* value_node::store() { return this; }
file_position value_node::get_position() const { UNDEFINED_ERROR(); }
+ int value_node::get_int() const { UNDEFINED_ERROR(); }
std::string value_node::get_quickbook() const { UNDEFINED_ERROR(); }
std::string value_node::get_boostbook() const { UNDEFINED_ERROR(); }
value_node* value_node::get_list() const { UNDEFINED_ERROR(); }
@@ -196,6 +198,62 @@
}
////////////////////////////////////////////////////////////////////////////
+ // Integers
+
+ namespace detail
+ {
+ struct value_int_impl : public value_node
+ {
+ public:
+ explicit value_int_impl(int, value::tag_type);
+ private:
+ char const* type_name() const { return "integer"; }
+ virtual value_node* clone() const;
+ virtual int get_int() const;
+ virtual std::string get_quickbook() const;
+ virtual std::string get_boostbook() const;
+ virtual bool empty() const;
+
+ int value_;
+ };
+
+ value_int_impl::value_int_impl(int v, value::tag_type t)
+ : value_node(t)
+ , value_(v)
+ {}
+
+ value_node* value_int_impl::clone() const
+ {
+ return new value_int_impl(value_, tag_);
+ }
+
+ int value_int_impl::get_int() const
+ {
+ return value_;
+ }
+
+ std::string value_int_impl::get_quickbook() const
+ {
+ return boost::lexical_cast<std::string>(value_);
+ }
+
+ std::string value_int_impl::get_boostbook() const
+ {
+ return boost::lexical_cast<std::string>(value_);
+ }
+
+ bool value_int_impl::empty() const
+ {
+ return false;
+ }
+ }
+
+ value int_value(int v, value::tag_type t)
+ {
+ return value(new detail::value_int_impl(v, t));
+ }
+
+ ////////////////////////////////////////////////////////////////////////////
// Strings
namespace detail
@@ -675,11 +733,6 @@
}
}
- value list_value(value::tag_type t)
- {
- return value(new detail::value_list_impl(t));
- }
-
//////////////////////////////////////////////////////////////////////////
// List builder
Modified: trunk/tools/quickbook/src/values.hpp
==============================================================================
--- trunk/tools/quickbook/src/values.hpp (original)
+++ trunk/tools/quickbook/src/values.hpp 2011-03-19 12:24:39 EDT (Sat, 19 Mar 2011)
@@ -51,6 +51,7 @@
virtual file_position get_position() const;
virtual std::string get_quickbook() const;
virtual std::string get_boostbook() const;
+ virtual int get_int() const;
virtual bool empty() const;
virtual bool is_list() const;
@@ -110,6 +111,8 @@
{ return value_->get_quickbook(); }
std::string get_boostbook() const
{ return value_->get_boostbook(); }
+ int get_int() const
+ { return value_->get_int(); }
protected:
value_node* value_;
@@ -219,8 +222,13 @@
explicit value(detail::value_node*);
};
+ // Empty
value empty_value(value::tag_type = value::default_tag);
- value list_value(value::tag_type = value::default_tag);
+
+ // Integers
+ value int_value(int, value::tag_type = value::default_tag);
+
+ // Boostbook and quickbook strings
value qbk_value(iterator, iterator, value::tag_type = value::default_tag);
value qbk_value(std::string const&,
file_position = file_position(),
Modified: trunk/tools/quickbook/src/values_parse.hpp
==============================================================================
--- trunk/tools/quickbook/src/values_parse.hpp (original)
+++ trunk/tools/quickbook/src/values_parse.hpp 2011-03-19 12:24:39 EDT (Sat, 19 Mar 2011)
@@ -74,6 +74,12 @@
{
b.insert(qbk_value(v, begin.get_position(), tag));
}
+
+ void operator()(int v,
+ value::tag_type tag = value::default_tag) const
+ {
+ b.insert(int_value(v, tag));
+ }
value_builder& b;
};
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk