Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71095 - in trunk/boost/wave: . util
From: hartmut.kaiser_at_[hidden]
Date: 2011-04-07 20:03:04


Author: hkaiser
Date: 2011-04-07 20:03:03 EDT (Thu, 07 Apr 2011)
New Revision: 71095
URL: http://svn.boost.org/trac/boost/changeset/71095

Log:
Wave: Added new pp hook: locate_include_file
Text files modified:
   trunk/boost/wave/cpp_context.hpp | 12 +++--
   trunk/boost/wave/preprocessing_hooks.hpp | 76 +++++++++++++++++++++++++++++++++++----
   trunk/boost/wave/util/cpp_include_paths.hpp | 2
   trunk/boost/wave/util/cpp_iterator.hpp | 15 ++-----
   trunk/boost/wave/util/cpp_macromap.hpp | 1
   trunk/boost/wave/util/cpp_macromap_predef.hpp | 2
   6 files changed, 83 insertions(+), 25 deletions(-)

Modified: trunk/boost/wave/cpp_context.hpp
==============================================================================
--- trunk/boost/wave/cpp_context.hpp (original)
+++ trunk/boost/wave/cpp_context.hpp 2011-04-07 20:03:03 EDT (Thu, 07 Apr 2011)
@@ -291,6 +291,9 @@
     }
     boost::wave::language_support get_language() const { return language; }
 
+ position_type &get_main_pos() { return macros.get_main_pos(); }
+ position_type const& get_main_pos() const { return macros.get_main_pos(); }
+
 // change and ask for maximal possible include nesting depth
     void set_max_include_nesting_depth(iter_size_type new_depth)
         { iter_ctxs.set_max_include_nesting_depth(new_depth); }
@@ -337,9 +340,6 @@
         { return macros.is_defined(begin, end); }
 
 // maintain include paths (helper functions)
- bool find_include_file (std::string &s, std::string &d, bool is_system,
- char const *current_file) const
- { return includes.find_include_file(s, d, is_system, current_file); }
     void set_current_directory(char const *path_)
         { includes.set_current_directory(path_); }
 
@@ -364,8 +364,6 @@
     void push_iteration_context(position_type const &act_pos, iteration_ptr_type iter_ctx)
         { iter_ctxs.push(*this, act_pos, iter_ctx); }
 
- position_type &get_main_pos() { return macros.get_main_pos(); }
-
 ///////////////////////////////////////////////////////////////////////////////
 //
 // expand_tokensequence():
@@ -429,6 +427,10 @@
     std::string const &get_current_relative_filename() const
         { return current_relative_filename; }
 
+ bool find_include_file (std::string &s, std::string &d, bool is_system,
+ char const *current_file) const
+ { return includes.find_include_file(s, d, is_system, current_file); }
+
 #if BOOST_WAVE_SERIALIZATION != 0
 public:
     BOOST_STATIC_CONSTANT(unsigned int, version = 0x10);

Modified: trunk/boost/wave/preprocessing_hooks.hpp
==============================================================================
--- trunk/boost/wave/preprocessing_hooks.hpp (original)
+++ trunk/boost/wave/preprocessing_hooks.hpp 2011-04-07 20:03:03 EDT (Thu, 07 Apr 2011)
@@ -12,6 +12,8 @@
 #define DEFAULT_PREPROCESSING_HOOKS_HPP_INCLUDED
 
 #include <boost/wave/wave_config.hpp>
+#include <boost/wave/util/cpp_include_paths.hpp>
+
 #include <vector>
 
 // this must occur after all of the includes and before any code appears
@@ -56,7 +58,7 @@
     // invocation (starting with the opening parenthesis and ending after the
     // closing one).
     //
- // The return value defines, whether the corresponding macro will be
+ // The return value defines whether the corresponding macro will be
     // expanded (return false) or will be copied to the output (return true).
     // Note: the whole argument list is copied unchanged to the output as well
     // without any further processing.
@@ -99,7 +101,7 @@
     //
     // The parameter 'macrocall' marks the position, where this macro invoked.
     //
