2
0
mirror of https://github.com/boostorg/wave.git synced 2026-02-23 16:12:11 +00:00

Added Wave review candidate to repository.

[SVN r1909]
This commit is contained in:
Hartmut Kaiser
2004-01-26 06:23:58 +00:00
parent b683dba9be
commit bb119d710a
140 changed files with 74210 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
# Wave: A Standard compliant C++ preprocessor library
#
# Boost Wave Library Sample Build Jamfile (list_includes)
#
# Copyright (c) 2001-2004 Hartmut Kaiser
# http://spirit.sourceforge.net/
#
# Use, modification, and distribution is subject to 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)
subproject libs/wave/samples/list_includes/build ;
exe list_includes
: ../list_includes.cpp
<lib>../../../build/boost_wave
<lib>../../../../../libs/program_options/build/boost_program_options
<lib>../../../../../libs/filesystem/build/boost_filesystem
:
<sysinclude>$(BOOST_ROOT)
<vc7.1><*><rtti>off # workaround for compiler bug
:
<runtime-link>static
<threading>single
;

View File

@@ -0,0 +1,23 @@
# Wave: A Standard compliant C++ preprocessor library
#
# Boost Wave Library Sample Build Jamfile (list_includes)
#
# Copyright (c) 2001-2004 Hartmut Kaiser
# http://spirit.sourceforge.net/
#
# Use, modification, and distribution is subject to 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)
exe list_includes
: ../list_includes.cpp
<lib>../../../build/boost_wave
<lib>../../../../../libs/program_options/build/boost_program_options
<lib>../../../../../libs/filesystem/build/boost_filesystem
:
<vc7.1><*><rtti>off # workaround for compiler bug
:
<runtime-link>static
<threading>single
;

View File

