Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56143 - in trunk/boost/spirit/home/lex: . lexer lexer/lexertl
From: hartmut.kaiser_at_[hidden]
Date: 2009-09-10 21:28:43


Author: hkaiser
Date: 2009-09-10 21:28:41 EDT (Thu, 10 Sep 2009)
New Revision: 56143
URL: http://svn.boost.org/trac/boost/changeset/56143

Log:
Spirit: added static lexer version verifying compatibility with generated tables
Added:
   trunk/boost/spirit/home/lex/lexer/lexertl/static_version.hpp (contents, props changed)
Text files modified:
   trunk/boost/spirit/home/lex/lexer/lexer.hpp | 4 +++-
   trunk/boost/spirit/home/lex/lexer/lexertl/generate_static.hpp | 5 +++++
   trunk/boost/spirit/home/lex/lexer/lexertl/static_lexer.hpp | 9 +++++++++
   trunk/boost/spirit/home/lex/lexer_type.hpp | 14 +++++++-------
   4 files changed, 24 insertions(+), 8 deletions(-)

Modified: trunk/boost/spirit/home/lex/lexer/lexer.hpp
==============================================================================
--- trunk/boost/spirit/home/lex/lexer/lexer.hpp (original)
+++ trunk/boost/spirit/home/lex/lexer/lexer.hpp 2009-09-10 21:28:41 EDT (Thu, 10 Sep 2009)
@@ -292,7 +292,9 @@
     // This represents a lexer object
     ///////////////////////////////////////////////////////////////////////////
 
- // this is the first token id automatically assigned by the library if needed
+ ///////////////////////////////////////////////////////////////////////////
+ // This is the first token id automatically assigned by the library
+ // if needed
     enum tokenids
     {
         min_token_id = 0x10000

Modified: trunk/boost/spirit/home/lex/lexer/lexertl/generate_static.hpp
==============================================================================
--- trunk/boost/spirit/home/lex/lexer/lexertl/generate_static.hpp (original)
+++ trunk/boost/spirit/home/lex/lexer/lexertl/generate_static.hpp 2009-09-10 21:28:41 EDT (Thu, 10 Sep 2009)
@@ -16,7 +16,9 @@
 #include <boost/spirit/home/support/detail/lexer/rules.hpp>
 #include <boost/spirit/home/support/detail/lexer/size_t.hpp>
 #include <boost/spirit/home/support/detail/lexer/state_machine.hpp>
+#include <boost/spirit/home/lex/lexer/lexertl/static_version.hpp>
 #include <boost/algorithm/string.hpp>
+#include <boost/lexical_cast.hpp>
 
 ///////////////////////////////////////////////////////////////////////////////
 namespace boost { namespace spirit { namespace lex { namespace lexertl
@@ -95,6 +97,9 @@
         generate_delimiter(os_);
         os_ << "// this defines a generic accessors for the information above\n";
         os_ << "struct lexer" << suffix << "\n{\n";
+ os_ << " // version number of compatible static lexer engine\n";
+ os_ << " enum { static_version = "
+ << boost::lexical_cast<std::string>(SPIRIT_STATIC_LEXER_VERSION) << " };\n\n";
         os_ << " // return the number of lexer states\n";
         os_ << " static std::size_t const state_count()\n";
         os_ << " {\n return lexer_state_count" << suffix << "; \n }\n\n";

Modified: trunk/boost/spirit/home/lex/lexer/lexertl/static_lexer.hpp
==============================================================================
--- trunk/boost/spirit/home/lex/lexer/lexertl/static_lexer.hpp (original)
+++ trunk/boost/spirit/home/lex/lexer/lexertl/static_lexer.hpp 2009-09-10 21:28:41 EDT (Thu, 10 Sep 2009)
@@ -15,6 +15,7 @@
 #include <boost/spirit/home/lex/lexer/lexertl/functor.hpp>
 #include <boost/spirit/home/lex/lexer/lexertl/static_functor_data.hpp>
 #include <boost/spirit/home/lex/lexer/lexertl/iterator.hpp>
+#include <boost/spirit/home/lex/lexer/lexertl/static_version.hpp>
 #if defined(BOOST_SPIRIT_DEBUG)
 #include <boost/spirit/home/support/detail/lexer/debug.hpp>
 #endif
@@ -140,6 +141,14 @@
 
         typedef LexerTables tables_type;
 
+ // The following static assertion fires if the referenced static lexer
+ // tables are generated by a different static lexer version as used for
+ // the current compilation unit. Please regenerate your static lexer
+ // tables before trying to create a static_lexer<> instance.
+ BOOST_SPIRIT_ASSERT_MSG(
+ tables_type::static_version == SPIRIT_STATIC_LEXER_VERSION
+ , incompatible_static_lexer_version, (LexerTables));
+
     public:
         // Return the start iterator usable for iterating over the generated
         // tokens, the generated function next_token(...) is called to match

Added: trunk/boost/spirit/home/lex/lexer/lexertl/static_version.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/spirit/home/lex/lexer/lexertl/static_version.hpp 2009-09-10 21:28:41 EDT (Thu, 10 Sep 2009)
@@ -0,0 +1,20 @@
+// Copyright (c) 2001-2009 Hartmut Kaiser
+//
+// 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)
+
+#if !defined(BOOST_SPIRIT_LEX_STATIC_LEXER_VERSION_SEP_10_2009_0811PM)
+#define BOOST_SPIRIT_LEX_STATIC_LEXER_VERSION_SEP_10_2009_0811PM
+
+#if defined(_MSC_VER)
+#pragma once
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
+// This is the version of the static lexer format. It is used to ensure a
+// static lexer has been generated using the same data format as expected
+// by the executing application.
+///////////////////////////////////////////////////////////////////////////////
+#define SPIRIT_STATIC_LEXER_VERSION 0x010000
+
+#endif

Modified: trunk/boost/spirit/home/lex/lexer_type.hpp
==============================================================================
--- trunk/boost/spirit/home/lex/lexer_type.hpp (original)
+++ trunk/boost/spirit/home/lex/lexer_type.hpp 2009-09-10 21:28:41 EDT (Thu, 10 Sep 2009)
@@ -25,7 +25,7 @@
 
         // Requirement: l.collect(def, state) -> void
         //
- // l: a lexer
+ // l: a lexer component
         // def: token definition container
         // state: lexer state this token definition needs to be added to
 
@@ -46,13 +46,13 @@
     {
         struct unary_lexer_id;
 
- // Requirement: l.subject -> subject lexer
+ // Requirement: l.subject -> subject lexer component
         //
- // l: a unary lexer
+ // l: a unary lexer component
 
- // Requirement: L::subject_type -> subject lexer type
+ // Requirement: L::subject_type -> subject lexer component type
         //
- // L: a unary lexer type
+ // L: a unary lexer component type
     };
 
     template <typename Derived>
@@ -62,11 +62,11 @@
 
         // Requirement: l.elements -> fusion sequence
         //
- // l: a composite lexer
+ // l: a composite lexer component
 
         // Requirement: L::elements_type -> fusion sequence
         //
- // L: a composite lexer type
+ // L: a composite lexer component type
     };
 
 }}}


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