|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r63168 - branches/quickbook-1.5-spirit2
From: daniel_james_at_[hidden]
Date: 2010-06-20 16:32:58
Author: danieljames
Date: 2010-06-20 16:32:57 EDT (Sun, 20 Jun 2010)
New Revision: 63168
URL: http://svn.boost.org/trac/boost/changeset/63168
Log:
Remove use of std container.
Some std::deque implementations can't be declared with an incomplete
type, so just use a manual linked list instead.
Text files modified:
branches/quickbook-1.5-spirit2/fwd.hpp | 1
branches/quickbook-1.5-spirit2/template.cpp | 46 ++++++++++++++++-----------------------
branches/quickbook-1.5-spirit2/template.hpp | 14 ++++-------
3 files changed, 24 insertions(+), 37 deletions(-)
Modified: branches/quickbook-1.5-spirit2/fwd.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/fwd.hpp (original)
+++ branches/quickbook-1.5-spirit2/fwd.hpp 2010-06-20 16:32:57 EDT (Sun, 20 Jun 2010)
@@ -42,7 +42,6 @@
struct call_template;
struct define_template;
- struct template_symbol;
// encoder
Modified: branches/quickbook-1.5-spirit2/template.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/template.cpp (original)
+++ branches/quickbook-1.5-spirit2/template.cpp 2010-06-20 16:32:57 EDT (Sun, 20 Jun 2010)
@@ -62,13 +62,13 @@
template_scope() : parent_scope() {}
template_scope const* parent_scope;
template_symbols symbols;
+ boost::scoped_ptr<template_scope> next;
};
template_stack::template_stack()
: scope(template_stack::parser(*this))
- , scopes()
+ , top_scope(new template_scope())
{
- scopes.push_front(template_scope());
}
template_stack::~template_stack() {}
@@ -78,7 +78,7 @@
// search all scopes for the longest matching symbol.
iterator found = first;
template_symbol const* result = 0;
- for (template_scope const* i = &*scopes.begin(); i; i = i->parent_scope)
+ for (template_scope const* i = top_scope.get(); i; i = i->parent_scope)
{
iterator iter = first;
template_symbol const* symbol = i->symbols.prefix_find(iter, last);
@@ -94,7 +94,7 @@
template_symbol const* template_stack::find(std::string const& symbol) const
{
- for (template_scope const* i = &*scopes.begin(); i; i = i->parent_scope)
+ for (template_scope const* i = top_scope.get(); i; i = i->parent_scope)
{
if (template_symbol const* ts = i->symbols.find(symbol.c_str()))
return ts;
@@ -104,20 +104,14 @@
template_symbol const* template_stack::find_top_scope(std::string const& symbol) const
{
- return scopes.front().symbols.find(symbol.c_str());
+ return top_scope->symbols.find(symbol.c_str());
}
- template_scope const& template_stack::top_scope() const
- {
- BOOST_ASSERT(!scopes.empty());
- return scopes.front();
- }
-
bool template_stack::add(
define_template const& definition,
template_scope const* parent)
{
- BOOST_ASSERT(!scopes.empty());
+ BOOST_ASSERT(top_scope);
if (this->find_top_scope(definition.id)) {
return false;
@@ -136,28 +130,28 @@
is_block,
definition.body,
definition.callouts,
- parent ? parent : &top_scope());
+ parent ? parent : top_scope.get());
- scopes.front().symbols.add(ts.identifier.c_str(), ts);
+ top_scope->symbols.add(ts.identifier.c_str(), ts);
return true;
}
void template_stack::push()
{
- template_scope const& old_front = scopes.front();
- scopes.push_front(template_scope());
- set_parent_scope(old_front);
- }
+ boost::scoped_ptr<template_scope> new_scope(
+ new template_scope());
+ new_scope->parent_scope = top_scope.get();
- void template_stack::pop()
- {
- scopes.pop_front();
+ new_scope->next.swap(top_scope);
+ new_scope.swap(top_scope);
}
- void template_stack::set_parent_scope(template_scope const& parent)
+ void template_stack::pop()
{
- scopes.front().parent_scope = &parent;
+ boost::scoped_ptr<template_scope> popped_scope;
+ popped_scope.swap(top_scope);
+ popped_scope->next.swap(top_scope);
}
namespace
@@ -379,7 +373,7 @@
//
// Note that for quickbook 1.4- this value is just ignored when the
// arguments are expanded.
- template_scope const& call_scope = state.templates.top_scope();
+ template_scope const& call_scope = *state.templates.top_scope;
std::string result;
state.push(); // scope the state
@@ -393,7 +387,7 @@
// Quickbook 1.5+: Use the scope the template was defined in
// (the static scope).
if (qbk_version_n >= 105)
- state.templates.set_parent_scope(*x.symbol->parent);
+ state.templates.top_scope->parent_scope = x.symbol->parent;
std::vector<template_value> args = x.args;
@@ -497,5 +491,3 @@
return nothing();
}
}
-
-
Modified: branches/quickbook-1.5-spirit2/template.hpp
==============================================================================
--- branches/quickbook-1.5-spirit2/template.hpp (original)
+++ branches/quickbook-1.5-spirit2/template.hpp 2010-06-20 16:32:57 EDT (Sun, 20 Jun 2010)
@@ -10,16 +10,19 @@
#define BOOST_SPIRIT_QUICKBOOK_TEMPLATE_STACK_HPP
#include <string>
-#include <deque>
#include <vector>
#include <boost/spirit/include/qi_parse.hpp>
#include <boost/spirit/home/qi/detail/assign_to.hpp>
+#include <boost/scoped_ptr.hpp>
#include "fwd.hpp"
namespace quickbook
{
namespace qi = boost::spirit::qi;
+ struct template_scope;
+ struct template_symbol;
+
struct template_value
{
template_value() {}
@@ -79,13 +82,8 @@
std::vector<template_value> args;
};
- struct template_scope;
- struct template_symbol;
-
struct template_stack
{
- typedef std::deque<template_scope> deque;
-
struct parser : boost::spirit::qi::primitive_parser<parser>
{
template <typename Ctx, typename Itr>
@@ -114,7 +112,6 @@
template_symbol const* prefix_find(iterator& first, iterator const& last) const;
template_symbol const* find(std::string const& symbol) const;
template_symbol const* find_top_scope(std::string const& symbol) const;
- template_scope const& top_scope() const;
// Add the given template symbol to the current scope.
// If a parent scope isn't supplied, uses the current scope.
bool add(define_template const&, template_scope const* parent = 0);
@@ -125,11 +122,10 @@
void set_parent_scope(template_scope const&);
parser scope;
+ boost::scoped_ptr<template_scope> top_scope;
private:
-
friend struct parser;
- deque scopes;
template_stack(template_stack const&);
template_stack& operator=(template_stack const&);
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