$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r75263 - in branches/quickbook-dev/tools/quickbook: src test/versions
From: dnljms_at_[hidden]
Date: 2011-11-02 04:48:56
Author: danieljames
Date: 2011-11-02 04:48:52 EDT (Wed, 02 Nov 2011)
New Revision: 75263
URL: http://svn.boost.org/trac/boost/changeset/75263
Log:
Quickbook: Fix issue with mixed version templates.
If a 1.5 template called a 1.4 template, its parent would be its
'dynamic' parent (the 1.5 template), whose parent would be its lexical
parent - breaking the dynamic lookup. I've changed it so that when
using a dynamic lookup, 1.5+ templates are skipped over. That means
they can use whatever variable names they wish without issues.
It does mean that if a 1.4- template was specifically written to use
dynamic lookup, then it wouldn't be callable from 1.5. So it might
be better if they didn't skip over 1.5+ templates.
Alternatively if might be better to always lexical scoping, even for
older versions, on the assumption that it was a bug.
Added:
   branches/quickbook-dev/tools/quickbook/test/versions/
   branches/quickbook-dev/tools/quickbook/test/versions/Jamfile.v2   (contents, props changed)
   branches/quickbook-dev/tools/quickbook/test/versions/templates-1_1.qbk   (contents, props changed)
   branches/quickbook-dev/tools/quickbook/test/versions/templates-1_4.qbk   (contents, props changed)
   branches/quickbook-dev/tools/quickbook/test/versions/templates-1_5.qbk   (contents, props changed)
   branches/quickbook-dev/tools/quickbook/test/versions/versions-1_6.gold   (contents, props changed)
   branches/quickbook-dev/tools/quickbook/test/versions/versions-1_6.quickbook   (contents, props changed)
Text files modified: 
   branches/quickbook-dev/tools/quickbook/src/actions.cpp        |    14 ++++----------                          
   branches/quickbook-dev/tools/quickbook/src/template_stack.cpp |    30 ++++++++++++++++++++++++------          
   branches/quickbook-dev/tools/quickbook/src/template_stack.hpp |    19 +++++++++----------                     
   3 files changed, 37 insertions(+), 26 deletions(-)
Modified: branches/quickbook-dev/tools/quickbook/src/actions.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions.cpp	(original)
+++ branches/quickbook-dev/tools/quickbook/src/actions.cpp	2011-11-02 04:48:52 EDT (Wed, 02 Nov 2011)
@@ -1178,6 +1178,7 @@
 
         {
             template_state state(actions);
+            actions.templates.start_template(symbol);
 
             qbk_version_n = symbol->content.get_file()->version();
 
@@ -1194,13 +1195,6 @@
             // [section] and [endsect] tags in the template are balanced.
             actions.min_section_level = actions.ids.section_level();
 
-            // Quickbook 1.4-: When expanding the template continue to use the
-            //                 current scope (the dynamic scope).
-            // Quickbook 1.5+: Use the scope the template was defined in
-            //                 (the static scope).
-            if (qbk_version_n >= 105)
-                actions.templates.set_parent_scope(*symbol->parent);
-
             ///////////////////////////////////
             // Prepare the arguments as local templates
             bool get_arg_result;
@@ -1289,7 +1283,7 @@
             symbol->identifier,
             symbol->params,
             content,
-            symbol->parent);
+            symbol->lexical_parent);
         call_template(actions, &t, args, first);
 
         std::string block;
@@ -1875,7 +1869,7 @@
             std::string tname = ts.identifier;
             if (tname != "!")
             {
-                ts.parent = &actions.templates.top_scope();
+                ts.lexical_parent = &actions.templates.top_scope();
                 if (!actions.templates.add(ts))
                 {
                     detail::outerr(ts.content.get_file(), ts.content.get_position())
@@ -1893,7 +1887,7 @@
 
                 if (tname == "!")
                 {
-                    ts.parent = &actions.templates.top_scope();
+                    ts.lexical_parent = &actions.templates.top_scope();
                     call_code_snippet(actions, &ts, first);
                 }
             }
Modified: branches/quickbook-dev/tools/quickbook/src/template_stack.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/template_stack.cpp	(original)
+++ branches/quickbook-dev/tools/quickbook/src/template_stack.cpp	2011-11-02 04:48:52 EDT (Wed, 02 Nov 2011)
@@ -9,6 +9,7 @@
 
 #include <cassert>
 #include "template_stack.hpp"
+#include "files.hpp"
 
 #ifdef BOOST_MSVC
 #pragma warning(disable : 4355)
@@ -20,11 +21,11 @@
             std::string const& identifier,
             std::vector<std::string> const& params,
             value const& content,
-            template_scope const* parent)
+            template_scope const* lexical_parent)
        : identifier(identifier)
        , params(params)
        , content(content)