- // The return value defines, whether the corresponding macro will be
+ // The return value defines whether the corresponding macro will be
     // expanded (return false) or will be copied to the output (return true).
     //
     ///////////////////////////////////////////////////////////////////////////
@@ -168,6 +170,64 @@
 
     ///////////////////////////////////////////////////////////////////////////
     //
+ // The function 'locate_include_file' is called, whenever a #include
+ // directive was encountered. It is supposed to locate the given file and
+ // should return the full file name of the located file. This file name
+ // is expected to uniquely identify the referenced file.
+ //
+ // The parameter 'ctx' is a reference to the context object used for
+ // instantiating the preprocessing iterators by the user.
+ //
+ // The parameter 'file_path' contains the (expanded) file name found after
+ // the #include directive. This parameter holds the string as it is
+ // specified in the #include directive, i.e. <file> or "file" will result
+ // in a parameter value 'file'.
+ //
+ // The parameter 'is_system' is set to 'true' if this call happens as a
+ // result of a #include '<file>' directive, it is 'false' otherwise, i.e.
+ // for #include "file" directives.
+ //
+ // The parameter 'current_name' is only used if a #include_next directive
+ // was encountered (and BOOST_WAVE_SUPPORT_INCLUDE_NEXT was defined to be
+ // non-zero). In this case it points to unique full name of the current
+ // include file (if any). Otherwise this parameter is set to NULL.
+ //
+ // The parameter 'dir_path' on return is expected to hold the directory
+ // part of the located file.
+ //
+ // The parameter 'native_name' on return is expected to hold the unique
+ // full file name of the located file.
+ //
+ // The return value defines whether the found file will be included
+ // (return false) or will be skipped (return true).
+ //
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename ContextT>
+ bool
+ locate_include_file(ContextT& ctx, std::string &file_path,
+ bool is_system, char const *current_name, std::string &dir_path,
+ std::string &native_name)
+ {
+ if (!ctx.find_include_file (file_path, dir_path, is_system, current_name))
+ return false; // could not locate file
+
+ namespace fs = boost::filesystem;
+
+ fs::path native_path(wave::util::create_path(file_path));
+ if (!fs::exists(native_path)) {
+ BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, bad_include_file,
+ file_path.c_str(), ctx.get_main_pos());
+ return false;
+ }
+
+ // return the unique full file system path of the located file
+ native_name = wave::util::native_file_string(native_path);
+
+ return true; // include file has been located successfully
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ //
     // The function 'found_include_directive' is called, whenever a #include
     // directive was located.
     //
@@ -185,7 +245,7 @@
     // a #include_next directive and the BOOST_WAVE_SUPPORT_INCLUDE_NEXT
     // preprocessing constant was defined to something != 0.
     //
- // The return value defines, whether the found file will be included
+ // The return value defines whether the found file will be included
     // (return false) or will be skipped (return true).
     //
     ///////////////////////////////////////////////////////////////////////////
@@ -204,7 +264,7 @@
         return false; // ok to include this file
     }
 #endif
-
+
     ///////////////////////////////////////////////////////////////////////////
     //
     // The function 'opened_include_file' is called, whenever a file referred
@@ -220,7 +280,7 @@
     //
     // The include_depth parameter contains the current include file depth.
     //
- // The is_system_include parameter denotes, whether the given file was
+ // The is_system_include parameter denotes whether the given file was
     // found as a result of a #include <...> directive.
     //
     ///////////////////////////////////////////////////////////////////////////
@@ -485,7 +545,7 @@
     // The parameter 'directive' is a reference to the token holding the
     // preprocessing directive.
     //
- // The return value defines, whether the given expression has to be
+ // The return value defines whether the given expression has to be
     // to be executed in a normal way (return 'false'), or if it has to be
     // skipped altogether (return 'true'), which means it gets replaced in the
     // output by a single newline.
@@ -520,7 +580,7 @@
     // stream, which are to be used as the replacement text for the whole
     // line containing the unknown directive.
     //