@@ -0,0 +1,286 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Sample: List include dependencies of a given source file
The 'list_includes' sample shows a simple way, how to use the Wave C++
preprocessor library to extract a list of included files from a given
source file.
To get a hint which commandline options are supported, call it with the
--help option.
Copyright (c) 2001-2004 Hartmut Kaiser
http://spirit.sourceforge.net/
Use, modification and distribution is subject to 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)
=============================================================================*/
#include "list_includes.hpp" // config data
///////////////////////////////////////////////////////////////////////////////
// include required boost libraries
#include <boost/assert.hpp>
///////////////////////////////////////////////////////////////////////////////
// This sample requires the program_options library written by Vladimir Prus,
// which is currently under Boost review.
// It is available here: http://boost-sandbox.sourceforge.net/program_options
//
#include <boost/program_options.hpp>
///////////////////////////////////////////////////////////////////////////////
// Include Wave itself
#include <boost/wave.hpp>
//#include <boost/wave/util/time_conversion_helper.hpp>
//#include <boost/wave/util/file_position.hpp>
#include <boost/wave/token_ids.hpp>
#include <boost/wave/cpplexer/cpp_lex_token.hpp>
#include <boost/wave/cpplexer/cpp_lex_iterator.hpp>
#include <boost/wave/trace_policies.hpp>
#include <boost/wave/cpp_context.hpp>
///////////////////////////////////////////////////////////////////////////////
// include lexer specifics, import lexer names
#if !defined(BOOST_WAVE_SEPARATE_LEXER_INSTANTIATION)
#include <boost/wave/cpplexer/re2clex/cpp_re2c_lexer.hpp>
#endif // !defined(BOOST_WAVE_SEPARATE_LEXER_INSTANTIATION)
///////////////////////////////////////////////////////////////////////////////
// import required names
using namespace boost::spirit;
using std::string;
using std::vector;
using std::set;
using std::cout;
using std::cerr;
using std::endl;
using std::ifstream;
using std::ostream;
using std::istreambuf_iterator;
namespace po = boost::program_options;
///////////////////////////////////////////////////////////////////////////////
// print the current version
int print_version()
{
// get time of last compilation of this file
boost::wave::util::time_conversion_helper compilation_time(__DATE__ " " __TIME__);
// calculate the number of days since Jan 29 2003
// (the day the list_includes project was started)
std::tm first_day;
std::memset (&first_day, 0, sizeof(std::tm));
first_day.tm_mon = 0; // Jan
first_day.tm_mday = 29; // 29
first_day.tm_year = 103; // 2003
long seconds = long(std::difftime(compilation_time.get_time(),
std::mktime(&first_day)));
cout
<< LIST_INCLUDES_VERSION_MAJOR << '.'
<< LIST_INCLUDES_VERSION_MINOR << '.'
<< LIST_INCLUDES_VERSION_SUBMINOR << '.'
<< seconds/(3600*24); // get number of days from seconds
return 1; // exit app
}
///////////////////////////////////////////////////////////////////////////////
// policy class
struct trace_include_files
: public boost::wave::trace_policies::default_tracing
{
trace_include_files(set<string> &files_) : files(files_) {}
void
opened_include_file(string const &filename,
std::size_t include_depth, bool is_system_include)
{
set<string>::iterator it = files.find(filename);
if (it == files.end()) {
// print indented filename
for (size_t i = 0; i < include_depth; ++i)
cout << " ";
cout << filename << endl;
files.insert(filename);
}
}
set<string> &files;
};
///////////////////////////////////////////////////////////////////////////////
//
int do_actual_work (
po::options_and_arguments const opts, po::variables_map const &vm,
vector<string> const &pathes, vector<string> const &syspathes)
{
// current file position is saved for exception handling
boost::wave::util::file_position_t current_position;
try {
vector<string> const &arguments = opts.arguments();
vector<string>::const_iterator lastfile = arguments.end();
for (vector<string>::const_iterator file_it = arguments.begin();
file_it != lastfile; ++file_it)
{
ifstream instream((*file_it).c_str());
string instring;
if (!instream.is_open()) {
cerr << "Could not open input file: " << *file_it << endl;
continue;
}
instream.unsetf(ios::skipws);
instring = string(istreambuf_iterator<char>(instream.rdbuf()),
istreambuf_iterator<char>());
// The template boost::wave::cpplexer::lex_token<> is the token type to be
// used by the Wave library.
typedef boost::wave::cpplexer::lex_iterator<
boost::wave::cpplexer::lex_token<> >
lex_iterator_t;
typedef boost::wave::context<
std::string::iterator, lex_iterator_t,
boost::wave::iteration_context_policies::load_file_to_string,
trace_include_files
> context_t;
set<string> files;
trace_include_files trace(files);
// The preprocessor iterator shouldn't be constructed directly. It is
// to be generated through a wave::context<> object. This wave:context<>
// object is additionally to be used to initialize and define different
// parameters of the actual preprocessing.
// The preprocessing of the input stream is done on the fly behind the
// scenes during iteration over the context_t::iterator_t stream.
context_t ctx (instring.begin(), instring.end(), (*file_it).c_str(), trace);
// add include directories to the include path
if (vm.count("path")) {
vector<string>::const_iterator end = pathes.end();
for (vector<string>::const_iterator cit = pathes.begin();
cit != end; ++cit)
{
ctx.add_include_path((*cit).c_str());
}
}
// add system include directories to the include path
if (vm.count("syspath")) {
vector<string>::const_iterator end = syspathes.end();
for (vector<string>::const_iterator cit = syspathes.begin();
cit != end; ++cit)
{
ctx.add_sysinclude_path((*cit).c_str());
}
}
// analyze the actual file
context_t::iterator_t first = ctx.begin();
context_t::iterator_t last = ctx.end();
cout << "Printing dependency information for: "
<< *file_it << endl;
while (first != last) {
current_position = (*first).get_position();
++first;
}
// prepend endl before next file
cout << endl;
}
}
catch (boost::wave::cpp_exception &e) {
// some preprocessing error
cerr
<< e.file_name() << "(" << e.line_no() << "): "
<< e.description() << endl;
return 2;
}
catch (std::exception &e) {
// use last recognized token to retrieve the error position
cerr
<< current_position.get_file()
<< "(" << current_position.get_line() << "): "
<< "exception caught: " << e.what()
<< endl;
return 3;
}
catch (...) {
// use last recognized token to retrieve the error position
cerr
<< current_position.get_file()
<< "(" << current_position.get_line() << "): "
<< "unexpected exception caught." << endl;
return 4;
}
return 0;
}
///////////////////////////////////////////////////////////////////////////////
// here we go!
int
main (int argc, char const *argv[])
{
try {
// analyze the command line options and arguments
vector<string> pathes;
vector<string> syspathes;
po::options_description desc("Usage: list_includes [options] file ...");
desc.add_options()
("help,h", "", "print out program usage (this message)")
("version,v", "", "print the version number")
("path,I", po::parameter<vector<string> >("dir", &pathes),
"specify additional include directory")
("syspath,S", po::parameter<vector<string> >("dir", &syspathes),
"specify additional system include directory")
;
po::options_and_arguments opts = po::parse_command_line(argc, argv, desc);
po::variables_map vm;
po::store(opts, vm, desc);
if (vm.count("help")) {
cout << desc << endl;
return 1;
}
if (vm.count("version")) {
return print_version();
}
// if there is no input file given, then exit
if (0 == opts.arguments().size()) {
cerr << "list_includes: No input file given. "
<< "Use --help to get a hint." << endl;
return 5;
}
// iterate over all given input files
return do_actual_work(opts, vm, pathes, syspathes);
}
catch (std::exception &e) {
cout << "list_includes: exception caught: " << e.what() << endl;
return 6;
}
catch (...) {
cerr << "list_includes: unexpected exception caught." << endl;
return 7;
}
}