-       , parent(parent)
+       , lexical_parent(lexical_parent)
     {
         assert(content.get_tag() == template_tags::block ||
             content.get_tag() == template_tags::phrase ||
@@ -34,8 +35,10 @@
     template_stack::template_stack()
         : scope(template_stack::parser(*this))
         , scopes()
+        , parent_1_4(0)
     {
         scopes.push_front(template_scope());
+        parent_1_4 = &scopes.front();
     }
     
     template_symbol* template_stack::find(std::string const& symbol) const
@@ -69,7 +72,7 @@
     bool template_stack::add(template_symbol const& ts)
     {
         BOOST_ASSERT(!scopes.empty());
-        BOOST_ASSERT(ts.parent);
+        BOOST_ASSERT(ts.lexical_parent);
         
         if (this->find_top_scope(ts.identifier)) {
             return false;
@@ -85,17 +88,32 @@
     {
         template_scope const& old_front = scopes.front();
         scopes.push_front(template_scope());
-        set_parent_scope(old_front);
+        scopes.front().parent_1_4 = parent_1_4;
+        scopes.front().parent_scope = &old_front;
+        parent_1_4 = &scopes.front();
     }
 
     void template_stack::pop()
     {
+        parent_1_4 = scopes.front().parent_1_4;
         scopes.pop_front();
     }
 
-    void template_stack::set_parent_scope(template_scope const& parent)
+    void template_stack::start_template(template_symbol const* symbol)
     {
-        scopes.front().parent_scope = &parent;
+        // Quickbook 1.4-: When expanding the template continue to use the
+        //                 current scope (the dynamic scope).
+        // Quickbook 1.5+: Use the scope the template was defined in
+        //                 (the static scope).
+        if (symbol->content.get_file()->version() >= 105u)
+        {
+            parent_1_4 = scopes.front().parent_1_4;
+            scopes.front().parent_scope = symbol->lexical_parent;
+        }
+        else
+        {
+            scopes.front().parent_scope = scopes.front().parent_1_4;
+        }
     }
 }
 
Modified: branches/quickbook-dev/tools/quickbook/src/template_stack.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/template_stack.hpp	(original)
+++ branches/quickbook-dev/tools/quickbook/src/template_stack.hpp	2011-11-02 04:48:52 EDT (Wed, 02 Nov 2011)
@@ -40,19 +40,17 @@
         std::string identifier;
         std::vector<std::string> params;
         value content;
-        
-        // This is only used for quickbook 1.5+, 1.4 uses the dynamic scope.
-        // TODO: I should probably call this something like lexical_parent
-        // or static_parent for clarity.
-        template_scope const* parent;
+
+        template_scope const* lexical_parent;
     };
 
     typedef boost::spirit::classic::symbols<template_symbol> template_symbols;
     
     // template scope
     //
-    // 1.4-: parent_scope is the previous scope on the stack
-    //       (the template's dynamic parent).
+    // 1.4-: parent_scope is the previous scope on the dynamic
+    //       lookup chain. This moves up the stack skipping
+    //       1.5 templates (but not 1.5 included files).
     // 1.5+: parent_scope is the template's lexical parent.
     //
     // This means that a search along the parent_scope chain will follow the
@@ -62,8 +60,9 @@
     
     struct template_scope
     {
-        template_scope() : parent_scope() {}
+        template_scope() : parent_scope(), parent_1_4() {}
         template_scope const* parent_scope;
+        template_scope const* parent_1_4;
         template_symbols symbols;
     };
 
@@ -111,8 +110,7 @@
         void push();
         void pop();
 
-        // Set the current scope's parent.
-        void set_parent_scope(template_scope const&);
+        void start_template(template_symbol const*);
 
         boost::spirit::classic::functor_parser<parser> scope;
 
@@ -120,6 +118,7 @@
 
         friend struct parser;
         deque scopes;
+        template_scope const* parent_1_4;
     };
 }
 