- // The return value defines, whether the given expression has been
+ // The return value defines whether the given expression has been
     // properly interpreted by the hook function or not. If this function
     // returns 'false', the library will raise an 'ill_formed_directive'
     // preprocess_exception. Otherwise the tokens pushed back into 'pending'
@@ -551,7 +611,7 @@
     // The parameter expression_value contains the result of the evaluation of
     // the expression in the current preprocessing context.
     //
- // The return value defines, whether the given expression has to be
+ // The return value defines whether the given expression has to be
     // evaluated again, allowing to decide which of the conditional branches
     // should be expanded. You need to return 'true' from this hook function
     // to force the expression to be re-evaluated.

Modified: trunk/boost/wave/util/cpp_include_paths.hpp
==============================================================================
--- trunk/boost/wave/util/cpp_include_paths.hpp (original)
+++ trunk/boost/wave/util/cpp_include_paths.hpp 2011-04-07 20:03:03 EDT (Thu, 07 Apr 2011)
@@ -334,7 +334,7 @@
                 dirpath = create_path((*it).second);
                 dirpath /= create_path(s);
             }
-
+
             dir = dirpath.string();
             s = normalize(currpath).string(); // found the required file
             return true;

Modified: trunk/boost/wave/util/cpp_iterator.hpp
==============================================================================
--- trunk/boost/wave/util/cpp_iterator.hpp (original)
+++ trunk/boost/wave/util/cpp_iterator.hpp 2011-04-07 20:03:03 EDT (Thu, 07 Apr 2011)
@@ -1576,24 +1576,19 @@
 #endif
 
     file_path = util::impl::unescape_lit(file_path);
- if (!ctx.find_include_file (file_path, dir_path, is_system, current_name)) {
- BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, bad_include_file,
- file_path.c_str(), act_pos);
- return false;
- }
-
-fs::path native_path(wave::util::create_path(file_path));
+ std::string native_path_str;
 
- if (!fs::exists(native_path)) {
+ if (!ctx.get_hooks().locate_include_file(ctx, file_path, is_system,
+ current_name, dir_path, native_path_str))
+ {
         BOOST_WAVE_THROW_CTX(ctx, preprocess_exception, bad_include_file,
             file_path.c_str(), act_pos);
         return false;
     }
 
 // test, if this file is known through a #pragma once directive
- std::string native_path_str(wave::util::native_file_string(native_path));
 #if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
- if (!ctx.has_pragma_once(native_path.string()))
+ if (!ctx.has_pragma_once(native_path_str))
 #endif
     {
     // the new include file determines the actual current directory

Modified: trunk/boost/wave/util/cpp_macromap.hpp
==============================================================================
--- trunk/boost/wave/util/cpp_macromap.hpp (original)
+++ trunk/boost/wave/util/cpp_macromap.hpp 2011-04-07 20:03:03 EDT (Thu, 07 Apr 2011)
@@ -140,6 +140,7 @@
     void reset_macromap();
 
     position_type &get_main_pos() { return main_pos; }
+ position_type const& get_main_pos() const { return main_pos; }
 
 // interface for macro name introspection
     typedef typename defined_macros_type::name_iterator name_iterator;

Modified: trunk/boost/wave/util/cpp_macromap_predef.hpp
==============================================================================
--- trunk/boost/wave/util/cpp_macromap_predef.hpp (original)
+++ trunk/boost/wave/util/cpp_macromap_predef.hpp 2011-04-07 20:03:03 EDT (Thu, 07 Apr 2011)
@@ -229,7 +229,7 @@
         {
         static static_macros data[] = {
                 { "__STDC__", T_INTLIT, "1" },
- { "__cplusplus", T_INTLIT, "201101L" },
+ { "__cplusplus", T_INTLIT, "201108L" },
                 { "__STDC_VERSION__", T_INTLIT, "199901L" },
                 { "__STDC_HOSTED__", T_INTLIT, "0" },
                 { "__WAVE_HAS_VARIADICS__", T_INTLIT, "1" },


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