View File

@@ -0,0 +1,43 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Sample: List include dependencies of a given source file
Configuration data
Copyright (c) 2001-2004 Hartmut Kaiser
http://spirit.sourceforge.net/
Use, modification and distribution is subject to 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(LIST_INCLUDES_HPP_843DB412_3AA8_4BCF_8081_AA4A5FDE0BE7_INCLUDED)
#define LIST_INCLUDES_HPP_843DB412_3AA8_4BCF_8081_AA4A5FDE0BE7_INCLUDED
///////////////////////////////////////////////////////////////////////////////
// include often used files from the stdlib
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <set>
///////////////////////////////////////////////////////////////////////////////
// include boost config
#include <boost/config.hpp> // global configuration information
///////////////////////////////////////////////////////////////////////////////
// build version
#include "list_includes_version.hpp"
///////////////////////////////////////////////////////////////////////////////
// configure this app here (global configuration constants)
#include "list_includes_config.hpp"
///////////////////////////////////////////////////////////////////////////////
// include required boost libraries
#include <boost/assert.hpp>
#include <boost/pool/pool_alloc.hpp>
#endif // !defined(LIST_INCLUDES_HPP_843DB412_3AA8_4BCF_8081_AA4A5FDE0BE7_INCLUDED)

View File

@@ -0,0 +1,228 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Global application configuration of the list_includes sample
Copyright (c) 2001-2004 Hartmut Kaiser
http://spirit.sourceforge.net/
Use, modification and distribution is subject to 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(LIST_INCLUDES_CONFIG_HPP_0DE80E47_8D50_4DFA_9C1C_0EECAA8A934A_INCLUDED)
#define LIST_INCLUDES_CONFIG_HPP_0DE80E47_8D50_4DFA_9C1C_0EECAA8A934A_INCLUDED
///////////////////////////////////////////////////////////////////////////////
// Decide, whether to implement macro scopes (#scope/#endscope), variadics,
// placemarkers and well defined token pasting in C++ mode
//
// To implement these features, uncomment the following
//
#define BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS 0
///////////////////////////////////////////////////////////////////////////////
// Define the macro scoping keywords to be used for the experimental macro
// scoping support.
//
// If the following macros aren't defined, the corresponding default value is
// used.
//
// Note, if you change this, you will have to change the corresponding entries
// inside the wave/cpplexer/re2c/cpp.re file too.
//
//#define BOOST_WAVE_PP_REGION "region"
//#define BOOST_WAVE_PP_REGION_UC "REGION" // uppercase of BOOST_WAVE_PP_REGION
//#define BOOST_WAVE_PP_ENDREGION "endregion"
//#define BOOST_WAVE_PP_IMPORT "import"
///////////////////////////////////////////////////////////////////////////////
// Define the maximal include nesting depth allowed. If this value isn't
// defined it defaults to 1024
//
// To define a new initial include nesting depth uncomment the following and
// supply a new integer value.
//
//#define BOOST_WAVE_MAX_INCLUDE_LEVEL_DEPTH 1024
///////////////////////////////////////////////////////////////////////////////
// Decide, whether to support variadics and placemarkers
//
// To implement support variadics and placemarkers uncomment the following
//
#define BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS 0
///////////////////////////////////////////////////////////////////////////////
// Decide, whether to implement a #warning directive as
//
// To implement #warning directives, uncomment the following
//
#define BOOST_WAVE_SUPPORT_WARNING_DIRECTIVE 0
///////////////////////////////////////////////////////////////////////////////
// Decide, whether to implement #pragma once
//
// To implement #pragma once, uncomment the following
//
#define BOOST_WAVE_SUPPORT_PRAGMA_ONCE 0
///////////////////////////////////////////////////////////////////////////////
// Decide, whether to implement #include_next
// Please note, that this is an extension to the C++ Standard.
//
// To implement #include_next, uncomment the following
//
#define BOOST_WAVE_SUPPORT_INCLUDE_NEXT 1
///////////////////////////////////////////////////////////////////////////////
// Undefine the following, to enable some MS specific language extensions:
// __int8, __int16, __int32, __int64, __based, __declspec, __cdecl,
// __fastcall, __stdcall, __try, __except, __finally, __leave, __inline,
// __asm
#define BOOST_WAVE_SUPPORT_MS_EXTENSIONS 0
///////////////////////////////////////////////////////////////////////////////
// Allow the message body of the #error and #warning directives to be
// preprocessed before the diagnostic is issued.
//
// Uncommenting the following will preprocess the message bodies of #error and
// #warning messages before the error (warning) is issued
//
#define BOOST_WAVE_PREPROCESS_ERROR_MESSAGE_BODY 1
///////////////////////////////////////////////////////////////////////////////
// Allow the #pragma directives to be returned to the caller (optionally after
// preprocessing the body)
//
// Undefining the following will skip #pragma directives, so that the caller
// will not see them.
//
#define BOOST_WAVE_EMIT_PRAGMA_DIRECTIVES 0
///////////////////////////////////////////////////////////////////////////////
// Allow the body of a #pragma directive to be preprocessed before the
// directive is returned to the caller.
//
// Uncommenting the following will preprocess the bodies of #pragma directives
//
#define BOOST_WAVE_PREPROCESS_PRAGMA_BODY 0
///////////////////////////////////////////////////////////////////////////////
// Allow to define macros with the command line syntax (-DMACRO(x)=definition)
//
// Uncommenting the following will enable the possibility to define macros
// based on the command line syntax
//
#define BOOST_WAVE_ENABLE_COMMANDLINE_MACROS 0
///////////////////////////////////////////////////////////////////////////////
// Define the string type to be used to store the token values and the file
// names inside a file_position template class
//
// use the following, if you have a fast std::allocator<char>
#define BOOST_WAVE_STRINGTYPE wave::util::flex_string< \
char, std::char_traits<char>, std::allocator<char>, \
wave::util::CowString</*char,*/ \
wave::util::AllocatorStringStorage<char> > \
> \
/**/
#include <boost/wave/util/flex_string.hpp>
///////////////////////////////////////////////////////////////////////////////
// Uncomment the following, if you need debug output, the
// BOOST_SPIRIT_DEBUG_FLAGS constants below help to fine control the amount of
// the generated debug output
//#define BOOST_SPIRIT_DEBUG
///////////////////////////////////////////////////////////////////////////////
// debug rules, subrules and grammars only, for possible flags see
// spirit/debug.hpp
#if defined(BOOST_SPIRIT_DEBUG)
#define BOOST_SPIRIT_DEBUG_FLAGS ( \
BOOST_SPIRIT_DEBUG_FLAGS_NODES | \
BOOST_SPIRIT_DEBUG_FLAGS_CLOSURES \
) \
/**/
///////////////////////////////////////////////////////////////////////////////
// debug flags for the pp-iterator library, possible flags (defined in
// wave_config.hpp):
//
// #define BOOST_SPIRIT_DEBUG_FLAGS_CPP_GRAMMAR 0x0001
// #define BOOST_SPIRIT_DEBUG_FLAGS_TIME_CONVERSION 0x0002
// #define BOOST_SPIRIT_DEBUG_FLAGS_CPP_EXPR_GRAMMAR 0x0004
// #define BOOST_SPIRIT_DEBUG_FLAGS_INTLIT_GRAMMAR 0x0008
// #define BOOST_SPIRIT_DEBUG_FLAGS_CHLIT_GRAMMAR 0x0010
// #define BOOST_SPIRIT_DEBUG_FLAGS_DEFINED_GRAMMAR 0x0020
// #define BOOST_SPIRIT_DEBUG_FLAGS_PREDEF_MACROS_GRAMMAR 0x0040
#define BOOST_SPIRIT_DEBUG_FLAGS_CPP (\
/* insert the required flags from above */ \
) \
/**/
#endif
///////////////////////////////////////////////////////////////////////////////
//
// For all recognized preprocessor statements the output parse trees
// formatted as xml are printed. The formatted parse trees are streamed to the
// std::ostream defined by the WAVE_DUMP_PARSE_TREE_OUT constant.
//
// Uncomment the following, if you want to see these parse trees.
//
//#define BOOST_WAVE_DUMP_PARSE_TREE 1
//#define BOOST_WAVE_DUMP_PARSE_TREE_OUT std::cerr
///////////////////////////////////////////////////////////////////////////////
//
// For all #if and #elif directives the preprocessed expressions are printed.
// These expressions are streamed to the std::ostream defined by the
// WAVE_DUMP_CONDITIONAL_EXPRESSIONS_OUT constant.
//
// Uncomment the following, if you want to see the preprocessed expressions
//
//#define BOOST_WAVE_DUMP_CONDITIONAL_EXPRESSIONS 1
//#define BOOST_WAVE_DUMP_CONDITIONAL_EXPRESSIONS_OUT std::cerr
///////////////////////////////////////////////////////////////////////////////
// Decide, whether to use the separate compilation model for the instantiation
// of the C++ lexer objects.
//
// If this is defined, you should explicitly instantiate the C++ lexer
// template with the correct parameters in a separate compilation unit of
// your program (see the files instantiate_slex_lexer.cpp and
// instantiate_re2c_lexer.cpp).
//
// To use the lexer inclusion model, uncomment the following
//
#define BOOST_WAVE_SEPARATE_LEXER_INSTANTIATION 1
///////////////////////////////////////////////////////////////////////////////
// Decide, whether to use the separate compilation model for the instantiation
// of the grammar objects.
//
// If this is defined, you should explicitly instantiate the grammar
// templates with the correct parameters in a separate compilation unit of
// your program (see the files instantiate_cpp_grammar.cpp).
//
// To use the grammar inclusion model, uncomment the following
//
#define BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION 1
///////////////////////////////////////////////////////////////////////////////
// MSVC specific #pragma's
#if defined(BOOST_MSVC)
#pragma warning (disable: 4355) // 'this' used in base member initializer list
#pragma warning (disable: 4800) // forcing value to bool 'true' or 'false'
#pragma inline_depth(255)
#pragma inline_recursion(on)
#endif // defined(BOOST_MSVC)
///////////////////////////////////////////////////////////////////////////////
// Now include the cofiguration stuff for the Wave library itself
#include <boost/wave/wave_config.hpp>
#endif // !defined(LIST_INCLUDES_CONFIG_HPP_0DE80E47_8D50_4DFA_9C1C_0EECAA8A934A_INCLUDED)

View File

@@ -0,0 +1,21 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Sample: List include dependencies of a given source file version number
Copyright (c) 2001-2004 Hartmut Kaiser
http://spirit.sourceforge.net/
Use, modification and distribution is subject to 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(LIST_INCLUDES_VERSION_HPP_FF662D6C_C3E6_4BEC_A062_5D9BD7415EBF_INCLUDED)
#define LIST_INCLUDES_VERSION_HPP_FF662D6C_C3E6_4BEC_A062_5D9BD7415EBF_INCLUDED
#define LIST_INCLUDES_VERSION_MAJOR 0
#define LIST_INCLUDES_VERSION_MINOR 2
#define LIST_INCLUDES_VERSION_SUBMINOR 0
#endif // !defined(LIST_INCLUDES_VERSION_HPP_FF662D6C_C3E6_4BEC_A062_5D9BD7415EBF_INCLUDED)