Added: branches/quickbook-dev/tools/quickbook/test/versions/Jamfile.v2
==============================================================================
--- (empty file)
+++ branches/quickbook-dev/tools/quickbook/test/versions/Jamfile.v2	2011-11-02 04:48:52 EDT (Wed, 02 Nov 2011)
@@ -0,0 +1,18 @@
+#
+#   Copyright (c) 2011 Daniel James
+#
+#   Distributed under the Boost Software License, Version 1.0. (See
+#   accompanying file LICENSE_1_0.txt or copy at
+#   http://www.boost.org/LICENSE_1_0.txt)
+#
+
+project test/versions
+    : requirements
+        <toolset>msvc:<debug-symbols>off
+    ;
+
+import quickbook-testing : quickbook-test quickbook-error-test ;
+
+test-suite quickbook.test :
+    [ quickbook-test versions-1_6 ]
+    ;
Added: branches/quickbook-dev/tools/quickbook/test/versions/templates-1_1.qbk
==============================================================================
--- (empty file)
+++ branches/quickbook-dev/tools/quickbook/test/versions/templates-1_1.qbk	2011-11-02 04:48:52 EDT (Wed, 02 Nov 2011)
@@ -0,0 +1,15 @@
+[article 1.1 Templates
+[quickbook 1.1]
+]
+
+[template section_1_1[]
+[section In a 1.1 template]
+Some text
+[endsect]
+]
+
+[section 1.1 Document]
+[section_1_1]
+[section_1_4]
+[section_1_5]
+[endsect]
Added: branches/quickbook-dev/tools/quickbook/test/versions/templates-1_4.qbk
==============================================================================
--- (empty file)
+++ branches/quickbook-dev/tools/quickbook/test/versions/templates-1_4.qbk	2011-11-02 04:48:52 EDT (Wed, 02 Nov 2011)
@@ -0,0 +1,20 @@
+[article 1.4 Templates
+[quickbook 1.4]
+]
+
+[template section_1_4[]
+[section In a 1.4 template]
+Some text
+[endsect]
+]
+
+[section 1.4 Document]
+[section_1_1]
+[section_1_4]
+[section_1_5]
+[endsect]
+
+[/ Odd test for calling 1.4 -> 1.5 -> 1.4 template]
+
+[template skip_1_5[a] [skip_1_5_2 wrong]]
+[template skip_1_5_3[] [a]]
Added: branches/quickbook-dev/tools/quickbook/test/versions/templates-1_5.qbk
==============================================================================
--- (empty file)
+++ branches/quickbook-dev/tools/quickbook/test/versions/templates-1_5.qbk	2011-11-02 04:48:52 EDT (Wed, 02 Nov 2011)
@@ -0,0 +1,19 @@
+[article 1.5 Templates
+[quickbook 1.5]
+]
+
+[template section_1_5[]
+[section In a 1.5 template]
+Some text
+[endsect]
+]
+
+[section 1.5 Document]
+[section_1_1]
+[section_1_4]
+[section_1_5]
+[endsect]
+
+[/ Odd test for calling 1.4 -> 1.5 -> 1.4 template]
+
+[template skip_1_5_2[a] [skip_1_5_3]]
Added: branches/quickbook-dev/tools/quickbook/test/versions/versions-1_6.gold
==============================================================================
--- (empty file)
+++ branches/quickbook-dev/tools/quickbook/test/versions/versions-1_6.gold	2011-11-02 04:48:52 EDT (Wed, 02 Nov 2011)
@@ -0,0 +1,111 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE article PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
+<article id="mixed_version_tests" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
+ xmlns:xi="http://www.w3.org/2001/XInclude">
+  <title>Mixed version tests</title>
+  <para>
+    correct
+  </para>
+  <section id="mixed_version_tests.section_ids">
+    <title><link linkend="mixed_version_tests.section_ids">Section ids in templates</link></title>
+    <section id="mixed_version_tests.section_ids.in_a_1_1_template">
+      <title>In a 1.1 template</title>
+      <para>
+        Some text
+      </para>
+    </section>
+    <section id="mixed_version_tests.section_ids.in_a_1_4_template">
+      <title><link linkend="mixed_version_tests.section_ids.in_a_1_4_template">In
+      a 1.4 template</link></title>
+      <para>
+        Some text
+      </para>
+    </section>
+    <section id="mixed_version_tests.section_ids.in_a_1_5_template">
+      <title><link linkend="mixed_version_tests.section_ids.in_a_1_5_template">In
+      a 1.5 template</link></title>
+      <para>
+        Some text
+      </para>
+    </section>
+  </section>
+  <article id="1_1_templates" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
+  xmlns:xi="http://www.w3.org/2001/XInclude">
+    <title>1.1 Templates</title>
+    <section id="1_1_templates.1_1_document">
+      <title>1.1 Document</title>
+      <section id="1_1_templates.in_a_1_1_template">
+        <title>In a 1.1 template</title>
+        <para>
+          Some text
+        </para>
+      </section>
+      <section id="1_1_templates.in_a_1_4_template">
+        <title><link linkend="1_1_templates.in_a_1_4_template">In a 1.4 template</link></title>
+        <para>
+          Some text
+        </para>
+      </section>
+      <section id="1_1_templates.in_a_1_5_template">
+        <title><link linkend="1_1_templates.in_a_1_5_template">In a 1.5 template</link></title>
+        <para>
+          Some text
+        </para>
+      </section>
+    </section>
+  </article>
+  <article id="1_4_templates" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
+  xmlns:xi="http://www.w3.org/2001/XInclude">
+    <title>1.4 Templates</title>
+    <section id="1_4_templates.1_4_document">
+      <title><link linkend="1_4_templates.1_4_document">1.4 Document</link></title>
+      <section id="1_4_templates.1_4_document.in_a_1_1_template">
+        <title>In a 1.1 template</title>
+        <para>
+          Some text
+        </para>
+      </section>
+      <section id="1_4_templates.1_4_document.in_a_1_4_template">
+        <title><link linkend="1_4_templates.1_4_document.in_a_1_4_template">In a
+        1.4 template</link></title>
+        <para>
+          Some text
+        </para>
+      </section>
+      <section id="1_4_templates.1_4_document.in_a_1_5_template">
+        <title><link linkend="1_4_templates.1_4_document.in_a_1_5_template">In a
+        1.5 template</link></title>
+        <para>
+          Some text
+        </para>
+      </section>
+    </section>
+  </article>
+  <article id="1_5_templates" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
+  xmlns:xi="http://www.w3.org/2001/XInclude">
+    <title>1.5 Templates</title>
+    <section id="1_5_templates.1_5_document">
+      <title><link linkend="1_5_templates.1_5_document">1.5 Document</link></title>
+      <section id="1_5_templates.1_5_document.in_a_1_1_template">
+        <title>In a 1.1 template</title>
+        <para>
+          Some text
+        </para>
+      </section>
+      <section id="1_5_templates.1_5_document.in_a_1_4_template">
+        <title><link linkend="1_5_templates.1_5_document.in_a_1_4_template">In a
+        1.4 template</link></title>
+        <para>
+          Some text
+        </para>
+      </section>
+      <section id="1_5_templates.1_5_document.in_a_1_5_template">
+        <title><link linkend="1_5_templates.1_5_document.in_a_1_5_template">In a
+        1.5 template</link></title>
+        <para>
+          Some text
+        </para>
+      </section>
+    </section>
+  </article>
+</article>
Added: branches/quickbook-dev/tools/quickbook/test/versions/versions-1_6.quickbook
==============================================================================
--- (empty file)
+++ branches/quickbook-dev/tools/quickbook/test/versions/versions-1_6.quickbook	2011-11-02 04:48:52 EDT (Wed, 02 Nov 2011)
@@ -0,0 +1,27 @@
+[article Mixed version tests
+[quickbook 1.6]
+]
+
+[import templates-1_1.quickbook]
+[import templates-1_4.quickbook]
+[import templates-1_5.quickbook]
+
+[/ This test calls a 1.4 template -> 1.5 template -> 1.4 template.
+   The name lookup in the 1.4 template should skip the 1.5 template
+   when doing dynamic name lookup. ]
+[skip_1_5 correct]
+
+[/ When calling templates from old versions, the ids should
+   be consistent with their context ]
+
+[section:section_ids Section ids in templates]
+[section_1_1]
+[section_1_4]
+[section_1_5]
+[endsect]
+
+[/ For comparison]
+
+[include templates-1_1.quickbook]
+[include templates-1_4.quickbook]
+[include templates-1_5.quickbook]