2
0
mirror of https://github.com/boostorg/wave.git synced 2026-01-26 07:02:23 +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

926
ChangeLog Normal file
View File

@@ -0,0 +1,926 @@
Wave: A Standard compliant C++ preprocessor library
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)
-------------------------------------------------------------------------------
TODO (known issues):
- Fix expansion of macros, which replacement-list terminates in a partial macro
expansion.
- Fix the re2c lexer for iterators others then string::iterator
- Enforce, that #if/#endif and #region/#endregion are balanced file wise
- Try to remove the second parameter from the pp_iterator<>::force_include
function.
Sun Jan 25 20:26:45 WEST 2004
- Fixed invalid explicit instantiation syntax as reported by the Comeau
compiler.
- Added a missing header to flex_string.hpp.
Sat Jan 24 19:47:44 WEST 2004
- Completely decoupled the used lexer from the preprocessor.
- Unfortunately had to change the template interface of the context class. It
now instead of the token type takes the type of the lexer to use.
- Reintroduced the cpp_tokens, list_includes and waveidl samples.
. cpp_tokens is based on the SLex lexer
. list_includes shows the usage of the include file tracing capability
. waveidl uses the Re2C based IDL lexer in conjunction with the default token
type
Tue Jan 13 20:43:04 WEST 2004
- Fixed several compilation issues under linux (gcc 3.2.3, gcc 3.3, gcc 3.3.2,
gcc 3.4, Intel V7.1)
- Fixed a compatibility problem with Spirit versions older than V1.7.
Mon Jan 12 20:39:50 WEST 2004
- Boostified the code base:
. Moved code into namespace boost.
. Prefixed all pp constants with "BOOST_".
. Refactured the directory structure.
- Removed IDL mode and SLex lexer from the code base. These will be re-added as
samples.
- Changed the Wave configuration system to be more flexible (all
#if defined(BOOST_WAVE_...) changed to #if BOOST_WAVE_... != 0),
which allows to configure the library without changing the code base itself
Sat Jan 10 18:17:50 WEST 2004
- Incorporated Andrei Alexandrescu's latest changes to the flex_string class,
which resulted in an overall spedd gain of about 5-10%.
Wed Jan 7 17:46:45 WEST 2004
- Found a major performance hole! The achieved general speedup is about 50-70%.
- Added missing old MS specific extensions to the re2c lexer (_based,
_declspec, _cdecl, _fastcall, _stdcall, _inline and _asm).
- Added support for #include_next (as implemented by gcc).
- Fixed compilation problems with gcc 3.3.1
- Avoid to look up in symbol table of a potential macro name twice.
- Added the Spirit SLex lexer sample to the Wave source tree, because it was
removed from the Spirit distribution.
- Removed the configuration option, which allowed to reverse the names stored
in the symbol tables.
- Implemented experimental support for using a TST (ternary search tree) as the
container for the symbol tables.
Sun Jan 5 12:30:50 2004
- Released V1.0.0
Sun Jan 4 00:11:50 2004
- Removed tabs from the flex_string.hpp file.
- Modified the input_functor.hpp file to sqeeze out some milliseconds at
runtime.
- The --timer option now prints the overall elapsed time even if an error
occured.
- Added support for #pragma once.
Fri Jan 2 22:58:54 2004
- Fixed a bug in the code, which predefines the preprocessor constants.
- Fixed a bug in intlit_grammar<> initialisation code.
Thu Jan 1 21:15:03 2004
- Fixed a bug while predefining a macro with a value through the commmand line.
- Fixed a bug, which reported a macro definition as illegal, if the redefined
macro was a function like macro with parameters.
- Fixed a bug, if concatenation of two tokens resulted in a C++ comment start
token.
Thu Jan 1 15:01:54 2004
- Finished license migration.
Wed Dec 31 12:23:55 2003
- Changed the copyright and licensing policiy to be Boost compatible.
Wed Dec 31 12:01:14 2003
- Fixed a problem while compiling certain headers from the Microsoft Windows
SDK:
#define CreateWindowA(lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\
CreateWindowExA(0L, lpClassName, lpWindowName, dwStyle, x, y,\
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
where essentially is no whitespace between the parameter list and the macro
replacement list.
- Fixed a problem with the MS extension __declspec, which now is recognized
correctly.
Sat Dec 27 14:48:29 2003
- Fixed remaining problems with assign/assign_a.
- Fixed some gcc warnings about signed/unsigned comparision mismatch.
Tue Nov 11 20:51:41 WEST 2003
- Changed the IDL mode to recognize identifiers only. All keywords (except
'true' and 'false') are returned as identifiers. This allows for easy
extension of the IDL language. The drawback is, that after preprocessing
there needs to be just another lexing stage, which recognizes the keywords.
- Fixed a possible problem, when in between a #if/#elif directive and a
subsequent opening parenthesis Wave finds no whitespace:
#if(_WIN_VER >= 0x0500)
is now recognized correctly.
(This problem was pointed out by Porter Schermerhorn).
Sun Nov 9 21:05:23 WEST 2003
- Started to work on implementation of an IDL lexer for the TAO idl compiler.
. Branched off the Re2C C++ lexer and related files as a starting point for
the new IDL lexer. Added connfiguration means to allow compile time
decision, in which mode to operatoe (C++ or IDL).
. Implemented the Re2C based IDL lexing component.
. Fixed all occurences of non-IDL tokens (as T_COLON_COLON and T_ELLIPSIS)
Sat Nov 8 20:05:52 WEST 2003
- Version 1.0.0
- Munged the email addresses embedded within the source files.
- Adjusted for the new actor names in Spirit (assign_a and append_a).
Thu Aug 21 16:54:20 2003
- Removed the internally used macro 'countof()' to avoid possible nameclashes
with user code.
- Fixed a bug, which prevented the execution of the concatination operator '##'
while expanding object-like macros.
Tue Aug 5 10:04:00 2003
- Fixed a false assertion, if a #pragma directive started with some whitespace
on the line.
- Added the #pragma wave timer() directive to allow rough timings during
processing. This is done on top of a new callback hook for unrecognized
#pragma's, which allows to easily add new pragma commands without changing
the Wave library.
- Fixed a bug in the whitespace insertion engine, which prevented the insertion
of a whitespace token in between two consecutive identifier tokens or a
integer literal token followed by an identifier token.
- Fixed a bug during macro concatenation, which allowed to concatenate
unrelated tokens from the input stream:
#define CAT(a, b) PRIMITIVE_CAT(a, b)
#define PRIMITIVE_CAT(a, b) a ## b
#define X() B
#define ABC 1
CAT(A, X() C) // AB C
CAT(A, X()C) // correct: AB C, was 1
- Fixed a 64 bit portability problem.
- Added pragma wave timer(suspend) and wave timer(resume)
- Fixed a ODR problem with static initialization data for predefined macros.
- Ported the iterators to the new iterator_adaptors.
- Updated the documentation to reflect the recent changes
Sun Jun 29 12:35:00 2003
- Fixed 64 bit compatibility warnings.
- Fixed a bug, which prevented the correct recognition of a #line directive, if
only the filename part of this directive was generated by a macro expansion.
- Fixed a bug during macro expansion of conditional expressions, which
prevented the correct expansion of certain scoped macros.
Fri Jun 27 09:50:14 2003
- Changed the output of the overall elapsed time (option --timer) to cerr.
- Added a configuration constant WAVE_REVERSE_MACRONAMES_FOR_SYMBOLTABLE, which
reverses the macro names while storing them into the symbol table, which
allows to speed up name lookup especially, if the macro names are very long
and if these share a common prefix.
- Fixed a very subtle bug, which prevented the recognition of fully qualified
macro names during the macro expansion of conditionals expressions (for
#if/#elif).
- Improved the error output for the illformed pp expression error.
Thu Jun 26 08:20:30 2003
- Done a complete spell check of the source code comments.
Wed Jun 25 20:33:52 2003
- Changed the conditional expression engine to work with integer numeric
literals only. Distinguished signed and unsigned literals.
- Importing a region twice is allowed now.
- Fixed a bug, which does not removed all placeholder tokens from a expanded
token sequence while evaluating conditional expressions (C++0x mode only).
Wed Jun 25 15:01:51 2003
- Changed the conditional expression engine to respect the type of numeric
literals, now expressions like '#if 1 / 10 == 0' evaluate correctly (to true
:-)
- Fixed a bug, where macro names referring to global macros (as ::A::B) were
not correctly recognized under certain circumstances.
- Empty parameter lists for macros with ellipses only sometimes generated a
placemarker token in the output:
#define STR(...) #__VA_ARGS__
STR() // resulted in "§" instead of "" .
Wed Jun 25 08:35:06 2003
- Fixed several gcc compilation errors (missing typename's etc.)
- Fixed a compilation problem, if Wave is built on top of the SLEX scanner.
- Reformatted the --timer output from pure seconds to a more reasonable format.
Fri Jun 20 19:33:30 2003
- Changed the enable_tracing function of the tracing_policies to take a
trace_flags variable instead of a bool, to allow to control tracing with more
granulation.
- Added the tracing_enabled function to the tracing_policies, which returns the
current tracing status.
- Updated the documentation of the tracing policies.
Thu Jun 19 21:45:39 2003
- Reactivated the list_includes sample with the help of the new include file
tracing facility.
Thu Jun 19 17:55:35 2003
- Eliminated the TraceT template parameter from the macromap<> template.
- Added two hooks to the trace policy to allow to trace the opening and
closing of include files.
Thu Jun 19 14:08:10 2003
- Added the command line option --timer, which enables the output to std::cout
of the overall elapsed time during the preprocessing of the given file.
Fri Jun 13 09:11:29 2003
- Emitted an error message, if an ellipses was found as a formal macro
parameter and variadics were disabled.
- Fixed a false error message, that the last line was not terminated with a
newline, which occured, if no output was generated by the last line of the
source file.
Thu Jun 12 15:20:22 2003
- Fixed the recent change in argument expansion for the variadics/C99/C++0x
mode.
- Fixed a problem, where an additional whitespace between _Pragma and the
opening parenthesis resulted in a false error message.
- Used a pool allocator for the token sequence containers (std::list<>'s),
which gives a speed gain of more than 60% (while profiling the Order
library).
Wed Jun 11 22:18:54 2003
- Fixed a macro scoping/expansion problem, when a macro returned a full scope
which is continued on the call site to form a full qualified name, the name
wasn't recognized correctly:
# region A
# define MACRO 1
# region B
# define MACRO 2
# endregion
# endregion
# define ID(x) x
ID(A)::MACRO // 1
ID(A::B)::MACRO // 2, was expanded to A::B::MACRO
- Changed the expansion of macro arguments such, that these will be expanded
only, if the result is to be used for substitution during the expansion
of the replacement list.
Wed Jun 11 14:40:29 2003
- Included a whitespace eating finite state machine (FSM) for minimal
whitespace in the generated output. This was suggested by Paul Mensonides.
- Updated the acknowledgement section
Wed Jun 4 08:03:04 2003
- Fixed a bug reported by Faisal Vali, which prevented the correct evaluation
of conditional expressions, if these referenced macro names, which expanded
to a sequence containing non-expandable tokens.
- Fixed the above bug for #elif directives too (in the first place this was
fixed for #if directives only)
Mon May 26 22:15:40 2003
- Added missing copyrights in several files.
- Fixed false output, if a unknown _Pragma were encountered.
- Fixed a macro expansion problem with qualified names, were constructs like
the following were not expanded correctly:
#define ID(x) x
#region SCOPE
# define TEST 1
#endregion
ID(SCOPE::) TEST // should expand to 1
- Changed #import semantics for macros from copy semantics to reference
semantics, i.e. macros are now considered to be implicitly imported into the
scope, where they are defined. If a macro is imported into another scope and
the original macro is undefined, the imported macro still exists. Further,
if the imported macro is expanded, then while rescanning the original macro
is disabled too:
#region A
# define B(x) x
#endregion
#import A
B (A::B) (*) // A::B(*)
A::B (B) (*) // B(*)
B (B) (*) // B(*)
A::B (A::B) (*) // A::B(*)
- Fixed a recently introduced problem, where placemarker tokens slipped through
to the output under certain conditions (in variadics/C99/C++0x modes only).
Mon May 19 16:30:49 2003
- Fixed a bug, which prevented the recognition of the __lparen__, __rparen__ or
__comma__ alternative tokens, if these were the first token after an emitted
#line directive (reported by Vesa Karvonen).
- Added an optimization, that only those tokens are considered for a macro
expansion, which may result in an expansion.
Tue May 13 18:16:26 2003
- Fixed a newly introduced problem, where a omitted argument consisting out
of whitespace only were failed to be replaced by a placemarker token. This
lead to problems with constructs like the following:
#define paste(a, b, c) a ## b ## c
paste(1, , 3) // should expand to 13, but expanded to 1## 3
- Fixed a problem with the tracing support, which throwed an unexpected
exception if there were too few arguments given while expanding a macro.
- Allowed to open and to import the global scope ('#region ::' and
'#import ::').
- Fixed a bug, if more than one file was given with a --forceinclude command
line option.
Sat May 10 21:30:29 2003
- Added __STDC_FULL_REGION__ and __STDC_CURRENT_REGION__ to the list of not
undefinable macros.
- In normal C++ mode and C99 mode the #ifdef/#ifndef and the operator defined()
should not support qualified names. This is fixed now.
- Updated the documentation.
- Fixed minor gcc -Wall compilation warnings.
- Added better error support for qualified names used as arguments for #ifdef,
#ifndef and operator defined().
Sat May 10 09:51:18 2003
- Removed the feature, that the comma before the ellipsis parameter in a macro
definition may be omitted.
- Resolved an issue with the expansion of qualified macros, when these
qualified names were partially generated by a previous macro expansion
- Allowed to specify fully qualified names as arguments to the #region directive
Wed May 7 22:44:21 2003
- Changed the names of __SCOPE__ and __FULL_SCOPE__ predefined macros to
__STDC_CURRENT_REGION__ and __STDC_FULL_REGION__ resp. The names are subject
to change if the #region keyword actually will be renamed to #scope/#module
or whatever.
- In C++0x mode it is now possible to omit the last comma before a variadics
ellipsis in a macro definition:
#define cat_i(a, b, c, d, e ...) a ## b ## c ## d ## e
- Fixed a bug in the stringize code, where an ellipsis to stringize resulted in
stringizing of the first ellipsis parameter only. Preserved the original
whitespace delimiting in between the ellipsis arguments.
- Introduced the wave::language_support enum for convenient switching of the
supported language features throughout the library.
- Fixed a bug, which prevented the definition of the predefined macro
__WAVE_HAS_VARRIADICS__, if --variadics were given on the command line.
Tue May 6 15:49:45 2003
- Made predefined macros available at every macro scope without qualification.
- Predefined a new macro in C++0x mode: __STDC_GLOBAL__, which is defined at
global macro scope only and equals to '1' (integer literal).
- In C++0x mode there are two new predefined macros:
__SCOPE__: expands to the last part of the qualified name of the
current macro scope
__FULL_SCOPE__: expands to the full qualified name of the current macro
scope
Mon May 5 23:02:48 2003
- Fixed a problem in the new well defined token pasting code, which occured for
constructs like the following:
#define is_empty(...) is_empty_ ## __VA_ARGS__ ## _other
i.e. where two or more '##' operators were contained in the replacement text.
- Implemented __comma__, __lparen__ and __rparen__ alternative pp-tokens, which
may be used as the ',', '(' and ')' tokens during preprocessing. These are
only converted to there respective string representation in a special
translation phase after preprocessing. This was proposed by Vesa Karvonen.
- Changed the macro scoping rules to: "If a qualified name does not find a
nested name, it is not a qualified name to the preprocessor." This seems to
be the simplest usable solution for the possible ambiguities.
- Fixed a bug in the macro expansion engine in C++0x mode, where the skipping
of whitespace inside of a qualified name wasn't consistent.
Sun May 4 10:48:53 2003
- Fixed a bug in the expression grammar, which prevented 'not' to be recognized
as a valid operator.
- Qualified names are now supported as parameters to #ifdef and #ifndef too.
- Remove one specialization of the macro expansion engine. It gets instantiated
only twice now (for the main input iterator and for list<>'s of tokens.
- Simplified the required explicit specialization of the defined_grammar
template. It has to be explicitely instantiated by providing the token type
only (just as for the explicit instantiations of the other grammars).
Fri May 2 22:44:27 2003
- Qualified names are now allowed as parameters to the operator defined() in
C++0x mode.
- Separated the defined() functionality into a separate translation unit to
work around a VC7.1 ICE.
Fri May 2 15:38:26 2003
- The C++0x mode now has a special set of predefined macros.
- The predefined macro __WAVE_HAS_VARIADICS__ is now defined in C99 and C++0x
modes too (--variadics is implied for these modes).
- Updated the documentation to reflect the recent changes and additions.
- In C++0x mode Wave now supports macro scopes:
- new keywords #region/#endregion/#import
- qualified macro names
- In C++0x mode Wave now supports token pasting of unrelated tokens. These are
concatenated, the result is re-tokenized and inserted into the output stream.
- Fixed a minor bug in the macro expansion engine, if a qualified function-like
macro was found in an object-like context.
- Fixed an issue with well defined token pasting of unrelated tokens.
Tue Apr 29 08:47:37 2003
- Fixed a bug in the macro expansion engine, which prevented the expansion
of a certain macro under specific conditions (if the left of two tokens to
concatenate were a disabled one (T_NONREPLACABLE_IDENTIFIER), then the
resulting token was disabled too).
- Added additional diagnostics to the Wave driver to disambiguate the C99 and
C++0x modes.
- Implemented a new API function and a corresponding Wave driver command line
option, which allows to specify one or more include files to be preprocessed
before the regular file is preprocessed (the files are processed as normal
input and all the resulting output is included, before processing the regular
input file). The Wave driver command line option is --forceinclude (-F).
- Wave now compiles the Order library from Vesa Karvonen.
Mon Apr 28 07:57:10 2003
- Fixed a bug in the macro expansion engine.
- Removed a lot of (not needed) whitespace in the generated output (but still
not optimal).
Sat Apr 26 20:30:53 2003
- Fixed a bug in the initialization code of the Slex lexer while working in
C99 mode (reported by Reece Dunn).
Fri Apr 18 08:37:35 2003
- Fixed the handling of option_value's inside of pragma directives:
_Pragma("wave option(option_value)")
inside which all all whitespaces were deleted.
- Started to implement experimental macro scoping.
Thu Apr 10 10:20:07 2003
- Fixed a problem with the #pragma wave stop(), where only the first token
inside the stop directive was output, when the preprocessor stops in result
of this pragma.
- Implemented a new #pragma wave system(command), which spawns a new operation
system command exactly as specified inside the system directive, intercepts
the stdout output of this process, retokenizes this output and inserts the
generated token sequence in place of the original #pragma or operator _Pragma.
Please note that the generated output is _not_ subject to any macro expansion
before its insertion as the replacement of the pragma itself. If you need to
macro expand the replacement text, you always may force this by writing:
#define SCAN(x) x
SCAN(_Pragma("wave system(...)"))
which re-scans the replacement once.
- Replaced the Wave position_iterator with the boost::spirit::position_iterator
(without any problems!).
Mon Apr 7 10:45:30 2003
- Fixed macro_trace_policies::expand_object_like_macro not to be called with
the formal arguments as one of its parameters.
- Updated the documentation to reflect the changes needed for the tracing
stuff.
Mon Mar 31 19:07:05 2003
- Fixed variadics support in the trace output.
- Fixed preprocessing of operator _Pragma() before it's execution.
- Added _Pragma("wave stop(errmsg)") (#pragma wave stop(errmsg)) to allow
diagnostics output from inside macro expansion.
- Fixed operator _Pragma for unknown pragmas (these are simply put through to
the output).
- Implemented a maximal possible include nesting depth to avoid an out of
memory error. The initial value for this is configurable through the compile
time constant WAVE_MAX_INCLUDE_LEVEL_DEPTH, which defaults to 1024, if not
given.
Additionally this may be enlarged through a new command line option:
-n/--nesting (Wave driver only).
Sun Mar 30 20:40:17 2003
- Implemented the predefined macro __INCLUDE_LEVEL__, which expands to a
decimal integer constant that represents the depth of nesting in include
files. The value of this macro is incremented on every '#include' directive
and decremented at every end of file.
- Implemented the operator _Pragma(). It is recognized in C99 mode and whenever
variadics are enabled.
Sun Mar 30 08:30:12 2003
- Changed the tracing format to be more readable.
- Changed the tracing #pragma's to
enable tracing: #pragma wave trace(enable)
disable tracing: #pragma wave trace(disable)
or
enable tracing: #pragma wave trace(1)
disable tracing: #pragma wave trace(0)
- Changed the semantics of the -t (--traceto) switch. Without any -t switch
there isn't generated any trace output at all, even, if the corresponding
#pragma directives are found. To output the trace info to a file, the
'-t file' syntax may be used, to output to std::cerr, the '-t-' (or '-t -')
syntax may be used.
Fri Mar 28 17:27:25 2003
- Added a new template parameter to the wave::context<> object, which allows
to specify a policy for controlling the macro expansion tracing. The default
macro_trace_policy does no tracing at all. This way one can add specific
macro expansion tracing facilities to the library.
- #pragma directives starting with a STDC identifier are no longer not macro
expanded in C++ mode, in C++ mode these are now expanded as usual, in C99
mode not.
- The tracing can be enabled/disabled from inside the preprocessed stream by
inserting a special #pragma directive:
enable tracing: #pragma wave_option(trace: enable)
disable tracing: #pragma wave_option(trace: disable)
- The Wave driver now allows to specify a destination for the macro expansion
tracing trough a new command line switch: '-t path' or '--traceto path'. If
this option isn't given, the trace output goes to stderr.
- The Wave driver now allows to specify the name of the file, where the
preprocessed result stream is to be saved: '-o path' or '--output path'. If
this option is not given, the output goes to stdout.
Wed Mar 26 20:39:11 2003
- Fixed a problem with alternative tokens (as 'and', 'or' etc.) and trigraph
tokens, which were not correctly recognized inside #if/#elif expressions.
- Alternative tokens ('and', 'or' etc.) are no longer subject to a possible
macro redefinition.
- Fixed the special handling of 'true' and 'false' during the macro expansion
of #if/#elif expressions.
Tue Mar 25 12:12:35 2003
- Released Wave V0.9.1
Mon Mar 24 13:34:27 2003
- Implemented placemarkers, i.e. Wave now supports empty arguments during macro
invocations. This must be enabled by means of a new pp constant:
WAVE_SUPPORT_VARIADICS_PLACEMARKERS which must be defined to enable the
placemarker and variadics code and by defining the command line option
'--variadics' (Wave driver only).
- Implemented variadics, i.e. Wave now supports macros with variable parameter
counts. This must be enabled by means of the pp constant:
WAVE_SUPPORT_VARIADICS_PLACEMARKERS which must be defined to enable the
placemarker and variadics code and by defining the command line option
'--variadics' (Wave driver only).
- Implemented a C99 mode. This mode enables variadics and placemarkers by
default and rejects some specific C++ tokens (as the alternate keywords and
'::', '->*', '.*'). This mode must be enabled by the means of the pp constant
WAVE_SUPPORT_VARIADICS_PLACEMARKERS (see above). The C99 mode is enabled by
the command line switch '--c99' (Wave driver only).
This involved some changes in the C99/C++ lexers.
Fri Mar 21 16:02:10 2003
- Fixed a bug in the macro expansion engine, which prevented the expansion of
macros, which name was concatenated out of a identifier and a integer
followed directly by another identifier:
#define X() X_ ## 0R() // note: _zero_ followed by 'R'
#define X_0R() ...
X() // expanded to: X_0R(), but should expand to ...
This is a problem resulting from the fact, that the Standard requires the
preprocessor to act on so called pp-tokens, but Wave acts on C++ tokens.
Thu Mar 20 21:39:21 2003
- Fixed a problem with expression parsing (#if/#elif constant expressions),
which failed to produce an error message for expressions like
#if 1 2 3 4 5
i.e. where the token sequence starts with a valid constant expression, but
the remainder of the line contained other tokens than whitespace.
- Integrated the flex_string class from Andrei Alexandrescu (published on the
CUJ site) to get COW-string behaviour for the token values and position
filename strings. This resulted in a major overall speedup (about 2-3 times
faster in dependency of the complexity of pp usage in the input stream).
- Fixed a bug, which reported ill formed #if/#else expressions as errors, even
if the current if block status (conditional compilation status) is false.
- Added a warning, if the last line of a file does not end with a newline.
- Improved error recognition and handling for malformed preprocessor directives
Mon Mar 17 19:53:29 2003
- Fixed a concatenation problem: constructs like a##b##c where expanded
incorrectly.
- Optimized the recognition of pp directives:
- the parser is used only, if the next non-whitespace token starts a pp
directive
- null directives now are recognized without calling the parser
- the parser isn't called anymore, if the if_block_status is false and no
conditional pp directive (#if etc.) is to be recognized.
These optimizations give a speed improvement by upto 40%.
- Removed adjacent whitespace during macro expansion (needs to be revised,
since there is some whitespace left, which may be removed)
Sun Mar 16 23:19:11 2003
- Fixed a problem with include pathes given on the command line, if the file
to preprocess was not given as a full path (driver executable).
- Fixed a problem with path names containing blanks (driver executable).
- Cleaned command line and argument handling (driver executable).
- Fixed a severe memory leak.
- Fixed a bug, if a C++ keyword was used as a macro name or macro parameter
name, which prevented the macro recognition and expansion to function
properly.
- Implemented the WAVE_SUPPORT_MS_EXTENSIONS compiler switch for the re2c
generated lexer too.
- Fixed a problem, which caused an internal T_PLACEHOLDER token to show up
outside the macro replacement engine.
- Fixed a problem with macro #include directives, which prevents to find the
file to include, if after the macro expansion the token sequence representing
the filename began or ended with at least one whitespace token.
- Fixed a problem, which caused a false error message if the '#' character was
to be concatenated with an arbitrary other token.
- The concatenation of a whitespace token with an arbitrary other token was
reported as illegal token pasting (but it is certainly not).
Sat Mar 15 21:43:56 2003
- Added a default constructor to the wave::util::file_position template.
- Report the concatenation of unrelated tokens as an error.
- Finished the documentation.
Fri Mar 14 20:14:18 2003
- More work on documentation
- Changed file_position to expose accessor functions (the member variables are
marked as private now). This opens up the possibility to provide another
file_position implementation, which may be optimized in some way.
- Fixed a problem with the token name table, the alternate and trigraph token
names were printed incorrectly.
- Fixed a bug, which prevented the correct recognition of 'defined X' (without
parenthesises).
- Fixed a bug, which allowed to redefine and undefine the predefined name
'defined'.
- Fixed a bug, which prevents the correct recognition of a macro based #include
directive, if it expands to something like #include <...>.
- Fixed a bug, which prevented the recognition of duplicate macro parameter
names.
- Removed the insertion of additional whitespace inside of string literals
(during stringizing).
Wed Mar 12 19:16:40 2003
- Fixed a bug, which prevented the instantiation of the wave::context object
with auxiliary iterators. The token type isn't coupled anymore with the
iterator type.
This required some changes in the interface:
- The wave::context object now has three template parameters (the iterator
type, the token type and the input policy type)
- The token type does not have the iterator type as it's template parameter
anymore.
- Implemented a new position_iterator template on top of the iterator_adaptor<>
template to make it work even for input_iterator type iterators.
- Fixed a bug in the regular expressions for the Slex lexer.
- The function 'set_sys_include_delimiter()' was renamed to
'set_sysinclude_delimiter()' to better fit the naming scheme of the other
functions.
- Wrote more documentation
- Unified the different token definitions of the lexers, so that there is only
one token type left. This required some changes in the interface:
- There is no need anymore to explicitly specify the namespace of the token
type to use.
- Added the command line option -P to the Wave driver program, which predefines
a macro (i.e. defines it such, that is _not_ undefinable through an #undef
directive from inside the preprocessed program).
Sat Mar 8 07:46:43 2003
- Released Wave 0.9.0
Thu Mar 6 20:02:44 2003
- Compiled Wave with IntelV7.0/DinkumwareSTL (from VC6sp5)
- Fixed new compilation problems with gcc -Wall
- Fixed the list_includes and cpp_tokens samples to compile and link correctly.
- Fixed a bug, where a wrong filename was reported by the generated #line
directive.
- Fixed a bug, where the __FILE__ macro was expanded without '\"' around the
filename.
- The generated #line directives and the expanded __FILE__ macro now report
the filename in a native (to the system) format. Additionally the generated
string literals are now escaped correctly.
Wed Mar 5 21:11:14 2003
- Reorganized the directory structure to mirror the namespace structure of the
library
- Fixed a bug, where the complete input after the first found #include
directive were eaten up.
- Fixed a bug, where the __LINE__ macro expanded to a incorrect linenumber, if
the __LINE__ macro was encountered on a line after a '\\' '\n' sequence.
Tue Mar 4 11:50:24 2003
- The new name of the project is 'Wave'.
- Adjusted namespaces, comments etc. to reflect the new name.
- Added the command line option -U [--undefine], which allows to remove one of
the predefined macros (except __LINE__, __FILE__, __DATE__, __TIME__,
__STDC__ and __cplusplus)
Sun Mar 2 20:10:04 2003
- Fixed a bug while expanding macros without any definition part (empty macros)
- The pp-iterator will not emit a newline for every recognized preprocessing
directive anymore. The generated output is much more condensed this way.
- The pp-iterator now emits #line directives at appropriate places.
- Added an additional parser to the library, which may be used to parse macros
given in the command line syntax, i.e. something like 'MACRO(x)=definition'.
- Added the possibility to the cpp driver sample, to add macros from the
command line through the -D command line switch.
- Martin Wille contributed a test script to allow automatic testing of the
cpp driver sample by feeding all files contained in the test_files directory
through the cpp driver and comparing the generated output with the
corresponding expectations.
- Added config file support to allow for predefined option sets (for instance
for the emulation of other compilers)
- Changed the way, how include pathes are defined. It resembles now the
behaviour of gcc.
Any directories specified with '-I' options before an eventually given '-I-'
option are searched only for the case of '#include "file"', they are not
searched for '#include <file>' directives. If additional directories are
specified with '-I' options after a '-I-' option was given, these directories
are searched for all '#include' directives. In addition, the '-I-' option
inhibits the use of the current directory as the first search directory for
'#include "file"'. Therefore, the current directory is searched only if it is
requested explicitly with '-I.'. Specifying both '-I-' and '-I.' allows to
control precisely which directories are searched before the current one
and which are searched after.
- Added config file support to the cpp driver.
- stored not only the current 'name' of a file (given eventually by a #line
directive) but in parallel the actual full file system name of this file too.
Tue Feb 25 21:44:19 2003
- Fixed the warnings emitted by gcc -Wall.
- Fixed a bug in the cpp grammar, which causes to failing the recognition of
certain preprocessor directives if at the end of this directive were placed
a C++ comment.
- Simplified and extended the insertion of whitespace tokens at places, where
otherwise two adjacent tokens would form a new different token, if
retokenized.
Mon Feb 24 19:13:46 2003
- defined() functionality was broken
- added missing typename keywords
- added missing using namespace statements, where appropriate
- added a warning, when a predefined macro is to be undefined (by an #undef
directive)
- removed the 'compile in C mode' hack for the re2c generated lexer (VC7.1
(final beta) is not able to compile it with optimizations switched on
anyway :( )
- compiled with gcc 3.2 and Intel V7.0 (20030129Z)
Sun Feb 23 23:39:33 2003
- Fixed a couple of 'missing typename' bugs (thanks to Martin Wille)
- Added code to insert whitespace at places, where otherwise two adjacent
tokens would form a new different token, if retokenized.
- Fixed a severe macro expansion bug.
- Added the handling of invalid or not allowed universal character values
inside of string literals and character literals.
Sat Feb 22 20:52:06 2003
- Bumped version to 0.9.0
- Added test for invalid or not allowed universal character values (see
C++ Standard 2.2.2 [lex.charset] and Annex E)
- Fixed a bug with newlines between a macro name and the opening parenthesis
during the macro expansion and a bug with newlines inside the parameter list
during the macro expansion.
- Added the following predefined macros:
__SPIRIT_PP__
expands to the version number of the pp-iterator lib (i.e. 0x0090 for
V0.9.0)
__SPIRIT_PP_VERSION__
expands to the full version number of the pp-iterator lib (i.e.
0x00900436 for V0.9.0.436)
__SPIRIT_PP_VERSION_STR__
expands to the full version string of the pp-iterator lib (i.e.
"0.9.0.436")
Fri Feb 21 22:09:04 2003 (feature complete!)
- Allowed to optionally compile the Re2c generated lexer in 'C' mode, because
at least the VC7.1 (final beta) compiler has problems to compile it in 'C++'
mode with optimizations switch on
- Implemented #error and #warning (optional) directives (C++ standard 16.5).
Additionally there are now allowed the following preprocessor configuration
constants:
CPP_PREPROCESS_ERROR_MESSAGE_BODY
if defined, preprocesses the message body of #error and #warning
directives to allow for better diagnostics.
CPP_SUPPORT_WARNING_DIRECTIVE
if defined, then the #warning directive will be recognized such, that
a warning with the given message will be issued
- Adjusted the error handling for the Re2c generated C++ lexer, so that any
error inside the lexer is now propagated as an cpplexer_exception.
- Implemented the #line directive (C++ standard 16.4)
- Implemented #pragma directive (C++ standard 16.6)
Additionally there are now allowed the following preprocessor configuration
constants:
CPP_RETURN_PRAGMA_DIRECTIVES
if defined, then the whole pragma directive is returned as a token
sequence to the caller, if not defined the whole pragma directive is
skipped
CPP_PREPROCESS_PRAGMA_BODY
if defined, then the #pragma body will be preprocessed
- Implemented #include directive with macro arguments (C++ standard 16.2.4)
- Made the namespace structure finer granulated to leave only the main
interface classes in the main namespace cpp. All other classes are moved into
sub-namespaces to reflect the logical dependencies
- Reorganized the public interface of the context<> template class, made all
non relevant functions into the protected.
- Implemented predefined macros (__LINE__ et.al.) (C++ standard 16.8)
- Further documentation work
Wed Feb 19 23:44:47 2003
- Corrected a lot of bugs in the macro expansion engine, which now should be
conformant to the C++ standard.
- # (null) directive (C++ standard 16.7)
Sun Feb 16 08:40:38 2003
- Added a macro expansion engine which expands macros with arguments
C++ standard 16.3 [cpp.replace]
- Added a new sample: cpp_tokens. This sample preprocesses a given file and
prints out the string representations of all tokens returned from the pp
iterator
- Added documentation (to be continued!)
- Added a couple of small test files to test elementary functionality
(the tests mainly were contributed by Paul Mensonides)
- The main cpp sample is now a simple preprocessor driver program, which
outputs the string representation of the preprocessed input stream. Use
cpp --help to get a hint, how to use it.
- Fixed a bug in the preprocessor grammar which failed to recognize a pp
statement, if there was a C++ comment at the end of the line
- Added '#' operator (C++ standard 16.3.2) [cpp.stringize]
- Fixed a bug in the slex based C++ lexer to handle the concatenation
characters correctly ('\\' followed by a '\n')
Sun Feb 9 23:01:00 2003
- Improved error handling for #if et.al.
- Fixed a pair of lexer errors
- Implemented the #if/#elif statements, the sample now contains a complete C++
expression evaluation engine (for the calculation of the outcome of the
#if/#elif statement conditions)
- Implemented macro replacement (with parameters)
- Implemented the '##' [cpp.concat] operator
- Implemented the defined() [cpp.cond] operator
Sun Feb 2 23:28:24 2003
- Implemented the #define, #undef, #ifdef, #ifndef, #else and #endif
statements
- Added optional parse tree output as xml stream (controlled through the config
pp constant CPP_DUMP_PARSE_TREE)
Fri Jan 31 21:30:55 2003
- Fixed different minor issues and a border case (#include statement at the
last line of a included file)
Wed Jan 29 21:13:32 2003
- Fixed exception handling to report the correct error position
- Fixed another bug in the stream position calculation scheme
- Added a more elaborate sample 'list_includes' which lists the dependency
information for a given source file (see test/list_includes/readme.txt).
Sat Jan 18 22:01:03 2003
- Fixed a bug in the stream position calculation scheme
- Made cpp::exceptions more standard conformant (added 'throw()' at appropriate
places)
- Overall housekeeping :-)
Wed Jan 15 21:54:20 2003
Changes since project start (still 0.5.0)
- Added #include <...> and #include "..." functionality
- pp directives are now generally recognized
- Decoupled the C++ lexers and the pp grammar to separate compilation
units (optionally) to speed up compilation (a lot!)
Thu Jan 2 12:39:30 2003
A completely new version 0.5.0 of the C preprocessor was started. It's a
complete rewrite of the existing code base. The main differences are:
- The preprocessor is now implemented as an iterator, which returns the
current preprocessed token from the input stream.
- The preprocessing of include files isn't implemented through recursion
anymore. This follows directly from the first change. As a result of this
change the internal error handling is simplified.
- The C preprocessor iterator itself is feeded by a new unified C++ lexer
iterator. BTW, this C++ lexer iterator could be used standalone and is not
tied to the C preprocessor. There are two different C++ lexers implemented
now, which are functionally completely identical. These expose a similar
interface, so the C preprocessor could be used with both of them.
- The C++ lexers integrated into the C preprocessor by now are:
Slex: A spirit based table driven regular expression lexer (the slex
engine originally was written by Dan Nuffer and is available as a
separate Spirit sample).
Re2c: A C++ lexer generated with the help of the re2c tool. This C++
lexer was written as a sample by Dan Nuffer too.
It isn't hard to plug in additional different C++ lexers. There are plans to
integrate a third one written by Juan Carlos Arevalo-Baeza, which is
available as a Spirit sample.
-------------------------------------------------------------------------------
Tue Feb 12 22:29:50 2002
Changes from 0.2.3 to 0.2.4:
- Moved XML dumping functions to the main Spirit directory
- Fixed operator '##', it was not correctly implemented somehow :-(
Sun Feb 10 21:07:19 2002
Changes from 0.2.2 to 0.2.3:
- Implemented concatenation operator '##' (cpp.concat)
- Removed defined() functionality for Intel compiler (it ICE's) until this
issue is resolved
- Separated code for dumping a parse tree to XML for inclusion in the main
Spirit headers
Thu Jan 17 23:51:21 2002
Changes from 0.2.1 to 0.2.2:
- Fixes to compile with gcc 2.95.2 and gcc 3.0.2 (thanks Dan Nuffer)
- Reformatted the grammars to conform to a single formatting guideline
- Assigned explicit rule_id's to the rules of cpp_grammar, so that the
access code to the embedded definition class is not needed anymore
- Fixed a remaining const problem
Tue Jan 15 23:40:40 2002
Changes from 0.2.0 to 0.2.1:
- Corrected handling of defined() operator
- In preprocessing conditionals undefined identifiers now correctly
replaced by '0'
- Fixed several const problems
- Added parse_node_iterator for traversing one node in a parse_tree
without going deeper down the hierarchy than one level (this is useful,
if all inspected tokens arranged along a single node in the parse tree.
The main difference to the parse_tree_iterator is, that the underlying
iterator generally can be adjusted correctly after advancing the attached
parse_node_iterator
- Fixed a problem with gcc 2.95.2, which doesn't have a <sstream> header
- Prepared usage of slex for lexer states
Sun Jan 13 10:21:16 2002
Changes from 0.1.0 to 0.2.0:
- Added operator 'defined()'
- Added directive '#warning'
- Corrected error reporting
- Added command line option -I- for finer control of the searched include
directories (-I and -I- should now work as in gcc, see readme.html for
more info)
- Corrected conditional preprocessing (should be fully functional now)
- Fixed existing code base for changes made in parse tree support
- Moved parse tree utility functions to a separate header (prepared for
inclusion to the Spirit main library)

65
build/Jamfile Normal file
View File

@@ -0,0 +1,65 @@
# Wave: A Standard compliant C++ preprocessor library
#
# Boost Wave Library Build Jamfile
#
# 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/build ;
SOURCES = instantiate_cpp_exprgrammar
instantiate_cpp_grammar
instantiate_cpp_literalgrammars
instantiate_defined_grammar
instantiate_predef_macros
instantiate_re2c_lexer
instantiate_re2c_lexer_string
cpplexer/re2clex/aq
cpplexer/re2clex/cpp.re
;
lib boost_wave
: ../src/$(SOURCES).cpp
: # build requirements
[ common-names ] # magic for install and auto-link features
<include>$(BOOST_ROOT)
<sysinclude>$(BOOST_ROOT)
<vc7.1><*><rtti>off # workaround for compiler bug
<no-warn>cpp.re.cpp
: debug release # build variants
;
#dll boost_wave
# : ../src/$(SOURCES).cpp
# : # build requirements
# [ common-names ] # magic for install and auto-link features
# <define>BOOST_FILESYSTEM_DYN_LINK=1 # tell source we're building dll's
# <runtime-link>dynamic # build only for dynamic runtimes
# <include>$(BOOST_ROOT)
# <sysinclude>$(BOOST_ROOT)
# : debug release # build variants
# ;
install wave lib
: <lib>boost_wave
# <dll>boost_wave
;
stage stage/lib : <lib>boost_wave # <dll>boost_wave
:
# copy to a path rooted at BOOST_ROOT:
<locate>$(BOOST_ROOT)
# make sure the names of the libraries are correctly named:
[ common-names ]
# add this target to the "stage" and "all" pseudo-targets:
<target>stage
<target>all
:
debug release
;
# end

31
build/Jamfile.v2 Normal file
View File

@@ -0,0 +1,31 @@
# Wave: A Standard compliant C++ preprocessor library
#
# Boost Wave Library Build Jamfile
#
# 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)
project boost/wave
: source-location ../src
;
SOURCES = instantiate_cpp_exprgrammar
instantiate_cpp_grammar
instantiate_cpp_literalgrammars
instantiate_defined_grammar
instantiate_predef_macros
instantiate_re2c_lexer
instantiate_re2c_lexer_string
cpplexer/re2clex/aq
cpplexer/re2clex/cpp.re
;
lib boost_wave
: $(SOURCES).cpp
: <vc7.1><*><rtti>off # workaround for compiler bug
<no-warn>cpp.re.cpp
;

85
doc/acknowledgements.html Normal file
View File

@@ -0,0 +1,85 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Acknowledgements</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="theme/style.css" type="text/css">
</head>
<body text="#000000" background="theme/bkd.gif">
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21"> <h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">Acknowledgements</font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="wave_driver.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="references.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>Special thanks to:</p>
<blockquote>
<p> <b>Paul Mensonides</b> for his invaluable help while developing the macro
expansion engine and his insightful tips. He developed the recursive macro
expansion algorithm implemented herein and also contributed most of the small
testcases used for testing the correctness of the macro expansion.</p>
<p><b>Dan Nuffer</b>, who wrote the initial Re2C based C++ lexer and the Slex
(Spirit Lex) scanner generator sample.</p>
<p><b>Martin Wille</b> for helping with the port to linux and for contributing
the automated test scripts.</p>
<p><b>Vladimir Prus</b> for helping with the command line and config file options
analysis fro the <tt>Wave</tt> driver executable.</p>
<p><b>Juan Carlos Arevalo-Baeza</b>, who wrote the Spirit cpp_lexer sample,
from which are taken some ideas.</p>
<p> <strong>Andrei Alexandrescu</strong> for allowing to use his flex_string class,
a policy based std::basic_string&lt;&gt; compatible string implementation.</p>
<p><strong>Reece Dunn</strong>, <strong>Vesa Karvonen</strong>, <strong>Faisal Vali</strong>, <strong>Porter Schermerhorn</strong> and <strong>Daniel Fontijne</strong> for
reporting several problems and bugs.</p>
<p><strong>Tarmo Pikaro</strong> for reporting several bug while compiling specific
headers from the Microsoft Windows SDK.</p>
</blockquote>
<p>and last but not least </p>
<blockquote>
<p><b>Joel de Guzman</b> for nudging me into this adventure and for his work
on the <tt>Spirit</tt> parser framework, without which the <tt>Wave</tt> library
wouldn't have been possible.</p>
</blockquote>
<p>The <tt>Wave</tt> library uses the following <tt>Boost</tt> <a href="references.html#boost">[8]</a>
libraries:</p>
<blockquote>
<p><b><img src="theme/bullet.gif" width="13" height="13" id="IMG1"></b>&nbsp;Boost
Spirit (LL parser framework that represents parsers directly as EBNF grammars
in inlined C++)<br>
<b><img src="theme/bullet.gif" width="13" height="13" id="IMG1"></b> Boost
Iterator Adaptor Library (Adapt a base type into a standard conforming iterator)<br>
<b><img src="theme/bullet.gif" width="13" height="13" id="IMG1"></b> Boost
Filesystem Library (Portable paths, iteration over directories, and other
useful filesystem operations)<br>
<b><img src="theme/bullet.gif" width="13" height="13" id="IMG1"></b>&nbsp;Program
options and arguments library</p>
</blockquote>
<p>and other small parts of different <tt>Boost</tt> libraries. </p>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="wave_driver.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="references.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
<br>
<font size="2">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)
</font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Thursday, January 22, 2004 18:00<!-- #EndDate -->
</span>
</body>
</html>

View File

@@ -0,0 +1,447 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>The Context Object</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="theme/style.css" type="text/css">
</head>
<body text="#000000" background="theme/bkd.gif">
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21"> <h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">The
Context Object</font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="quickstart.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="class_reference_inputpolicy.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<blockquote>
<p><a href="class_reference_context.html#introduction">Introduction</a><br>
<a href="class_reference_context.html#header_synopsis">Header 'wave/context.hpp' synopsis</a><br>
<a href="class_reference_context.html#public_typedefs">Public Typedefs</a><br>
<a href="class_reference_context.html#template_parameters">Template parameters</a><br>
<a href="class_reference_context.html#member_functions">Member functions</a></p>
</blockquote>
<h2><b><a name="introduction"></a>Introduction</b></h2>
<p>The <tt>wave::context&lt;&gt;</tt> object is the main user visible object of
the <tt>Wave</tt> library. It exists to generate the pair of iterators, which
while iterated return the preprocessed tokens. Additionally it is to be used
to control other aspects of the preprocessing, such as </p>
<blockquote>
<p><STRONG><IMG id="IMG1" height="13" src="theme/bullet.gif" width="13"></STRONG>&nbsp;include
search pathes, which define, where to search for files to be included with
<tt>#include&nbsp;&lt;...&gt;</tt> and <tt>#include&nbsp;"..."</tt> directives<br>
<STRONG><img src="theme/bullet.gif" width="13" height="13">&nbsp;</STRONG>which
macros to predefine and which of the predefined macros to undefine<br>
<STRONG><img src="theme/bullet.gif" width="13" height="13">&nbsp;</STRONG>several
other options as for instance to control, whether to enable several extensions
to the C++ Standard (as for instance variadics and placemarkers) or not.</p>
</blockquote>
<h2><b><a name="header_synopsis"></a>Header <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/spirit/spirit/wave/wave/cpp_context.hpp?rev=HEAD&content-type=text/vnd.viewcvs-markup">wave/context.hpp</a>
synopsis</b></h2>
<pre><span class="keyword">namespace</span> <span class="identifier">boost</span> {
<span class="keyword">namespace</span> <span class="identifier">wave</span> {
<span class="keyword">template</span> &lt;
<span class="keyword">typename</span> IteratorT, <span class="keyword">typename</span> LexIteratorT,
<span class="keyword">typename</span> InputPolicyT, <span class="keyword">typename</span> TracePolicyT
&gt;
<span class="keyword">class</span> context : <span class="keyword">public</span> InputPolicyT
{
<span class="keyword">public</span>:
<span class="keyword">typedef</span> pp_iterator&lt;context&gt; iterator_t;
<span class="keyword">typedef</span> TokenT token_t;
<span class="keyword">typedef</span> <span class="keyword">typename</span> token_t::position_t position_t;
<span class="comment">// constructor</span>
<a href="class_reference_context.html#constructor">context</a>(IteratorT <span class="keyword">const</span> &amp;first_,
IteratorT <span class="keyword">const</span> &amp;last_,
<span class="keyword">char const</span> *fname = <span class="string">"&lt;Unknown&gt;"</span>,
TracePolicyT &amp;trace = TracePolicyT())
<span class="comment">// iterator interface</span>
iterator_t <a href="class_reference_context.html#iterator_interface_begin">begin</a>() <span class="keyword">const</span>;
iterator_t <a href="class_reference_context.html#iterator_interface_end">end</a>() <span class="keyword">const</span>;
<span class="comment">// maintain include paths</span>
<span class="keyword">bool</span> <a href="class_reference_context.html#add_include_path">add_include_path</a>(<span class="keyword">char const</span> *path_);
<span class="keyword">bool</span> <a href="class_reference_context.html#add_sysinclude_path">add_sysinclude_path</a>(<span class="keyword">char const</span> *path_);
<span class="keyword">void</span> <a href="class_reference_context.html#set_sysinclude_delimiter">set_sysinclude_delimiter</a>();
size_t <a href="class_reference_context.html#get_iteration_depth">get_iteration_depth</a>() <span class="keyword">const</span>;
<span class="comment">// maintain defined macros</span>
<span class="keyword">bool</span> <a href="class_reference_context.html#add_macro_definition">add_macro_definition</a>(<span class="keyword">std::string</span> macrostring,
<span class="keyword">bool</span> is_predefined = <span class="keyword">false</span>);
<span class="keyword">bool</span> <a href="class_reference_context.html#is_defined_macro">is_defined_macro</a>(<span class="keyword">std::string const</span> &amp;name) <span class="keyword">const</span>;
<span class="keyword">bool</span> <a href="class_reference_context.html#remove_macro_definition">remove_macro_definition</a>(<span class="keyword">std::string const</span> &amp;name,
<span class="keyword">bool</span> even_predefined = <span class="keyword">false</span>);
<span class="keyword">void</span> <a href="class_reference_context.html#reset_macro_definitions">reset_macro_definitions</a>();
<span class="comment">// other options</span>
<span class="keyword">void</span> <a href="class_reference_context.html#language_support">set_language</a>(wave::language_support enable);
wave::language_support <a href="class_reference_context.html#language_support">get_language</a>() <span class="keyword">const</span>;<br>
<span class="keyword">void</span> <a href="class_reference_context.html#set_max_include_nesting_depth">set_max_include_nesting_depth</a>(size_t new_depth);<br> size_t <a href="class_reference_context.html#set_max_include_nesting_depth">get_max_include_nesting_depth</a>() <span class="keyword">const</span>;<br>
<span class="comment">// get the Wave version information </span>
<span class="keyword">static std::string</span> <a href="class_reference_context.html#get_version">get_version</a>();
<span class="keyword">static std::string</span> <a href="class_reference_context.html#get_version">get_version_string</a>();
};
} <span class="comment">// namespace wave</span>
} <span class="comment">// namespace boost</span></pre>
<h2><b><a name="template_parameters"></a>Template parameters</b></h2>
<p>The <tt>boost::wave::context</tt> object has three template parameters to specify
the concrete behaviour of its operation. The following table describes these
with more detail.</p>
<table width="90%" border="0" align="center">
<tr>
<td colspan="2" class="table_title"><b>Template parameters required for the
<tt>boost::wave::context</tt> class </b></td>
</tr>
<tr>
<td width="32%" class="table_cells"><code>IteratorT</code></td>
<td width="68%" class="table_cells"><p>The type of the underlying iterator,
through which the input stream is accessed. <br>
This should be at least an <tt>forward_iterator</tt> type iterator.</p></td>
</tr>
<tr>
<td class="table_cells"><code>LexIteratorT</code></td>
<td class="table_cells"><p>The type of the lexer type to be used by the <tt>Wave</tt>
library to identify tokens in the input stream.</p></td>
</tr>
<tr>
<td class="table_cells"><code>InputPolicyT</code></td>
<td class="table_cells"><p>The type of the input policy class, which allows
to customize the behaviour of the Wave library and the type of the iterators
to use, when it comes to including and opening an included file.</p></td>
</tr>
<tr>
<td class="table_cells"><code>TracePolicyT</code></td>
<td class="table_cells"><p>The type of the trace policy class, which allows
to customize the trace output generated while expanding macros. </p></td>
</tr>
</table>
<p>For further information about the lexer type to use, please refer to the <a href="class_reference_lexer.html">The
Lexer Interface </a>.</p>
<p>If the template parameter <tt>InputPolicyT</tt> is omitted, the template <tt>wave::iteration_context_policies::load_file_to_string</tt>
is used. For further information about the input policy, please refer to the
topic <a href="class_reference_inputpolicy.html">The Input Policy</a>.</p>
<p>If the template parameter TracePolicyT is omitted, the <tt>wave::macro_trace_policies::no_tracing</tt>
policy type is used, i.e. by default there is no tracing performed. For further
information about the tracing policy, please refer to the topic <a href="class_reference_tracepolicy.html">The
Tracing Policy</a>. </p>
<h2><a name="public_typedefs"></a>Public Typedefs</h2>
<p>The <tt>boost::wave::context</tt> template defines the following public typedefs, which may be useful while using this class:</p>
<table width="90%" border="0" align="center">
<tr>
<td colspan="2" class="table_title"><b>Public typedef's defined by the <tt>boost::wave::context</tt> class </b></td>
</tr>
<tr>
<td class="table_cells"><code>iterator_t</code></td>
<td class="table_cells"><p>The <tt>IteratorT</tt> template parameter provided, while the <tt>context</tt> class was instantiated. </p></td>
</tr>
<tr>
<td class="table_cells"><code>lex_t</code></td>
<td class="table_cells"><p>The <tt>LexIteratorT</tt> template parameter provided, while the <tt>context</tt> class was instantiated. </p></td>
</tr>
<tr>
<td width="32%" class="table_cells"><code>token_t</code></td>
<td width="68%" class="table_cells"><p>The token type, which is returned by the <tt>context</tt> generated iterators. This type is taken from the <tt>LexIteratorT</tt> template parameter provided, whicle the <tt>context</tt> class was instantiated.</p></td>
</tr>
<tr>
<td class="table_cells"><code>input_policy_t</code></td>
<td class="table_cells"><p>The <tt>InputPolicyT</tt> template parameter provided, while the <tt>context</tt> class was instantiated. </p></td>
</tr>
<tr>
<td class="table_cells"><code>trace_policy_t</code></td>
<td class="table_cells">The <tt>TracePolicyT</tt> template parameter provided, while the <tt>context</tt> class was instantiated. </td>
</tr>
<tr>
<td class="table_cells"><code>position_t</code></td>
<td class="table_cells"><p>The type of the position information contained in every returned token, which describes the point, at which the given token was recognised. </p></td>
</tr>
</table>
<h2><b><a name="member_functions"></a>Member functions</b></h2>
<p><b><a name="constructor" id="constructor"></a>Constructor</b></p>
<pre> context(IteratorT <span class="keyword">const</span> &amp;first,
IteratorT <span class="keyword">const</span> &amp;last,
<span class="keyword">char const</span> *filename,
TracePolicyT &amp;trace);</pre>
<blockquote>
<p>Constructs a context object on top of the input stream given by the pair
of auxilliary iterators <tt>[first,&nbsp;last)</tt>. The iterators should
be at least <tt>forward_iterator</tt> type iterators. The filename parameter
is to be supplied for informational purposes only. This string is used for
indicating the token positions inside the input stream, it is not validated
against the file system. If the filename parameter is not given it defaults
to <span class="copyright">&quot;&lt;Unknown&gt;&quot;</span>. If the trace
parameter isn't supplied it defaults to a default constructed <tt>TracePolicyT</tt>
object. </p>
<p>Additionally the macro symbol table is filled with the predefined macros
and the current reference directory is set to the path of the given filename.
If this filename does not reference valid file system item, the current reference
directory is set to the current system directory. (The current reference directory
is the file system path, which is used as the target directory during the
processing of <tt>#include&nbsp;&quot;...&quot;</tt> directives),</p>
</blockquote>
<h3>Iterator interface</h3>
<p>The pair of iterators returned by the <tt>context::begin</tt> and <tt>context::end</tt>
functions is the main interface for accessing the preprocessed tokens from the
preprocessor engine. While iterating over the given iterator range <tt>[begin,&nbsp;end)</tt>
there are returned the preprocessed C++ tokens, which are generated on the fly
from the underlying input stream. The returned iterators are conceptually of
<tt>forward_iterator</tt> type.</p>
<p><b><a name="iterator_interface_begin"></a></b><b>begin</b></p>
<pre> iterator_t begin();</pre>
<blockquote>
<p>Initializes and returns the starting iterator for the preprocessed token
stream.</p>
</blockquote>
<p><b><a name="iterator_interface_end" id="iterator_interface_end"></a></b><b>end</b></p>
<pre> iterator_t end() <span class="keyword">const</span>;</pre>
<blockquote>
<p>Initializes and returns the end of stream iterator to compare with for detecting
the end of the preprocessed token stream.</p>
</blockquote>
<h3>Maintain include paths</h3>
<p>The <tt>Wave</tt> library maintains two separate search pathes for include
files. A search path for user include files and a search path for system include
files. Any directories specified with the <a href="#add_include_path">add_include_path()</a>
function before the function <a href="class_reference_context.html#set_sysinclude_delimiter">set_sysinclude_delimiter()</a>
is called are searched only for the case of <tt>#include&nbsp;&quot;...&quot;</tt>
directives, they are not searched for <tt>#include&nbsp;&lt;file&gt;</tt> directives.
I.e. these directories are added to the user include search path. </p>
<p>If additional directories are specified with the <a href="#add_include_path">add_include_path()</a>
function after a call to the function <a href="class_reference_context.html#set_sysinclude_delimiter">set_sysinclude_delimiter()</a>,
these directories are searched for all <tt>#include</tt> directives. I.e. these
directories are added to the system include search path.</p>
<p>In addition, a call to the function <a href="class_reference_context.html#set_sysinclude_delimiter">set_sysinclude_delimiter()</a>
inhibits the use of the current reference directory as the first search directory
for <tt>#include&nbsp;&quot;...&quot;</tt> directives. Therefore, the current
reference directory is searched only, if it is requested explicitly with a call
to the function <a href="#add_include_path">add_include_path(&quot;.&quot;)</a>.
</p>
<p>Callig both functions, the <a href="class_reference_context.html#set_sysinclude_delimiter">set_sysinclude_delimiter()</a>
and <a href="#add_include_path">add_include_path(&quot;.&quot;)</a> allows you
to control precisely, which directories are searched before the current one
and which are searched after.</p>
<p>These functions are modelled after the command line behaviour implemented by
the popular gcc compiler.<br>
</p>
<p><a name="add_include_path"></a><b>add_include_path</b></p>
<pre> <span class="keyword">bool</span> add_include_path(<span class="keyword">char const</span> *path);
</pre>
<blockquote>
<p>Adds the given file system path to the user include search paths. After a
call to the <a href="#set_sys_include_delimiter">set_sysinclude_delimiter()</a>
this function adds the given file system path to the system include search
paths. Note though, that the given path is validated against the file system.
</p>
<p>If the given path string does not form a name of a valid file system directory
item, the function returns <tt>false</tt>. If the given path was successfully
added to the include search paths in question, the function returns <tt>true</tt>.</p>
</blockquote>
<p><a name="add_sysinclude_path"></a><b>add_sysinclude_path</b></p>
<pre> <span class="keyword">bool</span> add_sysinclude_path(<span class="keyword">char const</span> *path);</pre>
<blockquote>
<p>Adds the given file system path to the system include search paths. This
function operates on the system include search path regardless of the mode
of operation of the <a href="#add_include_path">add_include_path()</a>. Note
though, that the given path is validated against the file system.</p>
<p>If the given path string does not form a name of a valid file system directory
item, the function returns <tt>false</tt>. If the given path was successfully
added to the system include search paths, the function returns <tt>true</tt>.</p>
</blockquote>
<p><a name="set_sysinclude_delimiter" id="set_sysinclude_delimiter"></a><b>set_sysinclude_delimiter</b></p>
<pre> <span class="keyword">void</span> set_sysinclude_delimiter();</pre>
<blockquote>
<p>Switches the mode, how the <a href="#add_include_path">add_include_path()</a>
function operates. By default the given file system path is added to the user
include search paths. After calling this function a subsequent call to the
<a href="#add_include_path">add_include_path()</a> adds the given file system
path to the system include search paths. Additionally it inhibits the the
use of the current reference directory as the first search directory for <tt>#include&nbsp;&quot;...&quot;</tt>
directives.</p>
</blockquote>
<p><a name="get_iteration_depth"></a><b>get_iteration_depth</b></p>
<pre> size_t get_iteration_depth() <span class="keyword">const</span>;</pre>
<blockquote>
<p>Returns the actual include iteration depth, i.e. the current number of include
levels to be poped from the include iteration context, before the main (topmost)
iteration context is reached.</p>
</blockquote>
<h3>Maintain defined macros</h3>
<p><a name="add_macro_definition"></a><b>add_macro_definition</b></p>
<pre><span class="keyword"> bool</span> add_macro_definition(
<span class="keyword">std::string</span> macrostring,
bool is_predefined);
</pre>
<blockquote>
<p>Adds a new macro definition to the macro symbol table. The parameter <tt>macrostring</tt>
should contain the macro to define in the command line format, i.e. something
like <tt>MACRO(x)=definition</tt>. The following table describes this format
in more detail. The parameter <tt>is_predefined</tt> should be true while
defining predefined macros, i.e. macros, which are not undefinable with an
<tt>#undef</tt> directive from inside the preprocessed input stream. If this
parameter is not given, it defaults to <tt>false</tt>.</p>
<table width="90%" border="0" align="center">
<tr>
<td colspan="2" class="table_title"><b>Summary of possible formats for defining
macros </b></td>
</tr>
<tr>
<td width="32%" class="table_cells"><code>MACRO</code></td>
<td width="68%" class="table_cells"><code>define <tt>MACRO</tt> as 1</code></td>
</tr>
<tr>
<td class="table_cells"><code>MACRO=</code></td>
<td class="table_cells"><code>define <tt>MACRO</tt> as nothing (empty)</code></td>
</tr>
<tr>
<td class="table_cells"><code>MACRO=definition</code></td>
<td class="table_cells"><code>define <tt>MACRO</tt> as <tt>definition</tt></code></td>
</tr>
<tr>
<td width="32%" class="table_cells"><code>MACRO(x)</code></td>
<td width="68%" class="table_cells"><code>define <tt>MACRO(x)</tt> as 1</code></td>
</tr>
<tr>
<td class="table_cells"><code>MACRO(x)=</code></td>
<td class="table_cells"><code>define <tt>MACRO(x)</tt> as nothing (empty)</code></td>
</tr>
<tr>
<td class="table_cells"><code>MACRO(x)=definition</code></td>
<td class="table_cells"><code>define <tt>MACRO(x)</tt> as <tt>definition</tt></code></td>
</tr>
</table>
<p>The function returns <tt>false</tt>, if the macro to define already was defined
and the new definition is equivalent to the existing one, it returns true,
if the new macro was successfully added to the macro symbol table.</p>
<p>If the given macro definition resembles a redefinition and the new macro
is not identical to the already defined macro (in the sense defined by the
C++ Standard), the function throws a corresponding <tt>preprocess_exception</tt>.</p>
</blockquote>
<p><a name="is_defined_macro"></a><b>is_defined_macro</b></p>
<pre><span class="keyword"> bool</span> is_defined_macro(<span class="keyword">std::string const</span> &amp;name) <span class="keyword">const</span>; </pre>
<blockquote>
<p>Returns, if a macro with the given <tt>name</tt> is defined, i.e. if it is
contained in the macro symbol table.</p>
</blockquote>
<p><a name="remove_macro_definition"></a><b>remove_macro_definition</b></p>
<pre><span class="keyword"> bool</span> remove_macro_definition(
<span class="keyword">std::string const</span> &amp;name,
<span class="keyword">bool</span> even_predefined); </pre>
<blockquote>
<p>Removes the definition of the macro with the given <tt>name</tt> from the
macro symbol table. This operation is equivalent to an <tt>#undef</tt> directive
with this <tt>name</tt> executed from within the input stream. If the parameter
<tt>even_predefined</tt> is <tt>true</tt>, then the macro is removed from
the macro symbol table even, if it is defined as a predefined macro. </p>
<p>Note though, that the following macros are <b>not</b> undefinable in any
case: <tt>__FILE__</tt>, <tt>__LINE__</tt>, <tt>__DATE__</tt>, <tt>__TIME__</tt>,
<tt>__cplusplus</tt>, <tt>__STDC__</tt>. If the parameter <tt>even_predefined</tt>
is not given, it defaults to <tt>false</tt>.</p>
<p>The function returns <tt>false</tt>, if the macro to undefine was not defined
and returns <tt>true</tt> otherwise.</p>
<p>If the macro to remove may not be undefined (it is a predefined macro and
the parameter <tt>even_predefined</tt> is set to <tt>false</tt> or it is one
of the mentioned not undefinable macros above) the function throws a <tt>preprocess_exception</tt>.</p>
</blockquote>
<p><a name="reset_macro_definitions"></a><b>reset_macro_definitions</b></p>
<pre><span class="keyword"> void</span> reset_macro_definitions(); </pre>
<blockquote>
<p>Resets the macro symbol table to it's initial state, i.e. undefines all user
defined macros and inserts the internal predefined macros as described <a href="predefined_macros.html">here</a>.</p>
</blockquote>
<h3><a name="get_version"></a>Get Version information</h3>
<p><b>get_version</b></p>
<pre><span class="keyword"> </span><span class="keyword">static std::string</span> get_version(); </pre>
<blockquote>
<p>Returns a string containing the current Wave version formatted as <span class="string">0xvvrsbbbb</span>
(this is a string representation of the equivalent hexadecimal number), where
<span class="literal">'vv'</span> is the version number, <span class="literal">'r'</span>
the release number, <span class="literal">'s'</span> the subrelease number
and <span class="literal">'bbbb'</span> the build number. A possible return
value looks like <span class="literal">0x00910454</span>. The returned value
is the same as is inserted in the preprocessed token stream, when the predefined
macro <tt>__WAVE_VERSION__</tt> is expanded.</p>
</blockquote>
<p><b>get_version_str</b></p>
<pre><span class="keyword"> </span><span class="keyword">static std::string</span> get_version_str(); </pre>
<blockquote>
<p>Returns a string containing the current Wave version formatted as <span class="string">&quot;v.rr.ss.bbbb&quot;</span>,
where <span class="literal">'v'</span> is the version number, <span class="literal">'rr'</span>
the release number, <span class="literal">'ss'</span> the subrelease number
and <span class="literal">'bbbb'</span> the build number. A possible return
value looks like <span class="literal">&quot;0.9.1.454&quot;</span>. The returned
value is the same as is inserted in the preprocessed token stream, when the
predefined macro <tt>__WAVE_VERSION_STR__</tt> is expanded.</p>
</blockquote>
<h3>Control extended options</h3>
<p><a name="support_variadics_and_placemarkers"></a>set_language<br>
get_language</p>
<pre><span class="keyword"> void</span> set_language(<span class="keyword">wave::language_support</span> language);
<span class="keyword">wave::language_support</span> get_language() <span class="keyword">const</span>;</pre>
<blockquote>
<p>This functions allow to specify the language mode, in which the <tt>Wave</tt>
library should work. The possible language modes are defined by the enumerated
type <tt>wave::language_support</tt>:</p>
<pre> <span class="keyword">enum</span> language_support {
<span class="comment">// support flags for C++98</span>
support_normal = 0x01,
support_cpp = support_normal,
<span class="comment">// support flags for C99</span>
support_variadics = 0x02,
support_c99 = support_variadics,
<span class="comment">// support flags for experimental C++0x features</span>
support_extensions = 0x04,
support_cpp0x = support_normal |
support_variadics |
support_extensions,
};</pre>
<p>When used with <tt>support_variadics</tt> the support for variadics, placemarkers
and the <tt>operator _Pragma()</tt> is enabled in normal C++ mode. The <tt>support_c99</tt>
and <tt>support_cpp0x</tt> switch to the respective language support.</p>
</blockquote>
<p><a name="set_max_include_nesting_depth" id="set_max_include_nesting_depth"></a>set_max_include_nesting_depth<br>
g et_max_include_nesting_depth</p>
<pre><span class="keyword"> void</span> set_max_include_nesting_depth(size_t new_depth);
size_t get_max_include_nesting_depth() <span class="keyword">const</span>;</pre>
<blockquote>
<p>This functions allow to set or to get the maximal possible include file nesting
depth supported by the <tt>Wave</tt> library. The initial value for this is
determined by the preprocessing constant <tt>WAVE_MAX_INCLUDE_LEVEL_DEPTH</tt>
(see <a href="compiletime_config.html">here</a>).</p>
</blockquote>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="quickstart.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="class_reference_inputpolicy.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
<br>
<font size="2">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)
</font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Sunday, January 18, 2004 10:53<!-- #EndDate -->
</span>
<p>&nbsp;</p>
</body>
</html>

View File

@@ -0,0 +1,120 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>The File Position</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="theme/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21"> <h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">The
File Position</font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="token_ids.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="predefined_macros.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<blockquote>
<p><a href="class_reference_fileposition.html#introduction">Introduction</a><br>
<a href="class_reference_fileposition.html#header_synopsis">Header 'wave/util/file_position.hpp'
synopsis</a><br>
<a href="class_reference_fileposition.html#template_parameters">Template parameters</a><br>
<a href="class_reference_fileposition.html#member_functions">Member functions</a></p>
</blockquote>
<h2><b><a name="introduction"></a>Introduction</b></h2>
<p>The file position template is used to represent a concrete token position inside
the underlying input stream. This token position contains the corresponding
filename, the line number and the column number, where the token was recognized.</p>
<h2><b><a name="header_synopsis"></a>Header <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/spirit/spirit/wave/wave/util/file_position.h?rev=HEAD&content-type=text/vnd.viewcvs-markup">wave/util/file_position.hpp</a>
synopsis</b></h2>
<pre><span class="keyword">namespace</span> <span class="identifier">boost</span> {
<span class="keyword">namespace</span> <span class="identifier">wave</span> {
<span class="keyword">namespace</span> <span class="identifier">util</span> {
<span class="keyword">template</span> &lt;<span class="keyword">typename</span> StringT = <span class="keyword">std::string</span>&gt;
<span class="keyword">class</span> file_position {
<span class="keyword">public</span>:
<a href="class_reference_fileposition.html#constructors">file_position</a>();
<span class="keyword">explicit</span> <a href="class_reference_fileposition.html#constructors">file_position</a>(StringT const &amp;file,
int line_ = 1, int column_ = 1);
// accessors
StringT <span class="keyword">const</span> &amp;<a href="class_reference_fileposition.html#get_accessors">get_file</a>() <span class="keyword">const</span>;
<span class="keyword">int</span> <a href="class_reference_fileposition.html#get_accessors">get_line</a>() <span class="keyword">const</span>;
<span class="keyword">int</span> <a href="class_reference_fileposition.html#get_accessors">get_column</a>() <span class="keyword">const</span>;
<span class="keyword">void</span> <a href="class_reference_fileposition.html#set_accessors">set_file</a>(StringT <span class="keyword">const</span> &amp;file);
<span class="keyword">void</span> <a href="class_reference_fileposition.html#set_accessors">set_line</a>(<span class="keyword">int</span> line);
<span class="keyword">void</span> <a href="class_reference_fileposition.html#set_accessors">set_column</a>(<span class="keyword">int</span> column);
};
} <span class="comment">// namespace util</span>
} <span class="comment">// namespace wave</span>
} <span class="comment">// namespace boost</span></pre>
<h2><a name="template_parameters"></a>Template parameters</h2>
<p>The <tt>file_position</tt> template may be instantiatet with one template parameter,
which gives the string type to use for storing the file name member of the file
position. If this parameter isn't given, it defaults to a <tt>std::string</tt>.
Please note, that the type given as the template parameter must be compatible
with a <tt>std::string</tt>.</p>
<h2><a name="member_functions"></a>Member functions</h2>
<h3><a name="constructors"></a>Constructors</h3>
<pre> <a href="class_reference_fileposition.html#constructors">file_position</a>();
<span class="keyword">explicit</span> <a href="class_reference_fileposition.html#constructors">file_position</a>(StringT const &amp;file,
int line_ = 1, int column_ = 1);
</pre>
<blockquote>
<p>The constructors initialize a new instance of a <tt>file_position</tt> in
correspondence to the supplied parameters. The parameters default to an empty
filename and the line number and column number set to one.</p>
</blockquote>
<p><a name="get_accesssors"></a><b>get_file</b>, <b>get_line</b>, <b>get_column</b></p>
<pre> StringT <span class="keyword">const</span> &amp;<a href="class_reference_fileposition.html#get_accessors">get_file</a>() <span class="keyword">const</span>;
<span class="keyword">int</span> <a href="class_reference_fileposition.html#get_accessors">get_line</a>() <span class="keyword">const</span>;
<span class="keyword">int</span> <a href="class_reference_fileposition.html#get_accessors">get_column</a>() <span class="keyword">const</span>;
</pre>
<blockquote>
<p>The <tt>get_...</tt> functions are used to access the current values of the
file position members: the filename (<tt>get_file</tt>), the line number (<tt>get_line</tt>)
and the column number (<tt>get_column</tt>).</p>
</blockquote>
<p><a name="set_accessors"></a><b>set_file</b>, <b>set_line</b>, <b>set_column</b></p>
<pre> <span class="keyword">void</span> <a href="class_reference_fileposition.html#set_accessors">set_file</a>(StringT <span class="keyword">const</span> &amp;file);
<span class="keyword">void</span> <a href="class_reference_fileposition.html#set_accessors">set_line</a>(<span class="keyword">int</span> line);
<span class="keyword">void</span> <a href="class_reference_fileposition.html#set_accessors">set_column</a>(<span class="keyword">int</span> column);
</pre>
<blockquote>
<p>The <tt>set_...</tt> functions are used to set new values to the file position
members: the filename (<tt>set_file</tt>), the line number (<tt>set_line</tt>)
and the column number (<tt>set_column</tt>).</p>
</blockquote>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="token_ids.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="predefined_macros.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
<br>
<font size="2">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)
</font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Monday, January 5, 2004 14:57<!-- #EndDate -->
</span></body>
</html>
<!-- #BeginDate format:fcAm1m -->Wednesday, January 14, 2004 12:25<!-- #EndDate --><!-- #BeginDate format:fcAm1m -->Wednesday, January 14, 2004 12:26<!-- #EndDate -->

View File

@@ -0,0 +1,134 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>The Input Policy</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="theme/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21"> <h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">The
Input Policy</font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="class_reference_context.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="class_reference_tracepolicy.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<blockquote>
<p><a href="class_reference_inputpolicy.html#introduction">Introduction</a><br>
<a href="class_reference_inputpolicy.html#header_synopsis">Header 'wave/cpp_iteration_context.hpp'
synopsis</a><br>
<a href="class_reference_inputpolicy.html#template_parameters">Template parameters</a><br>
<a href="class_reference_inputpolicy.html#member_functions">Member functions</a></p>
</blockquote>
<h2><b><a name="introduction"></a>Introduction</b></h2>
<p>The input policy type may be specified as a template parameter to the <tt>wave::context</tt>
object and is used for customizing the way, how an included file is to be represented
by a pair of iterators pointing to the beginning and the end of the resulting
input sequence. If this template parameter is not given while instantiating
the context object, it defaults to the <tt>iteration_context_policies::load_file_to_string</tt>
type. </p>
<h2><b><a name="header_synopsis"></a>Header <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/spirit/spirit/wave/wave/cpp_iteration_context.hpp?rev=HEAD&content-type=text/vnd.viewcvs-markup">wave/cpp_iteration_context.hpp</a>
synopsis</b></h2>
<p>The following code listing does not show the required interface only, but for
brevity reasons the whole implementation of an input policy, which loads the
given file into a string variable and exposes the begin() and end() iterators
of this string to the <tt>Wave</tt> library.</p>
<pre><span class="keyword">namespace</span> boost {
<span class="keyword">namespace</span> wave {
<span class="keyword">namespace</span> iteration_context_policies {
<span class="keyword">struct</span> load_file_to_string {
<span class="keyword">template</span> &lt;<span class="keyword">typename</span> IterContextT&gt;
<span class="keyword">class</span> inner {
<span class="keyword">public</span>:
<span class="comment">// expose the begin and end iterators for the</span>
<span class="comment">// included file</span>
<span class="keyword">template</span> &lt;typename PositionT&gt;
<span class="keyword">static</span>
<span class="keyword">void</span> <a href="class_reference_inputpolicy.html#init_iterators">init_iterators</a>(IterContextT &iter_ctx,
PositionT const &act_pos)
{
<span class="keyword">typedef typename</span> IterContextT::iterator_t iterator_t;
<span class="keyword">std::ifstream</span> instream(iter_ctx.filename.c_str());
if (!instream.is_open()) {
CPP_THROW(preprocess_exception, bad_include_file,
iter_ctx.filename, act_pos);
}
iter_ctx.instring = <span class="keyword">std::string</span>(
<span class="keyword">std::istreambuf_iterator</span><char>(instream.rdbuf()),
<span class="keyword">std::istreambuf_iterator</span><char>());
iter_ctx.first = iterator_t(iter_ctx.instring.begin(),
iter_ctx.instring.end(),
PositionT(iter_ctx.filename));
iter_ctx.last = iterator_t();
}
<span class="keyword">private</span>:
<span class="keyword">std::string</span> instring;
};
};
} <span class="comment">// namespace iteration_context_policies</span>
} <span class="comment">// namespace wave </span>
} <span class="comment">// namespace boost </span> </pre>
<p>As you can see, an <tt>input_policy</tt> for the <tt>wave::context</tt> object
should implement one function only, the init_iterators function. The policy
shown is implemented with the help of an embedded class to avoid the need for
template template parameters, which aren't implemented by all systems today.
This embedded class should have the name <tt>inner</tt>.</p>
<h3><a name="template_parameters"></a>Template Parameters</h3>
<p>The <tt>inner</tt> class is instantiated with one template parameter, the iteration
context type, from which the policy is a part of. The iterator type <tt>iterator_t</tt>
which is used to access the underlying input stream has to be derived through
a typedef as shown. The iterator pair to initialize (which is accessible as
<tt>iter_ctx.first</tt> and <tt>iter_ctx.last</tt>) has to initialized from
an abritrary iterator type, representing the actual input stream.</p>
<h3><a name="member_functions"></a>Member Functions</h3>
<p><a name="init_iterators"></a><b>init_iterators</b></p>
<pre> <span class="keyword">template</span> &lt;<span class="keyword">typename</span> PositionT&gt;
<span class="keyword">static void</span> init_iterators(
IterContextT iter_ctx,
PositionT const &act_pos);</pre>
<blockquote>
<p>The <tt>init_iterators</tt> function is called, when an <tt>#include</tt>
directive was found in the input token stream. The main rationale for this
function is to initialize the pair of iterators <tt>iter_ctx.first</tt> and
<tt>iter_ctx.last</tt>, which are to be used to access the input stream corresponding
to the include file to be inserted from inside the preprocessing engine.<br>
</p>
</blockquote>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="class_reference_context.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="class_reference_tracepolicy.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
<br>
<font size="2">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)
</font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Wednesday, January 14, 2004 12:36<!-- #EndDate -->
</span></body>
</html>

View File

@@ -0,0 +1,103 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>The Lexer Interface</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="theme/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21"> <h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">The
Lexer Iterator Interface</font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="class_reference_tracepolicy.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="class_reference_tokentype.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<blockquote>
<p><a href="class_reference_lexer.html#introduction">Introduction</a><br>
<a href="class_reference_lexer.html#header_synopsis">Wave Lexer
synopsis</a><br>
<a href="class_reference_lexer.html#public_typedefs">Public Typedefs</a><br>
<a href="class_reference_lexer.html#member_functions">Member functions</a></p>
</blockquote>
<h2><b><a name="introduction"></a>Introduction</b></h2>
<p>Every lexer, which should be used in conjunction with the <tt>Wave</tt> library, has to return tokens formed from the input stream. These tokens should conform to the synopsis described in the topic <a href="class_reference_tokentype.html">The Token Type</a>. The lexer type should expose an interface, which conforms at least to a <tt>forward_iterator</tt> in the sense defined by the the C++ Standard. </p>
<h2><a name="header_synopsis"></a>Wave lexer
synopsis</h2>
<pre> <span class="keyword">struct</span> lex_iterator
{
<span class="keyword">typedef</span> boost::wave::lex_token&lt;&gt; <a href="class_reference_lexer.html#public_typedefs">token_t</a>;
<span class="comment"> // Every lex_iterator should implement at least a complete
// forward_iterator interface (not shown here)
</span><span class="keyword"> typedef</span> std::forward_iterator_tag iterator_category;
<span class="comment"> // additional requirements
</span> <a href="class_reference_lexer.html#member_functions">lex_iterator</a>();
<span class="keyword">template</span> &lt;<span class="keyword">typename</span> IteratorT&gt;
<a href="class_reference_lexer.html#constructor">lex_iterator</a>(IteratorT <span class="keyword">const</span> &amp;first, IteratorT <span class="keyword">const</span> &amp;last
<span class="keyword">typename</span> token_t::position_t <span class="keyword">const</span> &amp;pos,
boost::wave::language_support language)
};
</pre>
<h2><a name="public_typedefs" id="public_typedefs"></a>Public Typedefs</h2>
<p>Besides the typedefs mandated for a <tt>forward_iterator</tt> by the C++ standard every lexer to be used with the <tt>Wave</tt> library should define the following typedefs: </p>
<table width="90%" border="0" align="center">
<tr>
<td colspan="2" class="table_title"><b>Public typedef's defined by the <tt>boost::wave::context</tt> class </b></td>
</tr>
<tr>
<td width="32%" class="table_cells"><code>token_t</code></td>
<td width="68%" class="table_cells"><p>The <tt>token</tt> type returned by the lexer. This is type is used as the return value of the main iterators provided by the <tt>boost::wave:.context</tt> object too. </p></td>
</tr>
</table>
<h2><a name="member_functions"></a>Member functions</h2>
<p>Besides the functions, which should be provided for <tt>forward_iterators</tt> as mandated by the C++ Standard, every lexer must implement the following functions to be used with the <tt>Wave</tt> library: </p>
<p><a name="destructor"></a><b>constructor</b></p>
<pre> lex_iterator();</pre>
<blockquote>
<p>The default constructor should construct a lexer iterator, which may be used as the end iterator of the provided iterator range.</p>
</blockquote>
<pre>
<span class="keyword">template</span> &lt;<span class="keyword">typename</span> IteratorT&gt;
lex_iterator(IteratorT <span class="keyword">const</span> &amp;first, IteratorT <span class="keyword">const</span> &amp;last,
<span class="keyword">typename</span> token_t::position_t <span class="keyword">const</span> &amp;pos,
boost::wave::language_support language);</pre>
<blockquote>
<p>The second constructor should construct a lexer iterator, which may be used as a iterator traversing over the token sequence, generated by the lexer class.</p>
<p>The pair of iterators <tt>first</tt> and <tt>last</tt> should represent the input stream to be tokenized by the given lexer class. </p>
<p>The parameter <tt>pos</tt> contains the initial position information to be used for token generation.</p>
<p>The parameter <tt>language</tt> controls the reuqired mode with which the lexer should be initialised. </p>
</blockquote>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="class_reference_tracepolicy.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="class_reference_tokentype.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
<br>
<font size="2">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)
</font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Sunday, January 18, 2004 12:16<!-- #EndDate -->
</span></body>
</html>
<!-- #BeginDate format:fcAm1m -->Sunday, January 18, 2004 12:16<!-- #EndDate -->

View File

@@ -0,0 +1,173 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>The Token Type</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="theme/style.css" type="text/css">
</head>
<body text="#000000" background="theme/bkd.gif">
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21"> <h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">The
Token Type</font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="class_reference_lexer.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="token_ids.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<blockquote>
<p><a href="class_reference_tokentype.html#introduction">Introduction</a><br>
<a href="class_reference_tokentype.html#header_synopsis">Header 'wave/context.hpp'
synopsis</a><br>
<a href="class_reference_tokentype.html#template_parameters">Template parameters</a><br>
<a href="class_reference_tokentype.html#member_functions">Member functions</a></p>
</blockquote>
<h2><a name="Introduction"></a>Introduction</h2>
<p>The token type in <tt>Wave</tt> is the main carrier of information. It is returned
by dereferencing the main iterator. The tokens are originally generated by the
lexer (&quot;An entity that lexically transforms the subject of parsing to a
sequence of objects (called tokens) more suitable for subsequent parsing.&quot;).
The Wave library contains two different, interchangable C++ lexers, which may
be used as a starting point during developing your own application. The lexer
generated tokens are transformed by the preprocessing engine (macro expansion,
include file processing etc.) and after this returned to the user of the <tt>Wave</tt>
library.</p>
<p>You can use arbitrary token types in conjunction with your own lexer as long
as these implement some required interface. The required token type interface
is described below and is implemented by the <tt>wave::cpplexer::lex_token</tt>
template, the required lexer interface is described <a href="class_reference_lexer.html">here</a>.
</p>
<p>In the following is described the token type predefined inside the <tt>Wave</tt>
library, which is used in conjunction with the two predefined C++ lexers contained
in the <tt>Wave</tt> library too. If you need to use your own token type, it
is required to implement the interafce described below.</p>
<h2><b><a name="header_synopsis"></a>Header <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/spirit/spirit/wave/wave/cpplexer/cpp_lex_token.hpp?rev=HEAD&content-type=text/vnd.viewcvs-markup">wave/cpplexer/cpp_lex_token.hpp</a>
synopsis</b></h2>
<pre><span class="keyword">namespace</span> boost {
<span class="keyword">namespace</span> wave {
<span class="keyword">namespace</span> cpplexer {
<span class="keyword">template</span> &lt;<span class="keyword">typename</span> PositionT&gt;
<span class="keyword">class</span> lex_token
{
<span class="keyword">public</span>:
<span class="keyword">typedef</span> <span class="keyword">std::basic_string</span><char> string_t;
<span class="keyword">typedef</span> PositionT position_t;
<a href="class_reference_tokentype.html#constructor">lex_token</a>();
<a href="class_reference_tokentype.html#constructor">lex_token</a>(token_id id, string_t <span class="keyword">const</span> &value,
PositionT <span class="keyword">const</span> &pos);
// accessors
<a href="class_reference_tokentype.html#operator_tokenid">operator token_id</a>() <span class="keyword">const</span>;
string_t const &amp;<a href="class_reference_tokentype.html#get_value">get_value</a>() <span class="keyword">const</span>;
position_t const &amp;<a href="class_reference_tokentype.html#get_position">get_position</a>() <span class="keyword">const</span>;
void <a href="class_reference_tokentype.html#set_token_id">set_token_id</a> (token_id id);
void <a href="class_reference_tokentype.html#set_value">set_value</a> (string_t <span class="keyword">const</span> &amp;newval);
void <a href="class_reference_tokentype.html#set_position">set_position</a> (position_t <span class="keyword">const</span> &amp;pos);
};
} <span class="comment">// namespace cpplexer</span>
} <span class="comment">// namespace wave</span>
} <span class="comment">// namespace boost</span>
</pre>
<h2><b><a name="template_parameters" id="template_parameters"></a>Template parameters</b></h2>
<p>The predefined token type uses a template parameter <tt>PositionT</tt>, which
allows to specify the type to be used to carry the file position information
contained inside the generated tokens. This type should contain at least the
filename, the line number and the column number of the position, where the token
was recognized. It defaults to a simple file_position template class described
<a href="class_reference_fileposition.html">here</a>. </p>
<h2><b><a name="member_functions"></a>Member functions</b></h2>
<p><b><a name="constructor" id="constructor"></a>Constructors</b></p>
<pre> lex_token();
lex_token(token_id id,
string_t <span class="keyword">const</span> &amp;value,
PositionT <span class="keyword">const</span> &amp;pos);</pre>
<blockquote>
<p>The first (default) constructor is for generating an end of stream token,
which is used for indicating the end of the underlying input stream.</p>
<p>The second constructor initializes the newly created token object with its
token id (for a list of valid token id's please look <a href="token_ids.html">here</a>),
the string representation of its value and the file position, describing the
position inside the input stream , where this token was recognized.</p>
</blockquote>
<h2>Accessor functions</h2>
<p><a name="operator_tokenid"></a><b>operator token_id</b></p>
<pre> <span class="keyword">operator</span> token_id() <span class="keyword">const</span>;</pre>
<blockquote>
<p>Allows the access to the token id of the token. This access function is implemented
as an implicit conversion function to allow the operation of <tt>Spirit</tt>
parsers directly on top of a token stream. The possible token id's are described
<a href="token_ids.html">here</a>. </p>
<p>This function does not throw in any case.</p>
</blockquote>
<p><a name="get_value"></a><b>get_value</b></p>
<pre> string_t <span class="keyword">const</span> &amp;get_value() <span class="keyword">const</span>;</pre>
<blockquote>
<p>Returns the value of the token, as it was recognized in the input stream.
Even for constant tokens (as keywords or operators etc.) the returned value
reflects the character sequence as found in the input stream. </p>
<p>This function does not throw in any case.</p>
</blockquote>
<p><b><a name="get_position"></a>get_position</b></p>
<pre> PositionT <span class="keyword">const</span> &amp;get_position() <span class="keyword">const</span>;</pre>
<blockquote>
<p>Returns the position of the token in the input stream, where it was recognized.
The position contains information about the filename, the line number and
the column number of the token. By default the <tt>Wave</tt> library uses
a file_position template for this purpose, which is described in more detail
<a href="class_reference_fileposition.html">here</a>.</p>
<p>This function does not throw in any case.</p>
</blockquote>
<p><a name="set_token_id"></a><b>set_token_id</b></p>
<pre> void set_token_id(token_id id);</pre>
<blockquote>
<p>Changes the token id of the token to the new value. The possible token id's
are described <a href="token_ids.html">here</a>. Propably this function is
of little value for the library user, but it is required under certain circumstances
for correct operation of the preprocessing engine.</p>
<p>This function does not throw in any case.</p>
</blockquote>
<p><a name="set_value"></a><b>set_value</b></p>
<pre> void set_value(string_t <span class="keyword">const</span> &amp;newval);</pre>
<blockquote>
<p>Changes the value stored inside the token to the new value. Propably this
function is of little value for the library user, but it is required under
certain circumstances for correct operation of the preprocessing engine.</p>
</blockquote>
<p><a name="set_position"></a><b>set_position</b></p>
<pre> void set_position(PositionT <span class="keyword">const</span> &amp;newpos);</pre>
<blockquote>
<p>Changes the position stored inside the token to the new value. This is used
for instance for implementing the functionality required for to implement
the <tt>#line</tt> directive.</p>
</blockquote>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="class_reference_lexer.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="token_ids.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
<br>
<font size="2">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)
</font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Monday, January 5, 2004 14:57<!-- #EndDate -->
</span></body>
</html>
<!-- #BeginDate format:fcAm1m -->Wednesday, January 14, 2004 12:36<!-- #EndDate -->

View File

@@ -0,0 +1,249 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>The Tracing Policy</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="theme/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21"> <h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">The
Tracing Policy</font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="class_reference_inputpolicy.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="class_reference_lexer.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<blockquote>
<p><a href="class_reference_tracepolicy.html#introduction">Introduction</a><br>
<a href="class_reference_tracepolicy.html#header_synopsis">Header 'wave/trace_policies.hpp'
synopsis</a><br>
<a href="class_reference_tracepolicy.html#member_functions">Member functions</a></p>
</blockquote>
<h2><b><a name="introduction"></a>Introduction</b></h2>
<p>There is implemented an unique tracing facility as a part of the <tt>Wave</tt>
library, which allows to selectively trace all stages of the macro expansion
process, involving the argument expansion and the rescanning of the replacement
results. This tracing facility greatly helps to understand foreign code or to
debug your own macros.</p>
<p>The tracing policy is used to trace the macro expansion of macros whenever
it is requested from inside the input stream to preprocess through the <tt>#pragma&nbsp;wave_option(trace:&nbsp;enable)</tt>
(or <tt>_Pragma(&quot;wave&nbsp;trace(enable)&quot;)</tt>) directive. The macro
tracing may be disabled again with the help of a <tt>#pragma wave_option(trace:
disable)</tt> (or <tt>_Pragma(&quot;wave&nbsp;trace(disable)&quot;)</tt>) directive.
Note though, that the <tt>Wave</tt> driver executable requires additionally
to specify the <tt>-t</tt> (<tt>--trace</tt>) command line option, which defines
the stream, where the trace output goes.</p>
<p>This policy type is used as a template parameter to the <a href="class_reference_context.html"><tt>wave::context&lt;&gt;</tt></a>
object, where the default policy does no tracing at all.</p>
<h2><a name="header_synopsis"></a>Header <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/spirit/spirit/wave/wave/macro_trace_policies.hpp?rev=1.1&content-type=text/vnd.viewcvs-markup">wave/trace_policies.hpp</a>
synopsis</h2>
<pre>
<span class="keyword">namespace</span> boost {
<span class="keyword">namespace</span> wave {
<span class="keyword">namespace</span> trace_policies {
<span class="keyword">enum</span> trace_flags {
trace_nothing = 0, <span class="comment">// disable tracing</span>
trace_macros = 1, <span class="comment">// enable macro tracing</span>
trace_includes = 2 <span class="comment">// enable include file tracing</span>
};
<span class="keyword">struct</span> default_tracing {
<span class="comment">// general control function</span>
<span class="keyword">void</span> <a href="class_reference_tracepolicy.html#enable_tracing">enable_tracing</a>(trace_flags enable);
trace_flags <a href="class_reference_tracepolicy.html#tracing_enabled">tracing_enabled</a>();
<span class="comment">// macro tracing functions</span>
<span class="keyword">template</span> &lt;<span class="keyword">typename</span> TokenT, <span class="keyword">typename</span> ContainerT&gt;
<span class="keyword">void</span> <a href="class_reference_tracepolicy.html#expanding_function_like_macro">expanding_function_like_macro</a>(TokenT <span class="keyword">const</span> &amp;macrodef,
<span class="keyword">std::vector</span>&lt;TokenT&gt; <span class="keyword">const</span> &amp;formal_args,
ContainerT <span class="keyword">const</span> &amp;definition, TokenT <span class="keyword">const</span> &amp;macrocall,
<span class="keyword">std::vector</span>&lt;ContainerT&gt; <span class="keyword">const</span> &amp;arguments);
<span class="keyword">template</span> &lt;<span class="keyword">typename</span> TokenT, <span class="keyword">typename</span> ContainerT&gt;
<span class="keyword">void</span> <a href="class_reference_tracepolicy.html#expanding_object_like_macro">expanding_object_like_macro</a>(TokenT <span class="keyword">const</span> &amp;macro,
ContainerT <span class="keyword">const</span> &amp;definition, TokenT <span class="keyword">const</span> &amp;macrocall);
<span class="keyword">template</span> &lt;<span class="keyword">typename</span> ContainerT&gt;
<span class="keyword">void</span> <a href="class_reference_tracepolicy.html#expanded_macro">expanded_macro</a>(ContainerT <span class="keyword">const</span> &amp;result);
<span class="keyword">template</span> &lt;<span class="keyword">typename</span> ContainerT&gt;
<span class="keyword">void</span> <a href="class_reference_tracepolicy.html#expanded_macro">rescanned_macro</a>(ContainerT <span class="keyword">const</span> &amp;result);
<span class="comment">// include file tracing functions</span>
<span class="keyword">void </span><a href="class_reference_tracepolicy.html#opened_include_file">opened_include_file</a>(std::string <span class="keyword">const</span> &amp;filename,
std::size_t include_depth, <span class="keyword">bool</span> is_system_include);
<span class="keyword">void</span> <a href="class_reference_tracepolicy.html#returning_from_include_file">returning_from_include_file</a>();
<span class="comment">// interpretation of unknown #pragma's</span>
<span class="keyword">template</span> &lt;<span class="keyword">typename</span> TokenT, <span class="keyword">typename</span> ContainerT&gt;
bool <a href="class_reference_tracepolicy.html#interpret_pragma">interpret_pragma</a>(ContainerT &amp;pending,
TokenT const &amp;option, ContainerT <span class="keyword">const</span> &amp;values,
TokenT <span class="keyword">const</span> &amp;pragma_token, language_support language);
};
} <span class="comment">// namespace macro_trace_policy</span>
} <span <!-- #BeginDate format:fcAm1m -->Wednesday, January 14, 2004 12:46<!-- #EndDate -->st</span>
</pre>
<h2><a name="member_functions"></a>Member functions</h2>
<h3>General control functions</h3>
<p><a name="enable_tracing"></a><b>enable_tracing</b></p>
<pre> <span class="keyword">void</span> enable_tracing(<span class="keyword">trace_flags</span> enable);</pre>
<blockquote>
<p>The function <tt>enable_tracing</tt> is called, whenever the status of the
tracing was changed from inside the stream to preprocess.</p>
<p>The parameter <tt>enable</tt> is to be used as the new tracing status.</p>
</blockquote>
<p><a name="tracing_enabled"></a><b>tracing_enabled</b></p>
<pre> <span class="keyword">trace_flags</span> tracing_enabled();</pre>
<blockquote>
<p>The function <tt>tracing_enabled</tt> should return the current tracing status.</p>
</blockquote>
<h3>Tracing functions</h3>
<h4>Macro tracing functions</h4>
<p><a name="expanding_function_like_macro"></a><b>expanding_function_like_macro</b></p>
<pre><span class="keyword"> template</span> &lt;<span class="keyword">typename</span> TokenT, <span class="keyword">typename</span> ContainerT&gt;
<span class="keyword">void</span> expanding_function_like_macro(TokenT <span class="keyword">const</span> &amp;macrodef,
<span class="keyword">std::vector</span>&lt;TokenT&gt; <span class="keyword">const</span> &amp;formal_args,
ContainerT <span class="keyword">const</span> &amp;definition, TokenT <span class="keyword">const</span> &amp;macrocall,
<span class="keyword">std::vector</span>&lt;ContainerT&gt; <span class="keyword">const</span> &amp;arguments);</pre>
<blockquote>
<p>The function <tt>expanding_function_like_macro</tt> is called, whenever a
function-like macro is to be expanded, i.e. <i>before</i> the actual expansion
starts.</p>
<p>The <tt>macroname</tt> parameter marks the position, where the macro to expand
is defined. It contains the token, which identifies the macro name used inside
the corresponding macro definition.</p>
<p>The <tt>formal_args</tt> parameter holds the formal arguments used during
the definition of the macro. </p>
<p>The <tt>definition</tt> parameter holds the macro definition for the macro
to trace. This is a standard STL container, which holds the token sequence
identified during the macro definition as the macro replacement list.</p>
<p>The <tt>macrocall</tt> parameter marks the position, where this macro invoked.
It contains the token, which identifies the macro call inside the preprocessed
input stream. </p>
<p>The <tt>arguments</tt> parameter holds the macro arguments used during the
invocation of the macro. This is a vector of standard STL containers, which
contain the token sequences identified at the position of the macro call as
the arguments to be used during the macro expansion. </p>
</blockquote>
<p><a name="expanding_object_like_macro"></a><b>expanding_object_like_macro</b></p>
<pre> <span class="keyword">template</span> &lt;<span class="keyword">typename</span> TokenT, <span class="keyword">typename</span> ContainerT&gt;
<span class="keyword">void</span> expanding_object_like_macro(TokenT <span class="keyword">const</span> &amp;macro,
ContainerT <span class="keyword">const</span> &amp;definition, TokenT <span class="keyword">const</span> &amp;macrocall);
</pre>
<blockquote>
<p>The function <tt>expanding_object_like_macro</tt> is called, whenever a object-like
macro is to be expanded, i.e. <i>before</i> the actual expansion starts.</p>
<p>The <tt>macroname</tt> parameter marks the position, where the macro to expand
is defined. It contains the token, which identifies the macro name used inside
the corresponding macro definition.</p>
<p> The <tt>definition</tt> parameter holds the macro definition for the macro
to trace. This is a standard STL container, which holds the token sequence
identified during the macro definition as the macro replacement list.</p>
<p>The <tt>macrocall</tt> parameter marks the position, where this macro invoked.
It contains the token, which identifies the macro call inside the preprocessed
input stream. </p>
</blockquote>
<p><a name="expanded_macro"></a><b>expanded_macro</b></p>
<pre> <span class="keyword">template</span> &lt;<span class="keyword">typename</span> ContainerT&gt;
<span class="keyword">void</span> expanded_macro(ContainerT <span class="keyword">const</span> &amp;result);
</pre>
<blockquote>
<p>The function <tt>expanded_macro</tt> is called, whenever the expansion of
a macro is finished, the replacement list is completely scanned and the identified
macros herein are replaced by its corresponding expansion results, but <i>before</i>
the rescanning process starts.</p>
<p>The parameter <tt>result</tt> contains the the result of the macro expansion
so far. This is a standard STL container containing the generated token sequence.</p>
</blockquote>
<p><a name="rescanned_macro"></a><b>rescanned_macro</b></p>
<pre> <span class="keyword">template</span> &lt;<span class="keyword">typename</span> ContainerT&gt;
<span class="keyword">void</span> rescanned_macro(ContainerT <span class="keyword">const</span> &amp;result);
</pre>
<blockquote>
<p>The function <tt>rescanned_macro</tt> is called, whenever the rescanning
of a macro is finished, i.e. the macro expansion is complete.</p>
<p>The parameter <tt>result</tt> contains the the result of the whole macro
expansion. This is a standard STL container containing the generated token
sequence.</p>
</blockquote>
<h4>Include file tracing functions</h4>
<p><a name="opened_include_file" id="opened_include_file"></a><strong>opened_include_file</strong></p>
<pre> <span class="keyword">void</span> opened_include_file(std::string <span class="keyword">const</span> &amp;filename,
std::size_t include_depth, <span class="keyword">bool</span> is_system_include);
</pre>
<blockquote>
<p>The function <tt>opened_include_file</tt> is called, whenever a file referred
by an #include directive was successfully located and opened.</p>
<p>The parameter <tt>filename</tt> contains the full file system path of the
opened file.</p>
<p>The <tt>include_depth</tt> parameter contains the current include file depth.
</p>
<p>The <tt>is_system_include</tt> parameter denotes, if the given file was found
as a result of a <tt>#include&nbsp;&lt;...&gt;</tt> directive.</p>
</blockquote>
<p><a name="returning_from_include_file" id="returning_from_include_file"></a><strong>returning_from_include_file</strong></p>
<pre> <span class="keyword">void</span> returning_from_include_file();
</pre>
<blockquote>
<p>The function <tt>returning_from_include_file</tt> is called, whenever an
included file is about to be closed after it's processing is complete.</p>
</blockquote>
<p><strong><a name="interpret_pragma"></a>interpret_pragma</strong></p>
<pre> <span class="keyword">template</span> &lt;<span class="keyword">typename</span> TokenT, <span class="keyword">typename</span> ContainerT&gt;
bool <a href="class_reference_tracepolicy.html#interpret_pragma">interpret_pragma</a>(ContainerT &amp;pending,
TokenT const &amp;option, ContainerT <span class="keyword">const</span> &amp;values,
TokenT <span class="keyword">const</span> &amp;pragma_token, language_support language);
</pre>
<blockquote>
<p>The function <tt>interpret_pragma</tt> is called, whenever an unrecognized
<tt>#pragma&nbsp;wave&nbsp;...</tt> or operator <tt>_Pragma(&quot;wave&nbsp;...&quot;)</tt>
is found in the input stream.</p>
<p>The <tt>pending</tt> parameter may be used to push tokens back into the input
stream, which are to be used as the replacement text for the whole <tt>#pragma&nbsp;wave()</tt>
directive. If this sequence is left empty, no replacement takes place, i.e.
the interpreted directive is removed from the generated token stream.</p>
<p>The <tt>option</tt> parameter contains the name of the interpreted pragma.</p>
<p>The <tt>values</tt> parameter holds the value of the parameter provided to
the pragma operator.</p>
<p>The <tt>pragma_token</tt> parameter contains the actual #pragma token, which
may be used for extraction of the location information for some error output.</p>
<p>The <tt>language</tt> parameter contains the current language mode, in which
the <tt>Wave</tt> library operates.</p>
<p>If the return value is 'false', the whole #pragma directive is interpreted
as unknown and a corresponding error message is issued. A return value of
'true' signs a successful interpretation of the given #pragma.<br>
</p>
</blockquote>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="class_reference_inputpolicy.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="class_reference_lexer.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
<br>
<font size="2">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)
</font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Wednesday, January 14, 2004 12:36<!-- #EndDate -->
</span></body>
</html>

211
doc/compiletime_config.html Normal file
View File

@@ -0,0 +1,211 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Compile Time Configuration</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="theme/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21"> <h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">Compile
Time Configuration</font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="supported_pragmas.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="preliminary_cpp0x_support.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p><b><a name="compiletime_config"></a>Library compile time configuration</b></p>
<P dir="ltr">The C++ preprocessor iterator library may be configured at compile
time by specifying different preprocessor constants to include different additional
features. The possible preprocessor constants are described in the following
table. </P>
<table width="100%" border="0" align="center">
<tr>
<td colspan="2" class="table_title"><b>Summary of possible preprocessor constants
for<br>
library configuration</b></td>
</tr>
<tr>
<td width="46%" class="table_cells"><code>BOOST_WAVE_SUPPORT_WARNING_DIRECTIVE</code></td>
<td width="54%" class="table_cells"> <p>Support the #warning directive</p></td>
</tr>
<tr>
<td width="46%" class="table_cells"><code><code>BOOST_</code>WAVE_SUPPORT_MS_EXTENSIONS</code></td>
<td width="54%" class="table_cells"> <p>Support several MS specific language
extensions (i.e. <tt>__int8</tt> et.al.)</p></td>
</tr>
<tr>
<td class="table_cells"><code><code>BOOST_</code>WAVE_PREPROCESS_ERROR_MESSAGE_BODY</code></td>
<td class="table_cells"><p>Enable the preprocessing of the message bodies
of <span class="keyword">#error</span> and <span class="keyword">#warning</span>
directives.</p></td>
</tr>
<tr>
<td class="table_cells"><code><code>BOOST_</code>WAVE_RETURN_PRAGMA_DIRECTIVES</code></td>
<td class="table_cells"><p>If defined, then the <span class="keyword">#pragma</span>
directives are returned as a token sequence to the caller, if not defined,
the whole <span class="keyword">#pragma</span> directive is skipped. </p></td>
</tr>
<tr>
<td class="table_cells"><code><code>BOOST_</code>WAVE_PREPROCESS_PRAGMA_BODY</code></td>
<td class="table_cells"><p>Enable the preprocessing of the bodies of <span class="keyword">
#pragma</span> directives.<br>
Note though, that the body of an <tt>operator&nbsp;_Pragma()</tt> is preprocessed
always, as required by the C99 Standard <a href="references.html#iso_c">[2]</a>.
</p></td>
</tr>
<tr>
<td class="table_cells"><code><code>BOOST_</code>WAVE_ENABLE_COMMANDLINE_MACROS</code></td>
<td class="table_cells"><p>Enable the functionality required to define macros
with the command line syntax (-DMACRO(x)=definition)</p></td>
</tr>
<tr>
<td class="table_cells"><code><code>BOOST_</code>WAVE_STRINGTYPE</code></td>
<td class="table_cells"><p>The tokens generated by the <tt>Wave</tt> library
contain the token data and the file position, where this token was found
in the input stream. <br>
This constant may be used to redefine the data type, which is used to
hold the token data and the corresponding file name. If this isn't defined
it defaults to std::string. (The here defined data type should be compatible
to the std::string type)</p></td>
</tr>
<tr>
<td class="table_cells"><code><code>BOOST_</code>WAVE_SUPPORT_VARIADICS_PLACEMARKERS</code></td>
<td class="table_cells"><p>If defined, then the preprocessor library supports
variadics and placemarkers. Note, to support C99 mode, this constant must
be defined too.</p></td>
</tr>
<tr>
<td class="table_cells"><code><code>BOOST_</code>WAVE_MAX_INCLUDE_LEVEL_DEPTH</code></td>
<td class="table_cells"><p>If defined, it will determine the initial maximal
possible include file nesting depth supported. It defaults to 1024.</p></td>
</tr>
<tr>
<td class="table_cells"><code><code>BOOST_</code>WAVE_ENABLE_CPP0X_EXTENSIONS</code></td>
<td class="table_cells"><p>If defined, then the preprocessor library supports
a couple of experimental C++0x extensions, as macro scopes, variadics
and placemarkers in C++ mode, well defined token pasting of unrelated
tokens. For more details please refer to <a href="preliminary_cpp0x_support.html">The
Preliminary C++0x support</a>.</p></td>
</tr>
<tr>
<td class="table_cells"><code><code>BOOST_</code>WAVE_SUPPORT_PRAGMA_ONCE</code></td>
<td class="table_cells"><p>If defined, then the <code>#pragma once</code> directive is supported by <tt>Wave</tt>. This specifies that the file, in which the pragma resides, will be included
(opened) only once by the compiler in a build. </p></td>
</tr>
<tr>
<td class="table_cells"><code>BOOST_</code><code>WAVE_SUPPORT_INCLUDE_NEXT</code></td>
<td class="table_cells"><p>If defined, then the <code>#include_next</code> directive is supported by <tt>Wave</tt>. This is syntactically equivalent to the <code>#include</code> directives, but may be used to inherit a header file (i.e. to include a file, which is named as the current file containing the <code>#include_next</code>).</p></td>
</tr>
</table>
<P dir="ltr"><b><a name="using_custom_lexer"></a>Using a different token type or lexer type in conjunction with Wave </b></P>
<P dir="ltr">It is possible to use the <tt>Wave</tt> library while using your own token and/or lexer types. This may be achieved by providing your lexer type as the second template parameter while instantiating the <tt>boost::wave::context&lt;&gt;</tt> object. The token type used by the library is derived from the <tt>token_t</tt> typedef to be provided by the lexer type. If you want to provide your own token type only, you may use the <tt>boost::wave::lex_iterator&lt;&gt;</tt> type contained with the library. This type needs to be parametrized with the token type to use. </P>
<P dir="ltr">To show, how this may be done, the <tt>Wave</tt> library contains several samples illustrating this possibility. The <tt>cpp_tokens</tt> sample shows the usage of a custom lexer and a custom token types. The lexer type used is functionally fully compatible to the <tt>re2c</tt> <a href="references.html#re2c">[3]</a> based lexer used by default. It is implemented based on the <tt>SLex</tt> <a href="references.html#slex">[5]</a> lexer example written by Dan Nuffer. The used theiring token type is functionally equivalent to the default token type except for an additional <tt>operator&lt;&lt;</tt> used for dumping the information carried bz the token.</P>
<P dir="ltr"><b><a name="compilation_models"></a>Separation and inclusion compilation
models</b></P>
<P dir="ltr">The <tt>Wave</tt> C++ preprocessor iterator library is build almost
completely as a header only library (except for the re2c based lexer). If you're
trying to include all required files at once you will mention, that the resulting
compilation times are very large (up to an hour - depending on your system configuration).
This straightforward method we'll call the inclusion compilation model. If you
do not pay attention to compilation times, that's the way to go, no special
handling is needed.</P>
<P dir="ltr">If you're interested in decreasing compilation times, the following
method is to be used. This we will call it the separation compilation model.
The trick is to separate the different objects such, that they are compilable
separately. The function, which instantiates the templated object in question
is factored out such, that its definition is visible to only one translation
unit. To simplify this further this creation function is packaged into a small
generator template structure.</P>
<P dir="ltr">There are two levels of separation implemented: the separation of
the compilation of the C++ lexer and the separation of the compilation of the
different Spirit grammars used. To use these separations you will have to define
two preprocessor constants while compiling the whole application and you will
have to explicitely instantiate some helper templates. The following tables
shows these constants in detail.</P>
<table width="90%" border="0" align="center">
<tr>
<td colspan="2" class="table_title"><b>Summary of possible compilation constants
required <br>
to enable the separation compilation model</b></td>
</tr>
<tr class="table_title">
<td width="25%"><b>Separate</b></td>
<td width="75%"><p><code><font face="Verdana, Arial, Helvetica, sans-serif">Preprocessor
constant</font></code></p></td>
</tr>
<tr>
<td width="25%" class="table_cells"><code>C++ lexer</code></td>
<td width="75%" class="table_cells"> <p><code><code>BOOST_</code>WAVE_SEPARATE_LEXER_INSTANTIATION</code></p></td>
</tr>
<tr>
<td width="25%" class="table_cells"><code>Spirit grammars</code></td>
<td width="75%" class="table_cells"> <p><code><code>BOOST_</code>WAVE_SEPARATE_GRAMMAR_INSTANTIATION</code></p></td>
</tr>
</table>
<P dir="ltr">The following table shows the explicit template instantiations required,
if you want to use the separation compilation model. The <tt>TokenT</tt> placeholder
type has to be replaced with your token type to use and the <code><tt>LexIteratorT</tt></code> placeholder type has to be replaced with your lex iterator type you've used while instantiation of the <tt>boost::wave::context&lt;&gt;</tt> object. You will achieve the best
results, if you place these into separate compilation units each. The <tt>IteratorT</tt>
placeholder should be replaced by the iterator type, which was used to instantiate
the <tt>boost::wave::context&lt;&gt;</tt> object.</P>
<table width="90%" border="0" align="center">
<tr>
<td colspan="2" class="table_title"><b>Summary of required explicit template
instantiations <br>
required when using the separation compilation model</b></td>
</tr>
<tr class="table_title">
<td width="25%"><b>Separate</b></td>
<td width="75%"><p><code><font face="Verdana, Arial, Helvetica, sans-serif">Templates
to explicitly instantiate</font></code></p></td>
</tr>
<tr>
<td width="25%" class="table_cells"><code>C++ lexer</code></td>
<td width="75%" class="table_cells"> <code><span class="keyword">template</span>
cpplexer::re2clex::new_lexer_gen&lt;<tt>IteratorT</tt>&gt;;</code></td>
</tr>
<tr>
<td width="25%" class="table_cells"><code>Spirit grammars</code></td>
<td width="75%" class="table_cells"> <p><code><span class="keyword">template</span> wave::grammars::expression_grammar_gen&lt<tt>TokenT</tt>&gt;;<br>
<span class="keyword"> template</span> wave::grammars::intlit_grammar_gen&lt;<tt>TokenT</tt>&gt;;<br>
<span class="keyword"> template</span> wave::grammars::chlit_grammar_gen&lt;<tt>TokenT</tt>&gt;;<br>
<span class="keyword"> <code>template</code><code></code><code> wave::grammars::cpp_grammar_gen&lt;<tt>LexIteratorT</tt>&gt;;<br>
</code>template</span> wave::grammars::predefined_macros_grammar_gen&lt;<tt>LexIteratorT</tt>&gt;;<br>
<span class="keyword"> template</span> wave::grammars::defined_grammar_gen&lt;<tt>LexIteratorT</tt>&gt;;</code></p></td>
</tr>
</table>
<p>To see an example of this you can look at the <tt>Wave</tt> driver program
included as an acompanion sample to the C++ preprocessor iterator library. The
corresponding files are named obviously <span class="string">&quot;instantiate_...something.cpp&quot;</span>,
where the <span class="string">'...somthing'</span> is a hint, which grammars
are explicitely instantiated inside. By using the separation model the compilation
times required to build the <tt>Wave</tt> example are dropped by up to 90%.</p>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="supported_pragmas.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="preliminary_cpp0x_support.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
<br>
<font size="2">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)
</font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Friday, January 23, 2004 18:13<!-- #EndDate -->
</span></body>
</html>

92
doc/introduction.html Normal file
View File

@@ -0,0 +1,92 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Introduction</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="theme/style.css" rel="stylesheet" type="text/css">
</head>
<body text="#000000" background="theme/bkd.gif">
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21"> <h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">Introduction</font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="preface.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="quickstart.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<P dir="ltr">The <tt>Wave</tt> C++ preprocessor library is a Standards conformant
implementation of the mandated C++ preprocessor functionality packed behind
a simple to use interface, which integrates well with the well known idioms
of the Standard Template Library (STL).</P>
<P dir="ltr">The <tt>Wave</tt> C++ preprocessor is not a monolitic application,
it's rather a modular library, which exposes mainly a context object and an
iterator interface. The context object helps to configure the actual preprocessing
process (as search path's, predefined macros, etc.). The exposed iterators are
generated by this context object too. Iterating over the sequence defined by
the two iterators will return the preprocessed tokens, which are to be built
on the fly from the given input stream. </P>
<P dir="ltr"> The C++ preprocessor iterator itself is feeded by a C++ lexer iterator,
which implements an unified interface. BTW, the C++ lexers contained with the
<tt>Wave</tt> library may be used standalone too and are not tied to the C++
preprocessor iterator at all. </P>
<P dir="ltr">To make the C++ preprocessing library modular, the C++ lexer is held
completely separate and independend from the preprocessor. To proof this concept,
there are two different C++ lexers and aIDL lexer implemented by now,&nbsp;which are functionally
completely identical. The C++ lexers expose the mentioned unified interface,
so that the C++ preprocessor iterator may be used with both of them. The abstraction
of the C++ lexer from the C++ preprocessor iterator library was done to allow
to plug in different C++ lexers without the need to reimplement the preprocessor.
This will allow for benchmarking and specific finetuning of the process of preprocessing
itself.</P>
<P dir="ltr">The first of this C++ lexers is implemented with the help of the
wellknown <tt>Re2C</tt> <a href="references.html#re2c">[3]</a> tool, which generates
C code from given regular expressions. The lexers generated with <tt>Re2C</tt>
are known to be very fast, because they are not&nbsp;table driven but the whole
token building logic is coded directly (very similar to hand coded lexers).
</P>
<P dir="ltr">The second of this C++ lexers is build around a table driven lexer,
where the DFA tables are generated from regular expressions with the help of
a Spirit based lexer generating framework named <tt>Slex</tt> <a href="references.html#slex">[5]</a>.
The <tt>Slex</tt> is feeded during runtime with the token definitions (regular
expressions) and generates the resulting DFA table. This table is used to combine
the input characters into corresponding lexems (tokens). The generated DFA table
can be saved to disc to avoid the generation process at program startup.</P>
<P dir="ltr">Wave may be used for preprocessing IDL files too, since the token set needed for the IDL language is very similar to the C++ token set. That's the reason, why the <tt>Wave</tt> preprocessor library contains also an IDL lexer. The IDL lexer is based on the <tt>re2c</tt> tool too, but recognizes a different set of tokens. So this lexer does not recognize any keywords (except <tt>true</tt> and <tt>false</tt>, which are needed by the preprocessor itself). This is needed because there exist different IDL languages, where identifiers of one language may be keywords of others. Ok, this implies to postpone keyword identification after the preprocessing, but allows to use <tt>Wave</tt> for all of the IDL derivatives. </P>
<P dir="ltr">It is possible to build other C++ lexers if needed. Currently there
are plans to adapt the <tt>Spirit</tt> C++ lexer example <tt>cpplexer</tt> <a href="references.html#cpplexer">[6]</a>,
which is completely based on static <tt>Spirit<a href="references.html#spirit">[4]</a></tt>
grammars.</P>
<P dir="ltr">In fact both of the embedded lexers and the library itself is able
to act in a C99 compliant mode. In this mode the lexers reject C++ only tokens
(<tt>'::'</tt>, <tt>'-&gt;*'</tt>, <tt>'.*'</tt> and the alternate keywords
as <tt>'and'</tt> etc.). The preprocessor additionally handles placemarkers
(empty macro arguments) and variadics (macros with variable parameter count).
As an extension to the C++ Standard the library can be enabled to handle placemarkers
and variadics in the C++ mode too.</P>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="preface.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="quickstart.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
<br>
<font size="2">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)
</font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Saturday, January 24, 2004 18:25<!-- #EndDate -->
</span> </body>
</html>

View File

@@ -0,0 +1,101 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>The Macro Expansion Process</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="theme/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21"> <h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">The
Macro Expansion Process</font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="supported_pragmas.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="30"><a href="compiletime_config.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>The macro expansion process described here was initially developed by <a href="mailto:pmenso57@attbi.com">Paul
Mensonides</a> and is implemented in <tt>Wave</tt>. It is much more understandable
as the description of the desired macro expansion algorithm provided in the
C++ Standard <a href="references.html#iso_cpp">[1]</a>.</p>
<p>Macro replacement proceeds left-to-right. </p>
<p>If, during scanning (or rescanning) an identifier is found, it is looked up
in the symbol table. If the identifier is not found in the symbol table, it
is not a macro and scanning continues.</p>
<p>If the identifier is found, the value of a flag associated with the identifier
is used to determine if the identifier is available for expansion. If it is
not, the specific token (i.e. the specific instance of the identifier) is marked
as disabled and is not expanded. If the identifier is available for expansion,
the value of a different flag associated with the identifier in the symbol table
is used to determine if the identifier is an object-like or function-like macro.
If it is an object-like macro, it is expanded. If it is a function-like macro,
it is only expanded if the next token is an left parenthesis.<br>
An identifier is available for expansion if it is not marked as disabled and
if the the value of the flag associated with the identifier is not set, which
is used to determine if the identifier is available for expansion.</p>
<p>(If a macro is an object-like macro, skip past the next two paragraphs.)</p>
<p>If a macro to be expanded is a function-like macro, it must have the exact
number of actual arguments as the number of formal parameters required by the
definition of the macro. Each argument is recursively scanned and expanded.
Each parameter name found in the replacement list is replaced by the expanded
actual argument after leading and trailing whitespace and all placeholder tokens
are removed unless the parameter name immediately follows the stringizing operator
(<tt>'#'</tt>) or is adjacent to the token-pasting operator (<tt>'##'</tt>).</p>
<p>If the parameter name immediately follows the stringizing operator (<tt>'#'</tt>),
a stringized version of the unexpanded actual argument is inserted. If the parameter
name is adjacent to the token-pasting operator (<tt>'##'</tt>), the unexpanded
actual argument is inserted after all placeholder tokens are removed.</p>
<p>All concatenation takes place in the replacement list. (If a single concatenation
yields multiple tokens, the behavior is undefined. Moreover, <tt>Wave</tt> in
normal C++98 and C99 modes issues an error, if more then one token is produced
as the result of the concatenation. In C++0x mode <tt>Wave</tt> treats token-pasting
of unrelated tokens as well defined and inserts the reparsed string representation
of the concatenated tokens into the replacement list.).</p>
<p>The flag in the symbol table entry associated with the name of the macro being
expanded is set to indicate the that the macro is not available for expansion.</p>
<p>The replacement list is rescanned for further macro expansion. All leading
and trailing whitespace tokens in the replacement list are removed (the placeholder
tokens are left intact). </p>
<p>After rescanning completes, the flag in the symbol table entry associated with
the name of macro being expanded is cleared to indicate that the macro is again
available for expansion, and the sequence of tokens that constitutes the rescanned
replacement list is returned to the point of invocation of the macro.</p>
<p>If this sequence of tokens is empty, it is replaced by a placeholder token.
If a placeholder is found during scanning (or rescanning) it is ignored. (Also,
if the only thing separating a parameter from the stringizing operator or token-pasting
operator is placeholder, it is also ignored in that context.)</p>
<p>This sequence of tokens is inserted at the original point that the macro was
invoked, and scanning continues starting with the last token of the newly inserted
sequence of tokens. I.e. scanning looks back a single token (possibly a placeholder
token) and continues.<br>
</p>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="./index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="supported_pragmas.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="30"><a href="compiletime_config.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
<br>
<font size="2">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)
</font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Monday, January 5, 2004 14:57<!-- #EndDate -->
</span>
<p>&nbsp; </p>
</body>
</html>

175
doc/predefined_macros.html Normal file
View File

@@ -0,0 +1,175 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Predefined Macros</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="theme/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21"> <h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">Predefined
Macros </font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="class_reference_inputpolicy.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="supported_pragmas.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p dir="ltr">The following table lists the macros, which are predefined by the
<tt>Wave</tt> library. Some of these (all except the <code class="keyword">__LINE__</code>,
<code class="keyword">__FILE__</code>, <code class="keyword">__DATE__</code>,
<code class="keyword">__TIME__</code>, <code class="keyword">__STDC__, __INCLUDE_LEVEL__</code>
and <code class="keyword">__cplusplus</code> macros, and in C++0x mode the <code><tt>__STDC_GLOBAL__</tt></code>,
<tt>__STDC_FULL_REGION__</tt> and <tt>__STDC__CURRENT_REGION__</tt> macros are
not undefinable too) may be undefined from the command line of the driver executable
(<a href="wave_driver.html">see</a> the -U option) or through the function <a href="class_reference_context.html#remove_macro_definition">remove_macro_definition()</a>.</p>
<p dir="ltr">In C++0x mode the predefined macros are available at every macro
scope without explicit qualification (except <tt>__STDC_GLOBAL__</tt>, which is available at global macro scope
only).</p>
<table width="90%" border="0" align="center">
<tr>
<td colspan="3" class="table_title"><b>Summary of predefined macros</b></td>
</tr>
<tr class="table_title">
<td width="28%"><b>Name</b></td>
<td width="62%"><p><code><font face="Verdana, Arial, Helvetica, sans-serif">Value</font></code></p></td>
<td width="10%">Undefinable</td>
</tr>
<tr>
<td width="28%" class="table_cells"><code>__STDC__</code></td>
<td width="62%" class="table_cells"><p> 1 (a decimal constant)</p></td>
<td width="10%" class="table_cells"><p>yes</p></td>
</tr>
<tr>
<td width="28%" class="table_cells"><code>__cplusplus</code></td>
<td width="62%" class="table_cells"> <p>199711L (a decimal constant), this
is defined in C++ mode only (C99 mode is off)<br>
In the C++0x mode this decimal constant is guaranteed to be larger than
199711L (the concrete value is to be defined by the C++ committee).</p></td>
<td width="10%" class="table_cells"><p>no</p></td>
</tr>
<tr>
<td class="table_cells"><code>__LINE__</code></td>
<td class="table_cells"><p>The line number of the current source line (a decimal
constant)</p></td>
<td class="table_cells"><p>no</p></td>
</tr>
<tr>
<td class="table_cells"><code>__FILE__</code></td>
<td class="table_cells"><p>The presumed name of the source file (a character
string literal)</p></td>
<td class="table_cells"><p>no</p></td>
</tr>
<tr>
<td class="table_cells"><code>__DATE__</code></td>
<td class="table_cells"><p>The date of translation of the source file (a character
string literal of the form<br>
&quot;Mmm dd yyyy&quot;, where the names of the months are the same as
those generated by the asctime function, and the first character of dd
is a space character if the value is less than 10). </p></td>
<td class="table_cells"><p>no</p></td>
</tr>
<tr>
<td class="table_cells"><code>__TIME__</code></td>
<td class="table_cells"><p>The time of translation of the source file (a character
string literal of the form &quot;hh:mm:ss&quot;<br>
as in the time generated by the asctime function).</p></td>
<td class="table_cells"><p>no</p></td>
</tr>
<tr>
<td class="table_cells"><code>__INCLUDE_LEVEL__</code></td>
<td class="table_cells"><p>A decimal integer constant that represents the
depth of nesting in include <br>
files. The value of this macro is incremented on every <tt>#include</tt>
directive <br>
and decremented at every end of file. </p></td>
<td class="table_cells"><p>no</p></td>
</tr>
<tr>
<td class="table_cells"><code>__WAVE__</code><br> <code>__SPIRIT_PP__</code></td>
<td class="table_cells"><p>The version of the driver program (a hexadecinal
constant of the form 0xMmrr, where <span class="literal">'M'</span> is
the major version number, <span class="literal">'m'</span> the minor version
number and <span class="literal">'rr'</span> the release number).</p></td>
<td class="table_cells"><p>yes</p></td>
</tr>
<tr>
<td class="table_cells"><code>__WAVE_VERSION__</code><br> <code>__SPIRIT_PP_VERSION__</code></td>
<td class="table_cells"><p>The full version number of the driver program (a
hexadecinal constant of the form 0xMmrrbbbb, where <span class="literal">'M'</span>
is the major version number, <span class="literal">'m'</span> the minor
version number, <span class="literal">'rr'</span> the release number and
<span class="literal">'bbbb'</span> the build number).</p></td>
<td class="table_cells"><p>yes</p></td>
</tr>
<tr>
<td class="table_cells"><code>__WAVE_VERSION_STR__</code><br> <code>__SPIRIT_PP_VERSION_STR__</code></td>
<td class="table_cells"><p>The full version number of the driver program (a
character string literal of the form <span class="string">&quot;M.m.rr.bbbb&quot;</span>,
where <span class="literal">'M'</span> is the major version number, <span class="literal">'m'</span>
the minor version number, <span class="literal">'rr'</span> the release
number and <span class="literal">'bbbb'</span> the build number).</p></td>
<td class="table_cells"><p>yes</p></td>
</tr>
<tr>
<td class="table_cells"><code>__STDC_VERSION__</code></td>
<td class="table_cells"><p>199901L (a decimal constant), this is defined in
C99 mode only</p></td>
<td class="table_cells"><p>yes</p></td>
</tr>
<tr>
<td class="table_cells"><code>__WAVE_HAS_VARIADICS__</code></td>
<td class="table_cells"><p>1 (a decimal constant), this is defined in C++
mode only, if variadics and placemarkers are enabled, further it is defined
in C99 and C++0x modes</p></td>
<td class="table_cells"><p>no</p></td>
</tr>
<tr>
<td class="table_cells"><code>__STDC_GLOBAL__</code></td>
<td class="table_cells"><p>1 (a decimal constant), this is defined in C++0x
mode only and only at global macro scope</p></td>
<td class="table_cells"><p>no</p></td>
</tr>
<tr>
<td class="table_cells"><code>__STDC_CURRENT_REGION__</code></td>
<td class="table_cells"><p>The name of the current active macro region (a
string literal). This constant does not contain the full qualified scope
name, but only it's last part. This macro is defined in C++0x mode only.</p></td>
<td class="table_cells"><p>no</p></td>
</tr>
<tr>
<td class="table_cells"><code>__STDC_FULL_REGION__</code></td>
<td class="table_cells"><p>The name of the current active macro region (a
string literal). This constant does contain the full qualified scope name,
not only it's last part. This macro is defined in C++0x mode only.</p></td>
<td class="table_cells"><p>no</p></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="class_reference_inputpolicy.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="supported_pragmas.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
<br>
<font size="2">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)
</font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Wednesday, January 14, 2004 12:41<!-- #EndDate -->
</span></body>
</html>

109
doc/preface.html Normal file
View File

@@ -0,0 +1,109 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Preface</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="theme/style.css" rel="stylesheet" type="text/css">
</head>
<body text="#000000" background="theme/bkd.gif">
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21"> <h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">Preface</font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><img src="theme/l_arr_disabled.gif" width="20" height="19" border="0"></td>
<td width="30"><a href="introduction.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>During the last time many new features were developed as additions to the <tt>Spirit</tt>
<a href="references.html#spirit">[4]</a> parser construction framework and we
felt more and more, that it would be very helpful, to have a 'real world' example,
which could be used as a sandbox for testing the usability of certain features.
Additionally&nbsp;a recent discussion on the Boost mailing list showed the widespread
interest of developers to have a modern, open source C++ preprocessor library
to play with.&nbsp; So we had the idea to implement a C++ preprocessor to fit
this needs&nbsp;-&nbsp;<tt>Wave</tt> was born.</p>
<p align="justify">The <tt>Wave</tt> C++ preprocessor library uses the <a href="http://spirit.sourceforge.net/">
</a> <tt>Spirit<a href="references.html#spirit">[4]</a></tt> parser construction
library to implement a C++ lexer with ISO/ANSI standard conformant preprocessing
capabilities. It exposes an iterator interface, which returns the current preprocessed
token from the input stream. This preprocessed token is generated on the fly
while iterating over the preprocessor iterator sequence (in the terminology
of the STL these iterators are forward iterators). </p>
<p align="justify"> The C++ preprocessor is a macro processor that under normal
circumstances is used automatically by your C++ compiler to transform your program
before actual compilation. It is called a macro processor because it allows
you to define macros, which are brief abbreviations for longer constructs. The
C++ preprocessor provides four separate facilities that you can use as you see
fit: </p>
<blockquote>
<p><b><img src="theme/bullet.gif" width="13" height="13" id="IMG1">&nbsp;</b>Inclusion
of header files<br>
<b><img src="theme/bullet.gif" width="13" height="13" id="IMG1">&nbsp;</b>Macro
expansion<br>
<b><img src="theme/bullet.gif" width="13" height="13" id="IMG1">&nbsp;</b>Conditional
compilation<br>
<b><img src="theme/bullet.gif" width="13" height="13" id="IMG1">&nbsp;</b>Line
control</p>
</blockquote>
<p>These features are greatly underestimated today, even more, the preprocessor
has been frowned on for so long that its usage just hasn't been effectively
pushed until the Boost preprocessor library <a href="references.html#pp_lib">[7]</a>
came into being a few years ago. Only today we begin to understand, that preprocessor
generative metaprogramming combined with template metaprogramming in C++ is
by far one of the most powerful compile-time reflection/metaprogramming facilities
that any language has ever supported.</p>
<p align="justify">The main goals for the <tt>Wave</tt> project are:</p>
<blockquote>
<p><b><img src="theme/bullet.gif" width="13" height="13" id="IMG1">&nbsp;</b>full
conformance with the C++ standard (ISO/IEC 14882:1998) <a href="references.html#iso_cpp">[1]</a>
and with the C99 standard (INCITS/ISO/IEC 9899:1999) <a href="references.html#iso_c">[2]</a><br>
<b><img src="theme/bullet.gif" width="13" height="13">&nbsp;</b>usage of <tt>Spirit<a href="references.html#spirit">[4]</a></tt>
for the parsing parts of the game (certainly :-)<br>
<b><img src="theme/bullet.gif" width="13" height="13">&nbsp;</b>maximal usage
of STL and/or <tt>Boost</tt> libraries (for compactness and maintainability)<br>
<b><img src="theme/bullet.gif" width="13" height="13">&nbsp;</b>straightforward
extendability for the implementation of additional features<br>
<b><img src="theme/bullet.gif" width="13" height="13">&nbsp;</b>building a
flexible library for different C++ lexing and preprocessing needs</p>
</blockquote>
<p>At the first steps it is not planned to make a very high performance or very
small C++ preprocessor. If you are looking for these objectives you probably
have to look at other places. Although our C++ preprocessor iterator should
work as expected and will be usable as a reference implementation, for instance
for testing of other preprocessor oriented libraries as the Boost Preprocessor
library <a href="references.html#pp_lib">[7]</a> et.al.</p>
<p>As tests showed, the <tt>Wave</tt> library is very conformant to the C++ Standard,
such that it compiles several strict conformant macro definitions, which are
not even compilable with EDG based preprocessors (i.e. Comeau or Intel). It
is shown further, that the EDG preprocessor will outperform the <tt>Wave</tt>
preprocessor in simple cases. However, as complexity increases, time dilates
expontentially on EDG. Preprocessing time dilates linearly under <tt>Wave</tt>,
which causes it to easily outperform EDG based preprocessors when complexity
increases.</p>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><img src="theme/l_arr_disabled.gif" width="20" height="19" border="0"></td>
<td width="30"><a href="introduction.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
<br>
<font size="2">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)
</font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Monday, January 5, 2004 14:57<!-- #EndDate -->
</span></body>
</html>

View File

@@ -0,0 +1,317 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Preliminary C++0x support</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="theme/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21"> <h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">Preliminary
C++0x support</font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="class_reference_inputpolicy.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="wave_driver.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>In order to prepare a proposal for the C++ Standards committee, which should
describe certain new and enhanced preprocessor features, the Wave preprocessor
library has implemented experimental support for the following features:</p>
<p><a href="preliminary_cpp0x_support.html#variadic_macros">Variadic macros</a><br>
<a href="preliminary_cpp0x_support.html#placemarker_tokens">Placemarker tokens</a><br>
<a href="preliminary_cpp0x_support.html#token_pasting">Well defined token-pasting</a><br>
<a href="preliminary_cpp0x_support.html#macro_scoping">Macro scoping mechanism</a><br>
<a href="preliminary_cpp0x_support.html#new_alternative_tokens">New alternative tokens</a></p>
<p>The described features are enabled by the <tt>--c++0x</tt> command line option
of the <tt>Wave</tt> driver. Alternatively you can enable these features by
calling the <tt>wave::context&lt;&gt;::set_language()</tt> function with the
<tt>wave::support_cpp0x</tt> value. </p>
<h2><a name="variadic_macros"></a>Variadic macros</h2>
<p>Both variadic macros and placemarker tokens have already been added to C99
<a href="references.html#iso_c">[2]</a>. This represents an unnecessary incompatibility
between C and C++. Adding these facilities to the C++ preprocessor would cause
no code to break that is currently well-defined and would closing the gap between
C and C++ in this field.</p>
<p>Variadic macros were added to the C preprocessor as of C99 <a href="references.html#iso_c">[2]</a>.
They are, effectively, a way to pass a variable number of arguments to a macro.
The specific syntax is as follows:</p>
<pre> <span class="preprocessor">#define</span> A(...) <span class="preprocessor">__VA_ARGS__</span>
<span class="preprocessor">#define</span> B(a, ...) <span class="preprocessor">__VA_ARGS__</span>
A(1, 2, 3) <span class="comment">// expands to: 1, 2, 3</span>
B(1, 2, 3) <span class="comment">// expands to: 2, 3</span>
</pre>
<p>The ellipsis is used to denote that the macro can accept any number of trailing
arguments. It must always occur as the last formal parameter of the macro. The
variadic arguments passed to the macro are identified by the special symbol
<tt>__VA_ARGS__</tt> in the replacement list of a variadic macro. The use of
this symbol is prohibited in any other context.</p>
<h2><a name="placemarker_tokens"></a>Placemarker tokens</h2>
<p>Placemarker tokens (technically, preprocessing tokens) are simply a well-defined
way of passing &quot;nothing&quot; as a macro argument. This facility was also
added to the C preprocessor as of C99 <a href="references.html#iso_c">[2]</a>.</p>
<pre> <span class="preprocessor">#define</span> X(p) f(p)
X(&quot;abc&quot;) <span class="comment">// expands to: f(&quot;abc&quot;)</span>
X() <span class="comment">// expands to: f()</span>
<span class="preprocessor">#define</span> Y(a, b) <span class="keyword">int</span>[a][b]
Y(2, 2) <span class="comment">// expands to: int[2][2]</span>
Y(, 2) <span class="comment">// expands to: int[][2]</span>
</pre>
<p>Placemarker tokens are a natural counterpart to variadic macros. They formalize the optional nature of a variadic argument (or arguments) so that variadic macros appear similar to the variadic functions, but have been generalized to include named parameters as well.
</p>
<h2><a name="token_pasting"></a>Well defined token-pasting</h2>
<p>Currently, as of both C++98 and C99, if token-pasting results in multiple preprocessing
tokens, the behavior is undefined. For example,</p>
<pre> <span class="preprocessor">#define</span> PASTE(a, b) a <span class="preprocessor">##</span> b
PASTE(1, 2) <span class="comment">// okay</span>
PASTE(+, -) <span class="comment">// undefined behavior</span></pre>
<p>Token-pasting of unrelated tokens (i.e. token-pasting resulting in multiple
preprocessing tokens) is currently undefined for no substantial reason. It is
not dependent on architecture nor is it difficult for an implementation to diagnose.
Furthermore, retokenization is what most, if not all, preprocessors already
do and what most programmers already expect the preprocessor to do. Well-defined
behavior is simply standardizing existing practice and removing an arbitrary
and unnecessary undefined behavior from the standard.</p>
<p>To achieve well-defined behavior in this context <tt>Wave</tt> retokenizes
the result of the token-pasting and inserts the newly created token sequence
as the macro replacement text.</p>
<pre> PASTE(+, ==) <span class="comment">// expands to: += =</span></pre>
<h2><a name="macro_scoping"></a>Macro scoping mechanism</h2>
<p>One of the major problems of the preprocessor is that macro definitions do
not respect any of the scoping mechanisms of the core language. As history has
shown, this is a major inconvenience and drastically increases the likelihood
of name clashes within a translation unit. The solution is to add both a named
and unnamed scoping mechanism to the C++ preprocessor. This limits the scope
of macro definitions without limiting its accessibility. Here are the details.
</p>
<p>The scoping mechanism is implemented with the help of three new preprocessor
directives: <span class="preprocessor">#region</span>, <span class="preprocessor">#endregion</span>
and <span class="preprocessor">#import</span>. Additionally it changes minor
details of some of the existing preprocessor directives: <span class="preprocessor">#ifdef</span>,
<span class="preprocessor">#ifndef</span> and the <span class="preprocessor">operator
defined()</span>.</p>
<h3>The #region directive</h3>
<p>The <span class="preprocessor">#region</span> directive starts a new named
or unnamed macro scope.</p>
<h4>Syntax</h4>
<blockquote>
<p><tt>#region &lt;qualified-identifier&gt;</tt></p>
<p> Where <tt>&lt;qualified-identifier&gt;</tt> is an optionally qualified name
defining the name of the region to open.<br>
This name is optional. If the name is omitted a nameless region is opened.
</p>
</blockquote>
<p>If the qualified identifier starts with an <tt>'::'</tt> the name is looked
up relative to the global scope (the <tt>&lt;qualified-identifier&gt;</tt> is
called <em>absolute</em>), if it starts with an identifier, the region is looked
up relative to the current open region (the <tt>&lt;qualified-identifier&gt;</tt>
is called <em>relative</em>). If the specified region is not defined, it is
created. </p>
<p>The <span class="preprocessor">#region</span> directive is opaque for all macro
definitions made outside this region, i.e. no macros defined inside of other
regions or at the global scope are directly accessible from inside the opened
region. To access such macros these must be imported (see the <span class="preprocessor">#import</span>
directive) or must be referred to through it's qualified name. </p>
<p>Regions may be nested. </p>
<p>A region may be re-opened (i.e. a <span class="preprocessor">#region</span>
directive with the same name is found at the same scope), and macros defined
inside the previous occurences of this region will be visible. </p>
<p>Region names and macro names of the same scope are stored into the same symbol
table. This implies, that at one scope there shall not be defined a region and
a macro with the same name.</p>
<p>Macros defined inside a nameless region may not be accessed from outside this
region. Further, from inside a nameless region it is not allowed to open an
enclosed region through an <em>absolute</em> name.</p>
<p>The argument of the <span class="preprocessor">#region</span> directive is
<strong>not</strong> subject to macro expansion before it is evaluated.</p>
<p>The following is a small code sample, which shows possible usages of preprocessor
regions.</p>
<pre> <span class="preprocessor">#define</span> A() 1
<span class="comment">/////////////////////////////////////</span>
<span class="preprocessor">#region</span> region_A
<span class="preprocessor"># define</span> B() 2
<span class="comment">/////////////////////////////////////</span>
<span class="preprocessor"># region</span> region_B
<span class="preprocessor"># define</span> C() 3
A() <span class="comment">// expands to: A()</span>
B() <span class="comment">// expands to: B()</span>
C() <span class="comment">// expands to: 3</span>
<span class="preprocessor"># endregion</span> <span class="comment">// region_B</span>
<span class="comment">/////////////////////////////////////</span>
A() <span class="comment">// expands to: A()</span>
B() <span class="comment">// expands to: 2</span>
C() <span class="comment">// expands to: C()</span>
region_B::C() <span class="comment">// expands to: 3</span>
::region_A::region_B::C() <span class="comment">// expands to: 3</span>
<span class="preprocessor">#endregion</span> <span class="comment">// region_A</span>
<span class="comment">/////////////////////////////////////</span>
A() <span class="comment">// expands to: 1</span>
B() <span class="comment">// expands to: B()</span>
region_A::B() <span class="comment">// expands to: 2</span>
::region_A::B() <span class="comment">// expands to: 2</span>
region_A::region_B::C() <span class="comment">// expands to: 3</span>
::region_A::region_B::C() <span class="comment">// expands to: 3</span>
<span class="preprocessor">#define</span> region_A ... <span class="comment">// error, name clash with region_A</span>
<span class="preprocessor">#region</span> A <span class="comment">// error, name clash with macro A</span>
<span class="preprocessor">#endregion</span>
</pre>
<h3>The #endregion directive</h3>
<p>The <span class="preprocessor">#endregion</span> directive closes the last
macro scope opened with a <span class="preprocessor">#region</span> directive
.</p>
<h4>Syntax</h4>
<blockquote>
<p><tt>#endregion</tt></p>
</blockquote>
<p>The <span class="preprocessor">#endregion</span> directive is opaque for all
macros defined inside the closed region. Macros defined inside this region may
be accessed from outside of this region only if imported (see the <span class="preprocessor">
#import</span> directive) or if referenced through qualified names specifying
the region and the macro name and if the region isn't unnamed.</p>
<p>The <span class="preprocessor">#region</span> and <span class="preprocessor">#endregion</span>
directives shall be balanced over the whole translation unit. Otherwise an error
is raised.</p>
<h3>The #import directive</h3>
<p>The <span class="preprocessor">#import</span> directive allows to import macros
or whole macro scopes into the current macro scope.</p>
<h4>Syntax</h4>
<blockquote>
<p><tt>#import &lt;qualified-identifier&gt; [, &lt;qualified-identifier&gt;
...]</tt></p>
</blockquote>
<blockquote>
<p>Where <tt>&lt;qualified-identifier&gt;</tt> is an optionally qualified name
defining the name of the macro or region to import. The <span class="preprocessor">#import</span>
directive may specify one or more comma separated qualified names.</p>
</blockquote>
<p>If the qualified identifier starts with an <tt>'::'</tt> the name is looked
up relative to the global scope (the <tt>&lt;qualified-identifier&gt;</tt> is
called <em>absolute</em>), if it starts with an identifier, the region is looked
up relative to the current open region (the <tt>&lt;qualified-identifier&gt;</tt>
is called <em>relative</em>). </p>
<p>If <tt>&lt;qualified-identifier&gt;</tt> refers to a macro, then the referenced
macro definition is made available in the current region, just if it were defined
here. Both macro definitions (the original macro definition and the imported
one) refer to the same macro. This is significant for disabling of a certain
macro during the rescanning of a replacement list. If one of the different instances
of the macro definition is marked as disabled for expansion, the others are
marked as disabled for expansion too.</p>
<p>If <tt>&lt;qualified-identifier&gt;</tt> refers to a region, then</p>
<ul>
<li>all macro definitions of the referenced region are made available in the
current region, just if these were defined here.</li>
<li> all sub-regions of the referenced region are made available from the current
region, just if these were defined as direct sub-regions of the current region.</li>
</ul>
<p> Imported macros may be undefined with the <span class="preprocessor">#undef</span>
directive as usual. This removes the referenced macro from the current region,
but leaves it unchanged in the original region, where it was defined initially.<br>
<br>
The argument of the <span class="preprocessor">#import</span> directive is <strong>not</strong>
subject to macro expansion before it is evaluated. </p>
<h3>Changes to the #ifdef, #ifndef directives and the operator defined()</h3>
<p>To fully support macro regions, the <span class="preprocessor">#ifdef</span>
and <span class="preprocessor">#ifndef</span> directives and the <span class="preprocessor">operator
defined()</span> may be used with qualified identifiers as its arguments too.
Therefor the following sample is completely wellformed (courtesy to Paul Mensonides):</p>
<pre> <span class="preprocessor"># ifndef</span> ::CHAOS_PREPROCESSOR::chaos::WSTRINGIZE_HPP
<span class="preprocessor"># region</span> ::CHAOS_PREPROCESSOR::chaos
<span class="preprocessor">#</span>
<span class="preprocessor"># define</span> WSTRINGIZE_HPP
<span class="preprocessor">#</span>
<span class="preprocessor"># include</span> <span class="copyright">&lt;chaos/experimental/cat.hpp&gt;</span>
<span class="preprocessor">#</span>
<span class="preprocessor">#</span> <span class="comment">// wstringize</span>
<span class="preprocessor">#</span>
<span class="preprocessor"># define</span> wstringize(...) \
chaos::primitive_wstringize(__VA_ARGS__) \
<span class="comment">/**/</span>
<span class="preprocessor">#</span>
<span class="preprocessor">#</span> <span class="comment">// primitive_wstringize</span>
<span class="preprocessor">#</span>
<span class="preprocessor"># define</span> primitive_wstringize(...) \
chaos::primitive_cat(L, #__VA_ARGS__) \
<span class="comment">/**/</span>
<span class="preprocessor">#</span>
<span class="preprocessor"># endregion</span>
<span class="preprocessor"># endif</span>
<span class="preprocessor"># import</span> ::CHAOS_PREPROCESSOR
chaos::wstringize(a,b,c) <span class="comment">// L&quot;a,b,c&quot;</span>
</pre>
<p>In the context of the <span class="preprocessor">#ifdef</span> and <span class="preprocessor">#ifndef</span>
directives and the <span class="preprocessor">operator defined()</span> a qualified
macro name is considered to be defined if:</p>
<ul>
<li>all regions referenced by the qualified name exist (opened at least once)
and</li>
<li>the referenced macro scope contains the definition of a macro with the given
name.</li>
</ul>
<h2><a name="new_alternative_tokens"></a>New alternative tokens</h2>
<p>Vesa Karvonen recently suggested on the <a href="http://aspn.activestate.com/ASPN/Mail/Message/boost/1618972">Boost
mailing list</a> the following addition to the preprocessor, which is implemented
by <tt>Wave</tt> in C++0x mode.</p>
<p>Consider the following example:</p>
<pre> <span class="preprocessor">#define</span> ID(x) x
ID( ( )
ID( a , b )
ID( ) )</pre>
<p>The macro expansion of the above preprocessor code does not produce the intended
result: </p>
<pre> ( a , b )</pre>
<p>The basic idea is that the keywords <tt>__lparen__</tt>, <tt>__rparen__</tt>
and <tt>__comma__</tt> could be used in place of <span class="literal">'('</span>,
<span class="literal">')'</span> and <span class="literal">','</span>, respectively.
The <br>
above example would now become:</p>
<pre> <span class="preprocessor">#define</span> ID(x) x
ID( __lparen__ )
ID( a __comma__ b )
ID( __rparen__ )</pre>
<p>and it would expand into:</p>
<pre> __lparen__ a __comma__ b __rparen__</pre>
<p>which would be recognized in translation phases after macro replacement as
equivalent to the token sequence:</p>
<pre> ( a , b )</pre>
<p>This trivial extension makes it an order of magnitude easier to generate C++
code using the C++ preprocessor.</p>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="class_reference_inputpolicy.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="wave_driver.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
Copyright &copy; 2003 Paul Mensonides<br>
Copyright &copy; 2003 Vesa Karvonen<br>
<br>
<font size="2">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)
</font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Monday, January 5, 2004 14:57<!-- #EndDate -->
</span>
<p>&nbsp;</p>
</body>
</html>

114
doc/quickstart.html Normal file
View File

@@ -0,0 +1,114 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Quick Start</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="theme/style.css" rel="stylesheet" type="text/css">
</head>
<body text="#000000" background="theme/bkd.gif">
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21"> <h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">Quick
Start </font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="introduction.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="class_reference_context.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>The actual preprocessing itself is a highly configurable process, so obviously
you have to define a couple of parameters to&nbsp;control this process, such
as:</p>
<BLOCKQUOTE dir="ltr" style="MARGIN-RIGHT: 0px">
<P><STRONG><IMG id="IMG1" height="13" src="theme/bullet.gif" width="13"></STRONG>&nbsp;include
search pathes, which define, where to search for files to be included with
<tt>#include&nbsp;&lt;...&gt;</tt> and <tt>#include&nbsp;"..."</tt> directives<br>
<STRONG><img src="theme/bullet.gif" width="13" height="13">&nbsp;</STRONG>which
macros to predefine and which of the predefined macros to undefine<br>
<STRONG><img src="theme/bullet.gif" width="13" height="13">&nbsp;</STRONG>several
other options as for instance to control, whether to enable several extensions
to the C++ Standard (as for instance variadics and placemarkers) or not.</P>
</BLOCKQUOTE>
<p>You can access all these processing parameters through the <tt>boost::wave::context</tt>
object. So you have to instantiate one object of this type to use the <tt>Wave</tt>
library. For more information about the context template class please refer
to the class reference <a href="class_reference_context.html">here</a>. To instantiate
the <tt>boost::wave::context</tt> object you have to supply at least two template parameters:
the iterator type of the underlying input stream to use and the type of the
token to be returned from the preprocessing engine.</p>
<P dir="ltr">The main preprocessing iterators are not to be instantiated directly,
but should be generated through this context object too. </P>
<pre><span class="comment"> // The following preprocesses a given input file.
// Open the file and read it into a string variable</span>
<span class="keyword">std::ifstream</span> instream(<span class="string">&quot;input.cpp&quot;</span>);<br> <span class="keyword">std::string </span>input<span class="keyword">(
std::istreambuf_iterator&lt;char&gt;</span>(instream.rdbuf());
<span class="keyword">std::istreambuf_iterator&lt;char&gt;</span>());
<span class="comment">// The template wave::cpplexer::lex_token&lt;&gt; is the token
// type to be used by the Wave library.
// This token type is one of the central types throughout
// the library, because it is a template parameter to many
// of the public classes and templates and it is returned
// from the iterators itself.</span>
<span class="keyword">typedef</span> boost::wave::context&lt;<span class=keyword>std::string::iterator</span>,
boost::wave::cpplexer::lex_token&lt;&gt; &gt;
context_t;
<span class="comment">// The C++ preprocessor iterators shouldn't be constructed
// directly. These are to be generated through a
// wave::context&lt;&gt; object. Additionally this wave::context&lt;&gt;
// object is to be used to initialize and define different
// parameters of the actual preprocessing.
</span> context_t ctx(input.begin(), input.end(), <span class="string">&quot;input.cpp&quot;</span>);
context_t::iterator_t first = ctx.begin();
context_t::iterator_t last = ctx.end();
<span class="comment"> // The preprocessing of the input stream is done on the fly
// behind the scenes during the iteration over the
// context_t::iterator_t based stream. </span>
<span class="keyword">while</span> (first != last) {
<span class="keyword">std::cout</span> &lt;&lt; (*first).get_value();
++first;
}
</pre>
<P dir="ltr">The constructor of the <tt>boost::wave::context</tt> object can
take a pair of arbitrary iterator types (at least <tt>input_iterator</tt> type
iterators) to the input stream, from where should be read the data to be preprocessed.
The third parameter supplies a filename, which is used subsequently inside the
preprocessed tokens returned from the preprocessing to indicate the token position
inside the underlying input stream. Note though, that this filename is used
only as long no <tt>#include</tt> or <tt>#line</tt> directives are encountered,
which in turn will alter the current filename.</P>
<P dir="ltr">The iteration over the preprocessed tokens is relativly straight
forward. Just get the starting and the ending iterators from the context object
(maybe after initializing some include search paths) and you are done! The dereferencing
of the iterator will return the preprocessed tokens, which are generated on
the fly from the input stream. To get further information about the token type,
you may want to look <a href="class_reference_tokentype.html">here</a>.</P>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="introduction.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="class_reference_context.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
<br>
<font size="2">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)
</font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Wednesday, January 14, 2004 12:41<!-- #EndDate -->
</span></body>
</html>

100
doc/references.html Normal file
View File

@@ -0,0 +1,100 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>References</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="theme/style.css" rel="stylesheet" type="text/css">
</head>
<body text="#000000" background="theme/bkd.gif">
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21"> <h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">References</font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="acknowledgements.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><img src="theme/r_arr_disabled.gif" width="20" height="19" border="0"></td>
</tr>
</table>
<br>
<table width="90%" border="0" align="center">
<tr>
<td class="table_cells"> 1.</td>
<td class="table_cells"> <a name="iso_cpp"></a>ISO/IEC </td>
<td class="table_cells"><a href="http://webstore.ansi.org/ansidocstore/product.asp?sku=INCITS%2FISO%2FIEC%2B14882%2D1998">&quot;Programming
languages - C++&quot;</a> <br>
ISO/IEC 14882:1998</td>
</tr>
<tr>
<td width="36" class="table_cells">2.</td>
<td width="236" class="table_cells"> <a name="iso_c"></a>INCITS/ISO/IEC </td>
<td width="520" class="table_cells"><a href="http://webstore.ansi.org/ansidocstore/product.asp?sku=INCITS/ISO/IEC%2B9899-1999">&quot;Programming
languages - C&quot;</a> <br>
INCITS/ISO/IEC 9899:1999</td>
</tr>
<tr>
<td class="table_cells">3.</td>
<td class="table_cells"> <a name="re2c"></a>Peter Bumbulis and <br>
Donald D. Cowan</td>
<td class="table_cells"><a href="http://www.tildeslash.org/re2c/index.html">Re2c
V0.9.1 </a><br>
A tool for generating C-based recognizers from regular expressions</td>
</tr>
<tr>
<td class="table_cells">4.</td>
<td class="table_cells"><a name="spirit"></a>Joel de Guzman et.al.</td>
<td class="table_cells"><a href="http://spirit.sourceforge.net/">Spirit v1.6.0
documentation</a></td>
</tr>
<tr>
<td class="table_cells">5.</td>
<td class="table_cells"><a name="slex"></a>Daniel C. Nuffer</td>
<td class="table_cells"><a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/boost/boost/libs/spirit/example/application/slex/">The
<tt>Spirit</tt> Slex example</a></td>
</tr>
<tr>
<td class="table_cells">6.</td>
<td class="table_cells"><a name="cpplexer"></a>Juan Carlos Arevalo-Baeza</td>
<td class="table_cells"><a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/boost/boost/libs/spirit/example/application/cpp_lexer/">The
<tt>Spirit</tt> cpplexer example</a></td>
</tr>
<tr>
<td class="table_cells">7.</td>
<td class="table_cells"><a name="pp_lib"></a>Vesa Karvonen and <br>
Paul Mensonides </td>
<td class="table_cells"><a href="http://www.boost.org/libs/preprocessor/doc/index.html">The
Boost Library Preprocessor Subset for C/C++</a> </td>
</tr>
<tr>
<td class="table_cells">8.</td>
<td class="table_cells"><a name="boost"></a>boost.org</td>
<td class="table_cells"><a href="http://www.boost.org">The Boost Libraries
Documentation.</a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="acknowledgements.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><img src="theme/r_arr_disabled.gif" width="20" height="19" border="0"></td>
</tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
<br>
<font size="2">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)
</font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Monday, January 5, 2004 14:57<!-- #EndDate -->
</span></body>
</html>

93
doc/samples.html Normal file
View File

@@ -0,0 +1,93 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Introduction</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="theme/style.css" type="text/css">
</head>
<body text="#000000" background="theme/bkd.gif">
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21">
<h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">Samples</font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="wave_driver.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="references.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p dir="ltr">The <tt>Wave</tt> library contains several samples illustrating how to use the different features. This section describes these samples and its main characteristics. </p>
<h2>The <strong>cpp_tokens sample </strong></h2>
<p dir="ltr">The <tt>cpp_tokens</tt> sample dumps out the information contained within the tokens returned from the iterator supplied by the <tt>Wave</tt> library. It shows, how to use the <tt>Wave</tt> library in conjunction with custom lexer and custom token types. The lexer used within this sample is <tt>SLex</tt> <a href="references.html#slex">[5]</a> based, i.e. it <tt></tt> is feeded during runtime (at startup) with the token definitions (regular expressions) and generates a resulting DFA table. This table is used for token identification and is saved to disc afterwards to avoid the table generation process at the next program startup. The name of the file to which the DFA table is saved is <tt>wave_slex_lexer.dfa</tt>. </p>
<p dir="ltr">The main advantage of this <tt>SLex</tt> based lexer if compared to the default <tt>Re2C</tt> <a href="references.html#re2c">[3]</a> generated lexer is, that it provides not only the line information, where a particular token was recognized, but also the related column position. Otherwise the <tt>SLex</tt> based lexer is functionally fully compatible to the <tt>Re2C</tt> based one, i.e. you always may switch your application to use it, if you additionally need to get the column information back from the preprocessing. </p>
<p dir="ltr">Since no additional command line parameters are supported by this sample, it won't work well with include files, which aren't located in the same directory as the inspected input file. The command line syntax is straight forward:</p>
<pre> cpp_tokens input_file</pre>
<h2 dir="ltr">The list_includes sample </h2>
<p dir="ltr">The <tt>list_includes</tt> sample shows how the <tt>Wave</tt> library may be used to generate a include file dependency list for a particular input file. It completely depends on the default library configuration. The command line syntax for this sample is given below: </p>
<pre> Usage: list_includes [options] file ...:
-h [ --help ] : print out program usage (this message)
-v [ --version ] : print the version number
-I [ --path ] dir : specify additional include directory
-S [ --syspath ] dir : specify additional system include directory
</pre>
<p dir="ltr">Please note though, that this sample will output only those include file names, which are visible to the preprocessor, i.e. given the following code snippet, only one of the two include file directives is triggered during preprocess<!-- #BeginDate format:fcAm1m -->Saturday, January 24, 2004 19:15<!-- #EndDate -->ned</span><span class="special">(</span>INCLUDE_FILE_A<span class="special">)</span>
<span class="preprocessor"> #include</span> <span class="literal">&quot;file_a.h&quot;</span>
<span class="preprocessor"> #else</span>
<span class="preprocessor"> #include</span> <span class="literal">&quot;file_b.h&quot;</span>
<span class="preprocessor"> #endif</span>
</pre>
<p dir="ltr">Besides on the <tt>Wave</tt> library, this sample depends on the <tt>program_options</tt> library from <a href="mailto:ghost@cs.msu.su">Vladimir Prus</a>, recently adopted to Boost. Since this library isn't contained yet within Boost, you'll have to download it separately from <a href="http://boost-sandbox.sourceforge.net/program_options/">here</a>. It integrates well into the Boost build process, so no additional tools needed to use it with the Wave driver.</p>
<h2 dir="ltr">The wave sample</h2>
<p dir="ltr">Because of its general usefulness the <tt>wave</tt> sample isn't located in the sample directory of the library, but inside the tools directory of Boost. The wave sample is usable as a full fledged preprocessor executable
on top of any other C++ compiler. It outputs the textual representation of the
preprocessed tokens generated from a given input file. It is described in more details <a href="wave_driver.html">here</a>. </p>
<h2 dir="ltr">The waveidl sample </h2>
<p dir="ltr">The main point of the waveidl sample is to show, how a completely independent lexer type may be used in conjunction with the default token type of the <tt>Wave</tt> library. The lexer used in this sample is supposed to be used for an IDL language based preprocessor. It is based on the <tt>Re2C</tt> tool too, but recognizes a different set of tokens as the default C++ lexer contained within the <tt>Wave</tt> library. So this lexer does not recognize any keywords (except <tt>true</tt> and <tt>false</tt>, which are needed by the preprocessor itself). This is needed because there exist different IDL languages, where identifiers of one language may be keywords of others. Certainly this implies to postpone keyword identification after the preprocessing, but allows to use <tt>Wave</tt> for all of the IDL derivatives. </p>
<p dir="ltr">It is only possible to use the <tt>Wave</tt> library to write an IDL preprocessor, because the token sets for both languages are very similar. The tokens to be recognized by the <tt>waveidl</tt> IDL language preprocessor is nearly a complete subset of the full C++ token set. </p>
<p dir="ltr">The command line syntax usable for this sample is shown below:</p>
<pre> Usage: waveidl [options] [@config-file(s)] file:
Options allowed on the command line only:
-h [ --help ] : print out program usage (this message)
-v [ --version ] : print the version number
-c [ --copyright ] : print out the copyright statement
--config-file filepath : specify a config file (alternatively: @filepath)
Options allowed additionally in a config file:
-o [ --output ] path : specify a file to use for output instead of stdout
-I [ --include ] path : specify an additional include directory
-S [ --sysinclude ] syspath : specify an additional system include directory
-D [ --define ] macro[=[value]] : specify a macro to define
-P [ --predefine ] macro[=[value]] : specify a macro to predefine
-U [ --undefine ] macro : specify a macro to undefine
</pre>
<p dir="ltr">Besides on the <tt>Wave</tt> library, this sample depends on the <tt>program_options</tt> library from <a href="mailto:ghost@cs.msu.su">Vladimir Prus</a>, recently adopted to Boost. Since this library isn't contained yet within Boost, you'll have to download it separately from <a href="http://boost-sandbox.sourceforge.net/program_options/">here</a>. It integrates well into the Boost build process, so no additional tools needed to use it with the <tt>waveidl</tt> sample. </p>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="wave_driver.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="references.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
<br>
<font size="2">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) </font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Saturday, January 24, 2004 19:15<!-- #EndDate -->
</span>
<p>&nbsp;</p>
</body>
</html>
<!-- #BeginDate format:fcAm1m -->Saturday, January 24, 2004 19:15<!-- #EndDate --><!-- #BeginDate format:fcAm1m -->Saturday, January 24, 2004 19:15<!-- #EndDate -->

128
doc/supported_pragmas.html Normal file
View File

@@ -0,0 +1,128 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Supported Pragma Directives</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="theme/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21"> <h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">Supported
Pragma Directives</font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="predefined_macros.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="30"><a href="macro_expansion_process.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>The Wave preprocessor library supports a couple of specific <tt>#pragma</tt>
directives, which may be used to control some of the library features. All directives
described here are usable as conventional <tt>#pragma</tt> directives and as
<tt>operator&nbsp;_Pragma</tt> (if variadics are enabled). So for instance the
following directives are functionally identical:</p>
<pre> #pragma wave trace(enable) </pre>
<p>and </p>
<pre> _Pragma(&quot;wave trace(enable)&quot;)</pre>
<p>All <tt>Wave</tt> specific pragma's must have the general form <tt>'wave option[(value)]'</tt>,
where <tt>'wave'</tt> is the specific keyword, <tt>'option'</tt> is the concrete
pragma functionality to trigger and <tt>'value'</tt> is an optional value to
be supplied to the <tt>'option'</tt> functionality. The following table lists
all possible pragma functions supported by the <tt>Wave</tt> library. </p>
<table width="77%" border="0" align="center">
<tr>
<td colspan="4"> <p class="table_title">Supported pragma's</p></td>
</tr>
<tr>
<td> <p class="toc_title" width="36%">pragma option</p></td>
<td> <p class="toc_title" width="28%">pragma value</p></td>
<td> <p class="toc_title" width="36%">description</p></td>
<td> <p class="toc_title" width="36%">supported by</p></td>
</tr>
<tr>
<td class="table_cells" width="19%"> <p>trace</p></td>
<td class="table_cells" width="18%"> <p>enable/on/1<br>
disable/off/0</p></td>
<td class="table_cells" width="43%"><p>Enable or disable the tracing of the
macro expansion process. This is needed, even if there is given the --trace
command line option, because the trace output is generated only, if there
is at least one trace(enable) pragma found.</p></td>
<td class="table_cells" width="20%"><p>Wave library</p></td>
</tr>
<tr>
<td class="table_cells"><p>stop</p></td>
<td class="table_cells"><p>message</p></td>
<td class="table_cells"><p>Stop the execution of <tt>Wave</tt> and print out
the given message. This is very helpful for direct debugging purposes.</p></td>
<td class="table_cells"><p>Wave library</p></td>
</tr>
<tr>
<td class="table_cells"><p>system</p></td>
<td class="table_cells"><p>command</p></td>
<td class="table_cells"><p>Try to spawn the 'command' as a new operating system
command and intercept the generated stdout and stderr. The stdout output
of this command (if any) is retokenized and used as the replacement text
for the whole pragma, the stderr output is ignored. The command is considered
to be successful, if/when the return value is zero, otherwise an error
is reported. <br>
</p></td>
<td class="table_cells"><p>Wave library</p></td>
</tr>
<tr>
<td class="table_cells"><p>timer</p></td>
<td class="table_cells"><p> restart/0<br>
&lt;no value&gt; <br>
suspend<br>
resume </p></td>
<td class="table_cells"><p>The value <tt>restart</tt> set the current elapsed
time to 0 and restarts the timer.<br>
If no value is provided, the current elpsed time is printed to the std::cerr
stream.<br>
The values <tt>suspend</tt> and <tt>resume</tt> allow to temporarily stop
the timing.</p></td>
<td class="table_cells"><p>Wave driver</p></td>
</tr>
</table>
<p>All pragma's not listed here but flagged as <tt>'wave'</tt> are reported as
errors. The handling of all remaining pragma's depends on the compilation constant
<code><tt>WAVE_RETURN_PRAGMA_DIRECTIVES</tt></code>, which allows to specify,
if those pragmas are left unchanged in the output stream or not. Please note,
that the operator _Pragma variant is always subject to full preprocessing, before
the pragma itself is evaluated. The #pragma variant is subject to preprocessing
only, if the <code><tt>WAVE_PREPROCESS_PRAGMA_BODY</tt></code> compilation constant
was specified during compilation. For more information about the possible compilation
constants look <a href="compiletime_config.html">here</a>.</p>
<p>Additionally the Wave preprocessor supports the <tt>#pragma once</tt> directive,
which specifies that the file, in which the pragma resides, will be included
(opened) only once by the compiler in a build. This may be used to optimize
the preprocessing of larger compilation units, which include a lot of files. Note though, that the #pragma once directive is supported only, if the compile time constant <tt>WAVE_SUPPORT_PRAGMA_ONCE</tt> was given during compilation of the library</span>.</p>
<p>It is fairly easy to implement your own <tt>#pragma wave ... </tt> directives. All you have to do is to implement your own <tt>interpret_pragma</tt> function (see <a href="class_reference_tracepolicy.html#interpret_pragma">here</a>) which should the handle additional directives. For an example of how to do it, you may have a look at the Wave driver application, which implements the <tt>#pragma wave timer()</tt> directive with the help of a supplied <tt>interpret_pragma</tt> function. </p>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="./index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="predefined_macros.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="30"><a href="macro_expansion_process.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
<br>
<font size="2">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)
</font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Wednesday, January 14, 2004 12:48<!-- #EndDate -->
</span>
<p>&nbsp;</p>
</body>
</html>

BIN
doc/theme/bkd.gif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
doc/theme/bkd2.gif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 843 B

BIN
doc/theme/bullet.gif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 B

BIN
doc/theme/l_arr.gif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

BIN
doc/theme/l_arr_disabled.gif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 B

BIN
doc/theme/r_arr.gif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

BIN
doc/theme/r_arr_disabled.gif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 B

175
doc/theme/style.css vendored Normal file
View File

@@ -0,0 +1,175 @@
body
{
background-image: url(bkd.gif);
background-color: #FFFFFF;
margin: 1em 2em 1em 2em;
}
h1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; text-align: left; }
h2 { font: 140% sans-serif; font-weight: bold; text-align: left; }
h3 { font: 120% sans-serif; font-weight: bold; text-align: left; }
h4 { font: bold 100% sans-serif; font-weight: bold; text-align: left; }
h5 { font: italic 100% sans-serif; font-weight: bold; text-align: left; }
h6 { font: small-caps 100% sans-serif; font-weight: bold; text-align: left; }
pre
{
border-top: gray 1pt solid;
border-right: gray 1pt solid;
border-left: gray 1pt solid;
border-bottom: gray 1pt solid;
padding-top: 2pt;
padding-right: 2pt;
padding-left: 2pt;
padding-bottom: 2pt;
display: block;
font-family: "courier new", courier, mono;
background-color: #eeeeee; font-size: small
}
code
{
font-family: "Courier New", Courier, mono;
font-size: small
}
tt
{
display: inline;
font-family: "Courier New", Courier, mono;
color: #000099;
font-size: small
}
p
{
text-align: justify;
font-family: Georgia, "Times New Roman", Times, serif
}
ul
{
list-style-image: url(bullet.gif);
font-family: Georgia, "Times New Roman", Times, serif
}
ol
{
font-family: Georgia, "Times New Roman", Times, serif
}
a
{
font-weight: bold;
color: #003366;
text-decoration: none;
}
a:hover { color: #8080FF; }
.literal { color: #666666; font-style: italic}
.keyword { color: #000099}
.identifier {}
.comment { font-style: italic; color: #990000}
.special { color: #800040}
.preprocessor { color: #990099}
.string { font-style: italic; color: #666666}
.copyright { color: #666666; font-size: small}
.white_bkd { background-color: #FFFFFF}
.dk_grey_bkd { background-color: #999999}
.quotes { color: #666666; font-style: italic; font-weight: bold}
.note_box
{
display: block;
border-top: gray 1pt solid;
border-right: gray 1pt solid;
border-left: gray 1pt solid;
border-bottom: gray 1pt solid;
padding-right: 12pt;
padding-left: 12pt;
padding-bottom: 12pt;
padding-top: 12pt;
font-family: Arial, Helvetica, sans-serif;
background-color: #E2E9EF;
font-size: small; text-align: justify
}
.table_title
{
background-color: #648CCA;
font-family: Verdana, Arial, Helvetica, sans-serif; color: #FFFFFF;
font-weight: bold
; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 4px
}
.table_cells
{
background-color: #E2E9EF;
font-family: Geneva, Arial, Helvetica, san-serif;
font-size: small
; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 4px
}
.toc
{
DISPLAY: block;
background-color: #E2E9EF
font-family: Arial, Helvetica, sans-serif;
border-top: gray 1pt solid;
border-left: gray 1pt solid;
border-bottom: gray 1pt solid;
border-right: gray 1pt solid;
padding-top: 24pt;
padding-right: 24pt;
padding-left: 24pt;
padding-bottom: 24pt;
}
.toc_title
{
background-color: #648CCA;
padding-top: 4px;
padding-right: 4px;
padding-bottom: 4px;
padding-left: 4px;
font-family: Geneva, Arial, Helvetica, san-serif;
color: #FFFFFF;
font-weight: bold
}
.toc_cells
{
background-color: #E2E9EF;
padding-top: 4px;
padding-right: 4px;
padding-bottom: 4px;
padding-left: 4px;
font-family: Geneva, Arial, Helvetica, san-serif;
font-size: small
}
div.logo
{
float: right;
}
.toc_cells_L0 { background-color: #E2E9EF; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 4px; font-family: Geneva, Arial, Helvetica, san-serif; font-size: small }
.toc_cells_L1 { background-color: #E2E9EF; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 44px; font-family: Geneva, Arial, Helvetica, san-serif; font-size: small }
.toc_cells_L2 { background-color: #E2E9EF; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 88px; font-family: Geneva, Arial, Helvetica, san-serif; font-size: small }
.toc_cells_L3 { background-color: #E2E9EF; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 122px; font-family: Geneva, Arial, Helvetica, san-serif; font-size: small }
.toc_cells_L4 { background-color: #E2E9EF; padding-top: 4px; padding-right: 4px; padding-bottom: 4px; padding-left: 166px; font-family: Geneva, Arial, Helvetica, san-serif; font-size: small }
.updated {
font-size: x-small;
color: #666666;
font-style: italic;
}

BIN
doc/theme/u_arr.gif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 B

BIN
doc/theme/uc.gif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 919 B

BIN
doc/theme/wave.gif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 938 B

972
doc/token_ids.html Normal file
View File

@@ -0,0 +1,972 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>The Token Identifiers</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="theme/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21"> <h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">The
Token Identifiers</font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="class_reference_tokentype.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="class_reference_fileposition.html"><img src="theme/r_arr.gif" width="20" height="19" border="0"></a></td>
</tr>
</table>
<blockquote>
<p><a href="token_ids.html#literal_tokens">Table of literal token identifiers</a><br>
<a href="token_ids.html#whitespace_tokens">Table of white token identifiers</a><br>
<a href="token_ids.html#keyword_tokens">Table of keyword token identifiers</a><br>
<a href="token_ids.html#operator_tokens">Table of operator token identifiers</a><br>
<a href="token_ids.html#preprocessor_tokens">Table of preprocessor token identifiers</a></p>
</blockquote>
<p>The following tables contain all those tokens, which should be recognized by
a C++ lexer, which is to be used in conjunction with the <tt>Wave</tt> preprocessing
engine. The tokens are grouped into categories to simplify some internal logic
and eventually the driver programs. The token identifiers are defined as an
<tt>enum</tt>, and it is recommended to reuse this definition for your own lexer
implementations.</p>
<p>Note though, that the preprocessor engine does some token transformation, so
that not all of the listet here token identifiers may occur inside tokens, returned
from the preprocessing iterator.</p>
<a name="literal_tokens"></a>
<table width="70%" border="0" align="center">
<tr>
<td colspan="3"> <p class="table_title">List of literal token id's</p></td>
</tr>
<tr>
<td> <p class="toc_title" width="36%" >Token identifier</p></td>
<td> <p class="toc_title" width="28%" >Token category</p></td>
<td> <p class="toc_title" width="36%" >Token value</p></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_CHARLIT  </p></td>
<td class="table_cells" width="31%"> <p>CharacterLiteralTokenType</p></td>
<td class="table_cells" width="29%"><p><code>'a', '\t', '\u0057'</code></p></td>
</tr>
<tr>
<td class="table_cells" > <p>T_FLOATLIT </p></td>
<td class="table_cells" > <p>FloatingLiteralTokenType</p></td>
<td class="table_cells" ><code>-1.23456e78</code></td>
</tr>
<tr>
<td class="table_cells" > <p>T_IDENTIFIER </p></td>
<td class="table_cells" > <p>IdentifierTokenType</p></td>
<td class="table_cells" ><code> C++ identifier</code></td>
</tr>
<tr>
<td class="table_cells" > <p>T_OCTALINT </p></td>
<td class="table_cells" > <p>IntegerLiteralTokenType</p></td>
<td class="table_cells" ><code>007</code></td>
</tr>
<tr>
<td class="table_cells" > <p>T_DECIMALINT </p></td>
<td class="table_cells" > <p>IntegerLiteralTokenType</p></td>
<td class="table_cells" ><code>10</code></td>
</tr>
<tr>
<td class="table_cells" > <p>T_HEXAINT </p></td>
<td class="table_cells" > <p>IntegerLiteralTokenType</p></td>
<td class="table_cells" ><code>0x1234</code></td>
</tr>
<tr>
<td class="table_cells" > <p>T_INTLIT </p></td>
<td class="table_cells" > <p>IntegerLiteralTokenType</p></td>
<td class="table_cells" ><code>T_OCTALINT, T_DECIMALINT or T_HEXAINT</code></td>
</tr>
<tr>
<td class="table_cells" > <p>T_STRINGLIT </p></td>
<td class="table_cells" > <p>StringLiteralTokenType</p></td>
<td class="table_cells" ><code>&quot;abc&quot;</code></td>
</tr>
<tr>
<td class="table_cells" > <p>T_FALSE </p></td>
<td class="table_cells" > <p>BoolLiteralTokenType</p></td>
<td class="table_cells" ><code>false</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_TRUE </p></td>
<td class="table_cells" width="31%" > <p>BoolLiteralTokenType</p></td>
<td class="table_cells" width="29%" ><code>true</code></td>
</tr>
</table>
<br>
<a name="whitespace_tokens"></a>
<table width="70%" border="0" align="center">
<tr>
<td colspan="3"> <p class="table_title">List of whitespace token id's</p></td>
</tr>
<tr>
<td> <p class="toc_title" width="36%" >Token identifier</p></td>
<td> <p class="toc_title" width="28%" >Token category</p></td>
<td> <p class="toc_title" width="36%" >Token value</p></td>
</tr>
<tr>
<td class="table_cells" width="40%"> <p>T_ANY </p></td>
<td class="table_cells" width="31%"> <p>UnknownTokenType</p></td>
<td class="table_cells" width="29%"> <p><code>any value not matched otherwise</code></p></td>
</tr>
<tr>
<td class="table_cells" > <p>T_CCOMMENT </p></td>
<td class="table_cells" > <p>WhiteSpaceTokenType</p></td>
<td class="table_cells" > <p><code>/* ... */</code></p></td>
</tr>
<tr>
<td class="table_cells" > <p>T_CPPCOMMENT </p></td>
<td class="table_cells" > <p>WhiteSpaceTokenType</p></td>
<td class="table_cells" ><code>// ... \n</code></td>
</tr>
<tr>
<td class="table_cells" > <p>T_SPACE </p></td>
<td class="table_cells" > <p>WhiteSpaceTokenType</p></td>
<td class="table_cells" > <p>blank or '\t'</p></td>
</tr>
<tr>
<td class="table_cells" > <p>T_SPACE2 </p></td>
<td class="table_cells" > <p>WhiteSpaceTokenType</p></td>
<td class="table_cells" ><code>'\v' or '\f'</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_EOF </p></td>
<td class="table_cells" width="31%" > <p>EOFTokenType</p></td>
<td class="table_cells" width="29%" ><code>end of input</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_CONTLINE </p></td>
<td class="table_cells" width="31%" > <p>EOLTokenType</p></td>
<td class="table_cells" width="29%" ><code>'\\' followed by '\n'</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_NEWLINE </p></td>
<td class="table_cells" width="31%" > <p>EOLTokenType</p></td>
<td class="table_cells" width="29%" ><code>'\n'</code></td>
</tr>
</table>
<br>
<br>
<a name="keyword_tokens"></a>
<table width="70%" border="0" align="center">
<tr>
<td colspan="3"> <p class="table_title">List of keyword token id's</p></td>
</tr>
<tr>
<td> <p class="toc_title" width="36%" >Token identifier</p></td>
<td> <p class="toc_title" width="28%" >Token category</p></td>
<td> <p class="toc_title" width="36%" >Token value</p></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_ASM </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>asm</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_AUTO </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>auto</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_BOOL </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>bool</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_BREAK </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>break</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_CASE </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>case</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_CATCH </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>catch</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_CHAR </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>char</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_CLASS </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>class</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_CONST </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>const</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_CONSTCAST </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>const_cast</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_CONTINUE </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>continue</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_DEFAULT </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>default</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_DEFINED </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>defined</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_DELETE </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>delete</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_DO </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>do</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_DOUBLE </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>double</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_DYNAMICCAST </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>dynamic_cast</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_ELSE </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>else</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_ENUM </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>enum</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_EXPLICIT </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>explicit</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_EXPORT </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>export</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_EXTERN </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>extern</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_FLOAT </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>float</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_FOR </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>for</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_FRIEND </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>friend</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_GOTO </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>goto</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_IF </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>if</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_INLINE </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>inline</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_INT </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>int</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_LONG </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>long</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_MUTABLE </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>mutable</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_NAMESPACE </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>namespace</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_NEW </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>new</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_OPERATOR </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>operator</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PRIVATE </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>private</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PROTECTED </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>protected</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PUBLIC </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>public</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_REGISTER </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>register</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_REINTERPRETCAST </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>reinterpret_cast</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_RETURN </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>return</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_SHORT </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>short</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_SIGNED </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>signed</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_SIZEOF </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>sizeof</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_STATIC </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>static</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_STATICCAST </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>static_cast</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_STRUCT </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>struct</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_SWITCH </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>switch</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_TEMPLATE </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>template</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_THIS </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>this</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_THROW </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>throw</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_TRY </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>try</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_TYPEDEF </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>typedef</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_TYPEID </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>typeid</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_TYPENAME </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>typename</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_UNION </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>union</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_UNSIGNED </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>unsigned</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_USING </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>using</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_VIRTUAL </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>virtual</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_VOID </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>void</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_VOLATILE </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>volatile</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_WCHART </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>wchar_t</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_WHILE </p></td>
<td class="table_cells" width="31%" > <p>KeywordTokenType</p></td>
<td class="table_cells" width="29%" ><code>while</code></td>
</tr>
</table>
<br>
<a name="operator_tokens"></a>
<table width="70%" border="0" align="center">
<tr>
<td colspan="3"> <p class="table_title">List of operator token id's</p></td>
</tr>
<tr>
<td> <p class="toc_title" width="36%" >Token identifier</p></td>
<td> <p class="toc_title" width="28%" >Token category</p></td>
<td> <p class="toc_title" width="36%" >Token value</p></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_AND </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>&amp;</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_ANDAND </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>&amp;&amp;</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_ASSIGN </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>=</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_ANDASSIGN </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>&amp;=</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_OR </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>|</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_ORASSIGN </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>|=</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_XOR </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>^</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_XORASSIGN </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>^=</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_COMMA </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>,</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_COLON </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>:</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_DIVIDE </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>/</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_DIVIDEASSIGN </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>/=</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_DOT </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>.</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_DOTSTAR </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>.*</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_ELLIPSIS </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>...</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_EQUAL </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>==</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_GREATER </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>&gt;</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_GREATEREQUAL </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>&gt;=</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_LEFTBRACE </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>{</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_LESS </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>&lt;</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_LESSEQUAL </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>&lt;=</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_LEFTPAREN </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>(</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_LEFTBRACKET </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>[</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_MINUS </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>-</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_MINUSASSIGN </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>-=</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_MINUSMINUS </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>--</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PERCENT </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>%</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PERCENTASSIGN </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>%=</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_NOT </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>!</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_NOTEQUAL </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>!=</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_OROR </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>||</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PLUS </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>+</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PLUSASSIGN </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>+=</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PLUSPLUS </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>++</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_ARROW </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>-&gt;</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_ARROWSTAR </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>-&gt;*</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_QUESTION_MARK </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>?</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_RIGHTBRACE </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>}</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_RIGHTPAREN </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>)</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_RIGHTBRACKET </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>]</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_COLON_COLON </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>::</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_SEMICOLON </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>;</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_SHIFTLEFT </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>&lt;&lt;</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_SHIFTLEFTASSIGN </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>&lt;&lt;=</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_SHIFTRIGHT </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>&gt;&gt;</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_SHIFTRIGHTASSIGN </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>&gt;&gt;=</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_STAR </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>*</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_COMPL </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>~</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_STARASSIGN </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>*=</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_POUND_POUND </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>##</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_POUND </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType</p></td>
<td class="table_cells" width="29%" ><code>#</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_AND_ALT </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| AltTokenType</p></td>
<td class="table_cells" width="29%" ><code>bitand</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_ANDASSIGN_ALT </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| AltTokenType</p></td>
<td class="table_cells" width="29%" ><code>and_eq</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_OR_ALT </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| AltTokenType</p></td>
<td class="table_cells" width="29%" ><code>or</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_ORASSIGN_ALT </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| AltTokenType</p></td>
<td class="table_cells" width="29%" ><code>or_eq</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_XOR_ALT </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| AltTokenType</p></td>
<td class="table_cells" width="29%" ><code>xor</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_XORASSIGN_ALT </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| AltTokenType</p></td>
<td class="table_cells" width="29%" ><code>xor_eq</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_LEFTBRACE_ALT </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| AltTokenType</p></td>
<td class="table_cells" width="29%" ><code>&lt;%</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_LEFTBRACKET_ALT </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| AltTokenType</p></td>
<td class="table_cells" width="29%" ><code>&lt;:</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_NOT_ALT </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| AltTokenType</p></td>
<td class="table_cells" width="29%" ><code>not</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_NOTEQUAL_ALT </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| AltTokenType</p></td>
<td class="table_cells" width="29%" ><code>not_eq</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_RIGHTBRACE_ALT </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| AltTokenType</p></td>
<td class="table_cells" width="29%" ><code>%&gt;</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_RIGHTBRACKET_ALT </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| AltTokenType</p></td>
<td class="table_cells" width="29%" ><code>:&gt;</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_COMPL_ALT </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| AltTokenType</p></td>
<td class="table_cells" width="29%" ><code>compl</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_POUND_POUND_ALT </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| AltTokenType</p></td>
<td class="table_cells" width="29%" ><code>%:%:</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_POUND_ALT </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| AltTokenType</p></td>
<td class="table_cells" width="29%" ><code>%:</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_OR_TRIGRAPH </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| TriGraphTokenType</p></td>
<td class="table_cells" width="29%" ><code>??!</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_XOR_TRIGRAPH </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| TriGraphTokenType</p></td>
<td class="table_cells" width="29%" ><code>??'</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_LEFTBRACE_TRIGRAPH </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| TriGraphTokenType</p></td>
<td class="table_cells" width="29%" ><code>??&lt;</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_LEFTBRACKET_TRIGRAPH </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| TriGraphTokenType</p></td>
<td class="table_cells" width="29%" ><code>??(</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_RIGHTBRACE_TRIGRAPH </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| TriGraphTokenType</p></td>
<td class="table_cells" width="29%" ><code>??&gt;</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_RIGHTBRACKET_TRIGRAPH </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| TriGraphTokenType</p></td>
<td class="table_cells" width="29%" ><code>??)</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_COMPL_TRIGRAPH </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| TriGraphTokenType</p></td>
<td class="table_cells" width="29%" ><code>??-</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_POUND_POUND_TRIGRAPH </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| TriGraphTokenType</p></td>
<td class="table_cells" width="29%" ><code>??=??=</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_POUND_TRIGRAPH </p></td>
<td class="table_cells" width="31%" > <p>OperatorTokenType&nbsp;| TriGraphTokenType</p></td>
<td class="table_cells" width="29%" ><code>??=</code></td>
</tr>
</table>
<p><br>
<a name="preprocessor_tokens"></a> The preprocessor tokens listet in the following
table are returned by the C++ lexer only. The preprocessor naturally acts on
these tokens and they are not returned by dereferencing the preprocessing iterators.</p>
<table width="70%" border="0" align="center">
<tr>
<td colspan="3"> <p class="table_title">List of preprocessor token id's</p></td>
</tr>
<tr>
<td> <p class="toc_title" width="36%" >Token identifier</p></td>
<td> <p class="toc_title" width="28%" >Token category</p></td>
<td> <p class="toc_title" width="36%" >Token value</p></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PP_DEFINE </p></td>
<td class="table_cells" width="31%" > <p>PPTokenType</p></td>
<td class="table_cells" width="29%" ><code>#define</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PP_IF </p></td>
<td class="table_cells" width="31%" > <p>PPTokenType</p></td>
<td class="table_cells" width="29%" ><code>#if</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PP_IFDEF </p></td>
<td class="table_cells" width="31%" > <p>PPTokenType</p></td>
<td class="table_cells" width="29%" ><code>#ifdef</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PP_IFNDEF </p></td>
<td class="table_cells" width="31%" > <p>PPTokenType</p></td>
<td class="table_cells" width="29%" ><code>#ifndef</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PP_ELSE </p></td>
<td class="table_cells" width="31%" > <p>PPTokenType</p></td>
<td class="table_cells" width="29%" ><code>#else</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PP_ELIF </p></td>
<td class="table_cells" width="31%" > <p>PPTokenType</p></td>
<td class="table_cells" width="29%" ><code>#elif</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PP_ENDIF </p></td>
<td class="table_cells" width="31%" > <p>PPTokenType</p></td>
<td class="table_cells" width="29%" ><code>#endif</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PP_ERROR </p></td>
<td class="table_cells" width="31%" > <p>PPTokenType</p></td>
<td class="table_cells" width="29%" ><code>#error</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PP_LINE </p></td>
<td class="table_cells" width="31%" > <p>PPTokenType</p></td>
<td class="table_cells" width="29%" ><code>#line</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PP_PRAGMA </p></td>
<td class="table_cells" width="31%" > <p>PPTokenType</p></td>
<td class="table_cells" width="29%" ><code>#pragma</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PP_UNDEF </p></td>
<td class="table_cells" width="31%" > <p>PPTokenType</p></td>
<td class="table_cells" width="29%" ><code>#undef</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PP_WARNING </p></td>
<td class="table_cells" width="31%" > <p>PPTokenType</p></td>
<td class="table_cells" width="29%" ><code>#warning</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PP_INCLUDE </p></td>
<td class="table_cells" width="31%" > <p>PPTokenType</p></td>
<td class="table_cells" width="29%" ><code>#include &quot;...&quot;</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PP_QHEADER </p></td>
<td class="table_cells" width="31%" > <p>PPTokenType</p></td>
<td class="table_cells" width="29%" ><code>#include &lt;...&gt;</code></td>
</tr>
<tr>
<td class="table_cells" width="40%" > <p>T_PP_HHEADER </p></td>
<td class="table_cells" width="31%" > <p>PPTokenType</p></td>
<td class="table_cells" width="29%" ><code>#include ...</code></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="class_reference_tokentype.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
<td width="30"><a href="class_reference_fileposition.html"><img src="theme/r_arr.gif" width="20" height="19" border="0"></a></td>
</tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
<br>
<font size="2">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)
</font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Monday, January 5, 2004 14:57<!-- #EndDate -->
</span></body>
</html>

162
doc/tracing_facility.html Normal file
View File

@@ -0,0 +1,162 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>The Tracing Facility</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="theme/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21"> <h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">The
Tracing Facility</font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="wave_driver.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="30"><a href="acknowledgements.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>If you ever had the need to debug a macro expansion you had to discover, that
your tools provide only little or no support for this task. For this reason
the <i>Wave</i> library got a tracing facility, which allows to get selectively
some information about the expansion of a certain macro or several macros. </p>
<p>The tracing of macro expansions generates a possibly huge amount of information,
so it is recommended, that you explicitely enable/disable the tracing for the
macro in question only. This may be done with the help of a special, <tt>Wave</tt>
specific #pragma:</p>
<pre><span class="preprocessor"> #pragma</span> wave trace(enable) <span class="comment">// enable the tracing</span>
<span class="comment">// the macro expansions here will be traced</span>
<span class="comment">// ...</span>
<span class="preprocessor"> #pragma</span> wave trace(disable) <span class="comment">// disable the tracing</span></pre>
<p>In C99 mode or when specifying the <tt>--variadics</tt> command line option
you may additionally use the <tt>operator&nbsp;_Pragma()</tt> variant to enable/disable
the tracing output:</p>
<pre><span class="preprocessor"> #define</span> CONCAT(x, y) \
<span class="preprocessor">_Pragma</span>(<span class="string">&quot;wave trace(enable)&quot;</span>) \
x \
<span class="preprocessor">_Pragma</span>(<span class="string">&quot;wave trace(disable)&quot;</span>) \
<span class="keyword">##</span> y</pre>
<p>This way you have the possibility to enable the tracing during the expansion
of a part of a macro only. In the sample shown there is traced the expansion
of the macro argument <tt>'x'</tt> only. Note, that the <tt>operator _Pragma()</tt>
directives expand to nothing inside the macro expansion result.</p>
<p>To see, what the <tt>Wave</tt> driver generates while expanding a simple macro,
let's have a look at the tracing output for the following example:</p>
<pre ><span class="comment"> // test.cpp</span>
<span class="preprocessor"> #define</span> X(x) x<br><span class="preprocessor"> #define</span> Y() 2<br><span class="preprocessor"> #define</span> CONCAT_(x, y) x <span class="keyword">##</span> y
<span class="preprocessor"> #define</span> CONCAT(x, y) CONCAT_(x, y)
<span class="preprocessor"> #pragma</span> wave trace(enable)
<span class="comment"> // this macro expansion is to be traced</span>
CONCAT(X(1), Y()) <span class="comment">// should expand to 12</span>
<span class="preprocessor"> #pragma</span> wave trace(disable)</pre>
<p>When preprocessed with <tt>'wave -t test.trace test.cpp'</tt> the <tt>Wave</tt>
driver generates a file <tt>test.trace</tt>, which contains (without the line
numbers in front of the lines):</p>
<pre> 1: test.cpp(8): CONCAT(X(1), Y())
2: test.cpp(5): see macro definition: CONCAT(x, y)
3: invoked with
4: [
5: x = X(1)
6: y = Y()
7: ]
8: [
9: test.cpp(2): see macro definition: X(x)
10: invoked with
11: [
12: x = 1
13: ]
14: [
15: 1
16: rescanning
17: [
18: 1
19: ]
20: ]
21: test.cpp(3): see macro definition: Y()
22: [
23: 2
24: rescanning
25: [
26: 2
27: ]
28: ]
29: CONCAT_(1, 2)
30: rescanning
31: [
32: test.cpp(4): see macro definition: CONCAT_(x, y)
33: invoked with
34: [
35: x = 1
36: y = 2
37: ]
38: [
39: 12
40: rescanning
41: [
42: 12
43: ]
44: ]
45: 12
46: ]
47: ]
</pre>
<p>The generated trace output is very verbose, but allows to follow every step
of the actual macro expansion process. The first line in this tracing example
contains the reference to the position, from where the macro expansion was initiated.
Additionally the following information is contained for every single macro expansion:</p>
<ul>
<li>The reference to the position, where the macro to expand was defined first
(see lines 2, 9, 21 and 32).</li>
<li>The real parameters supplied for this macro expansion (see lines 3, 10 and
33), this information is traced inside the <tt>invoked with</tt> block, where
the corresponding formal and actual parameters are listed.</li>
<li>The expansion of the given arguments (if any and if these are defined as
macros). This repeats the full tracing information for the argument macro
expansion, only intended by one level. Note though, that the macro expansion
of the actual arguments is traced, regardless of the fact, if this argument
is really to be inserted into the replacement list only after its expansion
or as it was initially supplied (see C++ Standard [16.3.1.1]: &quot;A parameter
in the replacement list, unless preceded by a <tt>#</tt> or <tt>##</tt> preprocessing
token or followed by a <tt>##</tt> preprocessing token, is replaced by the
corresponding argument after all macros contained therein have been expanded&quot;
<a href="references.html#iso_cpp">[1]</a>). </li>
<li>The result of the argument substitution (see lines 15, 23, 29 and 39), i.e.
the substituted replacement list.</li>
<li>The rescanning process, which again includes the full subsequent macro expansion
process of all found macros (see C++ Standard [16.3.4.1]: &quot;After all
parameters in the replacement list have been substituted, the resulting preprocessing
token sequence is rescanned with all subsequent preprocessing tokens of the
source file for more macro names to replace.&quot; <a href="references.html#iso_cpp">[1]</a>).</li>
<li>The result of the actual macro expansion (this is the last line inside the
corresponding rescanning block - see lines 18, 26, 42 and 45).</li>
</ul>
<p>Every found macro to expand will add an additional indentation level inside
the trace output.</p>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="./index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="wave_driver.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="30"><a href="acknowledgements.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
<br>
<font size="2">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)
</font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Sunday, January 4, 2004 0:17<!-- #EndDate -->
</span>
</body>
</html>
<!-- #BeginDate format:fcAm1m -->Monday, January 5, 2004 14:57<!-- #EndDate -->

215
doc/wave_driver.html Normal file
View File

@@ -0,0 +1,215 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>The Wave Driver</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="theme/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21"> <h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">The
Wave Driver</font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="preliminary_cpp0x_support.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="30"><a href="tracing_facility.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<p>There is implemented a driver program for the <tt>Wave</tt> library, which
utilizes nearly all capabilities of the library. It is usable as a preprocessor executable
on top of any other C++ compiler. It outputs the textual representation of the
preprocessed tokens generated from a given input file. This driver program has
the following command line syntax:</p>
<pre>Usage: wave [options] [@config-file(s)] file:
Options allowed on the command line only:
-h [--help]: print out program usage (this message)
-v [--version]: print the version number
-c [--copyright]: print out the copyright statement
--config-file filepath: specify a config file (alternatively: @filepath)
Options allowed additionally in a config file:
-o [--output] path: specify a file to use for output instead of stdout
-I [--include] path: specify an additional include directory
-S [--sysinclude] syspath: specify an additional system include directory
-F [--forceinclude] file: force inclusion of the given file
-D [--define] macro[=[value]]: specify a macro to define
-P [--predefine] macro[=[value]]: specify a macro to predefine
-U [--undefine] macro: specify a macro to undefine
-n [--nesting] depth: specify a new maximal include nesting depth
Extended options (allowed everywhere)
-t [--traceto] path: output trace info to a file [path] or to stderr [-]
--timer output overall elapsed computing time
--variadics: enable variadics and placemarkers in C++ mode
--c99: enable C99 mode (implies variadics and placemarkers)
--c++0x: enable C++0x support (implies --variadics)
</pre>
<P dir="ltr">The possible options are straightforward and self explanatory. The
following describes some of these options in more detail. Please note, that
the extended options (--c99 and --variadics) are available only, if the driver
was compiled with the constant <tt>WAVE_SUPPORT_VARIADICS_PLACEMARKERS</tt>
defined. </P>
<P dir="ltr">-o [--output] path</P>
<blockquote>
<p dir="ltr">Specify a filename to be used for the generated preprocessed output
stream. If this option is not given, then the standard output is used (stdout).</p>
</blockquote>
<P dir="ltr">-I [--include] option</P>
<blockquote>
<p dir="ltr">Add the given directory to the head of the list of directories
to be searched for header files. This can be used to override a system header
file, substituting your own version, since these directories are searched
before the system header file directories.<!-- #BeginDate format:fcAm1m -->Saturday, January 24, 2004 18:56<!-- #EndDate -->-right order, the system directories
come after. </p>
</blockquote>
<p dir="ltr">-I- [--include-] option</p>
<blockquote>
<p dir="ltr">The <tt>Wave</tt> library maintains two separate search pathes
for include files. A search path for user include files and a search path
for system include files. Any directories specified with '-I' options before
an eventually given '-I-' option are searched only for the case of '#include&nbsp;&quot;file&quot;'
(user include files), they are not searched for '#include&nbsp;&lt;file&gt;'
directives (system include files). If additional directories are specified
with '-I' options after a '-I-' option was given, these directories are searched
for all '#include' directives. In addition, the '-I-' option inhibits the
use of the current directory as the first search directory for '#include &quot;file&quot;'
directives. Therefore, the current directory is searched only if it is requested
explicitly with a '-I.' option. Specifying both '-I-' and '-I.' allows to
control precisely which directories are searched before the current one and
which are searched after.</p>
</blockquote>
<p dir="ltr">-S [--sysinclude] option</p>
<blockquote>
<p dir="ltr">Add the given directory to the head of the list of directories
to be searched for system header files. If you use more than one '-S' option,
the directories are scanned in left-to-right order. This option is most useful
in the wave.cfg configuration file to specify, where the system include files
are to be searched.</p>
</blockquote>
<p dir="ltr">-F [--forceinclude] option</p>
<blockquote>
<p dir="ltr">Process the given file as normal input and include all the resulting
output before the processing the regular input file starts. If more than one
such option is given, the files are pre-included in the sequence of its occurance
on the command line.</p>
</blockquote>
<p dir="ltr">-D [--define] macro[=definition]<br>-P [--predefine] macro[=definition]</p>
<blockquote>
<p dir="ltr">This option allows to define ('-D') or predefine ('-P') a macro
from the command line. The string given in conjunction with the '-D' or '-P'
option should conform to the usual syntax MACRO(x)=definition as is described
in more detail <a href="class_reference_context.html#add_macro_definition">here</a>.</p>
<p dir="ltr"> The only difference between the '-D' and the '-P' options is,
that the latter predefines a macro such, that it is <b>not</b> undefinable
through an <tt>#undef</tt> directive from inside the preprocessed program.</p>
</blockquote>
<p dir="ltr">-U [--undefine] option</p>
<blockquote>
<p dir="ltr">This allows to undefine some of the automatically predefined macros
of the <tt>Wave</tt> library (see Predefined macros). The only exception are
the <code class="keyword">__LINE__</code>, <code class="keyword">__FILE__</code>,
<code class="keyword">__DATE__</code>, <code class="keyword">__TIME__</code>,
<code class="keyword">__STDC__</code> and <code class="keyword">__cplusplus</code>
predefined macros, which are not undefinable. If -U and -D are both specified
for one name, the name is not predefined.</p>
</blockquote>
<p dir="ltr">-n [--nesting] depth</p>
<blockquote>
<p dir="ltr">Specify a new maximal include nesting depth. If the preprocessing
reaches this include file nesting depth, it aborts the preprocessing after
emitting an error message. The default include file nesting depth is 1024.</p>
</blockquote>
<p dir="ltr">-t [--traceto] path</p>
<blockquote>
<p dir="ltr">Enable the tracing facility build into the <tt>Wave</tt> library.
The path specifies the filename to use for the output of the generated trace
log. If the filename given equals to <tt>'-'</tt> (without the quotes), the
trace log is put into the standard error stream (stderr).</p>
</blockquote>
<p dir="ltr">--timer</p>
<blockquote>
<p dir="ltr">Enable to track the overall elapsed computing time required for
the given input file. The elapsed time is printed to stdout after the compilation
is completed.</p>
</blockquote>
<p dir="ltr">--variadics</p>
<blockquote>
<p dir="ltr">Enables support for variadics (macros with variable parameter lists),
placemarkers (empty macro arguments) and <tt>operator&nbsp;_Pragma</tt> in
normal C++ mode. This option predefines a special predefined macro <tt>__WAVE_HAS_VARIADICS__</tt>.</p>
</blockquote>
<p dir="ltr">--c99</p>
<blockquote>
<p dir="ltr">Enable the C99 mode. This mode enables certain C99 specific features
as variadics (macros with variable parameter lists), placemarkers (empty macro
arguments) and <tt>operator&nbsp;_Pragma</tt> support and disables some C++
specific token types as for <tt>'::'</tt>, <tt>'-&gt;*'</tt> and <tt>'-&gt;.'</tt>.
Several predefined macros are different for this mode, for more information
about predefined macros you may look <a href="predefined_macros.html">here</a>.
<br>
Note that the --c99 and the --c++0x options are mutually exclusive. If both
options are given a diagnostic is provided and the C99 mode is assumed.</p>
</blockquote>
<p dir="ltr">--c++0x</p>
<blockquote>
<p dir="ltr">Enable the (experimental) C++0x mode. This mode enables certain
C++ features, which are to be proposed for the new C++ Standard as macro scopes,
variadics, placemarkers and well defined pasting of unrelated tokens.<br>
Note that the --c99 and the --c++0x options are mutually exclusive. If both
options are given a diagnostic is provided and the C99 mode is assumed.</p>
<p dir="ltr">This option is available only, if the library was compiled with
the <tt>WAVE_ENABLE_CPP0X_EXTENSIONS</tt> compile time constant defined (for
more information about this constant please refere <a href="compiletime_config.html">here</a>).</p>
</blockquote>
<p dir="ltr">@ [--config-file] option</p>
<blockquote>
<p dir="ltr">Some of the possible command line options may be specified inside
of special configuration files. This is very useful, as a shorthand for different
global configurations. A config file may contain additional options (-I, -S,
-F, -U, -D and -P options), one option per line. Empty lines and lines beginning
with a '#' character are ignored (are treated as a comment lines). Note that
the '#' character is treated as the beginning of a comment only, if it is
the first non-whitespace character on a line.</p>
<p dir="ltr"> There is a shorthand for specifying a configuration file on the
command line: simply use the '@' character immediatly before the corresponding
file name.</p>
<p dir="ltr"> The options found in a configuration file are interpreted, as
if they were place instead of the configuration file option on the command
line.</p>
</blockquote>
<p dir="ltr">The <tt>Wave</tt> driver program looks at startup for a configuration
file named 'wave.cfg' in the same directory, where it was startet from (where
is located the driver executable). If this file exists, it is treated as a normal
configuration file and the specified herein options are interpreted as if they
were given as the first options on the command line. This feature is very useful
for defining a global environment for the <tt>Wave</tt> preprocessor driver.</p>
<p dir="ltr">Besides on the <tt>Wave</tt> library, this sample depends on the <tt>program_options</tt> library from <a href="mailto:ghost@cs.msu.su">Vladimir Prus</a>, recently adopted to Boost. Since this library isn't contained yet within Boost, you'll have to download it separately from <a href="http://boost-sandbox.sourceforge.net/program_options/">here</a>. It integrates well into the Boost build process, so no additional tools needed to use it with the Wave driver.</p>
<table border="0">
<tr>
<td width="10"></td>
<td width="30"><a href="./index.html"><img src="theme/u_arr.gif" border="0"></a></td>
<td width="30"><a href="preliminary_cpp0x_support.html"><img src="theme/l_arr.gif" border="0"></a></td>
<td width="30"><a href="tracing_facility.html"><img src="theme/r_arr.gif" border="0"></a></td>
</tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
<br>
<font size="2">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)
</font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Saturday, January 24, 2004 18:56<!-- #EndDate -->
</span></body>
</html>

21
include/boost/wave.hpp Normal file
View File

@@ -0,0 +1,21 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(WAVE_HPP_DCA0EA51_EF5B_4BF1_88A8_461DBC5F292B_INCLUDED)
#define WAVE_HPP_DCA0EA51_EF5B_4BF1_88A8_461DBC5F292B_INCLUDED
#include <boost/wave/wave_config.hpp>
#include <boost/wave/cpp_exceptions.hpp>
#include <boost/wave/cpplexer/cpplexer_exceptions.hpp>
#include <boost/wave/cpp_context.hpp>
#endif // !defined(WAVE_HPP_DCA0EA51_EF5B_4BF1_88A8_461DBC5F292B_INCLUDED)

View File

@@ -0,0 +1,305 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Definition of the preprocessor context
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(CPP_CONTEXT_HPP_907485E2_6649_4A87_911B_7F7225F3E5B8_INCLUDED)
#define CPP_CONTEXT_HPP_907485E2_6649_4A87_911B_7F7225F3E5B8_INCLUDED
#include <string>
#include <vector>
#include <stack>
#include <boost/concept_check.hpp>
#include <boost/wave/wave_config.hpp>
#include <boost/wave/token_ids.hpp>
#include <boost/wave/util/unput_queue_iterator.hpp>
#include <boost/wave/util/cpp_ifblock.hpp>
#include <boost/wave/util/cpp_include_pathes.hpp>
#include <boost/wave/util/iteration_context.hpp>
#include <boost/wave/util/cpp_iterator.hpp>
#include <boost/wave/util/cpp_macromap.hpp>
#include <boost/wave/trace_policies.hpp>
#include <boost/wave/cpp_iteration_context.hpp>
#include <boost/wave/language_support.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
///////////////////////////////////////////////////////////////////////////////
//
// The C preprocessor context template class
//
// The boost::wave::context template is the main interface class to
// control the behaviour of the preprocessing engine.
//
// The following template parameters has to be supplied:
//
// IteratorT The iterator type of the underlying input stream
// LexIteratorT The lexer iterator type to use as the token factory
// InputPolicyT The input policy type to use for loading the files
// to be included. This template parameter is optional and
// defaults to the
// iteration_context_policies::load_file_to_string
// type
// TraceT The trace policy to use for trace and include file
// notification callback.
//
///////////////////////////////////////////////////////////////////////////////
template <
typename IteratorT,
typename LexIteratorT,
typename InputPolicyT = iteration_context_policies::load_file_to_string,
typename TraceT = trace_policies::default_tracing
>
class context {
public:
// concept checks
// the given iterator shall be at least a forward iterator type
BOOST_CLASS_REQUIRE(IteratorT, boost, ForwardIteratorConcept);
// public typedefs
typedef typename LexIteratorT::token_t token_t;
typedef context<IteratorT, LexIteratorT, InputPolicyT, TraceT>
self_t;
typedef IteratorT target_iterator_t;
typedef LexIteratorT lex_t;
typedef pp_iterator<self_t> iterator_t;
typedef InputPolicyT input_policy_t;
typedef typename token_t::position_t position_t;
// type of a token sequence
typedef std::list<token_t, boost::fast_pool_allocator<token_t> >
token_sequence_t;
// types of the policies
typedef TraceT trace_policy_t;
private:
// stack of shared_ptr's to the pending iteration contexts
typedef boost::shared_ptr<base_iteration_context<lex_t> > iteration_ptr_t;
typedef boost::wave::util::iteration_context_stack<iteration_ptr_t>
iteration_context_stack_t;
typedef typename iteration_context_stack_t::size_type iter_size_t;
public:
context(target_iterator_t const &first_, target_iterator_t const &last_,
char const *fname = "<Unknown>", TraceT const &trace_ = TraceT())
: first(first_), last(last_), filename(fname)
#if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
, current_filename(fname)
#endif
, macros(*this), language(boost::wave::support_cpp), trace(trace_)
{
macros.init_predefined_macros();
includes.init_initial_path();
includes.set_current_directory(filename.c_str());
}
// iterator interface
iterator_t begin()
{
return iterator_t(*this, first, last, position_t(filename.c_str()),
get_language());
}
iterator_t end() const
{ return iterator_t(); }
// maintain include paths
bool add_include_path(char const *path_)
{ return includes.add_include_path(path_, false);}
bool add_sysinclude_path(char const *path_)
{ return includes.add_include_path(path_, true);}
void set_sysinclude_delimiter() { includes.set_sys_include_delimiter(); }
typename iteration_context_stack_t::size_type get_iteration_depth() const
{ return iter_ctxs.size(); }
// maintain defined macros
#if BOOST_WAVE_ENABLE_COMMANDLINE_MACROS != 0
bool add_macro_definition(std::string macrostring,
bool is_predefined = false)
{ return boost::wave::util::add_macro_definition(*this, macrostring,
is_predefined, get_language()); }
#endif
bool add_macro_definition(token_t const &name, bool has_params,
std::vector<token_t> &parameters, token_sequence_t &definition,
bool is_predefined = false)
{ return macros.add_macro(name, has_params, parameters, definition,
is_predefined); }
template <typename IteratorT2>
bool is_defined_macro(IteratorT2 const &begin, IteratorT2 const &end)
{ return macros.is_defined(begin, end); }
bool remove_macro_definition(typename token_t::string_t const &name,
bool even_predefined = false)
{ return macros.remove_macro(name, even_predefined); }
void reset_macro_definitions()
{ macros.reset_macromap(); macros.init_predefined_macros(); }
// get the pp-iterator version information
static std::string get_version()
{ return boost::wave::util::predefined_macros::get_fullversion(false); }
static std::string get_version_string()
{ return boost::wave::util::predefined_macros::get_versionstr(false); }
void set_language(boost::wave::language_support language_)
{
language = language_;
reset_macro_definitions();
}
boost::wave::language_support get_language() const { return language; }
// change and ask for maximal possible include nesting depth
void set_max_include_nesting_depth(iter_size_t new_depth)
{ iter_ctxs.set_max_include_nesting_depth(new_depth); }
iter_size_t get_max_include_nesting_depth() const
{ return iter_ctxs.get_max_include_nesting_depth(); }
// enable/disable tracing
void enable_tracing(trace_policies::trace_flags enable)
{ trace.enable_tracing(enable); }
trace_policies::trace_flags tracing_enabled()
{ return trace.tracing_enabled(); }
trace_policy_t &get_trace_policy() { return trace; }
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
protected:
friend class boost::wave::pp_iterator<
boost::wave::context<IteratorT, lex_t, InputPolicyT, TraceT> >;
friend class boost::wave::impl::pp_iterator_functor<
boost::wave::context<IteratorT, lex_t, InputPolicyT, TraceT> >;
#endif
// maintain include pathes (helper functions)
bool find_include_file (std::string &s, bool is_system,
char const *current_file) const
{ return includes.find_include_file(s, is_system, current_file); }
void set_current_directory(char const *path_)
{ includes.set_current_directory(path_); }
// conditional compilation contexts
bool get_if_block_status() const { return ifblocks.get_status(); }
void enter_if_block(bool new_status)
{ ifblocks.enter_if_block(new_status); }
bool enter_elif_block(bool new_status)
{ return ifblocks.enter_elif_block(new_status); }
bool enter_else_block() { return ifblocks.enter_else_block(); }
bool exit_if_block() { return ifblocks.exit_if_block(); }
typename boost::wave::util::if_block_stack::size_type get_if_block_depth() const
{ return ifblocks.get_if_block_depth(); }
// stack of iteration contexts
iteration_ptr_t pop_iteration_context()
{ iteration_ptr_t top = iter_ctxs.top(); iter_ctxs.pop(); return top; }
void push_iteration_context(position_t const &act_pos, iteration_ptr_t iter_ctx)
{ iter_ctxs.push(act_pos, iter_ctx); }
position_t &get_main_pos() { return macros.get_main_pos(); }
///////////////////////////////////////////////////////////////////////////////
//
// expand_tokensequence():
// expands all macros contained in a given token sequence, handles '##'
// and '#' pp operators and re-scans the resulting sequence
// (essentially preprocesses the token sequence).
//
// The expand_undefined parameter is true during macro expansion inside
// a C++ expression given for a #if or #elif statement.
//
///////////////////////////////////////////////////////////////////////////////
template <typename IteratorT2>
token_t expand_tokensequence(IteratorT2 &first, IteratorT2 const &last,
token_sequence_t &pending, token_sequence_t &expanded,
bool expand_undefined = false)
{
return macros.expand_tokensequence(first, last, pending, expanded,
expand_undefined);
}
template <typename IteratorT2>
void expand_whole_tokensequence(IteratorT2 &first, IteratorT2 const &last,
token_sequence_t &expanded, bool expand_undefined = true)
{
bool seen_qualified_name = false;
macros.expand_whole_tokensequence(expanded, first, last,
expand_undefined, &seen_qualified_name);
// remove any contained placeholder
boost::wave::util::impl::remove_placeholders(expanded);
}
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
// experimental: macro scoping support
template <typename IteratorT2>
void import_name(IteratorT2 const &begin, IteratorT2 const &end)
{ macros.import_name(begin, end); }
template <typename IteratorT2>
void begin_scope(IteratorT2 const &begin, IteratorT2 const &end)
{ macros.begin_scope(begin, end); }
void begin_unnamed_scope() { macros.begin_unnamed_scope(); }
void end_scope() { macros.end_scope(); }
#endif
public:
#if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
// support for #pragma once
// maintain the real name of the current preprocessed file
void set_current_filename(char const *real_name)
{ current_filename = real_name; }
std::string const &get_current_filename() const
{ return current_filename; }
// maintain the list of known headers containing #pragma once
bool has_pragma_once(std::string const &filename)
{ return includes.has_pragma_once(filename); }
bool add_pragma_once_header(std::string const &filename)
{ return includes.add_pragma_once_header(filename); }
#endif
template <typename ContainerT>
bool interpret_pragma(ContainerT &pending, token_t const &option,
ContainerT const &values, token_t const &act_token,
boost::wave::language_support language)
{
return trace.interpret_pragma(pending, option, values, act_token,
language);
}
private:
// the main input stream
target_iterator_t const &first; // underlying input stream
target_iterator_t const &last;
std::string filename; // associated main filename
#if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
std::string current_filename; // real name of current preprocessed file
#endif
boost::wave::util::if_block_stack ifblocks; // conditional compilation contexts
boost::wave::util::include_pathes includes; // lists of include directories to search
iteration_context_stack_t iter_ctxs; // iteration contexts
boost::wave::util::macromap<self_t> macros; // map of defined macros
boost::wave::language_support language; // supported language/extensions
trace_policy_t trace; // trace policy instance
};
///////////////////////////////////////////////////////////////////////////////
} // namespace wave
} // namespace boost
#endif // !defined(CPP_CONTEXT_HPP_907485E2_6649_4A87_911B_7F7225F3E5B8_INCLUDED)

View File

@@ -0,0 +1,287 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(CPP_EXCEPTIONS_HPP_5190E447_A781_4521_A275_5134FF9917D7_INCLUDED)
#define CPP_EXCEPTIONS_HPP_5190E447_A781_4521_A275_5134FF9917D7_INCLUDED
#include <exception>
#include <string>
#include <boost/assert.hpp>
#include <boost/config.hpp>
#include <boost/wave/wave_config.hpp>
///////////////////////////////////////////////////////////////////////////////
// helper macro for throwing exceptions
#if !defined(BOOST_WAVE_THROW)
#ifdef BOOST_NO_STRINGSTREAM
#include <strstream>
#define BOOST_WAVE_THROW(cls, code, msg, act_pos) \
{ \
using namespace boost::wave; \
std::strstream stream; \
stream << cls::severity_text(cls::code) << ": " \
<< cls::error_text(cls::code); \
if ((msg)[0] != 0) stream << ": " << (msg); \
stream << std::ends; \
std::string throwmsg = stream.str(); stream.freeze(false); \
throw cls(throwmsg.c_str(), cls::code, (act_pos).get_line(), \
(act_pos).get_column(), (act_pos).get_file().c_str()); \
} \
/**/
#else
#include <sstream>
#define BOOST_WAVE_THROW(cls, code, msg, act_pos) \
{ \
using namespace boost::wave; \
std::stringstream stream; \
stream << cls::severity_text(cls::code) << ": " \
<< cls::error_text(cls::code); \
if ((msg)[0] != 0) stream << ": " << (msg); \
stream << std::ends; \
throw cls(stream.str().c_str(), cls::code, (act_pos).get_line(), \
(act_pos).get_column(), (act_pos).get_file().c_str()); \
} \
/**/
#endif // BOOST_NO_STRINGSTREAM
#endif // BOOST_WAVE_THROW
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
///////////////////////////////////////////////////////////////////////////////
// exception severity
namespace util {
enum severity {
severity_remark = 0,
severity_warning,
severity_error,
severity_fatal,
severity_commandline_error
};
inline char const *
get_severity(severity level)
{
static char const *severity_text[] =
{
"remark", // severity_remark
"warning", // severity_warning
"error", // severity_error
"fatal error", // severity_fatal
"command line error" // severity_commandline_error
};
BOOST_ASSERT(severity_remark <= level &&
level <= severity_commandline_error);
return severity_text[level];
}
}
///////////////////////////////////////////////////////////////////////////////
// cpp_exception, the base class for all specific C preprocessor exceptions
class cpp_exception
: public std::exception
{
public:
cpp_exception(int line_, int column_, char const *filename_) throw()
: line(line_), column(column_)
{
unsigned int off = 0;
while (off < sizeof(filename) && *filename_)
filename[off++] = *filename_++;
filename[off] = 0;
}
~cpp_exception() throw() {}
virtual char const *what() const throw() = 0; // to be overloaded
virtual char const *description() const throw() = 0;
int line_no() const throw() { return line; }
int column_no() const throw() { return column; }
char const *file_name() const throw() { return filename; }
protected:
char filename[512];
int line;
int column;
};
///////////////////////////////////////////////////////////////////////////////
// preprocessor error
class preprocess_exception :
public cpp_exception
{
public:
enum error_code {
unexpected_error = 0,
macro_redefinition,
macro_insertion_error,
bad_include_file,
bad_include_statement,
ill_formed_directive,
error_directive,
warning_directive,
ill_formed_expression,
missing_matching_if,
missing_matching_endif,
ill_formed_operator,
bad_define_statement,
too_few_macroarguments,
too_many_macroarguments,
improperly_terminated_macro,
bad_line_statement,
bad_undefine_statement,
bad_macro_definition,
illegal_redefinition,
duplicate_parameter_name,
invalid_concat,
last_line_not_terminated,
ill_formed_pragma_option,
include_nesting_too_deep,
misplaced_operator,
unexpected_endregion,
illegal_global_region,
alreadydefined_name,
undefined_macroname,
invalid_macroname,
unexpected_qualified_name
};
preprocess_exception(char const *what_, error_code code, int line_,
int column_, char const *filename_) throw()
: cpp_exception(line_, column_, filename_), level(severity_level(code))
{
unsigned int off = 0;
while (off < sizeof(buffer) && *what_)
buffer[off++] = *what_++;
buffer[off] = 0;
}
~preprocess_exception() throw() {}
virtual char const *what() const throw()
{
return "boost::wave::preprocess_exception";
}
virtual char const *description() const throw()
{
return buffer;
}
util::severity get_severity()
{
return level;
}
static char const *error_text(int code)
{
// error texts in this array must appear in the same order as the items in
// the error enum above
static char const *preprocess_exception_errors[] = {
"unexpected error (should not happen)", // unexpected_error
"illegal macro redefinition", // macro_redefinition
"macro definition failed (out of memory?)", // macro_insertion_error
"could not find include file", // bad_include_file
"ill formed #include directive", // bad_include_statement
"ill formed preprocessor directive", // ill_formed_directive
"encountered #error directive or #pragma wave stop()", // error_directive
"encountered #warning directive", // warning_directive
"ill formed preprocessor expression", // ill_formed_expression
"the #if for this directive is missing", // missing_matching_if
"detected at least one missing #endif directive", // missing_matching_endif
"ill formed preprocessing operator", // ill_formed_operator
"ill formed #define directive", // bad_define_statement
"too few macro arguments", // too_few_macroarguments
"too many macro arguments", // too_many_macroarguments
"improperly terminated macro invocation "
"or replacement-list terminates in partial "
"macro expansion (not supported yet)", // improperly_terminated_macro
"ill formed #line directive", // bad_line_statement
"#undef may not be used on this predefined name", // bad_undefine_statement
"invalid macro definition", // bad_macro_definition
"this predefined name may not be redefined", // illegal_redefinition
"duplicate macro parameter name", // duplicate_parameter_name
"pasting the following two tokens does not "
"give a valid preprocessing token", // invalid_concat
"last line of file ends without a newline", // last_line_not_terminated
"unknown or illformed pragma option", // ill_formed_pragma_option
"include files nested too deep", // include_nesting_too_deep
"misplaced operator defined()", // misplaced_operator
"unexpected " BOOST_WAVE_PP_ENDREGION " at global scope", // unexpected_endregion
"a global " BOOST_WAVE_PP_REGION " may not be opened "
"inside a nameless " BOOST_WAVE_PP_REGION, // illegal_global_region
"the name is already used in this scope as "
"a macro or scope name", // alreadydefined_name
"undefined macro or scope name may not be imported", // undefined_macroname
"ill formed macro name or " BOOST_WAVE_PP_REGION " name", // invalid_macroname
"qualified names are supported in C++0x mode only" // unexpected_qualified_name
};
BOOST_ASSERT(unexpected_error <= code &&
code <= unexpected_qualified_name);
return preprocess_exception_errors[code];
}
static util::severity severity_level(int code)
{
static util::severity preprocess_exception_severity[] = {
util::severity_fatal, // unexpected_error
util::severity_warning, // macro_redefinition
util::severity_fatal, // macro_insertion_error
util::severity_error, // bad_include_file
util::severity_error, // bad_include_statement
util::severity_error, // ill_formed_directive
util::severity_fatal, // error_directive
util::severity_warning, // warning_directive
util::severity_error, // ill_formed_expression
util::severity_error, // missing_matching_if
util::severity_error, // missing_matching_endif
util::severity_error, // ill_formed_operator
util::severity_error, // bad_define_statement
util::severity_warning, // too_few_macroarguments
util::severity_warning, // too_many_macroarguments
util::severity_error, // improperly_terminated_macro
util::severity_warning, // bad_line_statement
util::severity_warning, // bad_undefine_statement
util::severity_commandline_error, // bad_macro_definition
util::severity_warning, // illegal_redefinition
util::severity_error, // duplicate_parameter_name
util::severity_error, // invalid_concat
util::severity_warning, // last_line_not_terminated
util::severity_warning, // ill_formed_pragma_option
util::severity_fatal, // include_nesting_too_deep
util::severity_error, // misplaced_operator
util::severity_error, // unexpected_endregion
util::severity_error, // illegal_global_region
util::severity_error, // alreadydefined_name
util::severity_error, // undefined_macroname
util::severity_error, // invalid_macroname
util::severity_error // unexpected_qualified_name
};
BOOST_ASSERT(unexpected_error <= code &&
code <= unexpected_qualified_name);
return preprocess_exception_severity[code];
}
static char const *severity_text(int code)
{
return util::get_severity(severity_level(code));
}
private:
char buffer[512];
util::severity level;
};
///////////////////////////////////////////////////////////////////////////////
} // namespace wave
} // namespace boost
#endif // !defined(CPP_EXCEPTIONS_HPP_5190E447_A781_4521_A275_5134FF9917D7_INCLUDED)

View File

@@ -0,0 +1,195 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Definition of the preprocessor context
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(CPP_ITERATION_CONTEXT_HPP_00312288_9DDB_4668_AFE5_25D3994FD095_INCLUDED)
#define CPP_ITERATION_CONTEXT_HPP_00312288_9DDB_4668_AFE5_25D3994FD095_INCLUDED
#include <iterator>
#include <fstream>
#if defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)
#include <sstream>
#endif
#include <boost/wave/wave_config.hpp>
#include <boost/wave/cpp_exceptions.hpp>
#include <boost/wave/language_support.hpp>
#include <boost/wave/util/file_position.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace iteration_context_policies {
///////////////////////////////////////////////////////////////////////////////
//
// The iteration_context_policies templates are policies for the
// boost::wave::iteration_context which allows to control, how a given input file
// is to be represented by a pair of iterators pointing to the begin and
// the end of the resulting input sequence.
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//
// load_file_to_string
//
// Loads a file into a string and returns the iterators pointing to
// the beginning and the end of the loaded string.
//
///////////////////////////////////////////////////////////////////////////
struct load_file_to_string {
template <typename IterContextT>
class inner {
public:
template <typename PositionT>
static
void init_iterators(IterContextT &iter_ctx,
PositionT const &act_pos)
{
typedef typename IterContextT::iterator_t iterator_t;
std::ifstream instream(iter_ctx.filename.c_str());
if (!instream.is_open()) {
BOOST_WAVE_THROW(preprocess_exception, bad_include_file,
iter_ctx.filename, act_pos);
}
instream.unsetf(std::ios::skipws);
#if defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)
// this is known to be very slow for large files on some systems
std::copy (istream_iterator<char>(instream),
istream_iterator<char>(),
std::inserter(iter_ctx.instring, iter_ctx.instring.end()));
#else
iter_ctx.instring = std::string(
std::istreambuf_iterator<char>(instream.rdbuf()),
std::istreambuf_iterator<char>());
#endif // defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)
iter_ctx.first = iterator_t(iter_ctx.instring.begin(),
iter_ctx.instring.end(), PositionT(iter_ctx.filename),
iter_ctx.language);
iter_ctx.last = iterator_t();
}
private:
std::string instring;
};
};
///////////////////////////////////////////////////////////////////////////////
//
// load_file
//
// The load_file policy opens a given file and returns the wrapped
// istreambuf_iterators.
//
///////////////////////////////////////////////////////////////////////////////
struct load_file {
template <typename IterContextT>
class inner {
public:
~inner() { if (instream.is_open()) instream.close(); }
template <typename PositionT>
static
void init_iterators(IterContextT &iter_ctx,
PositionT const &act_pos)
{
typedef typename IterContextT::iterator_t iterator_t;
iter_ctx.instream.open(iter_ctx.filename.c_str());
if (!iter_ctx.instream.is_open()) {
BOOST_WAVE_THROW(preprocess_exception, bad_include_file,
iter_ctx.filename, act_pos);
}
iter_ctx.instream.unsetf(std::ios::skipws);
using boost::spirit::make_multi_pass;
iter_ctx.first = iterator_t(
make_multi_pass(std::istreambuf_iterator<char>(
iter_ctx.instream.rdbuf())),
make_multi_pass(std::istreambuf_iterator<char>()),
PositionT(iter_ctx.filename), iter_ctx.language);
iter_ctx.last = iterator_t();
}
private:
std::ifstream instream;
};
};
} // namespace iterattion_context_policies
///////////////////////////////////////////////////////////////////////////////
//
template <typename IteratorT>
struct base_iteration_context {
public:
base_iteration_context(BOOST_WAVE_STRINGTYPE const &fname)
: real_filename(fname), filename(fname), line(1), emitted_lines(1)
{}
base_iteration_context(IteratorT const &first_, IteratorT const &last_,
BOOST_WAVE_STRINGTYPE const &fname)
: first(first_), last(last_), real_filename(fname), filename(fname),
line(1), emitted_lines(1)
{}
// the actual input stream
IteratorT first; // actual input stream position
IteratorT last; // end of input stream
BOOST_WAVE_STRINGTYPE real_filename; // real name of the current file
BOOST_WAVE_STRINGTYPE filename; // actual processed file
int line; // line counter of underlying stream
int emitted_lines; // count of emitted newlines
};
///////////////////////////////////////////////////////////////////////////////
//
template <
typename IteratorT,
typename InputPolicyT =
iteration_context_policies::load_file_to_string
>
struct iteration_context
: public base_iteration_context<IteratorT>,
public InputPolicyT::template
inner<iteration_context<IteratorT, InputPolicyT> >
{
typedef IteratorT iterator_t;
typedef typename IteratorT::token_t::position_t position_t;
typedef iteration_context<IteratorT, InputPolicyT> self_t;
iteration_context(BOOST_WAVE_STRINGTYPE const &fname,
position_t const &act_pos,
boost::wave::language_support language_)
: base_iteration_context<IteratorT>(fname),
language(language_)
{
InputPolicyT::template inner<self_t>::init_iterators(*this, act_pos);
}
boost::wave::language_support language;
};
///////////////////////////////////////////////////////////////////////////////
} // namespace wave
} // namespace boost
#endif // !defined(CPP_ITERATION_CONTEXT_HPP_00312288_9DDB_4668_AFE5_25D3994FD095_INCLUDED)

View File

@@ -0,0 +1,82 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Definition of the abstract lexer interface
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(CPP_LEX_INTERFACE_HPP_E83F52A4_90AC_4FBE_A9A7_B65F7F94C497_INCLUDED)
#define CPP_LEX_INTERFACE_HPP_E83F52A4_90AC_4FBE_A9A7_B65F7F94C497_INCLUDED
#include <boost/wave/util/file_position.hpp>
#include <boost/wave/language_support.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace cpplexer {
///////////////////////////////////////////////////////////////////////////////
//
// new_lexer_gen: generates a new instance of the required C++ lexer
//
///////////////////////////////////////////////////////////////////////////////
template <typename TokenT> struct lex_input_interface;
template <
typename IteratorT,
typename PositionT = boost::wave::util::file_position_t
>
struct new_lexer_gen
{
// The NewLexer function allows the opaque generation of a new lexer object.
// It is coupled to the token type to allow to decouple the lexer/token
// configurations at compile time.
static lex_input_interface<lex_token<PositionT> > *
new_lexer(IteratorT const &first, IteratorT const &last,
PositionT const &pos, boost::wave::language_support language);
};
///////////////////////////////////////////////////////////////////////////////
//
// The lex_input_interface decouples the lex_iterator_shim from the actual
// lexer. This is done to allow compile time reduction.
// Thanks to JCAB for having this idea.
//
///////////////////////////////////////////////////////////////////////////////
template <typename TokenT>
struct lex_input_interface
{
typedef typename TokenT::position_t position_t;
virtual TokenT get() = 0;
virtual void set_position(position_t const &pos) = 0;
virtual ~lex_input_interface() {}
// The new_lexer function allows the opaque generation of a new lexer object.
// It is coupled to the token type to allow to distinguish different
// lexer/token configurations at compile time.
template <typename IteratorT>
static lex_input_interface *
new_lexer(IteratorT const &first, IteratorT const &last,
position_t const &pos, boost::wave::language_support language)
{
return new_lexer_gen<IteratorT, position_t>::new_lexer (first, last,
pos, language);
}
};
///////////////////////////////////////////////////////////////////////////////
} // namespace cpplexer
} // namespace wave
} // namespace boost
#endif // !defined(CPP_LEX_INTERFACE_HPP_E83F52A4_90AC_4FBE_A9A7_B65F7F94C497_INCLUDED)

View File

@@ -0,0 +1,135 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Definition of the lexer iterator
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(CPP_LEX_ITERATOR_HPP_AF0C37E3_CBD8_4F33_A225_51CF576FA61F_INCLUDED)
#define CPP_LEX_ITERATOR_HPP_AF0C37E3_CBD8_4F33_A225_51CF576FA61F_INCLUDED
#include <string>
#include <iostream>
#include <boost/assert.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/spirit/iterator/multi_pass.hpp>
#include <boost/wave/util/file_position.hpp>
#include <boost/wave/util/functor_input.hpp>
#include <boost/wave/cpplexer/cpp_lex_interface.hpp>
#include <boost/wave/language_support.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace cpplexer {
namespace impl {
///////////////////////////////////////////////////////////////////////////////
//
// lex_iterator_functor_shim
//
///////////////////////////////////////////////////////////////////////////////
template <typename TokenT>
class lex_iterator_functor_shim
{
public:
template <typename IteratorT>
lex_iterator_functor_shim(IteratorT const &first, IteratorT const &last,
typename TokenT::position_t const &pos,
boost::wave::language_support language)
: functor_ptr(lex_input_interface<TokenT>
::new_lexer(first, last, pos, language))
{}
// interface to the boost::spirit::multi_pass_policies::functor_input policy
typedef TokenT result_type;
static result_type const eof;
result_type operator()()
{
BOOST_ASSERT(0 != functor_ptr.get());
return functor_ptr->get();
}
void set_position(typename TokenT::position_t const &pos)
{
BOOST_ASSERT(0 != functor_ptr.get());
functor_ptr->set_position(pos);
}
private:
boost::shared_ptr<lex_input_interface<TokenT> > functor_ptr;
};
///////////////////////////////////////////////////////////////////////////////
// eof token
template <typename LexT>
typename lex_iterator_functor_shim<LexT>::result_type const
lex_iterator_functor_shim<LexT>::eof;
///////////////////////////////////////////////////////////////////////////////
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
//
// lex_iterator
//
// A generic C++ lexer interface class, which allows to plug in different
// lexer implementations (template parameter LexT). The following
// requirement apply:
//
// - the lexer type should have a function implemented, which returnes
// the next lexed token from the input stream:
// typename LexT::token_t get();
// - at the end of the input stream this function should return the
// eof token equivalent
// - the lexer should implement a constructor taking two iterators
// pointing to the beginning and the end of the input stream and
// a third parameter containing the name of the parsed input file
//
///////////////////////////////////////////////////////////////////////////////
template <typename TokenT>
class lex_iterator
: public boost::spirit::multi_pass<
impl::lex_iterator_functor_shim<TokenT>,
boost::wave::util::functor_input
>
{
typedef impl::lex_iterator_functor_shim<TokenT> input_policy_t;
typedef
boost::spirit::multi_pass<input_policy_t,
boost::wave::util::functor_input>
base_t;
typedef lex_iterator<TokenT> self_t;
public:
typedef TokenT token_t;
lex_iterator()
{}
template <typename IteratorT>
lex_iterator(IteratorT const &first, IteratorT const &last,
typename TokenT::position_t const &pos,
boost::wave::language_support language)
: base_t(input_policy_t(first, last, pos, language))
{}
};
///////////////////////////////////////////////////////////////////////////////
} // namespace cpplexer
} // namespace wave
} // namespace boost
#endif // !defined(CPP_LEX_ITERATOR_HPP_AF0C37E3_CBD8_4F33_A225_51CF576FA61F_INCLUDED)

View File

@@ -0,0 +1,109 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
A generic C++ lexer token definition
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(CPP_TOKEN_HPP_53A13BD2_FBAA_444B_9B8B_FCB225C2BBA8_INCLUDED)
#define CPP_TOKEN_HPP_53A13BD2_FBAA_444B_9B8B_FCB225C2BBA8_INCLUDED
#include <boost/wave/wave_config.hpp>
#include <boost/wave/util/file_position.hpp>
#include <boost/wave/token_ids.hpp>
#include <boost/wave/language_support.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace cpplexer {
///////////////////////////////////////////////////////////////////////////////
// forward declaration of the token type
template <typename PositionT = boost::wave::util::file_position_t>
class lex_token;
///////////////////////////////////////////////////////////////////////////////
//
// lex_token
//
///////////////////////////////////////////////////////////////////////////////
template <typename PositionT>
class lex_token
{
public:
typedef BOOST_WAVE_STRINGTYPE string_t;
typedef PositionT position_t;
lex_token()
: id(T_EOI)
{}
lex_token(token_id id_, string_t const &value_, PositionT const &pos_)
: id(id_), value(value_), pos(pos_)
{}
// accessors
operator token_id() const { return id; }
string_t const &get_value() const { return value; }
position_t const &get_position() const { return pos; }
void set_token_id (token_id id_) { id = id_; }
void set_value (string_t const &newval) { value = newval; }
void set_position (position_t const &pos_) { pos = pos_; }
// debug support
#if BOOST_WAVE_DUMP_PARSE_TREE != 0
// access functions for the tree_to_xml functionality
static int get_token_id(lex_token const &t)
{ return ID_FROM_TOKEN(token_id(t)); }
static string_t get_token_value(lex_token const &t)
{ return t.get_value(); }
#endif
#if defined(BOOST_SPIRIT_DEBUG)
// debug support
void print (std::ostream &stream) const
{
stream << get_token_name(id) << "(";
for (std::size_t i = 0; i < value.size(); ++i) {
switch (value[i]) {
case '\r': stream << "\\r"; break;
case '\n': stream << "\\n"; break;
default:
stream << value[i];
break;
}
}
stream << ")";
}
#endif // defined(BOOST_SPIRIT_DEBUG)
private:
token_id id; // the token id
string_t value; // the text, which was parsed into this token
PositionT pos; // the original file position
};
#if defined(BOOST_SPIRIT_DEBUG)
template <typename PositionT>
inline std::ostream &
operator<< (std::ostream &stream, lex_token<PositionT> const &object)
{
object.print(stream);
return stream;
}
#endif // defined(BOOST_SPIRIT_DEBUG)
///////////////////////////////////////////////////////////////////////////////
} // namespace cpplexer
} // namespace wave
} // namespace boost
#endif // !defined(CPP_TOKEN_HPP_53A13BD2_FBAA_444B_9B8B_FCB225C2BBA8_INCLUDED)

View File

@@ -0,0 +1,195 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(CPPLEXER_EXCEPTIONS_HPP_1A09DE1A_6D1F_4091_AF7F_5F13AB0D31AB_INCLUDED)
#define CPPLEXER_EXCEPTIONS_HPP_1A09DE1A_6D1F_4091_AF7F_5F13AB0D31AB_INCLUDED
#include <exception>
#include <string>
#include <boost/assert.hpp>
#include <boost/config.hpp>
#include <boost/wave/wave_config.hpp>
///////////////////////////////////////////////////////////////////////////////
// helper macro for throwing exceptions
#if !defined(BOOST_WAVE_LEXER_THROW)
#ifdef BOOST_NO_STRINGSTREAM
#include <strstream>
#define BOOST_WAVE_LEXER_THROW(cls, code, msg, line, column, name) \
{ \
using namespace boost::wave; \
std::strstream stream; \
stream << cls::severity_text(cls::code) << ": " \
<< cls::error_text(cls::code); \
if (msg[0] != 0) stream << ": " << msg; \
stream << std::ends; \
std::string throwmsg = stream.str(); stream.freeze(false); \
throw cls(throwmsg.c_str(), cls::code, line, column, name); \
} \
/**/
#else
#include <sstream>
#define BOOST_WAVE_LEXER_THROW(cls, code, msg, line, column, name) \
{ \
using namespace boost::wave; \
std::stringstream stream; \
stream << cls::severity_text(cls::code) << ": " \
<< cls::error_text(cls::code); \
if (msg[0] != 0) stream << ": " << msg; \
stream << std::ends; \
throw cls(stream.str().c_str(), cls::code, line, column, name); \
} \
/**/
#endif // BOOST_NO_STRINGSTREAM
#endif // BOOST_WAVE_LEXER_THROW
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace cpplexer {
///////////////////////////////////////////////////////////////////////////////
// exception severity
namespace util {
enum severity {
severity_remark = 0,
severity_warning,
severity_error,
severity_fatal
};
inline char const *
get_severity(severity level)
{
static char const *severity_text[] =
{
"remark", // severity_remark
"warning", // severity_warning
"error", // severity_error
"fatal error" // severity_fatal
};
BOOST_ASSERT(severity_remark <= level && level <= severity_fatal);
return severity_text[level];
}
}
///////////////////////////////////////////////////////////////////////////////
// cpplexer_exception, the base class for all specific C++ lexer exceptions
class cpplexer_exception
: public std::exception
{
public:
cpplexer_exception(int line_, int column_, char const *filename_) throw()
: line(line_), column(column_)
{
unsigned int off = 0;
while (off < sizeof(filename) && *filename_)
filename[off++] = *filename_++;
filename[off] = 0;
}
~cpplexer_exception() throw() {}
virtual char const *what() const throw() = 0; // to be overloaded
virtual char const *description() const throw() = 0;
int line_no() const throw() { return line; }
int column_no() const throw() { return column; }
char const *file_name() const throw() { return filename; }
protected:
char filename[512];
int line;
int column;
};
///////////////////////////////////////////////////////////////////////////////
// lexing_exception error
class lexing_exception :
public cpplexer_exception
{
public:
enum error_code {
unexpected_error = 0,
universal_char_invalid = 1,
universal_char_base_charset = 2,
universal_char_not_allowed = 3,
generic_lexing_error = 4
};
lexing_exception(char const *what_, error_code code, int line_,
int column_, char const *filename_) throw()
: cpplexer_exception(line_, column_, filename_),
level(severity_level(code))
{
unsigned int off = 0;
while (off < sizeof(buffer) && *what_)
buffer[off++] = *what_++;
buffer[off] = 0;
}
~lexing_exception() throw() {}
virtual char const *what() const throw()
{
return "boost::wave::lexing_exception";
}
virtual char const *description() const throw()
{
return buffer;
}
util::severity get_severity()
{
return level;
}
static char const *error_text(int code)
{
// error texts in this array must appear in the same order as the items in
// the error enum above
static char const *preprocess_exception_errors[] = {
"unexpected error (should not happen)", // unexpected_error
"universal character name specifies an invalid character", // universal_char_invalid
"a universal character name cannot designate a character in the "
"basic character set", // universal_char_base_charset
"this universal character is not allowed in an identifier", // universal_char_not_allowed
"generic lexing error" // generic_lexing_error
};
return preprocess_exception_errors[code];
}
static util::severity severity_level(int code)
{
static util::severity preprocess_exception_severity[] = {
util::severity_fatal, // unexpected_error
util::severity_error, // universal_char_invalid
util::severity_error, // universal_char_base_charset
util::severity_error, // universal_char_not_allowed
util::severity_error // generic_lexing_error
};
return preprocess_exception_severity[code];
}
static char const *severity_text(int code)
{
return util::get_severity(severity_level(code));
}
private:
char buffer[512];
util::severity level;
};
///////////////////////////////////////////////////////////////////////////////
} // namespace cpplexer
} // namespace wave
} // namespace boost
#endif // !defined(CPPLEXER_EXCEPTIONS_HPP_1A09DE1A_6D1F_4091_AF7F_5F13AB0D31AB_INCLUDED)

View File

@@ -0,0 +1,53 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Copyright (c) 2001 Daniel C. Nuffer
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(AQ_HPP_A21D9145_B643_44C0_81E7_DB346DD67EE1_INCLUDED)
#define AQ_HPP_A21D9145_B643_44C0_81E7_DB346DD67EE1_INCLUDED
#include <cstdlib>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace cpplexer {
namespace re2clex {
typedef std::size_t aq_stdelement;
typedef struct tag_aq_queuetype
{
std::size_t head;
std::size_t tail;
std::size_t size;
std::size_t max_size;
aq_stdelement* queue;
} aq_queuetype;
typedef aq_queuetype* aq_queue;
int aq_enqueue(aq_queue q, aq_stdelement e);
int aq_enqueue_front(aq_queue q, aq_stdelement e);
int aq_serve(aq_queue q, aq_stdelement *e);
int aq_pop(aq_queue q);
#define AQ_EMPTY(q) (q->size == 0)
#define AQ_FULL(q) (q->size == q->max_size)
aq_queue aq_create(void);
void aq_terminate(aq_queue q);
int aq_grow(aq_queue q);
///////////////////////////////////////////////////////////////////////////////
} // namespace re2clex
} // namespace cpplexer
} // namespace wave
} // namespace boost
#endif // !defined(AQ_HPP_A21D9145_B643_44C0_81E7_DB346DD67EE1_INCLUDED)

View File

@@ -0,0 +1,35 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Re2C based C++ lexer
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(CPP_RE_HPP_B76C4F5E_63E9_4B8A_9975_EC32FA6BF027_INCLUDED)
#define CPP_RE_HPP_B76C4F5E_63E9_4B8A_9975_EC32FA6BF027_INCLUDED
#include <boost/wave/token_ids.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace cpplexer {
namespace re2clex {
///////////////////////////////////////////////////////////////////////////////
// The scanner function to call whenever a new token is requested
boost::wave::token_id scan(Scanner *s);
///////////////////////////////////////////////////////////////////////////////
} // namespace re2clex
} // namespace cpplexer
} // namespace wave
} // namespace boost
#endif // !defined(CPP_RE_HPP_B76C4F5E_63E9_4B8A_9975_EC32FA6BF027_INCLUDED)

View File

@@ -0,0 +1,301 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Re2C based C++ lexer
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(CPP_RE2C_LEXER_HPP_B81A2629_D5B1_4944_A97D_60254182B9A8_INCLUDED)
#define CPP_RE2C_LEXER_HPP_B81A2629_D5B1_4944_A97D_60254182B9A8_INCLUDED
#include <string>
#include <cstdio>
#include <cstdarg>
#if defined(BOOST_SPIRIT_DEBUG)
#include <iostream>
#endif // defined(BOOST_SPIRIT_DEBUG)
#include <boost/concept_check.hpp>
#include <boost/assert.hpp>
#include <boost/spirit/core.hpp>
#include <boost/wave/wave_config.hpp>
#include <boost/wave/language_support.hpp>
#include <boost/wave/token_ids.hpp>
#include <boost/wave/util/file_position.hpp>
#include <boost/wave/cpplexer/validate_universal_char.hpp>
#include <boost/wave/cpplexer/cpplexer_exceptions.hpp>
#include <boost/wave/cpplexer/token_cache.hpp>
#include <boost/wave/cpplexer/cpp_lex_token.hpp>
#include <boost/wave/cpplexer/cpp_lex_interface.hpp>
#include <boost/wave/cpplexer/re2clex/scanner.hpp>
#include <boost/wave/cpplexer/re2clex/cpp.re.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace cpplexer {
namespace re2clex {
///////////////////////////////////////////////////////////////////////////////
//
// encapsulation of the re2c based cpp lexer
//
///////////////////////////////////////////////////////////////////////////////
template <typename IteratorT, typename PositionT = boost::wave::util::file_position_t>
class lexer
{
public:
typedef char char_t;
typedef Scanner base_t;
typedef lex_token<PositionT> token_t;
typedef typename token_t::string_t string_t;
lexer(IteratorT const &first, IteratorT const &last,
PositionT const &pos, boost::wave::language_support language);
~lexer();
lex_token<PositionT> get();
void set_position(PositionT const &pos)
{
filename = pos.get_file();
scanner.line = pos.get_line();
scanner.file_name = filename.c_str();
}
// error reporting from the re2c generated lexer
static int report_error(Scanner *s, char *, ...);
private:
static char const *tok_names[];
Scanner scanner;
string_t filename;
string_t value;
bool at_eof;
token_cache<string_t> token_cache;
};
///////////////////////////////////////////////////////////////////////////////
// initialize cpp lexer
template <typename IteratorT, typename PositionT>
inline
lexer<IteratorT, PositionT>::lexer(IteratorT const &first,
IteratorT const &last, PositionT const &pos,
boost::wave::language_support language)
: filename(pos.get_file()), at_eof(false)
{
memset(&scanner, '\0', sizeof(Scanner));
scanner.fd = -1;
scanner.eol_offsets = aq_create();
scanner.first = scanner.act = (uchar *)&(*first);
scanner.last = (uchar *)&(*last);
scanner.line = 1; // start with line_no 1
scanner.error_proc = report_error;
scanner.file_name = filename.c_str();
#if BOOST_WAVE_SUPPORT_MS_EXTENSIONS != 0
scanner.enable_ms_extensions = 1;
#else
scanner.enable_ms_extensions = 0;
#endif
#if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
scanner.act_in_c99_mode = boost::wave::need_c99(language);
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
scanner.act_in_cpp0x_mode = boost::wave::need_cpp0x(language);
#endif
#endif
boost::ignore_unused_variable_warning(language);
}
template <typename IteratorT, typename PositionT>
inline
lexer<IteratorT, PositionT>::~lexer()
{
aq_terminate(scanner.eol_offsets);
free(scanner.bot);
}
///////////////////////////////////////////////////////////////////////////////
// get the next token from the input stream
template <typename IteratorT, typename PositionT>
inline lex_token<PositionT>
lexer<IteratorT, PositionT>::get()
{
if (at_eof)
return lex_token<PositionT>(); // return T_EOI
token_id id = token_id(scan(&scanner));
switch (id) {
case T_IDENTIFIER:
// test identifier characters for validity (throws if invalid chars found)
value = string_t((char const *)scanner.tok, scanner.cur-scanner.tok);
impl::validate_identifier_name(value, scanner.line, -1, filename);
break;
case T_STRINGLIT:
case T_CHARLIT:
// test literal characters for validity (throws if invalid chars found)
value = string_t((char const *)scanner.tok, scanner.cur-scanner.tok);
impl::validate_literal(value, scanner.line, -1, filename);
break;
#if BOOST_WAVE_SUPPORT_INCLUDE_NEXT != 0
case T_PP_HHEADER:
case T_PP_QHEADER:
case T_PP_INCLUDE:
// convert to the corresponding ..._next token, if appropriate
value = string_t((char const *)scanner.tok, scanner.cur-scanner.tok);
if (string_t::npos != value.find("include_"))
id = token_id(id | AltTokenType);
break;
#endif
case T_OCTALINT:
case T_DECIMALINT:
case T_HEXAINT:
case T_INTLIT:
case T_FLOATLIT:
case T_FIXEDPOINTLIT:
case T_CCOMMENT:
case T_CPPCOMMENT:
case T_SPACE:
case T_SPACE2:
case T_ANY:
value = string_t((char const *)scanner.tok, scanner.cur-scanner.tok);
break;
case T_EOF:
// T_EOF is returned as a valid token, the next call will return T_EOI,
// i.e. the actual end of input
at_eof = true;
break;
default:
if (CATEGORY_FROM_TOKEN(id) != EXTCATEGORY_FROM_TOKEN(id))
value = string_t((char const *)scanner.tok, scanner.cur-scanner.tok);
else
value = token_cache.get_token_value(id);
break;
}
return lex_token<PositionT>(id, value,
PositionT(filename, scanner.line, -1));
}
template <typename IteratorT, typename PositionT>
inline int
lexer<IteratorT, PositionT>::report_error(Scanner *s, char *msg, ...)
{
BOOST_ASSERT(0 != s);
BOOST_ASSERT(0 != msg);
using namespace std; // some system have vsprintf in namespace std
char buffer[200]; // should be large enough
va_list params;
va_start(params, msg);
vsprintf(buffer, msg, params);
va_end(params);
BOOST_WAVE_LEXER_THROW(lexing_exception, generic_lexing_error, buffer, s->line, -1,
s->file_name);
return 0; // unreachable code;
}
///////////////////////////////////////////////////////////////////////////////
//
// lex_functor
//
///////////////////////////////////////////////////////////////////////////////
template <typename IteratorT, typename PositionT = boost::wave::util::file_position_t>
class lex_functor
: public lex_input_interface<typename lexer<IteratorT, PositionT>::token_t>
{
public:
typedef typename lexer<IteratorT, PositionT>::token_t token_t;
lex_functor(IteratorT const &first, IteratorT const &last,
PositionT const &pos, boost::wave::language_support language)
: lexer(first, last, pos, language)
{}
virtual ~lex_functor() {}
// get the next token from the input stream
token_t get() { return lexer.get(); }
void set_position(PositionT const &pos)
{ lexer.set_position(pos); }
private:
lexer<IteratorT, PositionT> lexer;
};
} // namespace re2clex
///////////////////////////////////////////////////////////////////////////////
//
// The new_lexer_gen<>::new_lexer function (declared in cpp_slex_token.hpp)
// should be defined inline, if the lex_functor shouldn't be instantiated
// separately from the lex_iterator.
//
// Separate (explicit) instantiation helps to reduce compilation time.
//
///////////////////////////////////////////////////////////////////////////////
#if BOOST_WAVE_SEPARATE_LEXER_INSTANTIATION != 0
#define BOOST_WAVE_RE2C_NEW_LEXER_INLINE
#else
#define BOOST_WAVE_RE2C_NEW_LEXER_INLINE inline
#endif
///////////////////////////////////////////////////////////////////////////////
//
// The 'new_lexer' function allows the opaque generation of a new lexer object.
// It is coupled to the iterator type to allow to decouple the lexer/iterator
// configurations at compile time.
//
// This function is declared inside the cpp_slex_token.hpp file, which is
// referenced by the source file calling the lexer and the source file, which
// instantiates the lex_functor. But is is defined here, so it will be
// instantiated only while compiling the source file, which instantiates the
// lex_functor. While the cpp_re2c_token.hpp file may be included everywhere,
// this file (cpp_re2c_lexer.hpp) should be included only once. This allows
// to decouple the lexer interface from the lexer implementation and reduces
// compilation time.
//
///////////////////////////////////////////////////////////////////////////////
template <typename IteratorT, typename PositionT>
BOOST_WAVE_RE2C_NEW_LEXER_INLINE
lex_input_interface<lex_token<PositionT> > *
new_lexer_gen<IteratorT, PositionT>::new_lexer(IteratorT const &first,
IteratorT const &last, PositionT const &pos,
boost::wave::language_support language)
{
return new re2clex::lex_functor<IteratorT, PositionT>(first, last, pos,
language);
}
#undef BOOST_WAVE_RE2C_NEW_LEXER_INLINE
///////////////////////////////////////////////////////////////////////////////
} // namespace cpplexer
} // namespace wave
} // namespace boost
#endif // !defined(CPP_RE2C_LEXER_HPP_B81A2629_D5B1_4944_A97D_60254182B9A8_INCLUDED)

View File

@@ -0,0 +1,59 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Copyright (c) 2001 Daniel C. Nuffer
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(SCANNER_HPP_F4FB01EB_E75C_4537_A146_D34B9895EF37_INCLUDED)
#define SCANNER_HPP_F4FB01EB_E75C_4537_A146_D34B9895EF37_INCLUDED
#include <boost/wave/cpplexer/re2clex/aq.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace cpplexer {
namespace re2clex {
struct Scanner;
typedef unsigned char uchar;
typedef int (* ReportErrorProc)(struct Scanner *, char *, ...);
typedef struct Scanner {
int fd; /* file descriptor */
uchar* first; /* start of input buffer (if fd == -1) */
uchar* act; /* act position of input buffer (if fd == -1) */
uchar* last; /* end (one past last char) of input buffer (if fd == -1) */
uchar* bot; /* beginning of the current buffer */
uchar* top; /* top of the current buffer */
uchar* eof; /* when we read in the last buffer, will point 1 past the
end of the file, otherwise 0 */
uchar* tok; /* points to the beginning of the current token */
uchar* ptr; /* used for YYMARKER - saves backtracking info */
uchar* cur; /* saves the cursor (maybe is redundant with tok?) */
uchar* lim; /* used for YYLIMIT - points to the end of the buffer */
/* (lim == top) except for the last buffer, it points to
the end of the input (lim == eof - 1) */
unsigned int line; /* current line being lexed */
ReportErrorProc error_proc; /* if != 0 this function is called to
report an error */
char const *file_name; /* name of the lexed file */
aq_queue eol_offsets;
int enable_ms_extensions; /* enable MS extensions */
int act_in_c99_mode; /* lexer works in C99 mode */
int act_in_cpp0x_mode; /* lexer works in C++0x mode */
} Scanner;
///////////////////////////////////////////////////////////////////////////////
} // namespace re2clex
} // namespace cpplexer
} // namespace wave
} // namespace boost
#endif // !defined(SCANNER_HPP_F4FB01EB_E75C_4537_A146_D34B9895EF37_INCLUDED)

View File

@@ -0,0 +1,51 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(TOKEN_CACHE_HPP_4D2320B7_1D56_4113_A114_397E70FA438C_INCLUDED)
#define TOKEN_CACHE_HPP_4D2320B7_1D56_4113_A114_397E70FA438C_INCLUDED
#include <boost/wave/token_ids.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace cpplexer {
template <typename StringT>
class token_cache
{
public:
token_cache()
: cache(T_LAST_TOKEN - T_FIRST_TOKEN)
{
typename std::vector<StringT>::iterator it = cache.begin();
typename std::vector<StringT>::iterator end = cache.end();
for (unsigned int i = T_FIRST_TOKEN; i < T_LAST_TOKEN; ++i, ++it)
{
*it = StringT(boost::wave::get_token_value(token_id(i)));
}
}
StringT const &get_token_value(token_id id)
{
return cache[BASEID_FROM_TOKEN(id) - T_FIRST_TOKEN];
}
private:
std::vector<StringT> cache;
};
///////////////////////////////////////////////////////////////////////////////
} // namespace cpplexer
} // namespace wave
} // namespace boost
#endif // !defined(TOKEN_CACHE_HPP_4D2320B7_1D56_4113_A114_397E70FA438C_INCLUDED)

View File

@@ -0,0 +1,315 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Grammar for universal character validation (see C++ standard: Annex E)
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(VALIDATE_UNIVERSAL_CHAR_HPP_55F1B811_CD76_4C72_8344_CBC69CF3B339_INCLUDED)
#define VALIDATE_UNIVERSAL_CHAR_HPP_55F1B811_CD76_4C72_8344_CBC69CF3B339_INCLUDED
#include <boost/spirit/core.hpp>
#include <boost/wave/util/file_position.hpp>
#include <boost/wave/cpplexer/cpplexer_exceptions.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace cpplexer {
namespace impl {
enum universal_char_type {
universal_char_type_valid = 0,
universal_char_type_invalid = 1,
universal_char_type_base_charset = 2,
universal_char_type_not_allowed_for_identifiers = 3,
};
namespace {
///////////////////////////////////////////////////////////////////////////
//
// is_range is a helper function for the classification by brute force
// below
//
///////////////////////////////////////////////////////////////////////////
inline bool
in_range(unsigned long ch, unsigned long l, unsigned long u)
{
return (l <= ch && ch <= u);
}
}
///////////////////////////////////////////////////////////////////////////////
//
// classify_universal_char
//
// This function classifies an universal character value into 4 subranges:
// universal_char_type_valid
// the universal character value is valid for identifiers
// universal_char_type_invalid
// the universal character value is not valid for its usage inside
// identifiers (see C++ Standard: 2.2.2 [lex.charset])
// universal_char_type_base_charset
// the universal character value designates a character from the base
// character set
// universal_char_type_not_allowed_for_identifiers
// the universal character value is not allowed in an identifier
//
// Implementation note:
// This classification isn't implemented very effectively here. This
// function should be rewritten with some range run matching algorithm.
//
///////////////////////////////////////////////////////////////////////////////
inline universal_char_type
classify_universal_char (unsigned long ch)
{
// test for invalid characters
if (ch <= 0x0020 || in_range(ch, 0x007f, 0x009f))
return universal_char_type_invalid;
// test for characters in the range of the base character set
if (in_range(ch, 0x0021, 0x005f) || in_range(ch, 0x0061, 0x007e))
return universal_char_type_base_charset;
// test for additional valid character values (see C++ Standard: Annex E)
if (in_range(ch, 0x00c0, 0x00d6) || in_range(ch, 0x00d8, 0x00f6) ||
in_range(ch, 0x00f8, 0x01f5) || in_range(ch, 0x01fa, 0x0217) ||
in_range(ch, 0x0250, 0x02a8) || in_range(ch, 0x1e00, 0x1e9a) ||
in_range(ch, 0x1ea0, 0x1ef9))
{
return universal_char_type_valid; // Latin
}
if (0x0384 == ch || in_range(ch, 0x0388, 0x038a) ||
0x038c == ch || in_range(ch, 0x038e, 0x03a1) ||
in_range(ch, 0x03a3, 0x03ce) || in_range(ch, 0x03d0, 0x03d6) ||
0x03da == ch || 0x03dc == ch || 0x03de == ch || 0x03e0 == ch ||
in_range(ch, 0x03e2, 0x03f3) || in_range(ch, 0x1f00, 0x1f15) ||
in_range(ch, 0x1f18, 0x1f1d) || in_range(ch, 0x1f20, 0x1f45) ||
in_range(ch, 0x1f48, 0x1f4d) || in_range(ch, 0x1f50, 0x1f57) ||
0x1f59 == ch || 0x1f5b == ch || 0x1f5d == ch ||
in_range(ch, 0x1f5f, 0x1f7d) || in_range(ch, 0x1f80, 0x1fb4) ||
in_range(ch, 0x1fb6, 0x1fbc) || in_range(ch, 0x1fc2, 0x1fc4) ||
in_range(ch, 0x1fc6, 0x1fcc) || in_range(ch, 0x1fd0, 0x1fd3) ||
in_range(ch, 0x1fd6, 0x1fdb) || in_range(ch, 0x1fe0, 0x1fec) ||
in_range(ch, 0x1ff2, 0x1ff4) || in_range(ch, 0x1ff6, 0x1ffc))
{
return universal_char_type_valid; // Greek
}
if (in_range(ch, 0x0401, 0x040d) || in_range(ch, 0x040f, 0x044f) ||
in_range(ch, 0x0451, 0x045c) || in_range(ch, 0x045e, 0x0481) ||
in_range(ch, 0x0490, 0x04c4) || in_range(ch, 0x04c7, 0x04c8) ||
in_range(ch, 0x04cb, 0x04cc) || in_range(ch, 0x04d0, 0x04eb) ||
in_range(ch, 0x04ee, 0x04f5) || in_range(ch, 0x04f8, 0x04f9))
{
return universal_char_type_valid; // Cyrillic
}
if (in_range(ch, 0x0531, 0x0556) || in_range(ch, 0x0561, 0x0587))
return universal_char_type_valid; // Armenian
if (in_range(ch, 0x05d0, 0x05ea) || in_range(ch, 0x05f0, 0x05f4))
return universal_char_type_valid; // Hebrew
if (in_range(ch, 0x0621, 0x063a) || in_range(ch, 0x0640, 0x0652) ||
in_range(ch, 0x0670, 0x06b7) || in_range(ch, 0x06ba, 0x06be) ||
in_range(ch, 0x06c0, 0x06ce) || in_range(ch, 0x06e5, 0x06e7))
{
return universal_char_type_valid; // Arabic
}
if (in_range(ch, 0x0905, 0x0939) || in_range(ch, 0x0958, 0x0962))
return universal_char_type_valid; // Devanagari
if (in_range(ch, 0x0985, 0x098c) || in_range(ch, 0x098f, 0x0990) ||
in_range(ch, 0x0993, 0x09a8) || in_range(ch, 0x09aa, 0x09b0) ||
0x09b2 == ch || in_range(ch, 0x09b6, 0x09b9) ||
in_range(ch, 0x09dc, 0x09dd) || in_range(ch, 0x09df, 0x09e1) ||
in_range(ch, 0x09f0, 0x09f1))
{
return universal_char_type_valid; // Bengali
}
if (in_range(ch, 0x0a05, 0x0a0a) || in_range(ch, 0x0a0f, 0x0a10) ||
in_range(ch, 0x0a13, 0x0a28) || in_range(ch, 0x0a2a, 0x0a30) ||
in_range(ch, 0x0a32, 0x0a33) || in_range(ch, 0x0a35, 0x0a36) ||
in_range(ch, 0x0a38, 0x0a39) || in_range(ch, 0x0a59, 0x0a5c) ||
0x0a5e == ch)
{
return universal_char_type_valid; // Gurmukhi
}
if (in_range(ch, 0x0a85, 0x0a8b) || 0x0a8d == ch ||
in_range(ch, 0x0a8f, 0x0a91) || in_range(ch, 0x0a93, 0x0aa8) ||
in_range(ch, 0x0aaa, 0x0ab0) || in_range(ch, 0x0ab2, 0x0ab3) ||
in_range(ch, 0x0ab5, 0x0ab9) || 0x0ae0 == ch)
{
return universal_char_type_valid; // Gujarati
}
if (in_range(ch, 0x0b05, 0x0b0c) || in_range(ch, 0x0b0f, 0x0b10) ||
in_range(ch, 0x0b13, 0x0b28) || in_range(ch, 0x0b2a, 0x0b30) ||
in_range(ch, 0x0b32, 0x0b33) || in_range(ch, 0x0b36, 0x0b39) ||
in_range(ch, 0x0b5c, 0x0b5d) || in_range(ch, 0x0b5f, 0x0b61))
{
return universal_char_type_valid; // Oriya
}
if (in_range(ch, 0x0b85, 0x0b8a) || in_range(ch, 0x0b8e, 0x0b90) ||
in_range(ch, 0x0b92, 0x0b95) || in_range(ch, 0x0b99, 0x0b9a) ||
0x0b9c == ch || in_range(ch, 0x0b9e, 0x0b9f) ||
in_range(ch, 0x0ba3, 0x0ba4) || in_range(ch, 0x0ba8, 0x0baa) ||
in_range(ch, 0x0bae, 0x0bb5) || in_range(ch, 0x0bb7, 0x0bb9))
{
return universal_char_type_valid; // Tamil
}
if (in_range(ch, 0x0c05, 0x0c0c) || in_range(ch, 0x0c0e, 0x0c10) ||
in_range(ch, 0x0c12, 0x0c28) || in_range(ch, 0x0c2a, 0x0c33) ||
in_range(ch, 0x0c35, 0x0c39) || in_range(ch, 0x0c60, 0x0c61))
{
return universal_char_type_valid; // Telugu
}
if (in_range(ch, 0x0c85, 0x0c8c) || in_range(ch, 0x0c8e, 0x0c90) ||
in_range(ch, 0x0c92, 0x0ca8) || in_range(ch, 0x0caa, 0x0cb3) ||
in_range(ch, 0x0cb5, 0x0cb9) || in_range(ch, 0x0ce0, 0x0ce1))
{
return universal_char_type_valid; // Kannada
}
if (in_range(ch, 0x0d05, 0x0d0c) || in_range(ch, 0x0d0e, 0x0d10) ||
in_range(ch, 0x0d12, 0x0d28) || in_range(ch, 0x0d2a, 0x0d39) ||
in_range(ch, 0x0d60, 0x0d61))
{
return universal_char_type_valid; // Malayalam
}
if (in_range(ch, 0x0e01, 0x0e30) || in_range(ch, 0x0e32, 0x0e33) ||
in_range(ch, 0x0e40, 0x0e46) || in_range(ch, 0x0e4f, 0x0e5b))
{
return universal_char_type_valid; // Thai
}
return universal_char_type_not_allowed_for_identifiers;
}
///////////////////////////////////////////////////////////////////////////////
//
// validate_identifier_name
//
// The validate_identifier_name function tests a given identifier name for
// its validity in regard to eventually contained universal characters.
// These should be in valid ranges (see the function
// classify_universal_char above).
//
// If the identifier name contains invalid or not allowed universal
// characters a corresponding lexing_exception is thrown.
//
///////////////////////////////////////////////////////////////////////////////
template <typename StringT>
inline void
validate_identifier_name (StringT const &name, int line, int column,
StringT const &file_name)
{
using namespace std; // some systems have strtoul in namespace std::
typename StringT::size_type pos = name.find_first_of('\\');
while (StringT::npos != pos) {
// the identifier name contains a backslash (must be universal char)
BOOST_SPIRIT_ASSERT('u' == name[pos+1] || 'U' == name[pos+1]);
StringT uchar_val(name.substr(pos+2, ('u' == name[pos+1]) ? 4 : 8));
universal_char_type type =
classify_universal_char(strtoul(uchar_val.c_str(), 0, 16));
if (universal_char_type_valid != type) {
// an invalid char was found, so throw an exception
StringT error_uchar(name.substr(pos, ('u' == name[pos+1]) ? 6 : 10));
if (universal_char_type_invalid == type) {
BOOST_WAVE_LEXER_THROW(lexing_exception, universal_char_invalid,
error_uchar, line, column, file_name.c_str());
}
else if (universal_char_type_base_charset == type) {
BOOST_WAVE_LEXER_THROW(lexing_exception, universal_char_base_charset,
error_uchar, line, column, file_name.c_str());
}
else {
BOOST_WAVE_LEXER_THROW(lexing_exception, universal_char_not_allowed,
error_uchar, line, column, file_name.c_str());
}
}
// find next universal char (if appropriate)
pos = name.find_first_of('\\', pos+2);
}
}
///////////////////////////////////////////////////////////////////////////////
//
// validate_literal
//
// The validate_literal function tests a given string or character literal
// for its validity in regard to eventually contained universal
// characters. These should be in valid ranges (see the function
// classify_universal_char above).
//
// If the string or character literal contains invalid or not allowed
// universal characters a corresponding lexing_exception is thrown.
//
///////////////////////////////////////////////////////////////////////////////
template <typename StringT>
inline void
validate_literal (StringT const &name, int line, int column,
StringT const &file_name)
{
using namespace std; // some systems have strtoul in namespace std::
typename StringT::size_type pos = name.find_first_of('\\');
while (StringT::npos != pos) {
// the literal contains a backslash (may be universal char)
if ('u' == name[pos+1] || 'U' == name[pos+1]) {
StringT uchar_val(name.substr(pos+2, ('u' == name[pos+1]) ? 4 : 8));
universal_char_type type =
classify_universal_char(strtoul(uchar_val.c_str(), 0, 16));
if (universal_char_type_valid != type &&
universal_char_type_not_allowed_for_identifiers != type)
{
// an invalid char was found, so throw an exception
StringT error_uchar(name.substr(pos, ('u' == name[pos+1]) ? 6 : 10));
if (universal_char_type_invalid == type) {
BOOST_WAVE_LEXER_THROW(lexing_exception, universal_char_invalid,
error_uchar, line, column, file_name.c_str());
}
else {
BOOST_WAVE_LEXER_THROW(lexing_exception, universal_char_base_charset,
error_uchar, line, column, file_name.c_str());
}
}
}
// find next universal char (if appropriate)
pos = name.find_first_of('\\', pos+2);
}
}
///////////////////////////////////////////////////////////////////////////////
} // namespace impl
} // namespace cpplexer
} // namespace wave
} // namespace boost
#endif // !defined(VALIDATE_UNIVERSAL_CHAR_HPP_55F1B811_CD76_4C72_8344_CBC69CF3B339_INCLUDED)

View File

@@ -0,0 +1,173 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(CPP_CHLIT_GRAMMAR_HPP_9527D349_6592_449A_A409_42A001E6C64C_INCLUDED)
#define CPP_CHLIT_GRAMMAR_HPP_9527D349_6592_449A_A409_42A001E6C64C_INCLUDED
#include <boost/spirit/core.hpp>
#include <boost/spirit/attribute/closure.hpp>
#if SPIRIT_VERSION >= 0x1700
#include <boost/spirit/actor/assign_actor.hpp>
#include <boost/spirit/actor/push_back_actor.hpp>
#endif // SPIRIT_VERSION >= 0x1700
#include <boost/spirit/phoenix/operators.hpp>
#include <boost/spirit/phoenix/primitives.hpp>
#include <boost/spirit/phoenix/statements.hpp>
#include <boost/wave/wave_config.hpp>
#include <boost/wave/cpp_exceptions.hpp>
#include <boost/wave/grammars/cpp_literal_grammar_gen.hpp>
#if !defined(spirit_append_actor)
#if SPIRIT_VERSION >= 0x1700
#define spirit_append_actor(actor) boost::spirit::push_back_a(actor)
#define spirit_assign_actor(actor) boost::spirit::assign_a(actor)
#else
#define spirit_append_actor(actor) boost::spirit::append(actor)
#define spirit_assign_actor(actor) boost::spirit::assign(actor)
#endif // SPIRIT_VERSION >= 0x1700
#endif // !defined(spirit_append_actor)
///////////////////////////////////////////////////////////////////////////////
//
// Reusable grammar to parse a C++ style character literal
//
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace grammars {
namespace closures {
struct chlit_closure
: boost::spirit::closure<chlit_closure, unsigned int>
{
member1 val;
};
}
///////////////////////////////////////////////////////////////////////////////
// define, whether the rule's should generate some debug output
#define TRACE_CHLIT_GRAMMAR \
bool(BOOST_SPIRIT_DEBUG_FLAGS_CPP & BOOST_SPIRIT_DEBUG_FLAGS_CHLIT_GRAMMAR) \
/**/
struct chlit_grammar :
public boost::spirit::grammar<chlit_grammar,
closures::chlit_closure::context_t>
{
chlit_grammar()
{
BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR_NAME(*this, "chlit_grammar",
TRACE_CHLIT_GRAMMAR);
}
template <typename ScannerT>
struct definition
{
typedef boost::spirit::rule<ScannerT> rule_t;
rule_t ch_lit;
definition(chlit_grammar const &self)
{
using namespace boost::spirit;
ch_lit
= !ch_p('L')
>> ch_p('\'')
>> ( ch_p('\\')
>> ( ch_p('a')[self.val = 0x07] // BEL
| ch_p('b')[self.val = 0x08] // BS
| ch_p('t')[self.val = 0x09] // HT
| ch_p('n')[self.val = 0x0a] // NL
| ch_p('v')[self.val = 0x0b] // VT
| ch_p('f')[self.val = 0x0c] // FF
| ch_p('r')[self.val = 0x0d] // CR
| ch_p('?')[spirit_assign_actor(self.val)]
| ch_p('\'')[spirit_assign_actor(self.val)]
| ch_p('\"')[spirit_assign_actor(self.val)]
| ch_p('\\')[spirit_assign_actor(self.val)]
| ch_p('x')
>> hex_p[spirit_assign_actor(self.val)]
| uint_parser<unsigned int, 8, 1, 3>()
[
spirit_assign_actor(self.val)
]
| ch_p('u')
>> uint_parser<unsigned int, 16, 4, 4>()
[
spirit_assign_actor(self.val)
]
| ch_p('U')
>> uint_parser<unsigned int, 16, 8, 8>()
[
spirit_assign_actor(self.val)
]
)
| anychar_p[spirit_assign_actor(self.val)]
)
>> ch_p('\'')
;
BOOST_SPIRIT_DEBUG_TRACE_RULE(ch_lit, TRACE_CHLIT_GRAMMAR);
}
// start rule of this grammar
rule_t const& start() const
{ return ch_lit; }
};
};
#undef TRACE_CHLIT_GRAMMAR
///////////////////////////////////////////////////////////////////////////////
//
// The following function is defined here, to allow the separation of
// the compilation of the intlit_grammap from the function using it.
//
///////////////////////////////////////////////////////////////////////////////
#if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0
#define BOOST_WAVE_CHLITGRAMMAR_GEN_INLINE
#else
#define BOOST_WAVE_CHLITGRAMMAR_GEN_INLINE inline
#endif
template <typename TokenT>
BOOST_WAVE_CHLITGRAMMAR_GEN_INLINE
unsigned int
chlit_grammar_gen<TokenT>::evaluate(TokenT const &token)
{
using namespace boost::spirit;
static chlit_grammar g;
unsigned int result = 0;
typename TokenT::string_t const &token_val = token.get_value();
parse_info<typename TokenT::string_t::const_iterator> hit =
parse(token_val.begin(), token_val.end(), g[spirit_assign_actor(result)]);
if (!hit.hit) {
BOOST_WAVE_THROW(preprocess_exception, ill_formed_expression,
token_val, token.get_position());
}
return result;
}
#undef BOOST_WAVE_CHLITGRAMMAR_GEN_INLINE
///////////////////////////////////////////////////////////////////////////////
} // namespace grammars
} // namespace wave
} // namespace boost
#endif // !defined(CPP_CHLIT_GRAMMAR_HPP_9527D349_6592_449A_A409_42A001E6C64C_INCLUDED)

View File

@@ -0,0 +1,206 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(CPP_DEFINED_GRAMMAR_HPP_F48287B2_DC67_40A8_B4A1_800EFBD67869_INCLUDED)
#define CPP_DEFINED_GRAMMAR_HPP_F48287B2_DC67_40A8_B4A1_800EFBD67869_INCLUDED
#include <boost/spirit/core.hpp>
#include <boost/spirit/core/assert.hpp>
#include <boost/spirit/attribute/closure.hpp>
#if SPIRIT_VERSION >= 0x1700
#include <boost/spirit/actor/assign_actor.hpp>
#include <boost/spirit/actor/push_back_actor.hpp>
#endif // SPIRIT_VERSION >= 0x1700
#include <boost/wave/wave_config.hpp>
#include <boost/wave/token_ids.hpp>
#include <boost/wave/util/pattern_parser.hpp>
#include <boost/wave/grammars/cpp_defined_grammar_gen.hpp>
#if !defined(spirit_append_actor)
#if SPIRIT_VERSION >= 0x1700
#define spirit_append_actor(actor) boost::spirit::push_back_a(actor)
#define spirit_assign_actor(actor) boost::spirit::assign_a(actor)
#else
#define spirit_append_actor(actor) boost::spirit::append(actor)
#define spirit_assign_actor(actor) boost::spirit::assign(actor)
#endif // SPIRIT_VERSION >= 0x1700
#endif // !defined(spirit_append_actor)
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace grammars {
///////////////////////////////////////////////////////////////////////////////
// define, whether the rule's should generate some debug output
#define TRACE_CPP_DEFINED_GRAMMAR \
bool(BOOST_SPIRIT_DEBUG_FLAGS_CPP & BOOST_SPIRIT_DEBUG_FLAGS_DEFINED_GRAMMAR) \
/**/
template <typename ContainerT>
struct defined_grammar :
public boost::spirit::grammar<defined_grammar<ContainerT> >
{
defined_grammar(ContainerT &result_seq_)
: result_seq(result_seq_)
{
BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR_NAME(*this, "defined_grammar",
TRACE_CPP_DEFINED_GRAMMAR);
}
template <typename ScannerT>
struct definition
{
typedef boost::spirit::rule<ScannerT> rule_t;
rule_t defined_op;
rule_t identifier;
//#if !defined(WAVE_USE_RE2C_IDL_LEXER)
rule_t qualified_name;
//#endif
definition(defined_grammar const &self)
{
using namespace boost::spirit;
using namespace boost::wave;
using namespace boost::wave::util;
//#if !defined(WAVE_USE_RE2C_IDL_LEXER)
defined_op // parens not required, see C++ standard 16.1.1
= ch_p(T_IDENTIFIER) // token contains 'defined'
>> (
( ch_p(T_LEFTPAREN)
>> qualified_name
>> ch_p(T_RIGHTPAREN)
)
| qualified_name
)
;
qualified_name
= !ch_p(T_COLON_COLON)
[
spirit_append_actor(self.result_seq)
]
>> identifier
>> *( ch_p(T_COLON_COLON)
[
spirit_append_actor(self.result_seq)
]
>> identifier
)
;
//#else
// defined_op // parens not required, see C++ standard 16.1.1
// = ch_p(T_IDENTIFIER) // token contains 'defined'
// >> (
// ( ch_p(T_LEFTPAREN)
// >> identifier
// >> ch_p(T_RIGHTPAREN)
// )
// | identifier
// )
// ;
//#endif
identifier
= ch_p(T_IDENTIFIER)
[
spirit_append_actor(self.result_seq)
]
| pattern_p(KeywordTokenType, TokenTypeMask)
[
spirit_append_actor(self.result_seq)
]
;
BOOST_SPIRIT_DEBUG_TRACE_RULE(defined_op, TRACE_CPP_DEFINED_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(identifier, TRACE_CPP_DEFINED_GRAMMAR);
//#if !defined(WAVE_USE_RE2C_IDL_LEXER)
BOOST_SPIRIT_DEBUG_TRACE_RULE(qualified_name, TRACE_CPP_DEFINED_GRAMMAR);
//#endif
}
// start rule of this grammar
rule_t const& start() const
{ return defined_op; }
};
ContainerT &result_seq;
};
///////////////////////////////////////////////////////////////////////////////
#undef TRACE_CPP_DEFINED_GRAMMAR
///////////////////////////////////////////////////////////////////////////////
//
// The following parse function is defined here, to allow the separation of
// the compilation of the defined_grammar from the function
// using it.
//
///////////////////////////////////////////////////////////////////////////////
#if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0
#define BOOST_WAVE_DEFINED_GRAMMAR_GEN_INLINE
#else
#define BOOST_WAVE_DEFINED_GRAMMAR_GEN_INLINE inline
#endif
// The parse_operator_define function is instantiated manually twice to
// simplify the explicit specialization of this template. This way the user
// has only to specify one template parameter (the lexer type) to correctly
// formulate the required explicit specialization.
// This results in no code overhead, because otherwise the function would be
// generated by the compiler twice anyway.
template <typename LexIteratorT>
BOOST_WAVE_DEFINED_GRAMMAR_GEN_INLINE
boost::spirit::parse_info<
typename defined_grammar_gen<LexIteratorT>::iterator1_t
>
defined_grammar_gen<LexIteratorT>::parse_operator_defined (
iterator1_t const &first, iterator1_t const &last,
token_sequence_t &found_qualified_name)
{
using namespace boost::spirit;
using namespace boost::wave;
defined_grammar<token_sequence_t> g(found_qualified_name);
return boost::spirit::parse (
first, last, g, ch_p(T_SPACE) | ch_p(T_CCOMMENT));
}
template <typename LexIteratorT>
BOOST_WAVE_DEFINED_GRAMMAR_GEN_INLINE
boost::spirit::parse_info<
typename defined_grammar_gen<LexIteratorT>::iterator2_t
>
defined_grammar_gen<LexIteratorT>::parse_operator_defined (
iterator2_t const &first, iterator2_t const &last,
token_sequence_t &found_qualified_name)
{
using namespace boost::spirit;
using namespace boost::wave;
defined_grammar<token_sequence_t> g(found_qualified_name);
return boost::spirit::parse (
first, last, g, ch_p(T_SPACE) | ch_p(T_CCOMMENT));
}
#undef BOOST_WAVE_DEFINED_GRAMMAR_GEN_INLINE
///////////////////////////////////////////////////////////////////////////////
} // namespace grammars
} // namespace wave
} // namespace boost
#endif // !defined(CPP_DEFINED_GRAMMAR_HPP_F48287B2_DC67_40A8_B4A1_800EFBD67869_INCLUDED)

View File

@@ -0,0 +1,64 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(CPP_DEFINED_GRAMMAR_GEN_HPP_825BE9F5_98A3_400D_A97C_AD76B3B08632_INCLUDED)
#define CPP_DEFINED_GRAMMAR_GEN_HPP_825BE9F5_98A3_400D_A97C_AD76B3B08632_INCLUDED
#include <list>
#include <boost/spirit/core/parser.hpp>
#include <boost/pool/pool_alloc.hpp>
#include <boost/wave/util/unput_queue_iterator.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace grammars {
template <typename LexIteratorT>
struct defined_grammar_gen
{
typedef typename LexIteratorT::token_t token_t;
typedef std::list<token_t, boost::fast_pool_allocator<token_t> >
token_sequence_t;
// The parse_operator_define function is instantiated manually twice to
// simplify the explicit specialization of this template. This way the user
// has only to specify one template parameter (the token type) to correctly
// formulate the required explicit specialization.
// This results in no code overhead, because otherwise the function would be
// generated by the compiler twice anyway.
typedef boost::wave::util::unput_queue_iterator<
typename token_sequence_t::iterator, token_t, token_sequence_t>
iterator1_t;
typedef boost::wave::util::unput_queue_iterator<
LexIteratorT, token_t, token_sequence_t>
iterator2_t;
// parse the operator defined and return the found qualified name
static boost::spirit::parse_info<iterator1_t>
parse_operator_defined (iterator1_t const &first, iterator1_t const &last,
token_sequence_t &found_qualified_name);
static boost::spirit::parse_info<iterator2_t>
parse_operator_defined (iterator2_t const &first, iterator2_t const &last,
token_sequence_t &found_qualified_name);
};
///////////////////////////////////////////////////////////////////////////////
} // namespace grammars
} // namespace wave
} // namespace boost
#endif // !defined(CPP_DEFINED_GRAMMAR_GEN_HPP_825BE9F5_98A3_400D_A97C_AD76B3B08632_INCLUDED)

View File

@@ -0,0 +1,533 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(CPP_EXPRESSION_GRAMMAR_HPP_099CD1A4_A6C0_44BE_8F24_0B00F5BE5674_INCLUDED)
#define CPP_EXPRESSION_GRAMMAR_HPP_099CD1A4_A6C0_44BE_8F24_0B00F5BE5674_INCLUDED
#include <boost/spirit/core.hpp>
#include <boost/spirit/core/assert.hpp>
#include <boost/spirit/attribute/closure.hpp>
#if SPIRIT_VERSION >= 0x1700
#include <boost/spirit/actor/assign_actor.hpp>
#include <boost/spirit/actor/push_back_actor.hpp>
#endif // SPIRIT_VERSION >= 0x1700
#include <boost/spirit/phoenix/functions.hpp>
#include <boost/spirit/phoenix/operators.hpp>
#include <boost/spirit/phoenix/primitives.hpp>
#include <boost/spirit/phoenix/statements.hpp>
#include <boost/spirit/phoenix/casts.hpp>
#include <boost/wave/wave_config.hpp>
#include <boost/wave/token_ids.hpp>
#include <boost/wave/cpp_exceptions.hpp>
#include <boost/wave/grammars/cpp_expression_grammar_gen.hpp>
#include <boost/wave/grammars/cpp_literal_grammar_gen.hpp>
#include <boost/wave/grammars/cpp_expression_value.hpp>
#include <boost/wave/util/pattern_parser.hpp>
#include <boost/wave/util/macro_helpers.hpp>
#if !defined(spirit_append_actor)
#if SPIRIT_VERSION >= 0x1700
#define spirit_append_actor(actor) boost::spirit::push_back_a(actor)
#define spirit_assign_actor(actor) boost::spirit::assign_a(actor)
#else
#define spirit_append_actor(actor) boost::spirit::append(actor)
#define spirit_assign_actor(actor) boost::spirit::assign(actor)
#endif // SPIRIT_VERSION >= 0x1700
#endif // !defined(spirit_append_actor)
///////////////////////////////////////////////////////////////////////////////
//
// Encapsulation of the grammar for evaluation of constant preprocessor
// expressions
//
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace grammars {
namespace closures {
///////////////////////////////////////////////////////////////////////////////
//
// define the closure type used throughout the C++ expression grammar
//
// Throughout this grammar all literal tokens are stored into a
// closure_value variables, which converts the types appropriately, where
// required.
//
///////////////////////////////////////////////////////////////////////////////
struct cpp_expr_closure
: boost::spirit::closure<cpp_expr_closure, closure_value>
{
member1 val;
};
} // namespace closures
namespace impl {
///////////////////////////////////////////////////////////////////////////////
//
// convert the given tokenvalue (integer literal) to a unsigned long
//
///////////////////////////////////////////////////////////////////////////////
struct convert_intlit {
template <typename ArgT>
struct result {
typedef boost::wave::grammars::closures::closure_value type;
};
template <typename TokenT>
boost::wave::grammars::closures::closure_value operator()(TokenT const &token) const
{
typedef boost::wave::grammars::closures::closure_value return_t;
bool is_unsigned = false;
unsigned long ul = intlit_grammar_gen<TokenT>::evaluate(token,
is_unsigned);
return is_unsigned ? return_t(ul) : return_t(static_cast<long>(ul));
}
};
phoenix::function<convert_intlit> const as_intlit;
///////////////////////////////////////////////////////////////////////////////
//
// convert the given tokenvalue (character literal) to a unsigned int
//
///////////////////////////////////////////////////////////////////////////////
struct convert_chlit {
template <typename ArgT>
struct result {
typedef boost::wave::grammars::closures::closure_value type;
};
template <typename TokenT>
boost::wave::grammars::closures::closure_value operator()(TokenT const &token) const
{
typedef boost::wave::grammars::closures::closure_value return_t;
return return_t(chlit_grammar_gen<TokenT>::evaluate(token));
}
};
phoenix::function<convert_chlit> const as_chlit;
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
// define, whether the rule's should generate some debug output
#define TRACE_CPP_EXPR_GRAMMAR \
bool(BOOST_SPIRIT_DEBUG_FLAGS_CPP & BOOST_SPIRIT_DEBUG_FLAGS_CPP_EXPR_GRAMMAR) \
/**/
struct expression_grammar :
public boost::spirit::grammar<
expression_grammar,
closures::cpp_expr_closure::context_t
>
{
expression_grammar()
{
BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR_NAME(*this, "expression_grammar",
TRACE_CPP_EXPR_GRAMMAR);
}
template <typename ScannerT>
struct definition
{
typedef closures::cpp_expr_closure closure_t;
typedef boost::spirit::rule<ScannerT, closure_t::context_t> rule_t;
typedef boost::spirit::rule<ScannerT> simple_rule_t;
simple_rule_t pp_expression;
rule_t const_exp;
rule_t logical_or_exp, logical_and_exp;
rule_t inclusive_or_exp, exclusive_or_exp, and_exp;
rule_t cmp_equality, cmp_relational;
rule_t shift_exp;
rule_t add_exp, multiply_exp;
rule_t unary_exp, primary_exp, constant;
boost::spirit::subrule<0, closure_t::context_t> const_exp_subrule;
boost::spirit::subrule<1, closure_t::context_t> shift_exp_clos;
definition(expression_grammar const &self)
{
using namespace boost::spirit;
using namespace phoenix;
using namespace boost::wave;
using boost::wave::util::pattern_p;
pp_expression
= const_exp[self.val = arg1]
;
const_exp
= logical_or_exp[const_exp.val = arg1]
>> !(const_exp_subrule =
ch_p(T_QUESTION_MARK)
>> logical_or_exp
[
if_(const_exp.val)
[
const_exp_subrule.val = arg1
]
]
>> ch_p(T_COLON)
>> logical_or_exp
[
if_(!const_exp.val)
[
const_exp_subrule.val = arg1
]
]
)[const_exp.val = arg1]
;
logical_or_exp
= logical_and_exp[logical_or_exp.val = arg1]
>> *( pattern_p(T_OROR, MainTokenMask)
>> logical_and_exp
[
logical_or_exp.val =
static_cast_<bool>(logical_or_exp.val)
|| static_cast_<bool>(arg1)
]
)
;
logical_and_exp
= inclusive_or_exp[logical_and_exp.val = arg1]
>> *( pattern_p(T_ANDAND, MainTokenMask)
>> inclusive_or_exp
[
logical_and_exp.val =
static_cast_<bool>(logical_and_exp.val)
&& static_cast_<bool>(arg1)
]
)
;
inclusive_or_exp
= exclusive_or_exp[inclusive_or_exp.val = arg1]
>> *( pattern_p(T_OR, MainTokenMask)
>> exclusive_or_exp
[
inclusive_or_exp.val =
static_cast_<unsigned int>(inclusive_or_exp.val)
| static_cast_<unsigned int>(arg1)
]
)
;
exclusive_or_exp
= and_exp[exclusive_or_exp.val = arg1]
>> *( pattern_p(T_XOR, MainTokenMask)
>> and_exp
[
exclusive_or_exp.val =
static_cast_<unsigned int>(exclusive_or_exp.val)
^ static_cast_<unsigned int>(arg1)
]
)
;
and_exp
= cmp_equality[and_exp.val = arg1]
>> *( pattern_p(T_AND, MainTokenMask)
>> cmp_equality
[
and_exp.val =
static_cast_<unsigned int>(and_exp.val)
& static_cast_<unsigned int>(arg1)
]
)
;
cmp_equality
= cmp_relational[cmp_equality.val = arg1]
>> *( ch_p(T_EQUAL)
>> cmp_relational
[
cmp_equality.val =
cmp_equality.val == arg1
]
| pattern_p(T_NOTEQUAL, MainTokenMask)
>> cmp_relational
[
cmp_equality.val =
cmp_equality.val != arg1
]
)
;
cmp_relational
= shift_exp[cmp_relational.val = arg1]
>> *( ch_p(T_LESSEQUAL)
>> shift_exp
[
cmp_relational.val =
cmp_relational.val <= arg1
]
| ch_p(T_GREATEREQUAL)
>> shift_exp
[
cmp_relational.val =
cmp_relational.val >= arg1
]
| ch_p(T_LESS)
>> shift_exp
[
cmp_relational.val =
cmp_relational.val < arg1
]
| ch_p(T_GREATER)
>> shift_exp
[
cmp_relational.val =
cmp_relational.val > arg1
]
)
;
shift_exp
= add_exp[shift_exp.val = arg1]
>> *(shift_exp_clos
= ch_p(T_SHIFTLEFT)
>> add_exp
[
shift_exp_clos.val = arg1,
if_(shift_exp_clos.val < -64)
[
shift_exp_clos.val = -64
],
if_(shift_exp_clos.val > 64)
[
shift_exp_clos.val = 64
],
shift_exp.val =
static_cast_<unsigned int>(shift_exp.val)
<< static_cast_<int>(shift_exp_clos.val)
]
| ch_p(T_SHIFTRIGHT)
>> add_exp
[
shift_exp_clos.val = arg1,
if_(shift_exp_clos.val < -64)
[
shift_exp_clos.val = -64
],
if_(shift_exp_clos.val > 64)
[
shift_exp_clos.val = 64
],
shift_exp.val =
static_cast_<unsigned int>(shift_exp.val)
>> static_cast_<int>(shift_exp_clos.val)
]
)
;
add_exp
= multiply_exp[add_exp.val = arg1]
>> *( ch_p(T_PLUS)
>> multiply_exp
[
add_exp.val += arg1
]
| ch_p(T_MINUS)
>> multiply_exp
[
add_exp.val -= arg1
]
)
;
multiply_exp
= unary_exp[multiply_exp.val = arg1]
>> *( ch_p(T_STAR)
>> unary_exp
[
multiply_exp.val *= arg1
]
| ch_p(T_DIVIDE)
>> unary_exp
[
multiply_exp.val /= arg1
]
| ch_p(T_PERCENT)
>> unary_exp
[
multiply_exp.val =
static_cast_<int>(multiply_exp.val)
% static_cast_<int>(arg1)
]
)
;
unary_exp
= primary_exp[unary_exp.val = arg1]
| ch_p(T_PLUS) >> unary_exp[unary_exp.val = arg1]
| ch_p(T_MINUS) >> unary_exp[unary_exp.val = -arg1]
| pattern_p(T_COMPL, MainTokenMask) >> unary_exp
[
unary_exp.val = ~static_cast_<unsigned int>(arg1)
]
| pattern_p(T_NOT, MainTokenMask) >> unary_exp
[
unary_exp.val = !static_cast_<bool>(arg1)
]
;
primary_exp
= constant[primary_exp.val = arg1]
| ch_p(T_LEFTPAREN)
>> const_exp[primary_exp.val = arg1]
>> ch_p(T_RIGHTPAREN)
;
constant
= ch_p(T_INTLIT)
[
constant.val = impl::as_intlit(arg1)
]
| ch_p(T_CHARLIT)
[
constant.val = impl::as_chlit(arg1)
]
;
BOOST_SPIRIT_DEBUG_TRACE_RULE(pp_expression, TRACE_CPP_EXPR_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(const_exp, TRACE_CPP_EXPR_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(logical_or_exp, TRACE_CPP_EXPR_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(logical_and_exp, TRACE_CPP_EXPR_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(inclusive_or_exp, TRACE_CPP_EXPR_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(exclusive_or_exp, TRACE_CPP_EXPR_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(and_exp, TRACE_CPP_EXPR_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(cmp_equality, TRACE_CPP_EXPR_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(cmp_relational, TRACE_CPP_EXPR_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(shift_exp, TRACE_CPP_EXPR_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(add_exp, TRACE_CPP_EXPR_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(multiply_exp, TRACE_CPP_EXPR_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(unary_exp, TRACE_CPP_EXPR_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(primary_exp, TRACE_CPP_EXPR_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(constant, TRACE_CPP_EXPR_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(const_exp_subrule, TRACE_CPP_EXPR_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(shift_exp_clos, TRACE_CPP_EXPR_GRAMMAR);
}
// start rule of this grammar
simple_rule_t const& start() const
{ return pp_expression; }
};
};
///////////////////////////////////////////////////////////////////////////////
#undef TRACE_CPP_EXPR_GRAMMAR
///////////////////////////////////////////////////////////////////////////////
//
// The following function is defined here, to allow the separation of
// the compilation of the expression_grammar from the function using it.
//
///////////////////////////////////////////////////////////////////////////////
#if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0
#define BOOST_WAVE_EXPRGRAMMAR_GEN_INLINE
#else
#define BOOST_WAVE_EXPRGRAMMAR_GEN_INLINE inline
#endif
template <typename TokenT>
BOOST_WAVE_EXPRGRAMMAR_GEN_INLINE
bool
expression_grammar_gen<TokenT>::evaluate(
typename token_sequence_t::const_iterator const &first,
typename token_sequence_t::const_iterator const &last,
typename token_t::position_t const &act_pos,
bool if_block_status)
{
using namespace boost::spirit;
using namespace boost::wave;
typedef typename token_sequence_t::const_iterator iterator_t;
static expression_grammar g; // expression grammar
boost::wave::grammars::closures::closure_value result; // expression result
parse_info<iterator_t> hit = parse (first, last, g[spirit_assign_actor(result)],
ch_p(T_SPACE) | ch_p(T_CCOMMENT) | ch_p(T_CPPCOMMENT));
if (!hit.hit) {
// expression is illformed
if (if_block_status) {
typedef typename token_sequence_t::value_type::string_t string_t;
BOOST_WAVE_THROW(preprocess_exception, ill_formed_expression,
boost::wave::util::impl::as_string<string_t>(first, last), act_pos);
}
else {
// as the if_block_status is false any errors will not be reported
return false;
}
}
if (!hit.full) {
// The token list starts with a valid expression, but there remains
// something. If the remainder consists out of whitespace only, the
// expression is still valid.
iterator_t next = hit.stop;
while (next != last) {
switch (token_id(*next)) {
case T_SPACE:
case T_SPACE2:
case T_CCOMMENT:
break; // ok continue
case T_NEWLINE:
case T_EOF:
case T_CPPCOMMENT: // contains newline
return bool(result); // expression is valid
default:
// expression is illformed
if (if_block_status) {
typedef typename token_sequence_t::value_type::string_t
string_t;
BOOST_WAVE_THROW(preprocess_exception, ill_formed_expression,
boost::wave::util::impl::as_string<string_t>(first, last),
act_pos);
}
else {
// as the if_block_status is false any errors will not be
// reported
return false;
}
}
++next;
}
}
// token sequence is a valid expression
return bool(result);
}
#undef BOOST_WAVE_EXPRGRAMMAR_GEN_INLINE
///////////////////////////////////////////////////////////////////////////////
} // namespace grammars
} // namespace wave
} // namespace boost
#endif // !defined(CPP_EXPRESSION_GRAMMAR_HPP_099CD1A4_A6C0_44BE_8F24_0B00F5BE5674_INCLUDED)

View File

@@ -0,0 +1,54 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(CPP_EXPRESSION_GRAMMAR_GEN_HPP_42399258_6CDC_4101_863D_5C7D95B5A6CA_INCLUDED)
#define CPP_EXPRESSION_GRAMMAR_GEN_HPP_42399258_6CDC_4101_863D_5C7D95B5A6CA_INCLUDED
#include <list>
#include <boost/pool/pool_alloc.hpp>
#include <boost/wave/cpp_iteration_context.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace grammars {
///////////////////////////////////////////////////////////////////////////////
//
// expression_grammar_gen template class
//
// This template helps separating the compilation of the
// expression_grammar class from the compilation of the main
// pp_iterator. This is done to safe compilation time.
//
///////////////////////////////////////////////////////////////////////////////
template <typename TokenT>
struct expression_grammar_gen {
typedef TokenT token_t;
typedef std::list<token_t, boost::fast_pool_allocator<token_t> >
token_sequence_t;
static bool evaluate(
typename token_sequence_t::const_iterator const &first,
typename token_sequence_t::const_iterator const &last,
typename token_t::position_t const &tok,
bool if_block_status);
};
///////////////////////////////////////////////////////////////////////////////
} // namespace grammars
} // namespace wave
} // namespace boost
#endif // !defined(CPP_EXPRESSION_GRAMMAR_GEN_HPP_42399258_6CDC_4101_863D_5C7D95B5A6CA_INCLUDED)

View File

@@ -0,0 +1,321 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(CPP_EXPRESSION_VALUE_HPP_452FE66D_8754_4107_AF1E_E42255A0C18A_INCLUDED)
#define CPP_EXPRESSION_VALUE_HPP_452FE66D_8754_4107_AF1E_E42255A0C18A_INCLUDED
#if defined (BOOST_SPIRIT_DEBUG)
#include <iostream>
#endif // defined(BOOST_SPIRIT_DEBUG)
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace grammars {
namespace closures {
///////////////////////////////////////////////////////////////////////////////
//
// The closure_value class represents the closure type, which is used for the
// expression grammar.
//
// This class was introduced to allow the expression grammar to respect
// the numeric type of a numeric literal or expression result.
//
///////////////////////////////////////////////////////////////////////////////
class closure_value {
typedef unsigned long ulong_t;
public:
enum value_type {
is_int = 1,
is_uint = 2,
is_bool = 3
};
closure_value() : type(is_int) { value.i = 0; }
explicit closure_value(int i) : type(is_int) { value.i = i; }
explicit closure_value(unsigned int ui) : type(is_uint) { value.ui = ui; }
explicit closure_value(long i) : type(is_int) { value.i = i; }
explicit closure_value(ulong_t ui) : type(is_uint) { value.ui = ui; }
explicit closure_value(bool b) : type(is_bool) { value.b = b; }
value_type get_type() const { return type; }
// implicit conversion
operator int() const
{
switch (type) {
case is_uint: return value.ui;
case is_bool: return value.b ? 1 : 0;
case is_int: break;
}
return value.i;
}
operator unsigned int() const
{
switch (type) {
case is_uint: return value.ui;
case is_bool: return value.b ? 1 : 0;
case is_int: break;
}
return value.i;
}
operator long() const
{
switch (type) {
case is_uint: return value.ui;
case is_bool: return value.b ? 1 : 0;
case is_int: break;
}
return value.i;
}
operator ulong_t() const
{
switch (type) {
case is_uint: return value.ui;
case is_bool: return value.b ? 1 : 0;
case is_int: break;
}
return value.i;
}
operator bool() const
{
switch (type) {
case is_uint: return value.ui != 0;
case is_bool: return value.b;
case is_int: break;
}
return value.i != 0.0;
}
// assignment
closure_value &operator= (closure_value const &rhs)
{
switch (rhs.get_type()) {
case is_int:
value.i = long(rhs);
type = is_int;
break;
case is_uint:
value.ui = ulong_t(rhs);
type = is_uint;
break;
case is_bool:
value.b = bool(rhs);
type = is_bool;
break;
}
return *this;
}
closure_value &operator= (int rhs)
{
type = is_int;
value.i = rhs;
return *this;
}
closure_value &operator= (unsigned int rhs)
{
type = is_uint;
value.ui = rhs;
return *this;
}
closure_value &operator= (long rhs)
{
type = is_int;
value.i = rhs;
return *this;
}
closure_value &operator= (ulong_t rhs)
{
type = is_uint;
value.ui = rhs;
return *this;
}
closure_value &operator= (bool rhs)
{
type = is_bool;
value.b = rhs;
return *this;
}
// arithmetics
closure_value &operator+= (closure_value const &rhs)
{
switch (type) {
case is_int: value.i += long(rhs); break;
case is_uint: value.ui += ulong_t(rhs); break;
case is_bool:
value.i = value.b + bool(rhs);
type = is_int;
}
return *this;
}
closure_value &operator-= (closure_value const &rhs)
{
switch (type) {
case is_int: value.i -= long(rhs); break;
case is_uint: value.ui -= ulong_t(rhs); break;
case is_bool:
value.i = value.b - bool(rhs);
type = is_int;
}
return *this;
}
closure_value &operator*= (closure_value const &rhs)
{
switch (type) {
case is_int: value.i *= long(rhs); break;
case is_uint: value.ui *= ulong_t(rhs); break;
case is_bool:
value.i = value.b * bool(rhs);
type = is_int;
}
return *this;
}
closure_value &operator/= (closure_value const &rhs)
{
switch (type) {
case is_int: value.i /= long(rhs); break;
case is_uint: value.ui /= ulong_t(rhs); break;
case is_bool:
value.i = int(value.b) / int(bool(rhs));
type = is_int;
}
return *this;
}
friend closure_value
operator- (closure_value const &rhs)
{
switch (rhs.type) {
case is_int: return closure_value(-long(rhs));
case is_bool: return closure_value(!bool(rhs));
case is_uint: break;
}
return closure_value(-(int)ulong_t(rhs));
}
friend closure_value
operator! (closure_value const &rhs)
{
switch (rhs.type) {
case is_int: return closure_value(!long(rhs));
case is_bool: return closure_value(!bool(rhs));
case is_uint: break;
}
return closure_value(!ulong_t(rhs));
}
// comparison
friend closure_value
operator== (closure_value const &lhs, closure_value const &rhs)
{
bool cmp = false;
switch (lhs.type) {
case is_int: cmp = long(lhs) == long(rhs); break;
case is_uint: cmp = ulong_t(lhs) == ulong_t(rhs); break;
case is_bool: cmp = bool(lhs) == bool(rhs); break;
}
return closure_value(cmp);
}
friend closure_value
operator!= (closure_value const &lhs, closure_value const &rhs)
{
return closure_value(!bool(lhs == rhs));
}
friend closure_value
operator> (closure_value const &lhs, closure_value const &rhs)
{
bool cmp = false;
switch (lhs.type) {
case is_int: cmp = long(lhs) > long(rhs); break;
case is_uint: cmp = ulong_t(lhs) > ulong_t(rhs); break;
case is_bool: cmp = bool(lhs) > bool(rhs); break;
}
return closure_value(cmp);
}
friend closure_value
operator< (closure_value const &lhs, closure_value const &rhs)
{
bool cmp = false;
switch (lhs.type) {
case is_int: cmp = long(lhs) < long(rhs); break;
case is_uint: cmp = ulong_t(lhs) < ulong_t(rhs); break;
case is_bool: cmp = bool(lhs) < bool(rhs); break;
}
return closure_value(cmp);
}
friend closure_value
operator<= (closure_value const &lhs, closure_value const &rhs)
{
return closure_value(!bool(lhs > rhs));
}
friend closure_value
operator>= (closure_value const &lhs, closure_value const &rhs)
{
return closure_value(!bool(lhs < rhs));
}
friend closure_value
operator> (closure_value const &lhs, int const rhs)
{
bool cmp = false;
switch (lhs.type) {
case is_int: cmp = long(lhs) > rhs; break;
case is_uint: cmp = ulong_t(lhs) > ulong_t(rhs); break;
case is_bool: cmp = (int)bool(lhs) > rhs; break;
}
return closure_value(cmp);
}
friend closure_value
operator< (closure_value const &lhs, int const rhs)
{
bool cmp = false;
switch (lhs.type) {
case is_int: cmp = long(lhs) < rhs; break;
case is_uint: cmp = ulong_t(lhs) < ulong_t(rhs); break;
case is_bool: cmp = (int)bool(lhs) < rhs; break;
}
return closure_value(cmp);
}
#if defined (BOOST_SPIRIT_DEBUG)
friend std::ostream&
operator<< (std::ostream &o, closure_value const &val)
{
switch (val.type) {
case is_int: o << "int(" << long(val) << ")"; break;
case is_uint: o << "unsigned int(" << ulong_t(val) << ")"; break;
case is_bool: o << "bool(" << bool(val) << ")"; break;
}
return o;
}
#endif // defined(BOOST_SPIRIT_DEBUG)
private:
value_type type;
union {
long i;
ulong_t ui;
bool b;
} value;
};
///////////////////////////////////////////////////////////////////////////////
} // namespace closures
} // namespace grammars
} // namespace wave
} // namespace boost
#endif // !defined(CPP_EXPRESSION_VALUE_HPP_452FE66D_8754_4107_AF1E_E42255A0C18A_INCLUDED)

View File

@@ -0,0 +1,779 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(CPP_GRAMMAR_HPP_FEAEBC2E_2734_428B_A7CA_85E5A415E23E_INCLUDED)
#define CPP_GRAMMAR_HPP_FEAEBC2E_2734_428B_A7CA_85E5A415E23E_INCLUDED
#include <boost/spirit/core.hpp>
#include <boost/spirit/tree/parse_tree.hpp>
#include <boost/spirit/tree/parse_tree_utils.hpp>
#include <boost/spirit/utility/confix.hpp>
#include <boost/spirit/utility/lists.hpp>
#include <boost/wave/wave_config.hpp>
#if BOOST_WAVE_DUMP_PARSE_TREE != 0
#include <map>
#include <boost/spirit/tree/tree_to_xml.hpp>
#endif
#include <boost/wave/token_ids.hpp>
#include <boost/wave/grammars/cpp_grammar_gen.hpp>
#include <boost/wave/util/pattern_parser.hpp>
#include <boost/wave/cpp_exceptions.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace grammars {
namespace impl {
///////////////////////////////////////////////////////////////////////////////
//
// store_position
//
// The store_position functor extracts the actual file position from the
// supplied token.
//
///////////////////////////////////////////////////////////////////////////////
template <typename PositionT>
struct store_position {
store_position(PositionT &pos_) : pos(pos_) {}
template <typename TokenT>
void operator()(TokenT const &token) const
{
pos = token.get_position();
}
PositionT &pos;
};
///////////////////////////////////////////////////////////////////////////////
//
// store_found_eof
//
// The store_found_eof functor sets a given flag if the T_EOF token was
// found during the parsing process
//
///////////////////////////////////////////////////////////////////////////////
struct store_found_eof {
store_found_eof(bool &found_eof_) : found_eof(found_eof_) {}
template <typename TokenT>
void operator()(TokenT const &token) const
{
found_eof = true;
}
bool &found_eof;
};
///////////////////////////////////////////////////////////////////////////////
//
// store_found_directive
//
// The store_found_directive functor stores the token_id of the recognized
// pp directive
//
///////////////////////////////////////////////////////////////////////////////
struct store_found_directive {
store_found_directive(boost::wave::token_id &found_directive_)
: found_directive(found_directive_) {}
template <typename TokenT>
void operator()(TokenT const &token) const
{
found_directive = boost::wave::token_id(token);
}
boost::wave::token_id &found_directive;
};
///////////////////////////////////////////////////////////////////////////////
//
// flush_underlying_parser
//
// The flush_underlying_parser flushes the underlying
// multi_pass_iterator during the normal parsing process. This is
// used at certain points during the parsing process, when it is
// clear, that no backtracking is needed anymore and the input
// gathered so far may be discarded.
//
///////////////////////////////////////////////////////////////////////////////
struct flush_underlying_parser
: public boost::spirit::parser<flush_underlying_parser>
{
typedef flush_underlying_parser this_t;
template <typename ScannerT>
typename boost::spirit::parser_result<this_t, ScannerT>::type
parse(ScannerT const& scan) const
{
scan.first.clear_queue();
return scan.empty_match();
}
};
flush_underlying_parser const
flush_underlying_parser_p = flush_underlying_parser();
} // anonymous namespace
///////////////////////////////////////////////////////////////////////////////
// define, whether the rule's should generate some debug output
#define TRACE_CPP_GRAMMAR \
bool(BOOST_SPIRIT_DEBUG_FLAGS_CPP & BOOST_SPIRIT_DEBUG_FLAGS_CPP_GRAMMAR) \
/**/
///////////////////////////////////////////////////////////////////////////////
// Encapsulation of the C++ preprocessor grammar.
template <typename PositionT>
struct cpp_grammar :
public boost::spirit::grammar<cpp_grammar<PositionT> >
{
typedef cpp_grammar<PositionT> grammar_t;
typedef impl::store_position<PositionT> store_pos_t;
typedef impl::store_found_eof store_found_eof_t;
typedef impl::store_found_directive store_found_directive_t;
template <typename ScannerT>
struct definition
{
// non-parse_tree generating rule type
typedef typename ScannerT::iteration_policy_t iteration_policy_t;
typedef boost::spirit::match_policy match_policy_t;
typedef typename ScannerT::action_policy_t action_policy_t;
typedef
boost::spirit::scanner_policies<
iteration_policy_t, match_policy_t, action_policy_t>
policies_t;
typedef
boost::spirit::scanner<typename ScannerT::iterator_t, policies_t>
non_tree_scanner_t;
typedef boost::spirit::rule<non_tree_scanner_t> no_tree_rule_t;
// 'normal' (parse_tree generating) rule type
typedef boost::spirit::rule<ScannerT> rule_t;
rule_t pp_statement;
rule_t include_file, system_include_file, macro_include_file;
rule_t plain_define, macro_definition, macro_parameters;
rule_t undefine;
rule_t ppifdef, ppifndef, ppif, ppelse, ppelif, ppendif;
rule_t ppline;
rule_t pperror;
rule_t ppwarning;
rule_t pppragma;
rule_t illformed;
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
rule_t ppregion;
rule_t ppendregion;
rule_t ppimport;
rule_t pp_regionsupport;
#endif
rule_t ppqualifiedname;
rule_t eol_tokens;
no_tree_rule_t ppsp;
definition(cpp_grammar const &self)
{
// import the spirit and cpplexer namespaces here
using namespace boost::spirit;
using namespace boost::wave;
using namespace boost::wave::util;
// save the rule id's for later use
self.rule_ids.pp_statement_id = pp_statement.id().to_long();
self.rule_ids.include_file_id = include_file.id().to_long();
self.rule_ids.sysinclude_file_id = system_include_file.id().to_long();
self.rule_ids.macroinclude_file_id = macro_include_file.id().to_long();
self.rule_ids.plain_define_id = plain_define.id().to_long();
self.rule_ids.macro_parameters_id = macro_parameters.id().to_long();
self.rule_ids.macro_definition_id = macro_definition.id().to_long();
self.rule_ids.undefine_id = undefine.id().to_long();
self.rule_ids.ifdef_id = ppifdef.id().to_long();
self.rule_ids.ifndef_id = ppifndef.id().to_long();
self.rule_ids.if_id = ppif.id().to_long();
self.rule_ids.elif_id = ppelif.id().to_long();
self.rule_ids.else_id = ppelse.id().to_long();
self.rule_ids.endif_id = ppendif.id().to_long();
self.rule_ids.line_id = ppline.id().to_long();
self.rule_ids.error_id = pperror.id().to_long();
self.rule_ids.warning_id = ppwarning.id().to_long();
self.rule_ids.pragma_id = pppragma.id().to_long();
self.rule_ids.illformed_id = illformed.id().to_long();
self.rule_ids.ppspace_id = ppsp.id().to_long();
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
self.rule_ids.ppregion_id = ppregion.id().to_long();
self.rule_ids.ppendregion_id = ppendregion.id().to_long();
self.rule_ids.pp_regionsupport_id = pp_regionsupport.id().to_long();
self.rule_ids.ppimport_id = ppimport.id().to_long();
#endif
self.rule_ids.ppqualifiedname_id = ppqualifiedname.id().to_long();
#if BOOST_WAVE_DUMP_PARSE_TREE != 0
self.map_rule_id_to_name.init_rule_id_to_name_map(self);
#endif
// recognizes preprocessor directives only
// C++ standard 16.1: A preprocessing directive consists of a sequence
// of preprocessing tokens. The first token in the sequence is #
// preprocessing token that is either the first character in the source
// file (optionally after white space containing no new-line
// characters) or that follows white space containing at least one
// new-line character. The last token in the sequence is the first
// new-line character that follows the first token in the sequence.
pp_statement
= ( include_file
| system_include_file
| macro_include_file
| plain_define
| undefine
| ppifdef
| ppifndef
| ppif
| ppelse
| ppelif
| ppendif
| ppline
| pperror
| ppwarning
| pppragma
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
| pp_regionsupport
#endif
| illformed
)
>> eol_tokens
#if !(defined(BOOST_SPIRIT_DEBUG) && \
(BOOST_SPIRIT_DEBUG_FLAGS_CPP & BOOST_SPIRIT_DEBUG_FLAGS_CPP_GRAMMAR))
>> impl::flush_underlying_parser_p
#endif // !(defined(BOOST_SPIRIT_DEBUG) &&
// (BOOST_SPIRIT_DEBUG_FLAGS_CPP & BOOST_SPIRIT_DEBUG_FLAGS_CPP_GRAMMAR))
;
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
// the pp_regionsupport is factored out, because else
// VC7.1 complains about an out of heapspace error (non-fixable)
pp_regionsupport
= ppregion
| ppendregion
| ppimport
;
#endif
// #include ...
include_file // include "..."
= ch_p(T_PP_QHEADER)
[ store_found_directive_t(self.found_directive) ]
#if BOOST_WAVE_SUPPORT_INCLUDE_NEXT != 0
| ch_p(T_PP_QHEADER_NEXT)
[ store_found_directive_t(self.found_directive) ]
#endif
;
system_include_file // include <...>
= ch_p(T_PP_HHEADER)
[ store_found_directive_t(self.found_directive) ]
#if BOOST_WAVE_SUPPORT_INCLUDE_NEXT != 0
| ch_p(T_PP_HHEADER_NEXT)
[ store_found_directive_t(self.found_directive) ]
#endif
;
macro_include_file // include ...anything else...
= no_node_d
[
ch_p(T_PP_INCLUDE)
[ store_found_directive_t(self.found_directive) ]
#if BOOST_WAVE_SUPPORT_INCLUDE_NEXT != 0
| ch_p(T_PP_INCLUDE_NEXT)
[ store_found_directive_t(self.found_directive) ]
#endif
]
>> *( anychar_p -
(ch_p(T_NEWLINE) | ch_p(T_CPPCOMMENT) | ch_p(T_EOF))
)
;
// #define FOO foo (with optional parameters)
plain_define
= no_node_d
[
ch_p(T_PP_DEFINE)
[ store_found_directive_t(self.found_directive) ]
>> +ppsp
]
>> ( ch_p(T_IDENTIFIER)
| pattern_p(KeywordTokenType, TokenTypeMask)
)
>> !macro_parameters
>> !macro_definition
;
// parameter list
// normal C++ mode
macro_parameters
= confix_p(
no_node_d[ch_p(T_LEFTPAREN) >> *ppsp],
!list_p(
( ch_p(T_IDENTIFIER)
| pattern_p(KeywordTokenType, TokenTypeMask)
#if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
| ch_p(T_ELLIPSIS)
#endif
),
no_node_d[*ppsp >> ch_p(T_COMMA) >> *ppsp]
),
no_node_d[*ppsp >> ch_p(T_RIGHTPAREN)]
)
;
// macro body (anything left until eol)
macro_definition
= no_node_d[*ppsp]
>> *( anychar_p -
(ch_p(T_NEWLINE) | ch_p(T_CPPCOMMENT) | ch_p(T_EOF))
)
;
// #undef FOO
undefine
= no_node_d
[
ch_p(T_PP_UNDEF)
[ store_found_directive_t(self.found_directive) ]
>> +ppsp
]
>> ( ch_p(T_IDENTIFIER)
| pattern_p(KeywordTokenType, TokenTypeMask)
)
;
// #ifdef et.al.
ppifdef
= no_node_d
[
ch_p(T_PP_IFDEF)
[ store_found_directive_t(self.found_directive) ]
>> +ppsp
]
>> ppqualifiedname
;
ppifndef
= no_node_d
[
ch_p(T_PP_IFNDEF)
[ store_found_directive_t(self.found_directive) ]
>> +ppsp
]
>> ppqualifiedname
;
ppif
= no_node_d
[
ch_p(T_PP_IF)
[ store_found_directive_t(self.found_directive) ]
>> *ppsp
]
>> +( anychar_p -
(ch_p(T_NEWLINE) | ch_p(T_CPPCOMMENT) | ch_p(T_EOF))
)
;
ppelse
= no_node_d
[
ch_p(T_PP_ELSE)
[ store_found_directive_t(self.found_directive) ]
]
;
ppelif
= no_node_d
[
ch_p(T_PP_ELIF)
[ store_found_directive_t(self.found_directive) ]
>> *ppsp
]
>> +( anychar_p -
(ch_p(T_NEWLINE) | ch_p(T_CPPCOMMENT) | ch_p(T_EOF))
)
;
ppendif
= no_node_d
[
ch_p(T_PP_ENDIF)
[ store_found_directive_t(self.found_directive) ]
]
;
// #line ...
ppline
= no_node_d
[
ch_p(T_PP_LINE)
[ store_found_directive_t(self.found_directive) ]
>> *ppsp
]
>> +( anychar_p -
(ch_p(T_NEWLINE) | ch_p(T_CPPCOMMENT) | ch_p(T_EOF))
)
;
// # something else (ill formed preprocessor directive)
illformed // for error reporting
= no_node_d[ch_p(T_POUND) >> *ppsp]
>> ( anychar_p -
(ch_p(T_NEWLINE) | ch_p(T_CPPCOMMENT) | ch_p(T_EOF))
)
>> no_node_d
[
*( anychar_p -
(ch_p(T_NEWLINE) | ch_p(T_CPPCOMMENT) | ch_p(T_EOF))
)
]
;
// #error
pperror
= no_node_d
[
ch_p(T_PP_ERROR)
[ store_found_directive_t(self.found_directive) ]
>> *ppsp
]
>> *( anychar_p -
(ch_p(T_NEWLINE) | ch_p(T_CPPCOMMENT) | ch_p(T_EOF))
)
;
// #warning
ppwarning
= no_node_d
[
ch_p(T_PP_WARNING)
[ store_found_directive_t(self.found_directive) ]
>> *ppsp
]
>> *( anychar_p -
(ch_p(T_NEWLINE) | ch_p(T_CPPCOMMENT) | ch_p(T_EOF))
)
;
// #pragma ...
pppragma
= no_node_d
[
ch_p(T_PP_PRAGMA)
[ store_found_directive_t(self.found_directive) ]
]
>> *( anychar_p -
(ch_p(T_NEWLINE) | ch_p(T_CPPCOMMENT) | ch_p(T_EOF))
)
;
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
// #region [name]
ppregion
= no_node_d
[
ch_p(T_PP_REGION)
[ store_found_directive_t(self.found_directive) ]
]
>> !(
no_node_d[+ppsp]
>> ppqualifiedname
)
;
// #endregion
ppendregion
= no_node_d
[
ch_p(T_PP_ENDREGION)
[ store_found_directive_t(self.found_directive) ]
]
;
// #import name
ppimport
= no_node_d
[
ch_p(T_PP_IMPORT)
[ store_found_directive_t(self.found_directive) ]
>> *ppsp
]
>> list_p(
ppqualifiedname,
no_node_d[*ppsp >> ch_p(T_COMMA) >> *ppsp]
)
;
#endif
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
// possibly qualified name
ppqualifiedname
= ch_p(T_COLON_COLON)
|| (no_node_d[*ppsp]
>> list_p(
( ch_p(T_IDENTIFIER)
| pattern_p(KeywordTokenType, TokenTypeMask)
),
no_node_d[*ppsp]
>> ch_p(T_COLON_COLON)
>> no_node_d[*ppsp]
)
)
;
#else
ppqualifiedname
= no_node_d[*ppsp]
>> ( ch_p(T_IDENTIFIER)
| pattern_p(KeywordTokenType, TokenTypeMask)
)
;
#endif // BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
// auxiliary helper rules
ppsp // valid space in a line with a preprocessor directive
= ch_p(T_SPACE) | ch_p(T_CCOMMENT)
;
// end of line tokens
eol_tokens
= no_node_d
[
*ppsp
>> ( ch_p(T_NEWLINE)
[ store_pos_t(self.pos_of_newline) ]
| ch_p(T_CPPCOMMENT)
[ store_pos_t(self.pos_of_newline) ]
| ch_p(T_EOF)
[ store_pos_t(self.pos_of_newline) ]
[ store_found_eof_t(self.found_eof) ]
)
]
;
BOOST_SPIRIT_DEBUG_TRACE_RULE(pp_statement, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(include_file, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(system_include_file, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(macro_include_file, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(plain_define, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(macro_definition, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(macro_parameters, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(undefine, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(ppifdef, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(ppifndef, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(ppif, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(ppelse, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(ppelif, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(ppendif, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(ppline, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(pperror, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(ppwarning, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(illformed, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(ppsp, TRACE_CPP_GRAMMAR);
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
BOOST_SPIRIT_DEBUG_TRACE_RULE(pp_regionsupport, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(ppregion, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(ppendregion, TRACE_CPP_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(ppimport, TRACE_CPP_GRAMMAR);
#endif
BOOST_SPIRIT_DEBUG_TRACE_RULE(ppqualifiedname, TRACE_CPP_GRAMMAR);
}
// start rule of this grammar
rule_t const& start() const
{ return pp_statement; }
};
cpp_grammar_rule_ids &rule_ids;
PositionT &pos_of_newline;
bool &found_eof;
boost::wave::token_id &found_directive;
cpp_grammar(cpp_grammar_rule_ids &rule_ids_, PositionT &pos_of_newline_,
bool &found_eof_, boost::wave::token_id &found_directive_)
: rule_ids(rule_ids_), pos_of_newline(pos_of_newline_),
found_eof(found_eof_), found_directive(found_directive_)
{
BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR_NAME(*this, "cpp_grammar",
TRACE_CPP_GRAMMAR);
}
#if BOOST_WAVE_DUMP_PARSE_TREE != 0
// helper function and data to get readable names of the rules known to us
struct map_ruleid_to_name :
public std::map<boost::spirit::parser_id, std::string>
{
typedef std::map<boost::spirit::parser_id, std::string> base_t;
void init_rule_id_to_name_map(cpp_grammar const &self)
{
struct {
int parser_id;
char const *rule_name;
}
init_ruleid_name_map[] = {
{ self.rule_ids.pp_statement_id, "pp_statement" },
{ self.rule_ids.include_file_id, "include_file" },
{ self.rule_ids.sysinclude_file_id, "system_include_file" },
{ self.rule_ids.macroinclude_file_id, "macro_include_file" },
{ self.rule_ids.plain_define_id, "plain_define" },
{ self.rule_ids.macro_parameters_id, "macro_parameters" },
{ self.rule_ids.macro_definition_id, "macro_definition" },
{ self.rule_ids.undefine_id, "undefine" },
{ self.rule_ids.ifdef_id, "ppifdef" },
{ self.rule_ids.ifndef_id, "ppifndef" },
{ self.rule_ids.if_id, "ppif" },
{ self.rule_ids.elif_id, "ppelif" },
{ self.rule_ids.else_id, "ppelse" },
{ self.rule_ids.endif_id, "ppendif" },
{ self.rule_ids.line_id, "ppline" },
{ self.rule_ids.error_id, "pperror" },
{ self.rule_ids.warning_id, "ppwarning" },
{ self.rule_ids.pragma_id, "pppragma" },
{ self.rule_ids.illformed_id, "illformed" },
{ self.rule_ids.ppsp_id, "ppsp" },
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
{ self.rule_ids.pp_regionsupport_id, "pp_regionsupport" },
{ self.rule_ids.ppregion_id, "pp" BOOST_WAVE_PP_REGION },
{ self.rule_ids.ppendregion_id, "pp" BOOST_WAVE_PP_ENDREGION },
{ self.rule_ids.ppimport_id, "pp" BOOST_WAVE_PP_IMPORT },
#endif
{ self.rule_ids.ppqualifiedname_id, "ppqualifiedname" },
{ 0 }
};
// initialize parser_id to rule_name map
for (int i = 0; 0 != init_ruleid_name_map[i].parser_id; ++i)
base_t::insert(base_t::value_type(
boost::spirit::parser_id(init_ruleid_name_map[i].parser_id),
std::string(init_ruleid_name_map[i].rule_name))
);
}
};
mutable map_ruleid_to_name map_rule_id_to_name;
#endif // WAVE_DUMP_PARSE_TREE != 0
};
///////////////////////////////////////////////////////////////////////////////
#undef TRACE_CPP_GRAMMAR
///////////////////////////////////////////////////////////////////////////////
//
// The following parse function is defined here, to allow the separation of
// the compilation of the cpp_grammar from the function using it.
//
///////////////////////////////////////////////////////////////////////////////
#if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0
#define BOOST_WAVE_GRAMMAR_GEN_INLINE
#else
#define BOOST_WAVE_GRAMMAR_GEN_INLINE inline
#endif
namespace {
char const *get_directivename(boost::wave::token_id id)
{
using namespace boost::wave;
switch (id) {
case T_PP_QHEADER:
case T_PP_HHEADER:
case T_PP_INCLUDE: return "#include";
case T_PP_DEFINE: return "#define";
case T_PP_UNDEF: return "#undef";
case T_PP_IFDEF: return "#ifdef";
case T_PP_IFNDEF: return "#ifndef";
case T_PP_IF: return "#if";
case T_PP_ELSE: return "#else";
case T_PP_ELIF: return "#elif";
case T_PP_ENDIF: return "#endif";
case T_PP_LINE: return "#line";
case T_PP_ERROR: return "#error";
case T_PP_WARNING: return "#warning";
case T_PP_PRAGMA: return "#pragma";
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
case T_PP_REGION: return "#" BOOST_WAVE_PP_REGION;
case T_PP_ENDREGION: return "#" BOOST_WAVE_PP_ENDREGION;
case T_PP_IMPORT: return "#" BOOST_WAVE_PP_IMPORT;
#endif
default:
return "#unknown directive";
}
}
}
template <typename LexIteratorT>
BOOST_WAVE_GRAMMAR_GEN_INLINE
boost::spirit::tree_parse_info<LexIteratorT>
cpp_grammar_gen<LexIteratorT>::parse_cpp_grammar (
LexIteratorT const &first, LexIteratorT const &last,
bool &found_eof_, position_t const &act_pos)
{
using namespace boost::spirit;
using namespace boost::wave;
pos_of_newline = position_t(); // reset position
found_eof = false; // reset flag
found_directive = T_EOF; // reset found directive
static cpp_grammar<position_t> g(
rule_ids, pos_of_newline, found_eof, found_directive);
tree_parse_info<LexIteratorT> hit = pt_parse (first, last, g);
#if BOOST_WAVE_DUMP_PARSE_TREE != 0
if (hit.match) {
tree_to_xml (BOOST_WAVE_DUMP_PARSE_TREE_OUT, hit.trees, "",
g.map_rule_id_to_name, &TokenT::get_token_id,
&TokenT::get_token_value);
}
#endif
if (!hit.match && found_directive != T_EOF) {
// recognized invalid directive
std::string directive = get_directivename(found_directive);
BOOST_WAVE_THROW(preprocess_exception, ill_formed_directive,
directive, act_pos);
}
found_eof_ = found_eof;
return hit;
}
#undef BOOST_WAVE_GRAMMAR_GEN_INLINE
///////////////////////////////////////////////////////////////////////////////
} // namespace grammars
} // namespace wave
} // namespace boost
#endif // !defined(CPP_GRAMMAR_HPP_FEAEBC2E_2734_428B_A7CA_85E5A415E23E_INCLUDED)

View File

@@ -0,0 +1,120 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(CPP_GRAMMAR_GEN_HPP_80CB8A59_5411_4E45_B406_62531A12FB99_INCLUDED)
#define CPP_GRAMMAR_GEN_HPP_80CB8A59_5411_4E45_B406_62531A12FB99_INCLUDED
#include <boost/spirit/tree/parse_tree.hpp>
#include <boost/wave/wave_config.hpp>
#include <boost/wave/language_support.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace grammars {
///////////////////////////////////////////////////////////////////////////////
//
// store parser_id's of all rules of the cpp_grammar here for later access
//
///////////////////////////////////////////////////////////////////////////////
struct cpp_grammar_rule_ids {
std::size_t pp_statement_id;
std::size_t include_file_id; // #include "..."
std::size_t sysinclude_file_id; // #include <...>
std::size_t macroinclude_file_id; // #include ...
std::size_t plain_define_id; // #define
std::size_t macro_parameters_id;
std::size_t macro_definition_id;
std::size_t undefine_id; // #undef
std::size_t ifdef_id; // #ifdef
std::size_t ifndef_id; // #ifndef
std::size_t if_id; // #if
std::size_t elif_id; // #elif
std::size_t else_id; // #else
std::size_t endif_id; // #endif
std::size_t line_id; // #line
std::size_t error_id; // #error
std::size_t warning_id; // #warning
std::size_t pragma_id; // #pragma
std::size_t illformed_id;
std::size_t ppspace_id;
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
std::size_t pp_regionsupport_id;
std::size_t ppregion_id; // #region
std::size_t ppendregion_id; // #endregion
std::size_t ppimport_id; // #import
#endif
std::size_t ppqualifiedname_id;
};
///////////////////////////////////////////////////////////////////////////////
//
// cpp_grammar_gen template class
//
// This template helps separating the compilation of the cpp_grammar
// class from the compilation of the main pp_iterator. This is done to
// safe compilation time.
//
///////////////////////////////////////////////////////////////////////////////
template <typename LexIteratorT>
struct cpp_grammar_gen
{
typedef LexIteratorT iterator_t;
typedef typename LexIteratorT::token_t token_t;
typedef typename token_t::position_t position_t;
// the parser_id's of all rules of the cpp_grammar are stored here
// note: these are valid only after the first call to parse_cpp_grammar
static cpp_grammar_rule_ids rule_ids;
// the actual position of the last matched T_NEWLINE is stored here into the
// member 'pos_of_newline'
static position_t pos_of_newline;
// the found_eof flag is set to true during the parsing, if the directive
// under inspection terminates with a T__EOF token
static bool found_eof;
// the found_directive contains the token_id of the recognized pp directive
static boost::wave::token_id found_directive;
// parse the cpp_grammar and return the resulting parse tree
static boost::spirit::tree_parse_info<iterator_t>
parse_cpp_grammar (iterator_t const &first, iterator_t const &last,
bool &found_eof_, position_t const &act_pos);
};
///////////////////////////////////////////////////////////////////////////////
// definitions of the static members
template <typename LexIteratorT>
cpp_grammar_rule_ids
cpp_grammar_gen<LexIteratorT>::rule_ids;
template <typename LexIteratorT>
typename LexIteratorT::token_t::position_t
cpp_grammar_gen<LexIteratorT>::pos_of_newline;
template <typename LexIteratorT>
bool cpp_grammar_gen<LexIteratorT>::found_eof = false;
template <typename LexIteratorT>
boost::wave::token_id cpp_grammar_gen<LexIteratorT>::found_directive =
boost::wave::T_EOF;
///////////////////////////////////////////////////////////////////////////////
} // namespace grammars
} // namespace wave
} // namespace boost
#endif // !defined(CPP_GRAMMAR_GEN_HPP_80CB8A59_5411_4E45_B406_62531A12FB99_INCLUDED)

View File

@@ -0,0 +1,184 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(CPP_INTLIT_GRAMMAR_HPP_2E1E70B1_F15C_4132_8554_10A231B0D91C_INCLUDED)
#define CPP_INTLIT_GRAMMAR_HPP_2E1E70B1_F15C_4132_8554_10A231B0D91C_INCLUDED
#include <boost/spirit/core.hpp>
#include <boost/spirit/attribute/closure.hpp>
#if SPIRIT_VERSION >= 0x1700
#include <boost/spirit/actor/assign_actor.hpp>
#include <boost/spirit/actor/push_back_actor.hpp>
#endif // SPIRIT_VERSION >= 0x1700
#include <boost/spirit/phoenix/operators.hpp>
#include <boost/spirit/phoenix/primitives.hpp>
#include <boost/spirit/phoenix/statements.hpp>
#include <boost/wave/wave_config.hpp>
#include <boost/wave/cpp_exceptions.hpp>
#include <boost/wave/grammars/cpp_literal_grammar_gen.hpp>
#if !defined(spirit_append_actor)
#if SPIRIT_VERSION >= 0x1700
#define spirit_append_actor(actor) boost::spirit::push_back_a(actor)
#define spirit_assign_actor(actor) boost::spirit::assign_a(actor)
#else
#define spirit_append_actor(actor) boost::spirit::append(actor)
#define spirit_assign_actor(actor) boost::spirit::assign(actor)
#endif // SPIRIT_VERSION >= 0x1700
#endif // !defined(spirit_append_actor)
///////////////////////////////////////////////////////////////////////////////
//
// Reusable grammar for parsing of C++ style integer literals
//
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace grammars {
namespace closures {
struct intlit_closure
: boost::spirit::closure<intlit_closure, unsigned long>
{
member1 val;
};
}
///////////////////////////////////////////////////////////////////////////////
// define, whether the rule's should generate some debug output
#define TRACE_INTLIT_GRAMMAR \
bool(BOOST_SPIRIT_DEBUG_FLAGS_CPP & BOOST_SPIRIT_DEBUG_FLAGS_INTLIT_GRAMMAR) \
/**/
struct intlit_grammar :
boost::spirit::grammar<intlit_grammar, closures::intlit_closure::context_t>
{
intlit_grammar(bool &is_unsigned_) : is_unsigned(is_unsigned_)
{
BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR_NAME(*this, "intlit_grammar",
TRACE_INTLIT_GRAMMAR);
}
template <typename ScannerT>
struct definition
{
typedef boost::spirit::rule<ScannerT> rule_t;
rule_t int_lit;
boost::spirit::subrule<0> sub_int_lit;
boost::spirit::subrule<1> oct_lit;
boost::spirit::subrule<2> hex_lit;
boost::spirit::subrule<3> dec_lit;
definition(intlit_grammar const &self)
{
using namespace boost::spirit;
using namespace phoenix;
int_lit = (
sub_int_lit =
( ch_p('0')[self.val = 0] >> (hex_lit | oct_lit)
| dec_lit
)
>> !as_lower_d[
(ch_p('u')[var(self.is_unsigned) = true] || ch_p('l'))
| (ch_p('l') || ch_p('u')[var(self.is_unsigned) = true])
]
,
hex_lit =
(ch_p('X') | ch_p('x'))
>> uint_parser<unsigned long, 16>()
[
self.val = arg1,
var(self.is_unsigned) = true
]
,
oct_lit =
!uint_parser<unsigned long, 8>()
[
self.val = arg1,
var(self.is_unsigned) = true
]
,
dec_lit =
int_parser<long, 10>()
[
self.val = arg1
]
)
;
BOOST_SPIRIT_DEBUG_TRACE_RULE(int_lit, TRACE_INTLIT_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(sub_int_lit, TRACE_INTLIT_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(hex_lit, TRACE_INTLIT_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(oct_lit, TRACE_INTLIT_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(dec_lit, TRACE_INTLIT_GRAMMAR);
}
// start rule of this grammar
rule_t const& start() const
{ return int_lit; }
};
bool &is_unsigned;
};
#undef TRACE_INTLIT_GRAMMAR
///////////////////////////////////////////////////////////////////////////////
//
// The following function is defined here, to allow the separation of
// the compilation of the intlit_grammap from the function using it.
//
///////////////////////////////////////////////////////////////////////////////
#if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0
#define BOOST_WAVE_INTLITGRAMMAR_GEN_INLINE
#else
#define BOOST_WAVE_INTLITGRAMMAR_GEN_INLINE inline
#endif
template <typename TokenT>
BOOST_WAVE_INTLITGRAMMAR_GEN_INLINE
unsigned long
intlit_grammar_gen<TokenT>::evaluate(TokenT const &token,
bool &is_unsigned)
{
using namespace boost::spirit;
intlit_grammar g(is_unsigned);
unsigned long result = 0;
typename TokenT::string_t const &token_val = token.get_value();
parse_info<typename TokenT::string_t::const_iterator> hit =
parse(token_val.begin(), token_val.end(), g[spirit_assign_actor(result)]);
if (!hit.hit) {
BOOST_WAVE_THROW(preprocess_exception, ill_formed_expression,
token_val, token.get_position());
}
return result;
}
#undef BOOST_WAVE_INTLITGRAMMAR_GEN_INLINE
///////////////////////////////////////////////////////////////////////////////
} // namespace grammars
} // namespace wave
} // namespace boost
#endif // !defined(CPP_INTLIT_GRAMMAR_HPP_2E1E70B1_F15C_4132_8554_10A231B0D91C_INCLUDED)

View File

@@ -0,0 +1,55 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(CPP_LITERAL_GRAMMAR_GEN_HPP_67794A6C_468A_4AAB_A757_DEDDB182F5A0_INCLUDED)
#define CPP_LITERAL_GRAMMAR_GEN_HPP_67794A6C_468A_4AAB_A757_DEDDB182F5A0_INCLUDED
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace grammars {
///////////////////////////////////////////////////////////////////////////////
//
// cpp_intlit_grammar_gen template class
//
// This template helps separating the compilation of the intlit_grammar
// class from the compilation of the expression_grammar. This is done
// to safe compilation time.
//
///////////////////////////////////////////////////////////////////////////////
template <typename TokenT>
struct intlit_grammar_gen {
static unsigned long evaluate(TokenT const &tok, bool &is_unsigned);
};
///////////////////////////////////////////////////////////////////////////////
//
// cpp_chlit_grammar_gen template class
//
// This template helps separating the compilation of the chlit_grammar
// class from the compilation of the expression_grammar. This is done
// to safe compilation time.
//
///////////////////////////////////////////////////////////////////////////////
template <typename TokenT>
struct chlit_grammar_gen {
static unsigned int evaluate(TokenT const &tok);
};
///////////////////////////////////////////////////////////////////////////////
} // namespace grammars
} // namespace wave
} // namespace boost
#endif // !defined(CPP_LITERAL_GRAMMAR_GEN_HPP_67794A6C_468A_4AAB_A757_DEDDB182F5A0_INCLUDED)

View File

@@ -0,0 +1,74 @@
/*=============================================================================
A Standard compliant C++ preprocessor
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(CPP_PREDEF_MACROS_GEN_HPP_CADB6D2C_76A4_4988_83E1_EFFC6902B9A2_INCLUDED)
#define CPP_PREDEF_MACROS_GEN_HPP_CADB6D2C_76A4_4988_83E1_EFFC6902B9A2_INCLUDED
#include <boost/spirit/tree/parse_tree.hpp>
#include <boost/wave/wave_config.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace grammars {
///////////////////////////////////////////////////////////////////////////////
//
// store parser_id's of all rules of the predefined_macros_grammar here
// for later access
//
///////////////////////////////////////////////////////////////////////////////
struct predefined_macros_grammar_rule_ids {
std::size_t plain_define_id; // #define
std::size_t macro_parameters_id;
std::size_t macro_definition_id;
};
///////////////////////////////////////////////////////////////////////////////
//
// predefined_macros_grammar_gen template class
//
// This template helps separating the compilation of the
// predefined_macros_grammar class from the compilation of the
// main pp_iterator. This is done to safe compilation time.
//
// This class helps parsing command line given macro definitions in a
// similar way, as macros are parsed by the cpp_grammar class.
//
///////////////////////////////////////////////////////////////////////////////
template <typename LexIteratorT>
struct predefined_macros_grammar_gen
{
typedef LexIteratorT iterator_t;
// the parser_id's of all rules of the cpp_grammar are stored here
// note: these are valid only after the first call to parse_cpp_grammar
static predefined_macros_grammar_rule_ids rule_ids;
// parse the cpp_grammar and return the resulting parse tree
static boost::spirit::tree_parse_info<iterator_t>
parse_predefined_macro (iterator_t const &first, iterator_t const &last);
};
///////////////////////////////////////////////////////////////////////////////
// definitions of the static members
template <typename LexIteratorT>
predefined_macros_grammar_rule_ids
predefined_macros_grammar_gen<LexIteratorT>::rule_ids;
///////////////////////////////////////////////////////////////////////////////
} // namespace grammars
} // namespace wave
} // namespace boost
#endif // !defined(CPP_PREDEF_MACROS_GEN_HPP_CADB6D2C_76A4_4988_83E1_EFFC6902B9A2_INCLUDED)

View File

@@ -0,0 +1,157 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(CPP_PREDEF_MACROS_GRAMMAR_HPP_53858C9A_C202_4D60_AD92_DC9CAE4DBB43_INCLUDED)
#define CPP_PREDEF_MACROS_GRAMMAR_HPP_53858C9A_C202_4D60_AD92_DC9CAE4DBB43_INCLUDED
#include <boost/spirit/core.hpp>
#include <boost/spirit/tree/parse_tree.hpp>
#include <boost/spirit/utility/confix.hpp>
#include <boost/spirit/utility/lists.hpp>
#include <boost/wave/wave_config.hpp>
#include <boost/wave/token_ids.hpp>
#include <boost/wave/grammars/cpp_predef_macros_gen.hpp>
#include <boost/wave/util/pattern_parser.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace grammars {
///////////////////////////////////////////////////////////////////////////////
// define, whether the rule's should generate some debug output
#define TRACE_PREDEF_MACROS_GRAMMAR \
bool(BOOST_SPIRIT_DEBUG_FLAGS_CPP & BOOST_SPIRIT_DEBUG_FLAGS_PREDEF_MACROS_GRAMMAR) \
/**/
///////////////////////////////////////////////////////////////////////////////
// Encapsulation of the grammar for command line driven predefined macros.
struct predefined_macros_grammar :
public boost::spirit::grammar<predefined_macros_grammar>
{
template <typename ScannerT>
struct definition
{
// 'normal' (parse_tree generating) rule type
typedef boost::spirit::rule<ScannerT> rule_t;
rule_t plain_define, macro_definition, macro_parameters;
definition(predefined_macros_grammar const &self)
{
// import the spirit and cpplexer namespaces here
using namespace boost::spirit;
using namespace boost::wave;
using namespace boost::wave::util;
// save the rule id's for later use
self.rule_ids.plain_define_id = plain_define.id().to_long();
self.rule_ids.macro_parameters_id = macro_parameters.id().to_long();
self.rule_ids.macro_definition_id = macro_definition.id().to_long();
// recognizes command line defined macro syntax, i.e.
// -DMACRO
// -DMACRO=
// -DMACRO=value
// -DMACRO(x)
// -DMACRO(x)=
// -DMACRO(x)=value
// This grammar resembles the overall structure of the cpp_grammar to
// make it possible to reuse the parse tree traversal code
plain_define
= ( ch_p(T_IDENTIFIER)
| pattern_p(KeywordTokenType, TokenTypeMask)
)
>> !macro_parameters
>> !macro_definition
;
// parameter list
macro_parameters
= confix_p(
no_node_d[ch_p(T_LEFTPAREN) >> *ch_p(T_SPACE)],
!list_p(
( ch_p(T_IDENTIFIER)
| pattern_p(KeywordTokenType, TokenTypeMask)
),
no_node_d
[
*ch_p(T_SPACE) >> ch_p(T_COMMA) >> *ch_p(T_SPACE)
]
),
no_node_d[*ch_p(T_SPACE) >> ch_p(T_RIGHTPAREN)]
)
;
// macro body (anything left until eol)
macro_definition
= no_node_d[ch_p(T_ASSIGN)]
>> *anychar_p
;
BOOST_SPIRIT_DEBUG_TRACE_RULE(plain_define, TRACE_PREDEF_MACROS_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(macro_definition, TRACE_PREDEF_MACROS_GRAMMAR);
BOOST_SPIRIT_DEBUG_TRACE_RULE(macro_parameters, TRACE_PREDEF_MACROS_GRAMMAR);
}
// start rule of this grammar
rule_t const& start() const
{ return plain_define; }
};
predefined_macros_grammar_rule_ids &rule_ids;
predefined_macros_grammar(predefined_macros_grammar_rule_ids &rule_ids_)
: rule_ids(rule_ids_)
{
BOOST_SPIRIT_DEBUG_TRACE_GRAMMAR_NAME(*this,
"predefined_macros_grammar", TRACE_PREDEF_MACROS_GRAMMAR);
}
};
///////////////////////////////////////////////////////////////////////////////
#undef TRACE_PREDEF_MACROS_GRAMMAR
///////////////////////////////////////////////////////////////////////////////
//
// The following parse function is defined here, to allow the separation of
// the compilation of the cpp_predefined_macros_grammar from the function
// using it.
//
///////////////////////////////////////////////////////////////////////////////
#if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0
#define BOOST_WAVE_PREDEF_MACROS_GRAMMAR_GEN_INLINE
#else
#define BOOST_WAVE_PREDEF_MACROS_GRAMMAR_GEN_INLINE inline
#endif
template <typename LexIteratorT>
BOOST_WAVE_PREDEF_MACROS_GRAMMAR_GEN_INLINE
boost::spirit::tree_parse_info<LexIteratorT>
predefined_macros_grammar_gen<LexIteratorT>::parse_predefined_macro (
LexIteratorT const &first, LexIteratorT const &last)
{
static predefined_macros_grammar g(rule_ids);
return boost::spirit::pt_parse (first, last, g);
}
#undef BOOST_WAVE_PREDEF_MACROS_GRAMMAR_GEN_INLINE
///////////////////////////////////////////////////////////////////////////////
} // namespace grammars
} // namespace wave
} // namespace boost
#endif // !defined(CPP_PREDEF_MACROS_GRAMMAR_HPP_53858C9A_C202_4D60_AD92_DC9CAE4DBB43_INCLUDED)

View File

@@ -0,0 +1,191 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Definition of the various language support constants
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(LANGUAGE_SUPPORT_HPP_93EDD057_2DEF_44BC_BC9F_FDABB9F51AFA_INCLUDED)
#define LANGUAGE_SUPPORT_HPP_93EDD057_2DEF_44BC_BC9F_FDABB9F51AFA_INCLUDED
#include <boost/wave/wave_config.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
enum language_support {
// support flags for C++98
support_normal = 0x01,
support_cpp = support_normal,
#if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
// support flags for C99
support_variadics = 0x02,
support_c99 = support_variadics,
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
// support flags for the experimental C++0x features
support_extensions = 0x04,
support_cpp0x = support_normal | support_variadics | support_extensions,
#endif
#endif
};
///////////////////////////////////////////////////////////////////////////////
//
// need_cpp
//
// Extract, if the language to support is C++98
//
///////////////////////////////////////////////////////////////////////////////
inline bool
need_cpp(language_support language)
{
return language == support_cpp;
}
#if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
///////////////////////////////////////////////////////////////////////////////
//
// need_variadics
//
// Extract, if the language to support needs variadics support
//
///////////////////////////////////////////////////////////////////////////////
inline bool
need_variadics(language_support language)
{
return (language & support_variadics) ? true : false;
}
///////////////////////////////////////////////////////////////////////////////
//
// enable_variadics
//
// Set variadics support in the language to support
//
///////////////////////////////////////////////////////////////////////////////
inline language_support
enable_variadics(language_support language, bool enable = true)
{
if (enable)
return static_cast<language_support>(language | support_variadics);
return static_cast<language_support>(language & ~support_variadics);
}
///////////////////////////////////////////////////////////////////////////////
//
// need_c99
//
// Extract, if the language to support is C99
//
///////////////////////////////////////////////////////////////////////////////
inline bool
need_c99(language_support language)
{
return language == support_c99;
}
///////////////////////////////////////////////////////////////////////////////
//
// enable_c99
//
// Set, whether to support C99 (alternatively C++98 is supported)
//
///////////////////////////////////////////////////////////////////////////////
inline language_support
enable_c99(bool enable = true)
{
return enable ? support_c99 : support_cpp;
}
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
///////////////////////////////////////////////////////////////////////////////
//
// need_cpp0x
//
// Extract, if the language to support is C++0x
//
///////////////////////////////////////////////////////////////////////////////
inline bool
need_cpp0x(language_support language)
{
return language == support_cpp0x;
}
///////////////////////////////////////////////////////////////////////////////
//
// enable_c99
//
// Set, whether to support the C++0x features (alternatively C++98 is
// supported)
//
///////////////////////////////////////////////////////////////////////////////
inline language_support
enable_cpp0x(bool enable = true)
{
return enable ? support_cpp0x : support_cpp;
}
#else // BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
///////////////////////////////////////////////////////////////////////////////
inline bool
need_cpp0x(language_support language)
{
return false;
}
//////////////////////////////////////////////////////////////////////////////
inline language_support
enable_cpp0x(bool enable = true)
{
return support_cpp;
}
#endif // BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
#else // BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
///////////////////////////////////////////////////////////////////////////////
inline bool
need_variadics(language_support language)
{
return false;
}
///////////////////////////////////////////////////////////////////////////////
inline language_support
enable_variadics(language_support language, bool enable = true)
{
return language;
}
//////////////////////////////////////////////////////////////////////////////
inline bool
need_c99(language_support language)
{
return false;
}
///////////////////////////////////////////////////////////////////////////////
inline language_support
enable_c99(bool enable = true)
{
return support_cpp;
}
#endif // BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
///////////////////////////////////////////////////////////////////////////////
} // namespace wave
} // namespace boost
#endif // !defined(LANGUAGE_SUPPORT_HPP_93EDD057_2DEF_44BC_BC9F_FDABB9F51AFA_INCLUDED)

View File

@@ -0,0 +1,17 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor
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(LEX_TOKEN_HPP_2CE9E5C3_4678_4CDA_A894_FD4819BC364E_INCLUDED)
#define LEX_TOKEN_HPP_2CE9E5C3_4678_4CDA_A894_FD4819BC364E_INCLUDED
#include <boost/wave/wave_config.hpp>
#include BOOST_WAVE_LEX_TOKEN
#endif // !defined(LEX_TOKEN_HPP_2CE9E5C3_4678_4CDA_A894_FD4819BC364E_INCLUDED)

View File

@@ -0,0 +1,694 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
The definition of a default set of token identifiers and related
functions.
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(TOKEN_IDS_HPP_414E9A58_F079_4789_8AFF_513815CE475B_INCLUDED)
#define TOKEN_IDS_HPP_414E9A58_F079_4789_8AFF_513815CE475B_INCLUDED
#include <string>
#include <boost/assert.hpp>
#include <boost/wave/wave_config.hpp>
///////////////////////////////////////////////////////////////////////////////
// Allow external redefinition of the token identifiers to use
#if !defined(BOOST_WAVE_TOKEN_IDS_DEFINED)
#define BOOST_WAVE_TOKEN_IDS_DEFINED
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
///////////////////////////////////////////////////////////////////////////////
// assemble tokenid's
#define TOKEN_FROM_ID(id, cat) ((id) | (cat))
#define ID_FROM_TOKEN(tok) ((tok) & ~TokenTypeMask)
#define BASEID_FROM_TOKEN(tok) ((tok) & ~ExtTokenTypeMask)
#define CATEGORY_FROM_TOKEN(tok) ((tok) & TokenTypeMask)
#define EXTCATEGORY_FROM_TOKEN(tok) ((tok) & ExtTokenTypeMask)
#define IS_CATEGORY(tok, cat) \
((CATEGORY_FROM_TOKEN(tok) == (cat)) ? true : false) \
/**/
#define IS_EXTCATEGORY(tok, cat) \
((EXTCATEGORY_FROM_TOKEN(tok) == (cat)) ? true : false) \
/**/
///////////////////////////////////////////////////////////////////////////////
// the token_category helps to classify the different token types
enum token_category {
IdentifierTokenType = 0x10000000,
ParameterTokenType = 0x11000000,
ExtParameterTokenType = 0x11100000,
KeywordTokenType = 0x20000000,
OperatorTokenType = 0x30000000,
LiteralTokenType = 0x40000000,
IntegerLiteralTokenType = 0x41000000,
FloatingLiteralTokenType = 0x42000000,
StringLiteralTokenType = 0x43000000,
CharacterLiteralTokenType = 0x44000000,
BoolLiteralTokenType = 0x45000000,
PPTokenType = 0x50000000,
PPConditionalTokenType = 0x50100000,
UnknownTokenType = 0xA0000000,
EOLTokenType = 0xB0000000,
EOFTokenType = 0xC0000000,
WhiteSpaceTokenType = 0xD0000000,
InternalTokenType = 0xE0000000,
TokenTypeMask = 0xFF000000,
AltTokenType = 0x00100000,
TriGraphTokenType = 0x00200000,
ExtTokenTypeMask = 0xFFF00000,
TokenValueMask = 0x000FFFFF,
MainTokenMask = TokenTypeMask|TokenValueMask,
};
///////////////////////////////////////////////////////////////////////////////
// the token_id assigns unique numbers to the different C++ lexemes
enum token_id {
T_FIRST_TOKEN = 256,
T_AND = TOKEN_FROM_ID(T_FIRST_TOKEN, OperatorTokenType),
T_AND_ALT = TOKEN_FROM_ID(T_FIRST_TOKEN, OperatorTokenType|AltTokenType),
T_ANDAND = TOKEN_FROM_ID(257, OperatorTokenType),
T_ANDAND_ALT = TOKEN_FROM_ID(257, OperatorTokenType|AltTokenType),
T_ASSIGN = TOKEN_FROM_ID(258, OperatorTokenType),
T_ANDASSIGN = TOKEN_FROM_ID(259, OperatorTokenType),
T_ANDASSIGN_ALT = TOKEN_FROM_ID(259, OperatorTokenType|AltTokenType),
T_OR = TOKEN_FROM_ID(260, OperatorTokenType),
T_OR_ALT = TOKEN_FROM_ID(260, OperatorTokenType|AltTokenType),
T_OR_TRIGRAPH = TOKEN_FROM_ID(260, OperatorTokenType|TriGraphTokenType),
T_ORASSIGN = TOKEN_FROM_ID(261, OperatorTokenType),
T_ORASSIGN_ALT = TOKEN_FROM_ID(261, OperatorTokenType|AltTokenType),
T_XOR = TOKEN_FROM_ID(262, OperatorTokenType),
T_XOR_ALT = TOKEN_FROM_ID(262, OperatorTokenType|AltTokenType),
T_XOR_TRIGRAPH = TOKEN_FROM_ID(262, OperatorTokenType|TriGraphTokenType),
T_XORASSIGN = TOKEN_FROM_ID(263, OperatorTokenType),
T_XORASSIGN_ALT = TOKEN_FROM_ID(263, OperatorTokenType|AltTokenType),
T_COMMA = TOKEN_FROM_ID(264, OperatorTokenType),
T_COLON = TOKEN_FROM_ID(265, OperatorTokenType),
T_DIVIDE = TOKEN_FROM_ID(266, OperatorTokenType),
T_DIVIDEASSIGN = TOKEN_FROM_ID(267, OperatorTokenType),
T_DOT = TOKEN_FROM_ID(268, OperatorTokenType),
T_DOTSTAR = TOKEN_FROM_ID(269, OperatorTokenType),
T_ELLIPSIS = TOKEN_FROM_ID(270, OperatorTokenType),
T_EQUAL = TOKEN_FROM_ID(271, OperatorTokenType),
T_GREATER = TOKEN_FROM_ID(272, OperatorTokenType),
T_GREATEREQUAL = TOKEN_FROM_ID(273, OperatorTokenType),
T_LEFTBRACE = TOKEN_FROM_ID(274, OperatorTokenType),
T_LEFTBRACE_ALT = TOKEN_FROM_ID(274, OperatorTokenType|AltTokenType),
T_LEFTBRACE_TRIGRAPH = TOKEN_FROM_ID(274, OperatorTokenType|TriGraphTokenType),
T_LESS = TOKEN_FROM_ID(275, OperatorTokenType),
T_LESSEQUAL = TOKEN_FROM_ID(276, OperatorTokenType),
T_LEFTPAREN = TOKEN_FROM_ID(277, OperatorTokenType),
T_LEFTBRACKET = TOKEN_FROM_ID(278, OperatorTokenType),
T_LEFTBRACKET_ALT = TOKEN_FROM_ID(278, OperatorTokenType|AltTokenType),
T_LEFTBRACKET_TRIGRAPH = TOKEN_FROM_ID(278, OperatorTokenType|TriGraphTokenType),
T_MINUS = TOKEN_FROM_ID(279, OperatorTokenType),
T_MINUSASSIGN = TOKEN_FROM_ID(280, OperatorTokenType),
T_MINUSMINUS = TOKEN_FROM_ID(281, OperatorTokenType),
T_PERCENT = TOKEN_FROM_ID(282, OperatorTokenType),
T_PERCENTASSIGN = TOKEN_FROM_ID(283, OperatorTokenType),
T_NOT = TOKEN_FROM_ID(284, OperatorTokenType),
T_NOT_ALT = TOKEN_FROM_ID(284, OperatorTokenType|AltTokenType),
T_NOTEQUAL = TOKEN_FROM_ID(285, OperatorTokenType),
T_NOTEQUAL_ALT = TOKEN_FROM_ID(285, OperatorTokenType|AltTokenType),
T_OROR = TOKEN_FROM_ID(286, OperatorTokenType),
T_OROR_ALT = TOKEN_FROM_ID(286, OperatorTokenType|AltTokenType),
T_PLUS = TOKEN_FROM_ID(287, OperatorTokenType),
T_PLUSASSIGN = TOKEN_FROM_ID(288, OperatorTokenType),
T_PLUSPLUS = TOKEN_FROM_ID(289, OperatorTokenType),
T_ARROW = TOKEN_FROM_ID(290, OperatorTokenType),
T_ARROWSTAR = TOKEN_FROM_ID(291, OperatorTokenType),
T_QUESTION_MARK = TOKEN_FROM_ID(292, OperatorTokenType),
T_RIGHTBRACE = TOKEN_FROM_ID(293, OperatorTokenType),
T_RIGHTBRACE_ALT = TOKEN_FROM_ID(293, OperatorTokenType|AltTokenType),
T_RIGHTBRACE_TRIGRAPH = TOKEN_FROM_ID(293, OperatorTokenType|TriGraphTokenType),
T_RIGHTPAREN = TOKEN_FROM_ID(294, OperatorTokenType),
T_RIGHTBRACKET = TOKEN_FROM_ID(295, OperatorTokenType),
T_RIGHTBRACKET_ALT = TOKEN_FROM_ID(295, OperatorTokenType|AltTokenType),
T_RIGHTBRACKET_TRIGRAPH = TOKEN_FROM_ID(295, OperatorTokenType|TriGraphTokenType),
T_COLON_COLON = TOKEN_FROM_ID(296, OperatorTokenType),
T_SEMICOLON = TOKEN_FROM_ID(297, OperatorTokenType),
T_SHIFTLEFT = TOKEN_FROM_ID(298, OperatorTokenType),
T_SHIFTLEFTASSIGN = TOKEN_FROM_ID(299, OperatorTokenType),
T_SHIFTRIGHT = TOKEN_FROM_ID(300, OperatorTokenType),
T_SHIFTRIGHTASSIGN = TOKEN_FROM_ID(301, OperatorTokenType),
T_STAR = TOKEN_FROM_ID(302, OperatorTokenType),
T_COMPL = TOKEN_FROM_ID(303, OperatorTokenType),
T_COMPL_ALT = TOKEN_FROM_ID(303, OperatorTokenType|AltTokenType),
T_COMPL_TRIGRAPH = TOKEN_FROM_ID(303, OperatorTokenType|TriGraphTokenType),
T_STARASSIGN = TOKEN_FROM_ID(304, OperatorTokenType),
T_ASM = TOKEN_FROM_ID(305, KeywordTokenType),
T_AUTO = TOKEN_FROM_ID(306, KeywordTokenType),
T_BOOL = TOKEN_FROM_ID(307, KeywordTokenType),
T_FALSE = TOKEN_FROM_ID(308, BoolLiteralTokenType),
T_TRUE = TOKEN_FROM_ID(309, BoolLiteralTokenType),
T_BREAK = TOKEN_FROM_ID(310, KeywordTokenType),
T_CASE = TOKEN_FROM_ID(311, KeywordTokenType),
T_CATCH = TOKEN_FROM_ID(312, KeywordTokenType),
T_CHAR = TOKEN_FROM_ID(313, KeywordTokenType),
T_CLASS = TOKEN_FROM_ID(314, KeywordTokenType),
T_CONST = TOKEN_FROM_ID(315, KeywordTokenType),
T_CONSTCAST = TOKEN_FROM_ID(316, KeywordTokenType),
T_CONTINUE = TOKEN_FROM_ID(317, KeywordTokenType),
T_DEFAULT = TOKEN_FROM_ID(318, KeywordTokenType),
T_DEFINED = TOKEN_FROM_ID(319, KeywordTokenType),
T_DELETE = TOKEN_FROM_ID(320, KeywordTokenType),
T_DO = TOKEN_FROM_ID(321, KeywordTokenType),
T_DOUBLE = TOKEN_FROM_ID(322, KeywordTokenType),
T_DYNAMICCAST = TOKEN_FROM_ID(323, KeywordTokenType),
T_ELSE = TOKEN_FROM_ID(324, KeywordTokenType),
T_ENUM = TOKEN_FROM_ID(325, KeywordTokenType),
T_EXPLICIT = TOKEN_FROM_ID(326, KeywordTokenType),
T_EXPORT = TOKEN_FROM_ID(327, KeywordTokenType),
T_EXTERN = TOKEN_FROM_ID(328, KeywordTokenType),
T_FLOAT = TOKEN_FROM_ID(329, KeywordTokenType),
T_FOR = TOKEN_FROM_ID(330, KeywordTokenType),
T_FRIEND = TOKEN_FROM_ID(331, KeywordTokenType),
T_GOTO = TOKEN_FROM_ID(332, KeywordTokenType),
T_IF = TOKEN_FROM_ID(333, KeywordTokenType),
T_INLINE = TOKEN_FROM_ID(334, KeywordTokenType),
T_INT = TOKEN_FROM_ID(335, KeywordTokenType),
T_LONG = TOKEN_FROM_ID(336, KeywordTokenType),
T_MUTABLE = TOKEN_FROM_ID(337, KeywordTokenType),
T_NAMESPACE = TOKEN_FROM_ID(338, KeywordTokenType),
T_NEW = TOKEN_FROM_ID(339, KeywordTokenType),
T_OPERATOR = TOKEN_FROM_ID(340, KeywordTokenType),
T_PRIVATE = TOKEN_FROM_ID(341, KeywordTokenType),
T_PROTECTED = TOKEN_FROM_ID(342, KeywordTokenType),
T_PUBLIC = TOKEN_FROM_ID(343, KeywordTokenType),
T_REGISTER = TOKEN_FROM_ID(344, KeywordTokenType),
T_REINTERPRETCAST = TOKEN_FROM_ID(345, KeywordTokenType),
T_RETURN = TOKEN_FROM_ID(346, KeywordTokenType),
T_SHORT = TOKEN_FROM_ID(347, KeywordTokenType),
T_SIGNED = TOKEN_FROM_ID(348, KeywordTokenType),
T_SIZEOF = TOKEN_FROM_ID(349, KeywordTokenType),
T_STATIC = TOKEN_FROM_ID(350, KeywordTokenType),
T_STATICCAST = TOKEN_FROM_ID(351, KeywordTokenType),
T_STRUCT = TOKEN_FROM_ID(352, KeywordTokenType),
T_SWITCH = TOKEN_FROM_ID(353, KeywordTokenType),
T_TEMPLATE = TOKEN_FROM_ID(354, KeywordTokenType),
T_THIS = TOKEN_FROM_ID(355, KeywordTokenType),
T_THROW = TOKEN_FROM_ID(356, KeywordTokenType),
T_TRY = TOKEN_FROM_ID(357, KeywordTokenType),
T_TYPEDEF = TOKEN_FROM_ID(358, KeywordTokenType),
T_TYPEID = TOKEN_FROM_ID(359, KeywordTokenType),
T_TYPENAME = TOKEN_FROM_ID(360, KeywordTokenType),
T_UNION = TOKEN_FROM_ID(361, KeywordTokenType),
T_UNSIGNED = TOKEN_FROM_ID(362, KeywordTokenType),
T_USING = TOKEN_FROM_ID(363, KeywordTokenType),
T_VIRTUAL = TOKEN_FROM_ID(364, KeywordTokenType),
T_VOID = TOKEN_FROM_ID(365, KeywordTokenType),
T_VOLATILE = TOKEN_FROM_ID(366, KeywordTokenType),
T_WCHART = TOKEN_FROM_ID(367, KeywordTokenType),
T_WHILE = TOKEN_FROM_ID(368, KeywordTokenType),
T_PP_DEFINE = TOKEN_FROM_ID(369, PPTokenType),
T_PP_IF = TOKEN_FROM_ID(370, PPConditionalTokenType),
T_PP_IFDEF = TOKEN_FROM_ID(371, PPConditionalTokenType),
T_PP_IFNDEF = TOKEN_FROM_ID(372, PPConditionalTokenType),
T_PP_ELSE = TOKEN_FROM_ID(373, PPConditionalTokenType),
T_PP_ELIF = TOKEN_FROM_ID(374, PPConditionalTokenType),
T_PP_ENDIF = TOKEN_FROM_ID(375, PPConditionalTokenType),
T_PP_ERROR = TOKEN_FROM_ID(376, PPTokenType),
T_PP_LINE = TOKEN_FROM_ID(377, PPTokenType),
T_PP_PRAGMA = TOKEN_FROM_ID(378, PPTokenType),
T_PP_UNDEF = TOKEN_FROM_ID(379, PPTokenType),
T_PP_WARNING = TOKEN_FROM_ID(380, PPTokenType),
T_IDENTIFIER = TOKEN_FROM_ID(381, IdentifierTokenType),
T_OCTALINT = TOKEN_FROM_ID(382, IntegerLiteralTokenType),
T_DECIMALINT = TOKEN_FROM_ID(383, IntegerLiteralTokenType),
T_HEXAINT = TOKEN_FROM_ID(384, IntegerLiteralTokenType),
T_INTLIT = TOKEN_FROM_ID(385, IntegerLiteralTokenType),
T_FLOATLIT = TOKEN_FROM_ID(386, FloatingLiteralTokenType),
T_FIXEDPOINTLIT = TOKEN_FROM_ID(386, FloatingLiteralTokenType|AltTokenType), // IDL specific
T_CCOMMENT = TOKEN_FROM_ID(387, WhiteSpaceTokenType),
T_CPPCOMMENT = TOKEN_FROM_ID(388, WhiteSpaceTokenType),
T_CHARLIT = TOKEN_FROM_ID(389, CharacterLiteralTokenType),
T_STRINGLIT = TOKEN_FROM_ID(390, StringLiteralTokenType),
T_CONTLINE = TOKEN_FROM_ID(391, EOLTokenType),
T_SPACE = TOKEN_FROM_ID(392, WhiteSpaceTokenType),
T_SPACE2 = TOKEN_FROM_ID(393, WhiteSpaceTokenType),
T_NEWLINE = TOKEN_FROM_ID(394, EOLTokenType),
T_POUND_POUND = TOKEN_FROM_ID(395, OperatorTokenType),
T_POUND_POUND_ALT = TOKEN_FROM_ID(395, OperatorTokenType|AltTokenType),
T_POUND_POUND_TRIGRAPH = TOKEN_FROM_ID(395, OperatorTokenType|TriGraphTokenType),
T_POUND = TOKEN_FROM_ID(396, OperatorTokenType),
T_POUND_ALT = TOKEN_FROM_ID(396, OperatorTokenType|AltTokenType),
T_POUND_TRIGRAPH = TOKEN_FROM_ID(396, OperatorTokenType|TriGraphTokenType),
T_ANY = TOKEN_FROM_ID(397, UnknownTokenType),
T_PP_INCLUDE = TOKEN_FROM_ID(398, PPTokenType),
T_PP_QHEADER = TOKEN_FROM_ID(399, PPTokenType),
T_PP_HHEADER = TOKEN_FROM_ID(400, PPTokenType),
T_PP_INCLUDE_NEXT = TOKEN_FROM_ID(398, PPTokenType|AltTokenType),
T_PP_QHEADER_NEXT = TOKEN_FROM_ID(399, PPTokenType|AltTokenType),
T_PP_HHEADER_NEXT = TOKEN_FROM_ID(400, PPTokenType|AltTokenType),
T_EOF = TOKEN_FROM_ID(401, EOFTokenType), // end of file reached
T_EOI = TOKEN_FROM_ID(402, EOFTokenType), // end of input reached
// experimental: alternative pp-tokens
T_COMMA_ALT = TOKEN_FROM_ID(264, OperatorTokenType|AltTokenType),
T_LEFTPAREN_ALT = TOKEN_FROM_ID(277, OperatorTokenType|AltTokenType),
T_RIGHTPAREN_ALT = TOKEN_FROM_ID(294, OperatorTokenType|AltTokenType),
// experimental: macro scoping support
T_PP_REGION = TOKEN_FROM_ID(403, PPTokenType),
T_PP_ENDREGION = TOKEN_FROM_ID(404, PPTokenType),
T_PP_IMPORT = TOKEN_FROM_ID(405, PPTokenType),
// MS extensions
T_MSEXT_INT8 = TOKEN_FROM_ID(406, KeywordTokenType),
T_MSEXT_INT16 = TOKEN_FROM_ID(407, KeywordTokenType),
T_MSEXT_INT32 = TOKEN_FROM_ID(408, KeywordTokenType),
T_MSEXT_INT64 = TOKEN_FROM_ID(409, KeywordTokenType),
T_MSEXT_BASED = TOKEN_FROM_ID(410, KeywordTokenType),
T_MSEXT_DECLSPEC = TOKEN_FROM_ID(411, KeywordTokenType),
T_MSEXT_CDECL = TOKEN_FROM_ID(412, KeywordTokenType),
T_MSEXT_FASTCALL = TOKEN_FROM_ID(413, KeywordTokenType),
T_MSEXT_STDCALL = TOKEN_FROM_ID(414, KeywordTokenType),
T_MSEXT_TRY = TOKEN_FROM_ID(415, KeywordTokenType),
T_MSEXT_EXCEPT = TOKEN_FROM_ID(416, KeywordTokenType),
T_MSEXT_FINALLY = TOKEN_FROM_ID(417, KeywordTokenType),
T_MSEXT_LEAVE = TOKEN_FROM_ID(418, KeywordTokenType),
T_MSEXT_INLINE = TOKEN_FROM_ID(419, KeywordTokenType),
T_MSEXT_ASM = TOKEN_FROM_ID(420, KeywordTokenType),
T_LAST_TOKEN_ID,
T_LAST_TOKEN = ID_FROM_TOKEN(T_LAST_TOKEN_ID),
// pseudo tokens to help streamlining macro replacement, these should not
// returned from the lexer nor should these be returned from the pp-iterator
T_NONREPLACABLE_IDENTIFIER = TOKEN_FROM_ID(T_LAST_TOKEN+1, IdentifierTokenType),
T_PLACEHOLDER = TOKEN_FROM_ID(T_LAST_TOKEN+2, WhiteSpaceTokenType),
T_PLACEMARKER = TOKEN_FROM_ID(T_LAST_TOKEN+3, InternalTokenType),
T_PARAMETERBASE = TOKEN_FROM_ID(T_LAST_TOKEN+4, ParameterTokenType),
T_EXTPARAMETERBASE = TOKEN_FROM_ID(T_LAST_TOKEN+5, ExtParameterTokenType),
};
///////////////////////////////////////////////////////////////////////////////
// redefine the TOKEN_FROM_ID macro to be more type safe
#undef TOKEN_FROM_ID
#define TOKEN_FROM_ID(id, cat) boost::wave::token_id((id) | (cat))
///////////////////////////////////////////////////////////////////////////////
// return a token name
inline BOOST_WAVE_STRINGTYPE
get_token_name(token_id tokid)
{
// Table of token names
//
// Please note that the sequence of token names must match the sequence of
// token id's defined in then enum token_id above.
static char const *tok_names[] = {
"AND",
"ANDAND",
"ASSIGN",
"ANDASSIGN",
"OR",
"ORASSIGN",
"XOR",
"XORASSIGN",
"COMMA",
"COLON",
"DIVIDE",
"DIVIDEASSIGN",
"DOT",
"DOTSTAR",
"ELLIPSIS",
"EQUAL",
"GREATER",
"GREATEREQUAL",
"LEFTBRACE",
"LESS",
"LESSEQUAL",
"LEFTPAREN",
"LEFTBRACKET",
"MINUS",
"MINUSASSIGN",
"MINUSMINUS",
"PERCENT",
"PERCENTASSIGN",
"NOT",
"NOTEQUAL",
"OROR",
"PLUS",
"PLUSASSIGN",
"PLUSPLUS",
"ARROW",
"ARROWSTAR",
"QUESTION_MARK",
"RIGHTBRACE",
"RIGHTPAREN",
"RIGHTBRACKET",
"COLON_COLON",
"SEMICOLON",
"SHIFTLEFT",
"SHIFTLEFTASSIGN",
"SHIFTRIGHT",
"SHIFTRIGHTASSIGN",
"STAR",
"COMPL",
"STARASSIGN",
"ASM",
"AUTO",
"BOOL",
"FALSE",
"TRUE",
"BREAK",
"CASE",
"CATCH",
"CHAR",
"CLASS",
"CONST",
"CONSTCAST",
"CONTINUE",
"DEFAULT",
"DEFINED",
"DELETE",
"DO",
"DOUBLE",
"DYNAMICCAST",
"ELSE",
"ENUM",
"EXPLICIT",
"EXPORT",
"EXTERN",
"FLOAT",
"FOR",
"FRIEND",
"GOTO",
"IF",
"INLINE",
"INT",
"LONG",
"MUTABLE",
"NAMESPACE",
"NEW",
"OPERATOR",
"PRIVATE",
"PROTECTED",
"PUBLIC",
"REGISTER",
"REINTERPRETCAST",
"RETURN",
"SHORT",
"SIGNED",
"SIZEOF",
"STATIC",
"STATICCAST",
"STRUCT",
"SWITCH",
"TEMPLATE",
"THIS",
"THROW",
"TRY",
"TYPEDEF",
"TYPEID",
"TYPENAME",
"UNION",
"UNSIGNED",
"USING",
"VIRTUAL",
"VOID",
"VOLATILE",
"WCHART",
"WHILE",
"PP_DEFINE",
"PP_IF",
"PP_IFDEF",
"PP_IFNDEF",
"PP_ELSE",
"PP_ELIF",
"PP_ENDIF",
"PP_ERROR",
"PP_LINE",
"PP_PRAGMA",
"PP_UNDEF",
"PP_WARNING",
"IDENTIFIER",
"OCTALINT",
"DECIMALINT",
"HEXAINT",
"INTLIT",
"FLOATLIT",
"CCOMMENT",
"CPPCOMMENT",
"CHARLIT",
"STRINGLIT",
"CONTLINE",
"SPACE",
"SPACE2",
"NEWLINE",
"POUND_POUND",
"POUND",
"ANY",
"PP_INCLUDE",
"PP_QHEADER",
"PP_HHEADER",
"EOF",
"EOI",
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
"PP_" BOOST_WAVE_PP_REGION,
"PP_" BOOST_WAVE_PP_ENDREGION,
"PP_" BOOST_WAVE_PP_IMPORT,
#else
"",
"",
"",
#endif // BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
// MS extensions
"MSEXT_INT8",
"MSEXT_INT16",
"MSEXT_INT32",
"MSEXT_INT64",
"MSEXT_BASED",
"MSEXT_DECLSPEC",
"MSEXT_CDECL",
"MSEXT_FASTCALL",
"MSEXT_STDCALL",
"MSEXT_TRY",
"MSEXT_EXCEPT",
"MSEXT_FINALLY",
"MSEXT_LEAVE",
"MSEXT_INLINE",
"MSEXT_ASM",
};
unsigned int id = BASEID_FROM_TOKEN(tokid)-T_FIRST_TOKEN;
BOOST_ASSERT(id < T_LAST_TOKEN-T_FIRST_TOKEN);
return tok_names[id];
}
///////////////////////////////////////////////////////////////////////////////
// return a token name
inline char const *
get_token_value(token_id tokid)
{
// Table of token values
//
// Please note that the sequence of token names must match the sequence of
// token id's defined in then enum token_id above.
static char const *tok_names[] = {
"&",
"&&",
"=",
"&=",
"|",
"|=",
"^",
"^=",
",",
":",
"/",
"/=",
".",
".*",
"...",
"==",
">",
">=",
"{",
"<",
"<=",
"(",
"[",
"-",
"-=",
"--",
"%",
"%=",
"!",
"!=",
"||",
"+",
"+=",
"++",
"->",
"->*",
"?",
"}",
")",
"]",
"::",
";",
"<<",
"<<=",
">>",
">>=",
"*",
"~",
"*=",
"asm",
"auto",
"bool",
"false",
"true",
"break",
"case",
"catch",
"char",
"class",
"const",
"const_cast",
"continue",
"default",
"defined",
"delete",
"do",
"double",
"dynamic_cast",
"else",
"enum",
"explicit",
"export",
"extern",
"float",
"for",
"friend",
"goto",
"if",
"inline",
"int",
"long",
"mutable",
"namespace",
"new",
"operator",
"private",
"protected",
"public",
"register",
"reinterpret_cast",
"return",
"short",
"signed",
"sizeof",
"static",
"static_cast",
"struct",
"switch",
"template",
"this",
"throw",
"try",
"typedef",
"typeid",
"typename",
"union",
"unsigned",
"using",
"virtual",
"void",
"volatile",
"wchar_t",
"while",
"#define",
"#if",
"#ifdef",
"#ifndef",
"#else",
"#elif",
"#endif",
"#error",
"#line",
"#pragma ",
"#undef ",
"#warning",
"", // identifier
"", // octalint
"", // decimalint
"", // hexlit
"", // intlit
"", // floatlit
"", // ccomment
"", // cppcomment
"", // charlit
"", // stringlit
"", // contline
"", // space
"", // space2
"\n",
"##",
"#",
"", // any
"#include",
"#include",
"#include",
"", // eof
"", // eoi
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
"#" BOOST_WAVE_PP_REGION,
"#" BOOST_WAVE_PP_ENDREGION,
"#" BOOST_WAVE_PP_IMPORT,
#else
"",
"",
"",
#endif // BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
// MS extensions
"__int8",
"__int16",
"__int32",
"__int64",
"__based",
"__declspec",
"__cdecl",
"__fastcall",
"__stdcall",
"__try",
"__except",
"__finally",
"__leave",
"__inline",
"__asm",
};
unsigned int id = BASEID_FROM_TOKEN(tokid)-T_FIRST_TOKEN;
BOOST_ASSERT(id < T_LAST_TOKEN-T_FIRST_TOKEN);
return tok_names[id];
}
///////////////////////////////////////////////////////////////////////////////
} // namespace wave
} // namespace boost
#endif // #if !defined(BOOST_WAVE_TOKEN_IDS_DEFINED)
#endif // !defined(TOKEN_IDS_HPP_414E9A58_F079_4789_8AFF_513815CE475B_INCLUDED)

View File

@@ -0,0 +1,199 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(TRACE_POLICIES_HPP_338DE478_A13C_4B63_9BA9_041C917793B8_INCLUDED)
#define TRACE_POLICIES_HPP_338DE478_A13C_4B63_9BA9_041C917793B8_INCLUDED
#include <vector>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace trace_policies {
///////////////////////////////////////////////////////////////////////////////
//
// trace_flags: enable single tracing functionality
//
///////////////////////////////////////////////////////////////////////////////
enum trace_flags {
trace_nothing = 0, // disable tracing
trace_macros = 1, // enable macro tracing
trace_includes = 2, // enable include file tracing
trace_timer = 3 // enable timer tracing
};
///////////////////////////////////////////////////////////////////////////////
//
// The default_tracing class is a placeholder for all macro
// expansion trace hooks contained inside the macro expansion engine
//
///////////////////////////////////////////////////////////////////////////////
struct default_tracing {
///////////////////////////////////////////////////////////////////////////
//
// The function enable_tracing is called, whenever the status of the
// tracing was changed.
//
// The parameter 'enable' is to be used as the new tracing status.
//
///////////////////////////////////////////////////////////////////////////
void enable_tracing(trace_flags flags)
{}
///////////////////////////////////////////////////////////////////////////
//
// The function tracing_enabled should return the current tracing status.
//
///////////////////////////////////////////////////////////////////////////
trace_flags tracing_enabled()
{ return trace_nothing; }
///////////////////////////////////////////////////////////////////////////
//
// The function 'expanding_function_like_macro' is called, whenever a
// function-like macro is to be expanded.
//
// The macroname parameter marks the position, where the macro to expand
// is defined.
// The formal_args parameter holds the formal arguments used during the
// definition of the macro.
// The definition parameter holds the macro definition for the macro to
// trace.
//
// The macro call parameter marks the position, where this macro invoked.
// The arguments parameter holds the macro arguments used during the
// invocation of the macro
//
///////////////////////////////////////////////////////////////////////////
template <typename TokenT, typename ContainerT>
void expanding_function_like_macro(
TokenT const &macrodef, std::vector<TokenT> const &formal_args,
ContainerT const &definition,
TokenT const &macrocall, std::vector<ContainerT> const &arguments)
{}
///////////////////////////////////////////////////////////////////////////
//
// The function 'expanding_object_like_macro' is called, whenever a
// object-like macro is to be expanded .
//
// The macroname parameter marks the position, where the macro to expand
// is defined.
// The definition parameter holds the macro definition for the macro to
// trace.
//
// The macro call parameter marks the position, where this macro invoked.
//
///////////////////////////////////////////////////////////////////////////
template <typename TokenT, typename ContainerT>
void expanding_object_like_macro(TokenT const &macro,
ContainerT const &definition, TokenT const &macrocall)
{}
///////////////////////////////////////////////////////////////////////////
//
// The function 'expanded_macro' is called, whenever the expansion of a
// macro is finished but before the rescanning process starts.
//
// The parameter 'result' contains the token sequence generated as the
// result of the macro expansion.
//
///////////////////////////////////////////////////////////////////////////
template <typename ContainerT>
void expanded_macro(ContainerT const &result)
{}
///////////////////////////////////////////////////////////////////////////
//
// The function 'rescanned_macro' is called, whenever the rescanning of a
// macro is finished.
//
// The parameter 'result' contains the token sequence generated as the
// result of the rescanning.
//
///////////////////////////////////////////////////////////////////////////
template <typename ContainerT>
void rescanned_macro(ContainerT const &result)
{}
///////////////////////////////////////////////////////////////////////////
//
// The function 'opened_include_file' is called, whenever a file referred
// by an #include directive was successfully located and opened.
//
// The parameter 'filename' contains the full file system path of the
// opened file.
//
// The include_depth parameter contains the current include file depth.
//
// The is_system_include parameter denotes, if the given file was found
// as a result of a #include <...> directive.
//
///////////////////////////////////////////////////////////////////////////
void
opened_include_file(std::string const &filename, std::size_t include_depth,
bool is_system_include)
{}
///////////////////////////////////////////////////////////////////////////
//
// The function 'returning_from_include_file' is called, whenever an
// included file is about to be closed after it's processing is complete.
//
///////////////////////////////////////////////////////////////////////////
void
returning_from_include_file()
{}
///////////////////////////////////////////////////////////////////////////
//
// The function 'interpret_pragma' is called, whenever a #pragma wave
// directive is found, which isn't known to the core Wave library.
//
// The parameter 'pending' may be used to push tokens back into the input
// stream, which are to be used as the replacement text for the whole
// #pragma wave() directive.
//
// The parameter 'option' contains the name of the interpreted pragma.
//
// The parameter 'values' holds the values of the parameter provided to
// the pragma operator.
//
// The parameter 'act_token' contains the actual #pragma token, which may
// be used for error output.
//
// The parameter 'language' contains the current language mode, in which
// the Wave library operates.
//
// If the return value is 'false', the whole #pragma directive is
// interpreted as unknown and a corresponding error message is issued. A
// return value of 'true' signs a successful interpretation of the given
// #pragma.
//
///////////////////////////////////////////////////////////////////////////
template <typename TokenT, typename ContainerT>
bool
interpret_pragma(ContainerT &pending, TokenT const &option,
ContainerT const &values, TokenT const &act_token,
boost::wave::language_support language)
{
return false;
}
};
///////////////////////////////////////////////////////////////////////////////
} // namespace trace_policies
} // namespace wave
} // namespace boost
#endif // !defined(TRACE_POLICIES_HPP_338DE478_A13C_4B63_9BA9_041C917793B8_INCLUDED)

View File

@@ -0,0 +1,148 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(CPP_IFBLOCK_HPP_D4676B36_00C5_41F4_BC9F_9CBBAE3B8006_INCLUDED)
#define CPP_IFBLOCK_HPP_D4676B36_00C5_41F4_BC9F_9CBBAE3B8006_INCLUDED
#include <stack>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace util {
///////////////////////////////////////////////////////////////////////////////
// the class if_blocks handles recursive conditional compilation contexts
class if_block
{
public:
if_block() :
status(true), some_part_status(true),
enclosing_status(true), is_in_else(false)
{
}
if_block(bool status_, bool enclosing_status_) :
status(status_),
some_part_status(status_),
enclosing_status(enclosing_status_),
is_in_else(false)
{
}
void set_status(bool status_)
{
status = status_;
if (status_)
some_part_status = true;
}
bool get_status() const { return status; }
bool get_some_part_status() const { return some_part_status; }
bool get_enclosing_status() const { return enclosing_status; }
bool get_in_else() const { return is_in_else; }
void set_in_else() { is_in_else = true; }
private:
bool status; // Current block is true
bool some_part_status; // One of the preceeding or current #if/#elif was true
bool enclosing_status; // Enclosing #if block is true
bool is_in_else; // Inside the #else part
};
///////////////////////////////////////////////////////////////////////////////
// stack of conditional compilation contexts
class if_block_stack
: private std::stack<if_block>
{
public:
typedef std::stack<if_block>::size_type size_type;
void enter_if_block(bool new_status)
{
// If enclosing block is false, then this block is also false
bool enclosing_status = get_status();
this->push (value_type (new_status && enclosing_status, enclosing_status));
}
bool enter_elif_block(bool new_status)
{
if (!is_inside_ifpart())
return false; // #elif without matching #if
if (get_enclosing_status()) {
if (get_status()) {
// entered a (false) #elif block from a true block
this->top().set_status(false);
}
else if (new_status && !this->top().get_some_part_status()) {
// Entered true #elif block and no previous block was true
this->top().set_status(new_status);
}
}
return true;
}
bool enter_else_block()
{
if (!is_inside_ifpart())
return false; // #else without matching #if
if (get_enclosing_status()) {
if (!this->top().get_some_part_status()) {
// Entered (true) #else block and no previous block was true
this->top().set_status(true);
}
else if (get_status()) {
// Entered (false) else block from true block
this->top().set_status(false);
}
// Set else flag
this->top().set_in_else();
}
return true;
}
bool exit_if_block()
{
if (0 == this->size())
return false; // #endif without matching #if
this->pop();
return true;
}
// return, wether the top (innermost) condition is true or false
bool get_status() const
{
return 0 == this->size() || this->top().get_status();
}
size_type get_if_block_depth() const { return this->size(); }
protected:
bool get_enclosing_status() const
{
return 0 == this->size() || this->top().get_enclosing_status();
}
bool is_inside_ifpart() const
{
return 0 != this->size() && !this->top().get_in_else();
}
bool is_inside_elsepart() const
{
return 0 != this->size() && this->top().get_in_else();
}
};
///////////////////////////////////////////////////////////////////////////////
} // namespace util
} // namespace wave
} // namespace boost
#endif // !defined(CPP_IFBLOCK_HPP_D4676B36_00C5_41F4_BC9F_9CBBAE3B8006_INCLUDED)

View File

@@ -0,0 +1,219 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(CPP_INCLUDE_PATHES_HPP_AF620DA4_B3D2_4221_AD91_8A1ABFFB6944_INCLUDED)
#define CPP_INCLUDE_PATHES_HPP_AF620DA4_B3D2_4221_AD91_8A1ABFFB6944_INCLUDED
#include <string>
#include <list>
#include <set>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/wave/wave_config.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace util {
///////////////////////////////////////////////////////////////////////////////
//
// include_pathes - controlling the include path search order
//
// General notes:
//
// Any directories specified with the 'add_include_path()' function before
// the function 'set_sys_include_delimiter()' is called are searched only
// for the case of '#include "file"' directives, they are not searched for
// '#include <file>' directives. If additional directories are specified
// with the 'add_include_path()' function after a call to the function
// 'set_sys_include_delimiter()', these directories are searched for all
// '#include' directives.
//
// In addition, a call to the function 'set_sys_include_delimiter()'
// inhibits the use of the current directory as the first search directory
// for '#include "file"' directives. Therefore, the current directory is
// searched only if it is requested explicitly with a call to the function
// 'add_include_path(".")'.
//
// Calling both functions, the 'set_sys_include_delimiter()' and
// 'add_include_path(".")' allows you to control precisely which
// directories are searched before the current one and which are searched
// after.
//
///////////////////////////////////////////////////////////////////////////////
class include_pathes
{
typedef std::list<boost::filesystem::path> include_list_t;
typedef std::set<std::string> pragma_once_set_t;
public:
include_pathes()
: was_sys_include_path(false),
current_dir(boost::filesystem::initial_path())
{}
bool add_include_path(char const *path_, bool is_system = false)
{
return add_include_path(path_, (is_system || was_sys_include_path) ?
system_include_pathes : user_include_pathes);
}
void set_sys_include_delimiter() { was_sys_include_path = true; }
bool find_include_file (std::string &s, bool is_system,
char const *current_file) const;
void set_current_directory(char const *path_);
void init_initial_path() { boost::filesystem::initial_path(); }
protected:
bool find_include_file (std::string &s, include_list_t const &pathes,
char const *) const;
bool add_include_path(char const *path_, include_list_t &pathes_);
private:
include_list_t user_include_pathes;
include_list_t system_include_pathes;
bool was_sys_include_path; // saw a set_sys_include_delimiter()
boost::filesystem::path current_dir;
#if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
public:
bool has_pragma_once(std::string const &filename)
{
return pragma_once_files.find(filename) != pragma_once_files.end();
}
bool add_pragma_once_header(std::string const &filename)
{
return pragma_once_files.insert(filename).second;
}
private:
pragma_once_set_t pragma_once_files;
#endif
};
///////////////////////////////////////////////////////////////////////////////
// Add an include path to one of the search lists (user include path or system
// include path).
inline
bool include_pathes::add_include_path (
char const *path_, include_list_t &pathes_)
{
namespace fs = boost::filesystem;
if (path_) {
fs::path newpath = fs::complete(fs::path(path_, fs::native), current_dir);
if (!fs::exists(newpath) || !fs::is_directory(newpath)) {
// the given path does not form a name of a valid file system directory
// item
return false;
}
pathes_.push_back (newpath);
return true;
}
return false;
}
///////////////////////////////////////////////////////////////////////////////
// Find an include file by traversing the list of include directories
inline
bool include_pathes::find_include_file (std::string &s,
include_list_t const &pathes, char const *current_file) const
{
namespace fs = boost::filesystem;
typedef include_list_t::const_iterator const_include_list_iter_t;
const_include_list_iter_t include_pathes_end = pathes.end();
for (const_include_list_iter_t it = pathes.begin();
it != include_pathes_end; ++it)
{
fs::path currpath (*it);
currpath /= s; // append filename
if (fs::exists(currpath) &&
( 0 == current_file ||
strcmp(currpath.native_file_string().c_str(), current_file)
)
)
{
// found the required file
s = currpath.string();
return true;
}
}
return false;
}
///////////////////////////////////////////////////////////////////////////////
// Find an include file by searching the user and system includes in the
// correct sequence (as it was configured by the user of the driver program)
inline bool
include_pathes::find_include_file (std::string &s, bool is_system,
char const *current_file) const
{
namespace fs = boost::filesystem;
// if not system include (<...>), then search current directory first
if (!is_system) {
if (!was_sys_include_path) { // set_sys_include_delimiter() not called
// first look in the current directory
fs::path currpath = current_dir;
currpath /= s;
if (fs::exists(currpath) &&
( 0 == current_file ||
strcmp(currpath.native_file_string().c_str(), current_file)
)
)
{
s = currpath.string(); // found in local directory
return true;
}
// iterate all user include file directories to find the file
return find_include_file(s, user_include_pathes, current_file);
}
// iterate all user include file directories to find the file
if (find_include_file(s, user_include_pathes, current_file))
return true;
// if nothing found, fall through
// ...
}
// iterate all system include file directories to find the file
return find_include_file (s, system_include_pathes, current_file);
}
///////////////////////////////////////////////////////////////////////////////
// Set current directory from a given file name
inline
void include_pathes::set_current_directory(char const *path_)
{
namespace fs = boost::filesystem;
fs::path filename = fs::complete(fs::path(path_, fs::native), current_dir);
if (fs::exists(filename) && fs::is_directory(filename))
current_dir = filename;
else
current_dir = filename.branch_path();
}
///////////////////////////////////////////////////////////////////////////////
} // namespace util
} // namespace wave
} // namespace boost
#endif // !defined(CPP_INCLUDE_PATHES_HPP_AF620DA4_B3D2_4221_AD91_8A1ABFFB6944_INCLUDED)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,160 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Whitespace eater
Copyright (c) 2003 Paul Mensonides
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(EAT_WHITESPACE_HPP_4CE9AD17_F82D_4AB2_A117_555DF0DCC801_INCLUDED)
#define EAT_WHITESPACE_HPP_4CE9AD17_F82D_4AB2_A117_555DF0DCC801_INCLUDED
#include <boost/wave/wave_config.hpp>
#include <boost/wave/token_ids.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace util {
template <typename TokenT>
class eat_whitespace {
public:
eat_whitespace();
bool may_skip (TokenT &token, bool &skipped_newline);
private:
typedef bool state_t(TokenT &token, bool &skipped_newline);
state_t eat_whitespace::* state;
state_t general, newline, newline_2nd, whitespace;
};
template <typename TokenT>
inline
eat_whitespace<TokenT>::eat_whitespace()
: state(&eat_whitespace::newline)
{
}
template <typename TokenT>
inline bool
eat_whitespace<TokenT>::may_skip(TokenT &token, bool &skipped_newline)
{
return (this->*state)(token, skipped_newline);
}
template <typename TokenT>
inline bool
eat_whitespace<TokenT>::general(TokenT &token, bool &skipped_newline)
{
using boost::wave::token_id;
token_id id = token_id(token);
if (T_NEWLINE == id || T_CPPCOMMENT == id) {
state = &eat_whitespace::newline;
}
else if (T_SPACE == id || T_SPACE2 == id || T_CCOMMENT == id) {
state = &eat_whitespace::whitespace;
if (T_CCOMMENT == id) {
if (TokenT::string_t::npos !=
token.get_value().find_first_of("\n"))
{
skipped_newline = true;
}
}
if (token.get_value().size() > 1)
token.set_value(" "); // replace with a single space
}
else {
state = &eat_whitespace::general;
}
return false;
}
template <typename TokenT>
inline bool
eat_whitespace<TokenT>::newline(TokenT &token, bool &skipped_newline)
{
using namespace boost::wave;
token_id id = token_id(token);
if (T_NEWLINE == id || T_CPPCOMMENT == id) {
skipped_newline = true;
state = &eat_whitespace::newline_2nd;
return true;
}
else if (T_SPACE != id && T_SPACE2 != id && T_CCOMMENT != id) {
return general(token, skipped_newline);
}
if (T_CCOMMENT == id) {
if (TokenT::string_t::npos !=
token.get_value().find_first_of("\n"))
{
skipped_newline = true;
}
}
return true;
}
template <typename TokenT>
inline bool
eat_whitespace<TokenT>::newline_2nd(TokenT &token, bool &skipped_newline)
{
using namespace boost::wave;
token_id id = token_id(token);
if (T_SPACE == id || T_SPACE2 == id)
return true;
if (T_CCOMMENT == id) {
if (TokenT::string_t::npos !=
token.get_value().find_first_of("\n"))
{
skipped_newline = true;
}
return true;
}
if (T_NEWLINE != id && T_CPPCOMMENT != id)
return general(token, skipped_newline);
skipped_newline = true;
return true;
}
template <typename TokenT>
inline bool
eat_whitespace<TokenT>::whitespace(TokenT &token, bool &skipped_newline)
{
using namespace boost::wave;
token_id id = token_id(token);
if (T_SPACE != id && T_SPACE2 != id && T_CCOMMENT != id)
return general(token, skipped_newline);
if (T_CCOMMENT == id) {
if (TokenT::string_t::npos !=
token.get_value().find_first_of("\n"))
{
skipped_newline = true;
}
}
return true;
}
///////////////////////////////////////////////////////////////////////////////
} // namespace util
} // namespace wave
} // namespace boost
#endif // !defined(EAT_WHITESPACE_HPP_4CE9AD17_F82D_4AB2_A117_555DF0DCC801_INCLUDED)

View File

@@ -0,0 +1,171 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Definition of the position_iterator and file_position templates
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(FILE_POSITION_H_52BDEDF7_DAD3_4F24_802F_E66BB8098F68_INCLUDED)
#define FILE_POSITION_H_52BDEDF7_DAD3_4F24_802F_E66BB8098F68_INCLUDED
#include <string>
#include <ostream>
#include <boost/spirit/version.hpp>
#include <boost/spirit/iterator/position_iterator.hpp>
#include <boost/wave/wave_config.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace util {
///////////////////////////////////////////////////////////////////////////////
//
// file_position
//
// A structure to hold positional information. This includes the filename,
// line number and column number of a current token position.
//
///////////////////////////////////////////////////////////////////////////////
template <typename StringT = std::string>
struct file_position {
public:
typedef StringT string_t;
file_position()
: file(), line(1), column(1)
{}
explicit file_position(string_t const& file_, int line_ = 1,
int column_ = 1)
: file(file_), line(line_), column(column_)
{}
// accessors
string_t const &get_file() const { return file; }
int get_line() const { return line; }
int get_column() const { return column; }
void set_file(string_t const &file_) { file = file_; }
void set_line(int line_) { line = line_; }
void set_column(int column_) { column = column_; }
private:
string_t file;
int line;
int column;
};
template <typename StringT>
bool operator== (file_position<StringT> const &lhs,
file_position<StringT> const &rhs)
{
return lhs.get_column() == rhs.get_column() &&
lhs.get_line() == rhs.get_line() && lhs.get_file() == rhs.get_file();
}
template <typename StringT>
inline std::ostream &
operator<< (std::ostream &o, file_position<StringT> const &pos)
{
o << pos.get_file() << "(" << pos.get_line() << ")";
return o;
}
typedef file_position<BOOST_WAVE_STRINGTYPE> file_position_t;
///////////////////////////////////////////////////////////////////////////////
//
// position_iterator
//
// The position_iterator used by Wave is now based on the corresponding Spirit
// type. This type is used with our own file_position though. The needed
// specialization of the boost::spirit::position_policy class is provided
// below.
//
///////////////////////////////////////////////////////////////////////////////
template <typename IteratorT, typename PositionT>
struct position_iterator
: boost::spirit::position_iterator<IteratorT, PositionT>
{
typedef boost::spirit::position_iterator<IteratorT, PositionT> base_t;
position_iterator()
{
}
position_iterator(IteratorT const &begin, IteratorT const &end,
PositionT const &pos)
: base_t(begin, end, pos)
{
}
};
///////////////////////////////////////////////////////////////////////////////
} // namespace util
} // namespace wave
///////////////////////////////////////////////////////////////////////////////
#if SPIRIT_VERSION >= 0x1700
namespace spirit {
///////////////////////////////////////////////////////////////////////////////
//
// The boost::spirit::position_policy has to be specialized for our
// file_position class
//
///////////////////////////////////////////////////////////////////////////////
template <>
class position_policy<boost::wave::util::file_position_t> {
public:
position_policy()
: m_CharsPerTab(4)
{}
void next_line(boost::wave::util::file_position_t &pos)
{
pos.set_line(pos.get_line() + 1);
pos.set_column(1);
}
void set_tab_chars(unsigned int chars)
{
m_CharsPerTab = chars;
}
void next_char(boost::wave::util::file_position_t &pos)
{
pos.set_column(pos.get_column() + 1);
}
void tabulation(boost::wave::util::file_position_t &pos)
{
pos.set_column(pos.get_column() + m_CharsPerTab -
(pos.get_column() - 1) % m_CharsPerTab);
}
private:
unsigned int m_CharsPerTab;
};
///////////////////////////////////////////////////////////////////////////////
} // namespace spirit
#endif // SPIRIT_VERSION >= 0x1700
} // namespace boost
#endif // !defined(FILE_POSITION_H_52BDEDF7_DAD3_4F24_802F_E66BB8098F68_INCLUDED)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,133 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(FUNCTOR_INPUT_HPP_ED3A4C21_8F8A_453F_B438_08214FAC106A_INCLUDED)
#define FUNCTOR_INPUT_HPP_ED3A4C21_8F8A_453F_B438_08214FAC106A_INCLUDED
#include <boost/spirit/iterator/multi_pass.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace util {
///////////////////////////////////////////////////////////////////////////////
//
// class functor_input
//
// Implementation of the InputPolicy used by multi_pass
// functor_input gets tokens from a functor
// Note: the functor must have a typedef for result_type
// It also must have a static variable of type result_type defined
// to represent eof that is called eof.
//
// This functor input policy template is essentially the same as the
// predefined multi_pass functor_input policy. The difference is,
// that the first token is not read at initialization time, but only
// just before returning the first token.
//
///////////////////////////////////////////////////////////////////////////////
struct functor_input {
template <typename FunctorT>
class inner {
typedef typename FunctorT::result_type result_type;
struct Data {
Data(FunctorT const &ftor_)
: ftor(ftor_), was_initialized(false)
{}
FunctorT ftor;
result_type curtok;
bool was_initialized;
};
public:
typedef result_type value_type;
typedef std::ptrdiff_t difference_type;
typedef result_type *pointer;
typedef result_type &reference;
protected:
inner()
: data(0)
{}
inner(FunctorT const &x)
: data(new Data(x))
{}
inner(inner const &x)
: data(x.data)
{}
void destroy()
{
delete data;
data = 0;
}
bool same_input(inner const &x) const
{
return data == x.data;
}
void swap(inner &x)
{
boost::spirit::impl::mp_swap(data, x.data);
}
void ensure_initialized() const
{
if (data && !data->was_initialized) {
data->curtok = (data->ftor)(); // get the first token
data->was_initialized = true;
}
}
public:
reference get_input() const
{
ensure_initialized();
return data->curtok;
}
void advance_input()
{
BOOST_SPIRIT_ASSERT(0 != data);
data->curtok = (data->ftor)();
}
bool input_at_eof() const
{
ensure_initialized();
return !data || data->curtok == data->ftor.eof;
}
FunctorT& get_functor() const
{
BOOST_SPIRIT_ASSERT(0 != data);
return data->ftor;
}
private:
mutable Data *data;
};
};
///////////////////////////////////////////////////////////////////////////////
} // namespace util
} // namespace wave
} // namespace boost
#endif // !defined(FUNCTOR_INPUT_HPP_ED3A4C21_8F8A_453F_B438_08214FAC106A_INCLUDED)

View File

@@ -0,0 +1,331 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Detect the need to insert a whitespace token into the output stream
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(INSERT_WHITESPACE_DETECTION_HPP_765EF77B_0513_4967_BDD6_6A38148C4C96_INCLUDED)
#define INSERT_WHITESPACE_DETECTION_HPP_765EF77B_0513_4967_BDD6_6A38148C4C96_INCLUDED
#include <boost/wave/wave_config.hpp>
#include <boost/wave/token_ids.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace util {
namespace impl {
// T_IDENTIFIER
template <typename StringT>
inline bool
would_form_universal_char (StringT const &value)
{
if ('u' != value[0] && 'U' != value[0])
return false;
if ('u' == value[0] && value.size() < 5)
return false;
if ('U' == value[0] && value.size() < 9)
return false;
typename StringT::size_type pos =
value.find_first_not_of("0123456789abcdefABCDEF", 1);
if (StringT::npos == pos ||
('u' == value[0] && pos > 5) ||
('U' == value[0] && pos > 9))
{
return true; // would form an universal char
}
return false;
}
template <typename StringT>
inline bool
handle_identifier(boost::wave::token_id prev,
boost::wave::token_id before, StringT const &value)
{
using namespace boost::wave;
switch (static_cast<unsigned int>(prev)) {
case T_IDENTIFIER:
case T_NONREPLACABLE_IDENTIFIER:
case T_INTLIT:
case T_FLOATLIT:
case T_COMPL_ALT:
case T_OR_ALT:
case T_AND_ALT:
case T_NOT_ALT:
case T_XOR_ALT:
case T_ANDASSIGN_ALT:
case T_ORASSIGN_ALT:
case T_XORASSIGN_ALT:
case T_NOTEQUAL_ALT:
case T_FIXEDPOINTLIT:
return true;
// avoid constructing universal characters (\u1234)
case TOKEN_FROM_ID('\\', UnknownTokenType):
return would_form_universal_char(value);
}
return false;
}
// T_INTLIT
inline bool
handle_intlit(boost::wave::token_id prev, boost::wave::token_id before)
{
using namespace boost::wave;
switch(prev) {
case T_IDENTIFIER:
case T_NONREPLACABLE_IDENTIFIER:
case T_INTLIT:
case T_FLOATLIT:
case T_FIXEDPOINTLIT:
return true;
}
return false;
}
// T_FLOATLIT
inline bool
handle_floatlit(boost::wave::token_id prev,
boost::wave::token_id before)
{
using namespace boost::wave;
switch(prev) {
case T_IDENTIFIER:
case T_NONREPLACABLE_IDENTIFIER:
case T_INTLIT:
case T_FLOATLIT:
case T_FIXEDPOINTLIT:
return true;
}
return false;
}
// <% T_LEFTBRACE
inline bool
handle_alt_leftbrace(boost::wave::token_id prev,
boost::wave::token_id before)
{
using namespace boost::wave;
switch(prev) {
case T_LESS: // <<%
case T_SHIFTLEFT: // <<<%
return true;
}
return false;
}
// <: T_LEFTBRACKET
inline bool
handle_alt_leftbracket(boost::wave::token_id prev,
boost::wave::token_id before)
{
using namespace boost::wave;
switch(prev) {
case T_LESS: // <<:
case T_SHIFTLEFT: // <<<:
return true;
}
return false;
}
// T_FIXEDPOINTLIT
inline bool
handle_fixedpointlit(boost::wave::token_id prev,
boost::wave::token_id before)
{
using namespace boost::wave;
switch(prev) {
case T_IDENTIFIER:
case T_NONREPLACABLE_IDENTIFIER:
case T_INTLIT:
case T_FLOATLIT:
case T_FIXEDPOINTLIT:
return true;
}
return false;
}
// T_DOT
inline bool
handle_dot(boost::wave::token_id prev, boost::wave::token_id before)
{
using namespace boost::wave;
switch(prev) {
case T_DOT:
if (T_DOT == before)
return true; // ...
break;
}
return false;
}
// T_QUESTION_MARK
inline bool
handle_questionmark(boost::wave::token_id prev,
boost::wave::token_id before)
{
using namespace boost::wave;
switch(static_cast<unsigned int>(prev)) {
case TOKEN_FROM_ID('\\', UnknownTokenType): // \?
case T_QUESTION_MARK: // ??
return true;
}
return false;
}
// T_NEWLINE
inline bool
handle_newline(boost::wave::token_id prev,
boost::wave::token_id before)
{
using namespace boost::wave;
switch(static_cast<unsigned int>(prev)) {
case TOKEN_FROM_ID('\\', UnknownTokenType): // \ \n
case T_DIVIDE:
if (T_QUESTION_MARK == before)
return true; // ?/\n // may be \\n
break;
}
return false;
}
} // namespace impl
class insert_whitespace_detection
{
public:
insert_whitespace_detection()
: prev(boost::wave::T_EOF), beforeprev(boost::wave::T_EOF)
{}
template <typename StringT>
bool must_insert(boost::wave::token_id current, StringT const &value)
{
using namespace boost::wave;
switch (current) {
case T_NONREPLACABLE_IDENTIFIER:
case T_IDENTIFIER:
return impl::handle_identifier(prev, beforeprev, value);
case T_INTLIT:
return impl::handle_intlit(prev, beforeprev);
case T_FLOATLIT:
return impl::handle_floatlit(prev, beforeprev);
case T_STRINGLIT:
if (TOKEN_FROM_ID('L', UnknownTokenType) == prev) // 'L'
return true;
break;
case T_LEFTBRACE_ALT:
return impl::handle_alt_leftbrace(prev, beforeprev);
case T_LEFTBRACKET_ALT:
return impl::handle_alt_leftbracket(prev, beforeprev);
case T_FIXEDPOINTLIT:
return impl::handle_fixedpointlit(prev, beforeprev);
case T_DOT:
return impl::handle_dot(prev, beforeprev);
case T_QUESTION_MARK:
return impl::handle_questionmark(prev, beforeprev);
case T_NEWLINE:
return impl::handle_newline(prev, beforeprev);
case T_LEFTPAREN:
case T_RIGHTPAREN:
case T_LEFTBRACKET:
case T_RIGHTBRACKET:
case T_SEMICOLON:
case T_COMMA:
case T_COLON:
switch (prev) {
case T_LEFTPAREN:
case T_RIGHTPAREN:
case T_LEFTBRACKET:
case T_RIGHTBRACKET:
case T_LEFTBRACE:
case T_RIGHTBRACE:
return false; // no insertion between parens/brackets/braces
default:
break;
}
break;
case T_LEFTBRACE:
case T_RIGHTBRACE:
switch (prev) {
case T_LEFTPAREN:
case T_RIGHTPAREN:
case T_LEFTBRACKET:
case T_RIGHTBRACKET:
case T_LEFTBRACE:
case T_RIGHTBRACE:
case T_SEMICOLON:
case T_COMMA:
case T_COLON:
return false; // no insertion between parens/brackets/braces
case T_QUESTION_MARK:
if (T_QUESTION_MARK == beforeprev)
return true;
break;
default:
break;
}
break;
case T_MINUS:
case T_MINUSMINUS:
case T_LESS:
case T_EQUAL:
case T_ASSIGN:
case T_GREATER:
case T_DIVIDE:
case T_CHARLIT:
case T_NOT:
case T_NOTEQUAL:
case T_DIVIDEASSIGN:
case T_MINUSASSIGN:
if (T_QUESTION_MARK == prev && T_QUESTION_MARK == beforeprev)
return true; // ??{op}
break;
case T_COMPL_ALT:
case T_OR_ALT:
case T_AND_ALT:
case T_NOT_ALT:
case T_XOR_ALT:
case T_ANDASSIGN_ALT:
case T_ORASSIGN_ALT:
case T_XORASSIGN_ALT:
case T_NOTEQUAL_ALT:
if (T_IDENTIFIER == prev || T_NONREPLACABLE_IDENTIFIER == prev ||
IS_CATEGORY(prev, KeywordTokenType))
return true;
break;
}
// else, handle operators separately
if (IS_CATEGORY(current, OperatorTokenType) &&
IS_CATEGORY(prev, OperatorTokenType))
{
return true; // operators must be delimited always
}
return false;
}
void shift_tokens (boost::wave::token_id next_id)
{
beforeprev = prev;
prev = next_id;
}
private:
boost::wave::token_id prev; // the previous analyzed token
boost::wave::token_id beforeprev; // the token before the previous
};
///////////////////////////////////////////////////////////////////////////////
} // namespace util
} // namespace wave
} // namespace boost
#endif // !defined(INSERT_WHITESPACE_DETECTION_HPP_765EF77B_0513_4967_BDD6_6A38148C4C96_INCLUDED)

View File

@@ -0,0 +1,269 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(INTERPRET_PRAGMA_HPP_B1F2315E_C5CE_4ED1_A343_0EF548B7942A_INCLUDED)
#define INTERPRET_PRAGMA_HPP_B1F2315E_C5CE_4ED1_A343_0EF548B7942A_INCLUDED
#include <cstdlib>
#include <cstdio>
#include <string>
#include <list>
#include <boost/spirit/core.hpp>
#if SPIRIT_VERSION >= 0x1700
#include <boost/spirit/actor/assign_actor.hpp>
#include <boost/spirit/actor/push_back_actor.hpp>
#endif // SPIRIT_VERSION >= 0x1700
#include <boost/wave/wave_config.hpp>
#include <boost/wave/util/pattern_parser.hpp>
#include <boost/wave/util/macro_helpers.hpp>
#include <boost/wave/token_ids.hpp>
#include <boost/wave/cpp_exceptions.hpp>
#include <boost/wave/cpp_iteration_context.hpp>
#include <boost/wave/language_support.hpp>
#include <boost/wave/trace_policies.hpp>
#if !defined(spirit_append_actor)
#if SPIRIT_VERSION >= 0x1700
#define spirit_append_actor(actor) boost::spirit::push_back_a(actor)
#define spirit_assign_actor(actor) boost::spirit::assign_a(actor)
#else
#define spirit_append_actor(actor) boost::spirit::append(actor)
#define spirit_assign_actor(actor) boost::spirit::assign(actor)
#endif // SPIRIT_VERSION >= 0x1700
#endif // !defined(spirit_append_actor)
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace util {
///////////////////////////////////////////////////////////////////////////////
namespace impl {
///////////////////////////////////////////////////////////////////////////////
//
// Interpret the different Wave specific pragma directives/operators
//
///////////////////////////////////////////////////////////////////////////////
template <typename ContextT, typename ContainerT>
inline bool
interpret_pragma_trace(ContextT &ctx, ContainerT const &values,
typename ContextT::token_t const &act_token)
{
typedef typename ContextT::token_t token_t;
typedef typename token_t::string_t string_t;
bool valid_option = false;
if (1 == values.size()) {
token_t const &value = values.front();
using namespace boost::wave::trace_policies;
if (value.get_value() == "enable" ||
value.get_value() == "on" ||
value.get_value() == "1")
{
ctx.enable_tracing(static_cast<trace_flags>(
ctx.tracing_enabled() | trace_macros));
valid_option = true;
}
else if (value.get_value() == "disable" ||
value.get_value() == "off" ||
value.get_value() == "0")
{
ctx.enable_tracing(static_cast<trace_flags>(
ctx.tracing_enabled() & ~trace_macros));
valid_option = true;
}
}
if (!valid_option) {
// unknown option value
string_t option_str ("trace");
if (values.size() > 0) {
option_str += "(";
option_str += impl::as_string(values);
option_str += ")";
}
BOOST_WAVE_THROW(preprocess_exception, ill_formed_pragma_option,
option_str, act_token.get_position());
}
return true;
}
template <typename ContextT, typename ContainerT>
inline bool
interpret_pragma_system(ContextT &/*ctx*/, ContainerT &pending,
ContainerT const &values, typename ContextT::token_t const &act_token,
boost::wave::language_support language)
{
typedef typename ContextT::token_t token_t;
typedef typename token_t::string_t string_t;
if (0 == values.size()) {
BOOST_WAVE_THROW(preprocess_exception, ill_formed_pragma_option,
"system", act_token.get_position());
}
string_t stdout_file(std::tmpnam(0));
string_t stderr_file(std::tmpnam(0));
string_t system_str(impl::as_string(values));
string_t native_cmd(system_str);
system_str += " >" + stdout_file + " 2>" + stderr_file;
if (0 != std::system(system_str.c_str())) {
// unable to spawn the command
string_t error_str("unable to spawn command: ");
error_str += native_cmd;
BOOST_WAVE_THROW(preprocess_exception, ill_formed_pragma_option,
error_str, act_token.get_position());
}
// rescan the content of the stdout_file and insert it as the
// _Pragma replacement
typedef typename ContextT::lex_t lex_t;
typedef typename ContextT::input_policy_t input_policy_t;
typedef boost::wave::iteration_context<lex_t, input_policy_t> iteration_context_t;
iteration_context_t iter_ctx(stdout_file.c_str(), act_token.get_position(),
language);
ContainerT pragma;
for (/**/; iter_ctx.first != iter_ctx.last; ++iter_ctx.first)
pragma.push_back(*iter_ctx.first);
// prepend the newly generated token sequence to the 'pending' container
pending.splice(pending.begin(), pragma);
// erase the created tempfiles
std::remove(stdout_file.c_str());
std::remove(stderr_file.c_str());
return true;
}
///////////////////////////////////////////////////////////////////////////////
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
//
// The function interpret_pragma interprets the given token sequence as the
// body of a #pragma directive (or parameter to the _Pragma operator) and
// executes the actions associated with recognized Wave specific options.
//
///////////////////////////////////////////////////////////////////////////////
template <typename ContextT, typename IteratorT, typename ContainerT>
inline bool
interpret_pragma(ContextT &ctx, typename ContextT::token_t const &act_token,
IteratorT it, IteratorT const &end, ContainerT &pending,
boost::wave::language_support language)
{
typedef typename ContextT::token_t token_t;
typedef typename token_t::string_t string_t;
using namespace cpplexer;
if (T_IDENTIFIER == token_id(*it) && "wave" == (*it).get_value()) {
// this is a wave specific option, it should have the form:
// #pragma wave option(value)
// where '(value)' is required only for some pragma directives
//
// supported #pragma directives so far:
// wave trace(enable) or wave trace(1)
// wave trace(disable) or wave trace(0)
// wave stop(error message)
// wave system(command)
using namespace boost::spirit;
token_t option;
ContainerT values;
if (!parse (++it, end,
( ch_p(T_IDENTIFIER)
[spirit_assign_actor(option)]
| pattern_p(KeywordTokenType, TokenTypeMask)
[spirit_assign_actor(option)]
)
>> !( ch_p(T_LEFTPAREN)
>> lexeme_d[
*(anychar_p[spirit_append_actor(values)] - ch_p(T_RIGHTPAREN))
]
>> ch_p(T_RIGHTPAREN)
),
pattern_p(WhiteSpaceTokenType, TokenTypeMask)).hit)
{
return false;
}
// remove the falsely matched closing parenthesis
if (values.size() > 0) {
if (T_RIGHTPAREN == values.back()) {
typename ContainerT::reverse_iterator rit = values.rbegin();
values.erase((++rit).base());
}
else {
BOOST_WAVE_THROW(preprocess_exception, ill_formed_pragma_option,
"missing matching ')'", act_token.get_position());
}
}
// decode the option
if (option.get_value() == "trace") {
// enable/disable tracing option
return impl::interpret_pragma_trace(ctx, values, act_token);
}
else if (option.get_value() == "stop") {
// stop the execution and output the argument
BOOST_WAVE_THROW(preprocess_exception, error_directive,
impl::as_string(values), act_token.get_position());
}
else if (option.get_value() == "system") {
// try to spawn the given argument as a system command and return the
// std::cout of this process as the replacement of this _Pragma
return impl::interpret_pragma_system(ctx, pending, values,
act_token, language);
}
else if (!ctx.interpret_pragma(
pending, option, values, act_token, language))
{
// unknown #pragma option
string_t option_str (option.get_value());
if (values.size() > 0) {
option_str += "(";
option_str += impl::as_string(values);
option_str += ")";
}
BOOST_WAVE_THROW(preprocess_exception, ill_formed_pragma_option,
option_str, act_token.get_position());
}
return true;
}
#if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
else if (T_IDENTIFIER == token_id(*it) && "once" == (*it).get_value()) {
// #pragma once
return ctx.add_pragma_once_header(ctx.get_current_filename());
}
#endif
return false;
}
///////////////////////////////////////////////////////////////////////////////
} // namespace util
} // namespace wave
} // namespace boost
#endif // !defined(INTERPRET_PRAGMA_HPP_B1F2315E_C5CE_4ED1_A343_0EF548B7942A_INCLUDED)

View File

@@ -0,0 +1,72 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(ITERATION_CONTEXT_HPP_9556CD16_F11E_4ADC_AC8B_FB9A174BE664_INCLUDED)
#define ITERATION_CONTEXT_HPP_9556CD16_F11E_4ADC_AC8B_FB9A174BE664_INCLUDED
#include <cstdlib>
#include <stack>
#include <boost/wave/wave_config.hpp>
#include <boost/wave/cpp_exceptions.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace util {
///////////////////////////////////////////////////////////////////////////////
template <typename IterationContextT>
class iteration_context_stack
{
typedef std::stack<IterationContextT> base_t;
public:
typedef typename base_t::size_type size_type;
iteration_context_stack()
: max_include_nesting_depth(BOOST_WAVE_MAX_INCLUDE_LEVEL_DEPTH)
{}
void set_max_include_nesting_depth(size_type new_depth)
{ max_include_nesting_depth = new_depth; }
size_type get_max_include_nesting_depth() const
{ return max_include_nesting_depth; }
typename base_t::size_type size() const { return iter_ctx.size(); }
typename base_t::value_type &top() { return iter_ctx.top(); }
void pop() { iter_ctx.pop(); }
template <typename PositionT>
void push(PositionT const &pos, typename base_t::value_type const &val)
{
if (iter_ctx.size() == max_include_nesting_depth) {
char buffer[22]; // 21 bytes holds all NUL-terminated unsigned 64-bit numbers
using namespace std; // for some systems ltoa is in namespace std
sprintf(buffer, "%d", max_include_nesting_depth);
BOOST_WAVE_THROW(preprocess_exception, include_nesting_too_deep, buffer,
pos);
}
iter_ctx.push(val);
}
private:
size_type max_include_nesting_depth;
base_t iter_ctx;
};
///////////////////////////////////////////////////////////////////////////////
} // namespace util
} // namespace wave
} // namespace boost
#endif // !defined(ITERATION_CONTEXT_HPP_9556CD16_F11E_4ADC_AC8B_FB9A174BE664_INCLUDED)

View File

@@ -0,0 +1,127 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(MACRO_DEFINITION_HPP_D68A639E_2DA5_4E9C_8ACD_CFE6B903831E_INCLUDED)
#define MACRO_DEFINITION_HPP_D68A639E_2DA5_4E9C_8ACD_CFE6B903831E_INCLUDED
#include <vector>
#include <list>
#include <boost/wave/wave_config.hpp>
#include <boost/wave/token_ids.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace util {
///////////////////////////////////////////////////////////////////////////////
//
// macro_definition
//
// This class containes all infos for a defined macro.
//
///////////////////////////////////////////////////////////////////////////////
template <typename TokenT, typename ContainerT>
struct macro_definition {
typedef std::vector<TokenT> parameter_container_t;
typedef ContainerT definition_container_t;
typedef typename parameter_container_t::const_iterator
const_parameter_iterator_t;
typedef typename definition_container_t::const_iterator
const_definition_iterator_t;
macro_definition(TokenT const &token_, bool has_parameters,
bool is_predefined_, long uid_)
: macroname(token_), uid(uid_), is_functionlike(has_parameters),
replaced_parameters(false), is_available_for_replacement(true),
is_predefined(is_predefined_)
#if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
, has_ellipsis(false)
#endif
{
}
// generated copy constructor
// generated destructor
// generated assignment operator
// Replace all occurrences of the parameters throughout the macrodefinition
// with special parameter tokens to simplify later macro replacement.
// Additionally mark all occurrences of the macro name itself throughout
// the macro definition
void replace_parameters()
{
using namespace boost::wave;
if (!replaced_parameters) {
typename definition_container_t::iterator end = macrodefinition.end();
typename definition_container_t::iterator it = macrodefinition.begin();
for (/**/; it != end; ++it) {
if (T_IDENTIFIER == token_id(*it) ||
IS_CATEGORY(token_id(*it), KeywordTokenType))
{
// may be a parameter to replace
const_parameter_iterator_t cend = macroparameters.end();
const_parameter_iterator_t cit = macroparameters.begin();
for (typename parameter_container_t::size_type i = 0;
cit != cend; ++cit, ++i)
{
if ((*it).get_value() == (*cit).get_value()) {
(*it).set_token_id(token_id(T_PARAMETERBASE+i));
break;
}
#if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
else if (T_ELLIPSIS == token_id(*cit) &&
"__VA_ARGS__" == (*it).get_value())
{
// __VA_ARGS__ requires special handling
(*it).set_token_id(token_id(T_EXTPARAMETERBASE+i));
break;
}
#endif
}
}
}
#if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
// we need to know, if the last of the formal arguments is an ellipsis
if (macroparameters.size() > 0 &&
T_ELLIPSIS == token_id(macroparameters.back()))
{
has_ellipsis = true;
}
#endif
replaced_parameters = true; // do it only once
}
}
TokenT macroname; // macro name
parameter_container_t macroparameters; // formal parameters
definition_container_t macrodefinition; // macro definition token sequence
long uid; // unique id of this macro
bool is_functionlike;
bool replaced_parameters;
bool is_available_for_replacement;
bool is_predefined;
#if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
bool has_ellipsis;
#endif
};
///////////////////////////////////////////////////////////////////////////////
} // namespace util
} // namespace wave
} // namespace boost
#endif // !defined(MACRO_DEFINITION_HPP_D68A639E_2DA5_4E9C_8ACD_CFE6B903831E_INCLUDED)

View File

@@ -0,0 +1,226 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(MACRO_HELPERS_HPP_931BBC99_EBFA_4692_8FBE_B555998C2C39_INCLUDED)
#define MACRO_HELPERS_HPP_931BBC99_EBFA_4692_8FBE_B555998C2C39_INCLUDED
#include <boost/wave/wave_config.hpp>
#include <boost/wave/token_ids.hpp>
#include <boost/wave/cpplexer/validate_universal_char.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace util {
namespace impl {
// escape a string literal (insert '\\' before every '\"', '?' and '\\')
template <typename StringT>
inline StringT
escape_lit(StringT const &value)
{
StringT result(value);
typename StringT::size_type pos = 0;
while ((pos = result.find_first_of ("\"\\?", pos)) != StringT::npos)
{
result.insert (pos, 1, '\\');
pos += 2;
}
return result;
}
// un-escape a string literal (remove '\\' just before '\\', '\"' or '?')
template <typename StringT>
inline StringT
unescape_lit(StringT const &value)
{
StringT result(value);
typename StringT::size_type pos = 0;
while ((pos = result.find_first_of ("\\", pos)) != StringT::npos)
{
if ('\\' == result[pos+1] || '\"' == result[pos+1] ||
'?' == result[pos+1])
{
result.erase(pos, 1);
}
}
return result;
}
// return the string representation of a token sequence
template <typename ContainerT, typename PositionT>
inline typename ContainerT::value_type::string_t
as_stringlit (ContainerT const &token_sequence, PositionT const &pos)
{
using namespace boost::wave;
typedef typename ContainerT::value_type::string_t string_t;
string_t result("\"");
bool was_whitespace = false;
typename ContainerT::const_iterator end = token_sequence.end();
for (typename ContainerT::const_iterator it = token_sequence.begin();
it != end; ++it)
{
token_id id = token_id(*it);
if (IS_CATEGORY(*it, WhiteSpaceTokenType) || T_NEWLINE == id) {
if (!was_whitespace) {
// C++ standard 16.3.2.2 [cpp.stringize]
// Each occurrence of white space between the arguments
// preprocessing tokens becomes a single space character in the
// character string literal.
result += " ";
was_whitespace = true;
}
}
else if (T_STRINGLIT == id || T_CHARLIT == id) {
// string literals and character literals have to be escaped
result += impl::escape_lit((*it).get_value());
was_whitespace = false;
}
else
#if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
if (T_PLACEMARKER != id)
#endif
{
// now append this token to the string
result += (*it).get_value();
was_whitespace = false;
}
}
result += "\"";
// validate the resulting literal to contain no invalid universal character
// value (throws if invalid chars found)
boost::wave::cpplexer::impl::validate_literal(result, pos.get_line(),
pos.get_column(), pos.get_file());
return result;
}
#if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
// return the string representation of a token sequence
template <typename ContainerT, typename PositionT>
inline typename ContainerT::value_type::string_t
as_stringlit (std::vector<ContainerT> const &arguments,
typename std::vector<ContainerT>::size_type i, PositionT const &pos)
{
using namespace boost::wave;
typedef typename ContainerT::value_type::string_t string_t;
BOOST_SPIRIT_ASSERT(0 <= i && i < arguments.size());
string_t result("\"");
bool was_whitespace = false;
for (/**/; i < arguments.size(); ++i) {
// stringize all remaining arguments
typename ContainerT::const_iterator end = arguments[i].end();
for (typename ContainerT::const_iterator it = arguments[i].begin();
it != end; ++it)
{
token_id id = token_id(*it);
if (IS_CATEGORY(*it, WhiteSpaceTokenType) || T_NEWLINE == id) {
if (!was_whitespace) {
// C++ standard 16.3.2.2 [cpp.stringize]
// Each occurrence of white space between the arguments
// preprocessing tokens becomes a single space character in the
// character string literal.
result += " ";
was_whitespace = true;
}
}
else if (T_STRINGLIT == id || T_CHARLIT == id) {
// string literals and character literals have to be escaped
result += impl::escape_lit((*it).get_value());
was_whitespace = false;
}
else if (T_PLACEMARKER != id) {
// now append this token to the string
result += (*it).get_value();
was_whitespace = false;
}
}
// append comma, if not last argument
if (i < arguments.size()-1) {
result += ",";
was_whitespace = false;
}
}
result += "\"";
// validate the resulting literal to contain no invalid universal character
// value (throws if invalid chars found)
boost::wave::cpplexer::impl::validate_literal(result, pos.get_line(),
pos.get_column(), pos.get_file());
return result;
}
#endif // BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
// return the string representation of a token sequence
template <typename StringT, typename IteratorT>
inline StringT
as_string(IteratorT it, IteratorT end)
{
StringT result;
for (/**/; it != end; ++it)
{
result += (*it).get_value();
}
return result;
}
// return the string representation of a token sequence
template <typename ContainerT>
inline typename ContainerT::value_type::string_t
as_string (ContainerT const &token_sequence)
{
typedef typename ContainerT::value_type::string_t string_t;
return as_string<string_t>(token_sequence.begin(), token_sequence.end());
}
#if BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS != 0
///////////////////////////////////////////////////////////////////////////
//
// Copies all arguments beginning with the given index to the output
// sequence. The arguments are separated by commas.
//
template <typename ContainerT, typename PositionT>
void replace_ellipsis (std::vector<ContainerT> const &arguments,
typename ContainerT::size_type index,
ContainerT &expanded, PositionT const &pos)
{
using namespace cpplexer;
typedef typename ContainerT::value_type token_t;
token_t comma(T_COMMA, ",", pos);
for (/**/; index < arguments.size(); ++index) {
ContainerT const &arg = arguments[index];
std::copy(arg.begin(), arg.end(),
std::inserter(expanded, expanded.end()));
if (index < arguments.size()-1)
expanded.push_back(comma);
}
}
#endif
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
} // namespace util
} // namespace wave
} // namespace boost
#endif // !defined(MACRO_HELPERS_HPP_931BBC99_EBFA_4692_8FBE_B555998C2C39_INCLUDED)

View File

@@ -0,0 +1,56 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Global application configuration
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(BOOST_SPIRIT_PATTERN_PARSER_HPP)
#define BOOST_SPIRIT_PATTERN_PARSER_HPP
#include <boost/spirit/core/primitives/primitives.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace util {
///////////////////////////////////////////////////////////////////////////
//
// pattern_and class
//
///////////////////////////////////////////////////////////////////////////
template <typename CharT = char>
struct pattern_and : public boost::spirit::char_parser<pattern_and<CharT> >
{
pattern_and(CharT pattern_, unsigned long pattern_mask_ = 0UL)
: pattern(pattern_),
pattern_mask((0UL != pattern_mask_) ? pattern_mask_ : pattern_)
{}
template <typename T>
bool test(T pattern_) const
{ return (pattern_ & pattern_mask) == pattern; }
CharT pattern;
unsigned long pattern_mask;
};
template <typename CharT>
inline pattern_and<CharT>
pattern_p(CharT pattern, unsigned long pattern_mask = 0UL)
{ return pattern_and<CharT>(pattern, pattern_mask); }
///////////////////////////////////////////////////////////////////////////////
} // namespace util
} // namespace wave
} // namespace boost
#endif // defined(BOOST_SPIRIT_PATTERN_PARSER_HPP)

View File

@@ -0,0 +1,375 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(SYMBOL_TABLE_HPP_32B0F7C6_3DD6_4113_95A5_E16516C6F45A_INCLUDED)
#define SYMBOL_TABLE_HPP_32B0F7C6_3DD6_4113_95A5_E16516C6F45A_INCLUDED
#include <map>
#include <algorithm>
#include <boost/shared_ptr.hpp>
#include <boost/wave/wave_config.hpp>
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS == 0
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace util {
///////////////////////////////////////////////////////////////////////////////
//
// The symbol_table class is used for the storage of defined macros.
//
///////////////////////////////////////////////////////////////////////////////
template <typename StringT, typename MacroDefT>
struct symbol_table
: public std::map<StringT, boost::shared_ptr<MacroDefT> >
{
symbol_table(long uid_)
{}
};
///////////////////////////////////////////////////////////////////////////////
} // namespace util
} // namespace wave
} // namespace boost
#else // BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS == 0
#include <utility>
#include <algorithm>
#include <boost/concept_check.hpp>
//#define BOOST_WAVE_USE_TST_SYMBOLTABLE
#if defined(BOOST_WAVE_USE_TST_SYMBOLTABLE)
#include <boost/wave/util/tst.hpp>
#endif // defined(WAVE_USE_TST_SYMBOLTABLE)
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace util {
namespace {
template <typename StringT>
inline StringT
make_name(StringT const &name)
{
return !name.empty() ? name : "<unnamed>";
}
}
///////////////////////////////////////////////////////////////////////////////
//
// The symbol_table class is used for structured storage of defined macros. It
// supports macro scoping.
//
///////////////////////////////////////////////////////////////////////////////
template <typename StringT, typename MacroDefT>
class symbol_table {
typedef symbol_table<StringT, MacroDefT> self_t;
typedef boost::shared_ptr<self_t> self_ref_t;
typedef boost::shared_ptr<MacroDefT> macro_ref_t;
typedef std::map<StringT, self_ref_t> enclosed_scopes_t;
#if BOOST_WAVE_USE_TST_SYMBOLTABLE == 0
typedef std::map<StringT, macro_ref_t> defined_macros_t;
#else
typedef boost::spirit::tst<macro_ref_t, StringT> defined_macros_t;
#endif
public:
typedef typename defined_macros_t::value_type value_type;
typedef typename defined_macros_t::iterator iterator;
typedef typename defined_macros_t::const_iterator const_iterator;
typedef typename enclosed_scopes_t::value_type scope_type;
typedef typename enclosed_scopes_t::iterator scope_iterator;
typedef typename enclosed_scopes_t::const_iterator const_scope_iterator;
public:
// constructs global scope symbol table
symbol_table(long uid_)
: contains_unnamed_part(false), uid(uid_)
{}
// constructs any non-global scope symbol table
symbol_table(StringT const &scope_name_, StringT const &full_outer_name_,
bool contains_unnamed_part_, long uid_)
: scope_name(scope_name_),
full_scope_name(full_outer_name_ + "::" + make_name(scope_name_)),
contains_unnamed_part(contains_unnamed_part_),
uid(uid_)
{}
// generated copy constructor
// generated destructor
// generated assignment operator
// symbol table operations
iterator find(StringT const &macro_name)
{ return macro_names.find(macro_name); }
const_iterator find(StringT const &macro_name) const
{ return macro_names.find(macro_name); }
iterator begin() { return macro_names.begin(); }
const_iterator begin() const { return macro_names.begin(); }
iterator end() { return macro_names.end(); }
const_iterator end() const { return macro_names.end(); }
#if BOOST_WAVE_USE_TST_SYMBOLTABLE == 0
std::pair<iterator, bool> insert(value_type const &value)
{ return macro_names.insert(value); }
void erase(iterator where) { macro_names.erase(where); }
#else
std::pair<iterator, bool> insert(StringT const &value)
{ return macro_names.insert(value); }
void erase(iterator where)
{ macro_names.erase((*where).data()->macroname.get_value()); }
#endif
void clear() { macro_names.clear(); }
// scope manipulation
self_ref_t begin_scope(StringT const &name, long uid);
self_t *end_scope() const;
bool get_scope(StringT const &name, self_ref_t &scope) const;
bool get_contains_unnamed_part() const { return contains_unnamed_part; }
scope_iterator scope_begin() { return scopes.begin(); }
const_scope_iterator scope_begin() const { return scopes.begin(); }
scope_iterator scope_end() { return scopes.end(); }
const_scope_iterator scope_end() const { return scopes.end(); }
// import a given macro name into this scope
bool import_macroname (StringT const &name, macro_ref_t const &value);
// import a given scope into this scope
template <typename PositionT>
void import_scope (self_t *value, PositionT const &act_pos);
StringT const &get_full_name() const { return full_scope_name; }
private:
defined_macros_t macro_names; // macros defined inside this scope
StringT scope_name; // name of this scope (empty for global)
StringT full_scope_name; // full name of this scope ('::' for global)
enclosed_scopes_t scopes; // scopes defined inside this scope
bool contains_unnamed_part; // name contains unnamed part(s)
long uid;
};
///////////////////////////////////////////////////////////////////////////////
//
// begin_scope
//
// This function opens a new scope with the given name inside the current
// scope. If this scope already exists, the function does nothing.
// The newly created or existing scopes are returned.
//
///////////////////////////////////////////////////////////////////////////////
template <typename StringT, typename MacroDefT>
inline boost::shared_ptr<symbol_table<StringT, MacroDefT> >
symbol_table<StringT, MacroDefT>::begin_scope(StringT const &name, long uid)
{
// if this scope does not exist, create it, otherwise reuse the existing
scope_iterator it = scopes.find(name);
if (it == scopes.end()) {
// create the new scope
self_ref_t new_symbol_table(new self_t(name, full_scope_name,
contains_unnamed_part || name.empty(), uid));
std::pair<scope_iterator, bool> p = scopes.insert(
scope_type(name, new_symbol_table));
BOOST_SPIRIT_ASSERT(p.second);
it = p.first;
}
// return a pointer to the new scope
return (*it).second;
}
///////////////////////////////////////////////////////////////////////////////
//
// end_scope
//
// This function closes (ends) the currently active scope
// The next outer scope is returned
//
///////////////////////////////////////////////////////////////////////////////
template <typename StringT, typename MacroDefT>
inline symbol_table<StringT, MacroDefT> *
symbol_table<StringT, MacroDefT>::end_scope() const
{
return 0; // not used anymore
}
///////////////////////////////////////////////////////////////////////////////
//
// get_scope
//
// This function returns a scope with a given name, if this scope exists.
// The return value of this function indicates whether a scope with the
// given name was found or not.
//
///////////////////////////////////////////////////////////////////////////////
template <typename StringT, typename MacroDefT>
inline bool
symbol_table<StringT, MacroDefT>::get_scope(StringT const &name,
boost::shared_ptr<symbol_table<StringT, MacroDefT> > &scope) const
{
const_scope_iterator cit = scopes.find(name);
if (cit == scopes.end())
return false;
scope = (*cit).second;
return true;
}
///////////////////////////////////////////////////////////////////////////////
//
// import_macroname
//
// Import a given macro name into this scope
//
// The name parameter should be an unqualified macro name.
//
///////////////////////////////////////////////////////////////////////////////
template <typename StringT, typename MacroDefT>
inline bool
symbol_table<StringT, MacroDefT>::import_macroname (StringT const &name,
macro_ref_t const &value)
{
// the new name shouldn't exist in this scope
iterator it = find(name);
if (it != end()) {
// name already defined in this scope as a macro, may only be imported
// if it is the same macro
#if BOOST_WAVE_USE_TST_SYMBOLTABLE == 0
return ((*it).second->uid == value->uid);
#else
return ((*it).data()->uid == value->uid);
#endif
}
const_scope_iterator its = scopes.find(name);
if (its != scopes.end()) {
// name already defined in this scope as a scope, may not be imported
return false;
}
#if BOOST_WAVE_USE_TST_SYMBOLTABLE == 0
std::pair<iterator, bool> p = insert(value_type(name, value));
BOOST_SPIRIT_ASSERT(p.second);
boost::ignore_unused_variable_warning(p);
#else
std::pair<iterator, bool> p = insert(name);
BOOST_SPIRIT_ASSERT(p.second);
(*p.first).data() = value;
#endif
return true;
}
///////////////////////////////////////////////////////////////////////////////
//
// import_scope
//
// Import a given scope into this scope. This effectively makes available
// the whole scope hierarchy based at the scope to import into this scope.
//
// The name parameter should be an unqualified scope name.
//
///////////////////////////////////////////////////////////////////////////////
template <typename StringT, typename MacroDefT>
template <typename PositionT>
inline void
symbol_table<StringT, MacroDefT>::import_scope (self_t *value,
PositionT const &act_pos)
{
// import all macro names from the given scope
iterator end = value -> end();
for (iterator it = value -> begin(); it != end; ++it) {
#if BOOST_WAVE_USE_TST_SYMBOLTABLE == 0
if ((*it).second->is_predefined)
continue; // do not import predefined macros
if (!import_macroname((*it).first, (*it).second)) {
BOOST_WAVE_THROW(preprocess_exception, alreadydefined_name,
(*it).first, act_pos);
}
#else
if ((*it).data()->is_predefined)
continue; // do not import predefined macros
if (!import_macroname((*it).key(), (*it).data())) {
BOOST_WAVE_THROW(preprocess_exception, alreadydefined_name,
(*it).key(), act_pos);
}
#endif
}
// import all child scopes of the given one into this scope
const_scope_iterator scope_end = value -> scope_end();
for (const_scope_iterator scope_it = value -> scope_begin();
scope_it != scope_end; ++scope_it)
{
StringT name ((*scope_it).first);
// the new name shouldn't exist in this scope
iterator itm = find(name);
if (itm != this->end()) {
// name already defined in this scope as a macro, may not be imported
BOOST_WAVE_THROW(preprocess_exception, alreadydefined_name,
name, act_pos);
}
scope_iterator its = scopes.find(name);
if (its != scopes.end()) {
if ((*its).second->uid != (*scope_it).second->uid) {
// name already defined in this scope as a scope, may not be imported
BOOST_WAVE_THROW(preprocess_exception, alreadydefined_name,
name, act_pos);
}
continue; // this scope was imported already
}
// if this scope does not exist, import it
std::pair<scope_iterator, bool> p = scopes.insert(
scope_type(name, (*scope_it).second));
BOOST_SPIRIT_ASSERT(p.second);
boost::ignore_unused_variable_warning(p);
}
}
///////////////////////////////////////////////////////////////////////////////
} // namespace util
} // namespace wave
} // namespace boost
#endif // BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS == 0
#endif // !defined(SYMBOL_TABLE_HPP_32B0F7C6_3DD6_4113_95A5_E16516C6F45A_INCLUDED)

View File

@@ -0,0 +1,146 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(TIME_CONVERSION_HELPER_HPP_DA97E389_1797_43BA_82AE_B071064B3EF4_INCLUDED)
#define TIME_CONVERSION_HELPER_HPP_DA97E389_1797_43BA_82AE_B071064B3EF4_INCLUDED
#include <ctime>
#include <boost/spirit/core.hpp>
#include <boost/spirit/symbols.hpp>
#if SPIRIT_VERSION >= 0x1700
#include <boost/spirit/actor/assign_actor.hpp>
#include <boost/spirit/actor/push_back_actor.hpp>
#endif // SPIRIT_VERSION >= 0x1700
#if !defined(spirit_append_actor)
#if SPIRIT_VERSION >= 0x1700
#define spirit_append_actor(actor) boost::spirit::push_back_a(actor)
#define spirit_assign_actor(actor) boost::spirit::assign_a(actor)
#else
#define spirit_append_actor(actor) boost::spirit::append(actor)
#define spirit_assign_actor(actor) boost::spirit::assign(actor)
#endif // SPIRIT_VERSION >= 0x1700
#endif // !defined(spirit_append_actor)
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace util {
namespace time_conversion {
using namespace std; // some systems have std::tm etc. in namespace std
///////////////////////////////////////////////////////////////////////////////
// define, whether the rule's should generate some debug output
#define TRACE_CPP_TIME_CONVERSION \
(BOOST_SPIRIT_DEBUG_FLAGS_CPP & BOOST_SPIRIT_DEBUG_FLAGS_TIME_CONVERSION) \
/**/
///////////////////////////////////////////////////////////////////////////////
// Grammar for parsing a date/time string generated by the C++ compiler from
// __DATE__ and __TIME__
class time_conversion_grammar :
public boost::spirit::grammar<time_conversion_grammar>
{
public:
time_conversion_grammar() : fYearIsCorrected(false)
{
memset (&time_stamp, 0, sizeof(tm));
BOOST_SPIRIT_DEBUG_TRACE_RULE_NAME(*this, "time_conversion_grammar",
TRACE_CPP_TIME_CONVERSION);
}
template <typename ScannerT>
struct definition {
definition(time_conversion_grammar const &self)
{
using boost::spirit::int_p;
using boost::spirit::add;
char const *m[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
for (int i = 0; i < 12; ++i)
add (month, m[i], i);
time_rule // expected format is 'Dec 29 2001 11:23:59'
= month[spirit_assign_actor(self.time_stamp.tm_mon)]
>> int_p[spirit_assign_actor(self.time_stamp.tm_mday)]
>> int_p[spirit_assign_actor(self.time_stamp.tm_year)]
>> int_p[spirit_assign_actor(self.time_stamp.tm_hour)]
>> int_p[spirit_assign_actor(self.time_stamp.tm_min)]
>> int_p[spirit_assign_actor(self.time_stamp.tm_sec)]
;
BOOST_SPIRIT_DEBUG_TRACE_RULE(time_rule, TRACE_CPP_TIME_CONVERSION);
}
boost::spirit::rule<ScannerT> time_rule;
boost::spirit::symbols<> month;
boost::spirit::rule<ScannerT> const&
start() const { return time_rule; }
};
void correct_year()
{
if (!fYearIsCorrected) {
time_stamp.tm_year -= 1900;
fYearIsCorrected = true;
}
}
mutable tm time_stamp;
bool fYearIsCorrected;
};
///////////////////////////////////////////////////////////////////////////////
// calculate the time of the compilation as a std::time_t to ensure correctness
// of the saved dfa table
class time_conversion_helper
{
public:
time_conversion_helper(char const *act_time) : compile_time(0)
{
using namespace boost::spirit;
time_conversion_grammar g;
if (parse (act_time, g, space_p | ch_p(':')).full) {
g.correct_year();
compile_time = mktime(&g.time_stamp);
}
BOOST_ASSERT(0 != compile_time);
}
time_t get_time() const { return compile_time; }
private:
time_t compile_time;
};
///////////////////////////////////////////////////////////////////////////////
#undef TRACE_CPP_TIME_CONVERSION
} // namespace time_conversion
// import time_conversion into the boost::wave::util namespace
using namespace time_conversion;
///////////////////////////////////////////////////////////////////////////////
} // namespace util
} // namespace wave
} // namespace boost
#endif // !defined(TIME_CONVERSION_HELPER_HPP_DA97E389_1797_43BA_82AE_B071064B3EF4_INCLUDED)

View File

@@ -0,0 +1,152 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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(TRANSFORM_ITERATOR_HPP_D492C659_88C7_4258_8C42_192F9AE80EC0_INCLUDED)
#define TRANSFORM_ITERATOR_HPP_D492C659_88C7_4258_8C42_192F9AE80EC0_INCLUDED
#include <boost/iterator_adaptors.hpp>
#if BOOST_ITERATOR_ADAPTORS_VERSION >= 0x0200
#include <boost/iterator/transform_iterator.hpp>
#endif // BOOST_ITERATOR_ADAPTORS_VERSION >= 0x0200
#include <boost/assert.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace impl {
#if BOOST_ITERATOR_ADAPTORS_VERSION < 0x0200
///////////////////////////////////////////////////////////////////////////////
//
// Transform Iterator Adaptor
//
// Upon deference, apply some unary function object and return the
// result by reference.
//
// This class is adapted from the Boost.Iterator library, where a similar
// class exists, which returns the next item by value
template <class AdaptableUnaryFunctionT>
struct ref_transform_iterator_policies
: public boost::default_iterator_policies
{
ref_transform_iterator_policies()
{}
ref_transform_iterator_policies(const AdaptableUnaryFunctionT &f)
: m_f(f) {}
template <class IteratorAdaptorT>
typename IteratorAdaptorT::reference
dereference(const IteratorAdaptorT &iter) const
{ return m_f(*iter.base()); }
AdaptableUnaryFunctionT m_f;
};
template <class AdaptableUnaryFunctionT, class IteratorT>
class ref_transform_iterator_generator
{
typedef typename AdaptableUnaryFunctionT::result_type value_type;
public:
typedef boost::iterator_adaptor<
IteratorT,
ref_transform_iterator_policies<AdaptableUnaryFunctionT>,
value_type, value_type const &, value_type const *,
std::input_iterator_tag>
type;
};
template <class AdaptableUnaryFunctionT, class IteratorT>
inline
typename ref_transform_iterator_generator<
AdaptableUnaryFunctionT, IteratorT>::type
make_ref_transform_iterator(
IteratorT base,
const AdaptableUnaryFunctionT &f = AdaptableUnaryFunctionT())
{
typedef typename ref_transform_iterator_generator<
AdaptableUnaryFunctionT, IteratorT>::type
result_t;
return result_t(base, f);
}
// Retrieve the token value given a parse node
// This is used in conjunction with the ref_transform_iterator above, to
// get the token values while iterating directly over the parse tree.
template <typename TokenT, typename ParseTreeNodeT>
struct get_token_value {
typedef TokenT result_type;
TokenT const &operator()(ParseTreeNodeT const &node) const
{
BOOST_ASSERT(1 == std::distance(node.value.begin(),
node.value.end()));
return *node.value.begin();
}
};
#else
template <class AdaptableUnaryFunctionT, class IteratorT>
class ref_transform_iterator_generator
{
typedef typename AdaptableUnaryFunctionT::result_type return_type;
typedef typename AdaptableUnaryFunctionT::argument_type argument_type;
public:
typedef boost::transform_iterator<
return_type (*)(argument_type), IteratorT, return_type>
type;
};
template <class AdaptableUnaryFunctionT, class IteratorT>
inline
typename ref_transform_iterator_generator<
AdaptableUnaryFunctionT, IteratorT>::type
make_ref_transform_iterator(
IteratorT base, AdaptableUnaryFunctionT const &f)
{
typedef typename ref_transform_iterator_generator<
AdaptableUnaryFunctionT, IteratorT>::type
iterator_t;
return iterator_t(base, f.transform);
}
// Retrieve the token value given a parse node
// This is used in conjunction with the ref_transform_iterator above, to
// get the token values while iterating directly over the parse tree.
template <typename TokenT, typename ParseTreeNodeT>
struct get_token_value {
typedef TokenT const &result_type;
typedef ParseTreeNodeT const &argument_type;
static result_type
transform (argument_type node)
{
BOOST_ASSERT(1 == std::distance(node.value.begin(),
node.value.end()));
return *node.value.begin();
}
};
#endif // BOOST_ITERATOR_ADAPTORS_VERSION < 0x0200
///////////////////////////////////////////////////////////////////////////////
} // namespace impl
} // namespace wave
} // namespace boost
#endif // !defined(TRANSFORM_ITERATOR_HPP_D492C659_88C7_4258_8C42_192F9AE80EC0_INCLUDED)

View File

@@ -0,0 +1,408 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Definition of the unput queue iterator
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(UNPUT_QUEUE_ITERATOR_HPP_76DA23D0_4893_4AD5_ABCC_6CED7CFB89BC_INCLUDED)
#define UNPUT_QUEUE_ITERATOR_HPP_76DA23D0_4893_4AD5_ABCC_6CED7CFB89BC_INCLUDED
#include <list>
#include <boost/iterator_adaptors.hpp>
#include <boost/wave/wave_config.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace util {
#if !defined(BOOST_ITERATOR_ADAPTORS_VERSION) || \
BOOST_ITERATOR_ADAPTORS_VERSION < 0x0200
template <typename TokenT, typename ContainerT>
class unput_queue_policies : public boost::default_iterator_policies
{
public:
unput_queue_policies(ContainerT &unput_queue_)
: unput_queue(unput_queue_)
{}
unput_queue_policies &operator= (unput_queue_policies const &rhs)
{
unput_queue = rhs.unput_queue;
return *this;
}
template <typename BaseT>
void initialize(BaseT &)
{}
template <typename IteratorAdaptorT>
typename IteratorAdaptorT::reference
dereference(const IteratorAdaptorT &x) const
{
if (x.policies().unput_queue.size() > 0)
return x.policies().unput_queue.front();
return *x.base();
}
template <typename IteratorAdaptorT>
void
increment(IteratorAdaptorT &x)
{
if (x.policies().unput_queue.size() > 0) {
// there exist pending tokens in the unput queue
x.policies().unput_queue.pop_front();
}
else {
// the unput_queue is empty, so advance the base iterator
++x.base();
}
}
template <typename IteratorAdaptorT1, typename IteratorAdaptorT2>
bool
equal(const IteratorAdaptorT1 &x, const IteratorAdaptorT2 &y) const
{
// two iterators are equal, if both begin() iterators of the queue objects
// are equal and the base iterators too
return
(x.policies().unput_queue.begin() == y.policies().unput_queue.begin() ||
(0 == x.policies().queuesize() && 0 == y.policies().queuesize())) &&
x.base() == y.base();
}
typename ContainerT::size_type queuesize() const
{ return unput_queue.size(); }
ContainerT &get_unput_queue() { return unput_queue; }
private:
ContainerT &unput_queue;
};
///////////////////////////////////////////////////////////////////////////////
//
// unput_queue_iterator
//
// The unput_queue_iterator templates encapsulates an unput_queue together
// with the direct input to be read after the unput queue is emptied
//
// This version is for the old iterator_adaptors (Boost V1.30.x)
//
///////////////////////////////////////////////////////////////////////////////
template <typename IteratorT, typename TokenT, typename ContainerT>
class unput_queue_iterator
: public boost::iterator_adaptor<
IteratorT, unput_queue_policies<TokenT, ContainerT>, TokenT,
TokenT const &, TokenT const *>
{
typedef
boost::iterator_adaptor<
IteratorT, unput_queue_policies<TokenT, ContainerT>, TokenT,
TokenT const &, TokenT const *
>
base_t;
typedef unput_queue_policies<TokenT, ContainerT> policies_t;
public:
typedef ContainerT container_t;
typedef IteratorT iterator_t;
unput_queue_iterator(IteratorT const &it, ContainerT &queue)
: base_t(it, policies_t(queue))
{}
ContainerT &get_unput_queue() { return policies().get_unput_queue(); }
IteratorT &get_base_iterator() { return base(); }
};
#else // BOOST_ITERATOR_ADAPTORS_VERSION < 0x0200
///////////////////////////////////////////////////////////////////////////////
//
// unput_queue_iterator
//
// The unput_queue_iterator templates encapsulates an unput_queue together
// with the direct input to be read after the unput queue is emptied
//
// This version is for the new iterator_adaptors (should be released with
// Boost V1.31.0)
//
///////////////////////////////////////////////////////////////////////////////
template <typename IteratorT, typename TokenT, typename ContainerT>
class unput_queue_iterator
: public boost::iterator_adaptor<
unput_queue_iterator<IteratorT, TokenT, ContainerT>,
IteratorT, TokenT const, std::forward_iterator_tag>
{
typedef boost::iterator_adaptor<
unput_queue_iterator<IteratorT, TokenT, ContainerT>,
IteratorT, TokenT const, std::forward_iterator_tag>
base_t;
public:
typedef ContainerT container_t;
typedef IteratorT iterator_t;
unput_queue_iterator(IteratorT const &it, ContainerT &queue)
: base_t(it), unput_queue(queue)
{}
ContainerT &get_unput_queue() { return unput_queue; }
ContainerT const &get_unput_queue() const { return unput_queue; }
IteratorT &get_base_iterator() { return base_t::base_reference(); }
IteratorT const &get_base_iterator() const { return base_t::base_reference(); }
unput_queue_iterator &operator= (unput_queue_iterator const &rhs)
{
if (this != &rhs) {
unput_queue = rhs.unput_queue;
base_t::operator=(rhs);
}
return *this;
}
typename base_t::reference dereference() const
{
if (unput_queue.size() > 0)
return unput_queue.front();
return *base_t::base_reference();
}
void increment()
{
if (unput_queue.size() > 0) {
// there exist pending tokens in the unput queue
unput_queue.pop_front();
}
else {
// the unput_queue is empty, so advance the base iterator
++base_t::base_reference();
}
}
template <
typename OtherDerivedT, typename OtherIteratorT,
typename V, typename C, typename R, typename D
>
bool equal(
boost::iterator_adaptor<OtherDerivedT, OtherIteratorT, V, C, R, D>
const &x) const
{
// two iterators are equal, if both begin() iterators of the queue objects
// are equal and the base iterators too
OtherDerivedT const &rhs = static_cast<OtherDerivedT const &>(x);
return
(unput_queue.begin() == rhs.get_unput_queue().begin() ||
(0 == unput_queue.size() && 0 == rhs.get_unput_queue().size())) &&
get_base_iterator() == rhs.get_base_iterator();
}
private:
ContainerT &unput_queue;
};
#endif // BOOST_ITERATOR_ADAPTORS_VERSION < 0x0200
namespace impl {
///////////////////////////////////////////////////////////////////////////
template <typename IteratorT, typename TokenT, typename ContainerT>
struct gen_unput_queue_iterator {
typedef unput_queue_iterator<IteratorT, TokenT, ContainerT> return_t;
static return_t
generate(ContainerT &queue, IteratorT const &it)
{
return return_t(it, queue);
}
};
template <typename IteratorT, typename TokenT, typename ContainerT>
struct gen_unput_queue_iterator<
unput_queue_iterator<IteratorT, TokenT, ContainerT>,
TokenT, ContainerT>
{
typedef unput_queue_iterator<IteratorT, TokenT, ContainerT> return_t;
static return_t
generate(ContainerT &queue, return_t const &it)
{
return return_t(it.base(), queue);
}
};
///////////////////////////////////////////////////////////////////////////
template <typename IteratorT>
struct assign_iterator {
static void
do_ (IteratorT &dest, IteratorT const &src)
{
dest = src;
}
};
#if !defined(BOOST_ITERATOR_ADAPTORS_VERSION) || \
BOOST_ITERATOR_ADAPTORS_VERSION < 0x0200
template <typename IteratorT, typename TokenT, typename ContainerT>
struct assign_iterator<
unput_queue_iterator<IteratorT, TokenT, ContainerT> >
{
typedef unput_queue_iterator<IteratorT, TokenT, ContainerT> iterator_t;
static void
do_ (iterator_t &dest, iterator_t const &src)
{
dest.base() = src.base();
dest.policies() = src.policies();
}
};
#endif // BOOST_ITERATOR_ADAPTORS_VERSION < 0x0200
///////////////////////////////////////////////////////////////////////////
//
// Look for the first non-whitespace token and return this token id.
// Note though, that the embedded unput_queues are not touched in any way!
//
template <typename IteratorT>
struct next_token {
static boost::wave::token_id
peek(IteratorT it, IteratorT end, bool skip_whitespace = true)
{
using namespace boost::wave;
if (skip_whitespace) {
for (++it; it != end; ++it) {
if (!IS_CATEGORY(*it, WhiteSpaceTokenType) &&
T_NEWLINE != token_id(*it))
{
break; // stop at the first non-whitespace token
}
}
}
else {
++it; // we have at least to look ahead
}
if (it != end)
return token_id(*it);
return T_EOI;
}
};
template <typename IteratorT, typename TokenT, typename ContainerT>
struct next_token<
unput_queue_iterator<IteratorT, TokenT, ContainerT> > {
typedef unput_queue_iterator<IteratorT, TokenT, ContainerT> iterator_t;
static boost::wave::token_id
peek(iterator_t it, iterator_t end, bool skip_whitespace = true)
{
using namespace boost::wave;
typename iterator_t::container_t &queue = it.get_unput_queue();
// first try to find it in the unput_queue
if (0 != queue.size()) {
typename iterator_t::container_t::iterator cit = queue.begin();
typename iterator_t::container_t::iterator cend = queue.end();
if (skip_whitespace) {
for (++cit; cit != cend; ++cit) {
if (!IS_CATEGORY(*cit, WhiteSpaceTokenType) &&
T_NEWLINE != token_id(*cit))
{
break; // stop at the first non-whitespace token
}
}
}
else {
++cit; // we have at least to look ahead
}
if (cit != cend)
return token_id(*cit);
}
// second try to move on into the base iterator stream
typename iterator_t::iterator_t base_it = it.get_base_iterator();
typename iterator_t::iterator_t base_end = end.get_base_iterator();
if (0 == queue.size())
++base_it; // advance, if the unput queue is empty
if (skip_whitespace) {
for (/**/; base_it != base_end; ++base_it) {
if (!IS_CATEGORY(*base_it, WhiteSpaceTokenType) &&
T_NEWLINE != token_id(*base_it))
{
break; // stop at the first non-whitespace token
}
}
}
if (base_it == base_end)
return T_EOI;
return token_id(*base_it);
}
};
// Skip all whitespace characters and queue the skipped characters into the
// given container
template <typename IteratorT>
inline boost::wave::token_id
skip_whitespace(IteratorT &first, IteratorT const &last)
{
using namespace cpplexer;
token_id id = next_token<IteratorT>::peek(first, last, false);
if (IS_CATEGORY(id, WhiteSpaceTokenType)) {
do {
++first;
id = next_token<IteratorT>::peek(first, last, false);
} while (IS_CATEGORY(id, WhiteSpaceTokenType));
}
++first;
return id;
}
template <typename IteratorT, typename ContainerT>
inline boost::wave::token_id
skip_whitespace(IteratorT &first, IteratorT const &last, ContainerT &queue)
{
using namespace cpplexer;
queue.push_back (*first); // queue up the current token
token_id id = next_token<IteratorT>::peek(first, last, false);
if (IS_CATEGORY(id, WhiteSpaceTokenType)) {
do {
queue.push_back(*++first); // queue up the next whitespace
id = next_token<IteratorT>::peek(first, last, false);
} while (IS_CATEGORY(id, WhiteSpaceTokenType));
}
++first;
return id;
}
///////////////////////////////////////////////////////////////////////////////
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
} // namespace util
} // namespace wave
} // namespace boost
#endif // !defined(UNPUT_QUEUE_ITERATOR_HPP_76DA23D0_4893_4AD5_ABCC_6CED7CFB89BC_INCLUDED)

View File

@@ -0,0 +1,272 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Global application configuration
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(WAVE_CONFIG_HPP_F143F90A_A63F_4B27_AC41_9CA4F14F538D_INCLUDED)
#define WAVE_CONFIG_HPP_F143F90A_A63F_4B27_AC41_9CA4F14F538D_INCLUDED
#include <boost/config.hpp>
#include <boost/version.hpp>
///////////////////////////////////////////////////////////////////////////////
// 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
//
#if !defined(BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS)
#define BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS 1
#endif
///////////////////////////////////////////////////////////////////////////////
// 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.
//
#if !defined(BOOST_WAVE_PP_REGION)
#define BOOST_WAVE_PP_REGION "region"
#define BOOST_WAVE_PP_REGION_UC "REGION" // uppercase of BOOST_WAVE_PP_REGION
#endif
#if !defined(BOOST_WAVE_PP_ENDREGION)
#define BOOST_WAVE_PP_ENDREGION "endregion"
#endif
#if !defined(BOOST_WAVE_PP_IMPORT)
#define BOOST_WAVE_PP_IMPORT "import"
#endif
///////////////////////////////////////////////////////////////////////////////
// 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.
//
#if !defined(BOOST_WAVE_MAX_INCLUDE_LEVEL_DEPTH)
#define BOOST_WAVE_MAX_INCLUDE_LEVEL_DEPTH 1024
#endif
///////////////////////////////////////////////////////////////////////////////
// Decide, whether to support variadics and placemarkers
//
// To implement support variadics and placemarkers uncomment the following
//
#if !defined(BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS)
#define BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS 1
#endif
///////////////////////////////////////////////////////////////////////////////
// Decide, whether to implement a #warning directive as an extension to the
// C++ Standard (same as #error, but emits a warning, not an error)
//
// To implement #warning directives, uncomment the following
//
#if !defined(BOOST_WAVE_SUPPORT_WARNING_DIRECTIVE)
#define BOOST_WAVE_SUPPORT_WARNING_DIRECTIVE 1
#endif
///////////////////////////////////////////////////////////////////////////////
// Decide, whether to implement #pragma once
//
// To implement #pragma once, uncomment the following
//
#if !defined(BOOST_WAVE_SUPPORT_PRAGMA_ONCE)
#define BOOST_WAVE_SUPPORT_PRAGMA_ONCE 1
#endif
///////////////////////////////////////////////////////////////////////////////
// Decide, whether to implement #include_next
// Please note, that this is an extension to the C++ Standard.
//
// To implement #include_next, uncomment the following
//
#if !defined(BOOST_WAVE_SUPPORT_INCLUDE_NEXT)
#define BOOST_WAVE_SUPPORT_INCLUDE_NEXT 1
#endif
///////////////////////////////////////////////////////////////////////////////
// Uncomment the following, to enable some MS specific language extensions:
// __int8, __int16, __int32, __int64, __based, __declspec, __cdecl,
// __fastcall, __stdcall, __try, __except, __finally, __leave, __inline,
// __asm
#if !defined(BOOST_WAVE_SUPPORT_MS_EXTENSIONS)
#define BOOST_WAVE_SUPPORT_MS_EXTENSIONS 1
#endif
///////////////////////////////////////////////////////////////////////////////
// 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
//
#if !defined(BOOST_WAVE_PREPROCESS_ERROR_MESSAGE_BODY)
#define BOOST_WAVE_PREPROCESS_ERROR_MESSAGE_BODY 1
#endif
///////////////////////////////////////////////////////////////////////////////
// Allow the #pragma directives to be returned to the caller (optionally after
// preprocessing the body)
//
// Uncommenting the following will skip #pragma directives, so that the caller
// will not see them.
//
#if !defined(BOOST_WAVE_EMIT_PRAGMA_DIRECTIVES)
#define BOOST_WAVE_EMIT_PRAGMA_DIRECTIVES 1
#endif
///////////////////////////////////////////////////////////////////////////////
// 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
//
#if !defined(BOOST_WAVE_PREPROCESS_PRAGMA_BODY)
#define BOOST_WAVE_PREPROCESS_PRAGMA_BODY 1
#endif
///////////////////////////////////////////////////////////////////////////////
// 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
//
#if !defined(BOOST_WAVE_ENABLE_COMMANDLINE_MACROS)
#define BOOST_WAVE_ENABLE_COMMANDLINE_MACROS 1
#endif
///////////////////////////////////////////////////////////////////////////////
// Define the string type to be used to store the token values and the file
// names inside a file_position template class
//
#if !defined(BOOST_WAVE_STRINGTYPE)
#define BOOST_WAVE_STRINGTYPE boost::wave::util::flex_string< \
char, std::char_traits<char>, std::allocator<char>, \
boost::wave::util::CowString< \
boost::wave::util::AllocatorStringStorage<char> > \
> \
/**/
// This include is needed for the flex_string class used in the
// BOOST_WAVE_STRINGTYPE above.
#include <boost/wave/util/flex_string.hpp>
#endif
///////////////////////////////////////////////////////////////////////////////
// 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 flags for the pp-iterator library, possible flags:
#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
#if !defined(BOOST_SPIRIT_DEBUG_FLAGS_CPP)
#define BOOST_SPIRIT_DEBUG_FLAGS_CPP 0 // default is no debugging
#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.
//
#if !defined(BOOST_WAVE_DUMP_PARSE_TREE)
#define BOOST_WAVE_DUMP_PARSE_TREE 0
#endif
#if BOOST_WAVE_DUMP_PARSE_TREE != 0 && !defined(BOOST_WAVE_DUMP_PARSE_TREE_OUT)
#define BOOST_WAVE_DUMP_PARSE_TREE_OUT std::cerr
#endif
///////////////////////////////////////////////////////////////////////////////
//
// For all #if and #elif directives the preprocessed expressions are printed.
// These expressions are streamed to the std::ostream defined by the
// BOOST_WAVE_DUMP_CONDITIONAL_EXPRESSIONS_OUT constant.
//
// Uncomment the following, if you want to see the preprocessed expressions
//
#if !defined(BOOST_WAVE_DUMP_CONDITIONAL_EXPRESSIONS)
#define BOOST_WAVE_DUMP_CONDITIONAL_EXPRESSIONS 0
#endif
#if BOOST_WAVE_DUMP_CONDITIONAL_EXPRESSIONS != 0 && \
!defined(BOOST_WAVE_DUMP_CONDITIONAL_EXPRESSIONS_OUT)
#define BOOST_WAVE_DUMP_CONDITIONAL_EXPRESSIONS_OUT std::cerr
#endif
///////////////////////////////////////////////////////////////////////////////
// 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 file instantiate_re2c_lexer.cpp).
//
// To use the lexer inclusion model, uncomment the following
//
#if !defined(BOOST_WAVE_SEPARATE_LEXER_INSTANTIATION)
#define BOOST_WAVE_SEPARATE_LEXER_INSTANTIATION 1
#endif
///////////////////////////////////////////////////////////////////////////////
// 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 et.al.).
//
// To use the grammar inclusion model, uncomment the following
//
#if !defined(BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION)
#define BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION 1
#endif
///////////////////////////////////////////////////////////////////////////////
// The experimental C++0x mode implies the variadics and placemarkers
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0 && \
!defined(BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS)
#define BOOST_WAVE_SUPPORT_VARIADICS_PLACEMARKERS 1
#endif
///////////////////////////////////////////////////////////////////////////////
// configure Boost.Pool thread support
// (for now: no thread support at all)
#define BOOST_NO_MT
///////////////////////////////////////////////////////////////////////////////
// Auto library naming
#if BOOST_VERSION >= 103100
// auto link features work beginning from Boost V1.31.0
#if !defined(BOOST_WAVE_SOURCE) && !defined(BOOST_ALL_NO_LIB) && \
!defined(BOOST_WAVE_NO_LIB)
#define BOOST_LIB_NAME boost_wave
#include <boost/config/auto_link.hpp>
#endif // auto-linking disabled
#endif // BOOST_VERSION
#endif // !defined(WAVE_CONFIG_HPP_F143F90A_A63F_4B27_AC41_9CA4F14F538D_INCLUDED)

View File

@@ -0,0 +1,27 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
This is the current version of the Wave library
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(WAVE_VERSION_H_9D79ABDB_AC54_4C0A_89B1_F70A2DCFE21E_INCLUDED)
#define WAVE_VERSION_H_9D79ABDB_AC54_4C0A_89B1_F70A2DCFE21E_INCLUDED
// BOOST_WAVE_VERSION & 0x00FF is the sub-minor version
// BOOST_WAVE_VERSION & 0x0F00 is the minor version
// BOOST_WAVE_VERSION & 0xF000 is the major version
#define BOOST_WAVE_VERSION 0x1100
// The following defines contain the same information as above
#define BOOST_WAVE_VERSION_MAJOR 1
#define BOOST_WAVE_VERSION_MINOR 1
#define BOOST_WAVE_VERSION_SUBMINOR 0
#endif // !defined(WAVE_VERSION_H_9D79ABDB_AC54_4C0A_89B1_F70A2DCFE21E_INCLUDED)

109
index.html Normal file
View File

@@ -0,0 +1,109 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Wave V1.1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="doc/theme/style.css" rel="stylesheet" type="text/css">
</head>
<body text="#000000" background="theme/bkd.gif">
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
<tr>
<td width="21"> <h1></h1></td>
<td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">Wave
V1.1</font></b></font></td>
<td width="96"><a href="http://spirit.sf.net"><img src="doc/theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
</tr>
</table>
<br>
<table width="75%" border="0" align="center">
<tr>
<td class="table_title">Table of Contents</td>
</tr>
<tr>
<td class="toc_cells_L0"><a href="doc/preface.html">Preface</a></td>
</tr>
<tr>
<td class="toc_cells_L0"><a href="doc/introduction.html">Introduction</a></td>
</tr>
<tr>
<td class="toc_cells_L0"><a href="doc/quickstart.html">Quick Start</a></td>
</tr>
<tr>
<td class="toc_cells_L0"><b><font face="Geneva, Arial, Helvetica, san-serif">Class
References </font></b></td>
</tr>
<tr>
<td class="toc_cells_L1"><a href="doc/class_reference_context.html">The Context
Object</a></td>
</tr>
<tr>
<td class="toc_cells_L1"><a href="doc/class_reference_inputpolicy.html">The Input
Policy </a></td>
</tr>
<tr>
<td class="toc_cells_L1"><a href="doc/class_reference_tracepolicy.html">The Tracing
Policy </a></td>
</tr>
<tr>
<td class="toc_cells_L1"><a href="doc/class_reference_lexer.html">The Lexer Iterator Interface
</a></td>
</tr>
<tr>
<td class="toc_cells_L1"><a href="doc/class_reference_tokentype.html">The Token
Type</a></td>
</tr>
<tr>
<td class="toc_cells_L1"><a href="doc/token_ids.html">The Token Identifiers </a></td>
</tr>
<tr>
<td class="toc_cells_L1"><a href="doc/class_reference_fileposition.html">The File
Position</a></td>
</tr>
<tr>
<td class="toc_cells_L0"><b><a href="doc/predefined_macros.html">Predefined Macros</a></b></td>
</tr>
<tr>
<td class="toc_cells_L0"><a href="doc/supported_pragmas.html">Supported Pragma
Directives </a></td>
</tr>
<tr>
<td class="toc_cells_L0"><a href="doc/macro_expansion_process.html">The Macro
Expansion Process</a></td>
</tr>
<tr>
<td class="toc_cells_L0"><a href="doc/compiletime_config.html">Compile Time Configuration</a></td>
</tr>
<tr>
<td class="toc_cells_L0"><a href="doc/preliminary_cpp0x_support.html">Preliminary C++0x support </a></td>
</tr>
<tr>
<td class="toc_cells_L0"><a href="doc/samples.html">Samples</a></td>
</tr>
<tr>
<td class="toc_cells_L0"><b>The Wave Driver Executable</b></td>
</tr>
<tr>
<td class="toc_cells_L1"><b><a href="doc/wave_driver.html">The Wave Driver Command
Line </a></b></td>
</tr>
<tr>
<td class="toc_cells_L1"><b><a href="doc/tracing_facility.html">The Tracing Facility</a></b></td>
</tr>
<tr>
<td class="toc_cells_L0"><a href="doc/acknowledgements.html">Acknowledgments</a></td>
</tr>
<tr>
<td class="toc_cells_L0"><a href="doc/references.html">References</a> </td>
</tr>
</table>
<br>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
<br>
<font size="2">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)
</font> </p>
<span class="updated">Last updated:
<!-- #BeginDate format:fcAm1m -->Saturday, January 24, 2004 19:25<!-- #EndDate -->
</span></body>
</html>

View File

@@ -0,0 +1,31 @@
# Wave: A Standard compliant C++ preprocessor library
#
# Boost Wave Library Sample Build Jamfile (cpp_tokens)
#
# 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/cpp_tokens/build ;
exe cpp_tokens
: ../cpp_tokens.cpp
../instantiate_cpp_exprgrammar.cpp
../instantiate_cpp_grammar.cpp
../instantiate_cpp_literalgrammars.cpp
../instantiate_defined_grammar.cpp
../instantiate_slex_lexer.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,28 @@
# 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 cpp_tokens
: ../cpp_tokens.cpp
../instantiate_cpp_exprgrammar.cpp
../instantiate_cpp_grammar.cpp
../instantiate_cpp_literalgrammars.cpp
../instantiate_defined_grammar.cpp
../instantiate_slex_lexer.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,132 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Sample: Print out the preprocessed tokens returned by the Wave iterator
This sample shows, how it is possible to use a custom lexer type and a
custom token type with the Wave library.
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 "cpp_tokens.hpp" // global configuration
///////////////////////////////////////////////////////////////////////////////
// Include Wave itself
#include <boost/wave.hpp>
#include <boost/wave/token_ids.hpp>
///////////////////////////////////////////////////////////////////////////////
// The follwoing files contain the custom lexer type to use
#include "slex_token.hpp"
#include "slex_iterator.hpp"
///////////////////////////////////////////////////////////////////////////////
// include lexer specifics, import lexer names
#if !defined(BOOST_WAVE_SEPARATE_LEXER_INSTANTIATION)
#include "slex/cpp_slex_lexer.hpp"
#endif // !defined(BOOST_WAVE_SEPARATE_LEXER_INSTANTIATION)
///////////////////////////////////////////////////////////////////////////////
// import required names
using namespace boost::spirit;
using std::string;
using std::getline;
using std::ifstream;
using std::cout;
using std::cerr;
using std::endl;
using std::ostream;
///////////////////////////////////////////////////////////////////////////////
// main program
int
main(int argc, char *argv[])
{
if (2 != argc) {
cout << "Usage: cpp_tokens input_file" << endl;
return 1;
}
// read the file to analyse into a std::string
ifstream infile(argv[1]);
string teststr;
if (infile.is_open()) {
infile.unsetf(std::ios::skipws);
string line;
for (getline(infile, line); infile.good(); getline(infile, line)) {
teststr += line;
teststr += '\n';
}
}
else {
teststr = argv[1];
}
// The following typedef does the trick. It defines the context type to use,
// which depends on the lexer type (provided by the second template
// parameter). Our lexer type 'slex_iterator<>' depends on a custom token type
// 'slex_token<>'. Our custom token type differs from the original one povided
// by the Wave library only by defining an addition operator<<, which is used
// to dump the token information carried by a given token (see loop below).
typedef boost::wave::cpp_token_sample::slex_token<> token_t;
typedef boost::wave::cpp_token_sample::slex_iterator<token_t>
lex_iterator_t;
typedef boost::wave::context<std::string::iterator, lex_iterator_t>
context_t;
// The C++ preprocessor iterator shouldn't be constructed directly. It is to be
// generated through a boost::wave::context<> object. This 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 (teststr.begin(), teststr.end(), argv[1]);
context_t::iterator_t first = ctx.begin();
context_t::iterator_t last = ctx.end();
context_t::token_t current_token;
try {
// Traverse over the tokens generated from the input and dump the token
// contents.
while (first != last) {
// retrieve next token
current_token = *first;
// output token info
cout << "matched " << current_token << endl;
++first;
}
}
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_token.get_position().get_file()
<< "(" << current_token.get_position().get_line() << "): "
<< "unexpected exception: " << e.what()
<< endl;
return 3;
}
catch (...) {
// use last recognized token to retrieve the error position
cerr
<< current_token.get_position().get_file()
<< "(" << current_token.get_position().get_line() << "): "
<< "unexpected exception." << endl;
return 4;
}
return 0;
}

View File

@@ -0,0 +1,39 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Sample: Print out the preprocessed tokens returned by the Wave iterator
This sample shows, how it is possible to use a custom lexer object and a
custom token type with the Wave library.
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(CPP_TOKENS_HPP_D6A31137_CE14_4869_9779_6357E2C43187_INCLUDED)
#define CPP_TOKENS_HPP_D6A31137_CE14_4869_9779_6357E2C43187_INCLUDED
///////////////////////////////////////////////////////////////////////////////
// include often used files from the stdlib
#include <iostream>
#include <fstream>
#include <string>
///////////////////////////////////////////////////////////////////////////////
// include boost config
#include <boost/config.hpp> // global configuration information
///////////////////////////////////////////////////////////////////////////////
// configure this app here (global configuration constants)
#include "cpp_tokens_config.hpp"
///////////////////////////////////////////////////////////////////////////////
// include required boost libraries
#include <boost/assert.hpp>
#include <boost/pool/pool_alloc.hpp>
#endif // !defined(CPP_TOKENS_HPP_D6A31137_CE14_4869_9779_6357E2C43187_INCLUDED)

View File

@@ -0,0 +1,226 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Sample: Print out the preprocessed tokens returned by the Wave iterator
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(CPP_TOKENS_HPP_7C0F1F14_6ACA_4439_A073_32C61C0DB6C5_INCLUDED)
#define CPP_TOKENS_HPP_7C0F1F14_6ACA_4439_A073_32C61C0DB6C5_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.
//
//#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 0
///////////////////////////////////////////////////////////////////////////////
// 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 0
///////////////////////////////////////////////////////////////////////////////
// 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(CPP_TOKENS_HPP_7C0F1F14_6ACA_4439_A073_32C61C0DB6C5_INCLUDED)

View File

@@ -0,0 +1,45 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Sample: prints out the preprocessed tokens returned by the pp iterator
Explicit instantiation of the cpp_expression_grammar parsing
function
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)
See Copyright.txt for full acknowledgements.
=============================================================================*/
#include "cpp_tokens.hpp" // config data
#if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0
#include <string>
#include <boost/wave/token_ids.hpp>
#include "slex_token.hpp"
#include "slex_iterator.hpp"
#include <boost/wave/grammars/cpp_expression_grammar.hpp>
///////////////////////////////////////////////////////////////////////////////
//
// Explicit instantiation of the expression_grammar_gen template with the
// correct token type. This instantiates the corresponding parse function,
// which in turn instantiates the expression_grammar object (see
// wave/grammars/cpp_expression_grammar.hpp)
//
///////////////////////////////////////////////////////////////////////////////
typedef boost::wave::cpp_token_sample::slex_token<> token_t;
template struct boost::wave::grammars::expression_grammar_gen<token_t>;
#endif // #if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0

View File

@@ -0,0 +1,45 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Sample: prints out the preprocessed tokens returned by the pp iterator
Explicit instantiation of the cpp_grammar parsing function
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)
See Copyright.txt for full acknowledgements.
=============================================================================*/
#include "cpp_tokens.hpp" // config data
#if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0
#include <string>
#include <boost/wave/token_ids.hpp>
#include "slex_token.hpp"
#include "slex_iterator.hpp"
#include <boost/wave/grammars/cpp_grammar.hpp>
///////////////////////////////////////////////////////////////////////////////
//
// Explicit instantiation of the cpp_grammar_gen template with the correct
// token type. This instantiates the corresponding pt_parse function, which
// in turn instantiates the cpp_grammar object
// (see wave/grammars/cpp_grammar.hpp)
//
///////////////////////////////////////////////////////////////////////////////
typedef boost::wave::cpp_token_sample::slex_iterator<
boost::wave::cpp_token_sample::slex_token<> >
lex_t;
template struct boost::wave::grammars::cpp_grammar_gen<lex_t>;
#endif // #if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0

View File

@@ -0,0 +1,46 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Sample: prints out the preprocessed tokens returned by the pp iterator
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)
See Copyright.txt for full acknowledgements.
=============================================================================*/
#include "cpp_tokens.hpp" // config data
#if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0
#include <string>
#include <boost/wave/token_ids.hpp>
#include "slex_token.hpp"
#include "slex_iterator.hpp"
#include <boost/wave/grammars/cpp_literal_grammar_gen.hpp>
#include <boost/wave/grammars/cpp_intlit_grammar.hpp>
#include <boost/wave/grammars/cpp_chlit_grammar.hpp>
///////////////////////////////////////////////////////////////////////////////
//
// Explicit instantiation of the intlit_grammar_gen, chlit_grammar_gen and
// floatlit_grammar_gen templates with the correct token type. This
// instantiates the corresponding parse function, which in turn instantiates
// the corresponding parser object.
//
///////////////////////////////////////////////////////////////////////////////
typedef boost::wave::cpp_token_sample::slex_token<> token_t;
template struct boost::wave::grammars::intlit_grammar_gen<token_t>;
template struct boost::wave::grammars::chlit_grammar_gen<token_t>;
#endif // #if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0

View File

@@ -0,0 +1,40 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
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 "cpp_tokens.hpp" // config data
#if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0
#include <string>
#include <boost/wave/token_ids.hpp>
#include "slex_token.hpp"
#include "slex_iterator.hpp"
#include <boost/wave/grammars/cpp_defined_grammar.hpp>
///////////////////////////////////////////////////////////////////////////////
//
// Explicit instantiation of the defined_grammar_gen template
// with the correct token type. This instantiates the corresponding parse
// function, which in turn instantiates the defined_grammar
// object (see wave/grammars/cpp_defined_grammar.hpp)
//
///////////////////////////////////////////////////////////////////////////////
typedef boost::wave::cpp_token_sample::slex_iterator<
boost::wave::cpp_token_sample::slex_token<> >
lex_t;
template struct boost::wave::grammars::defined_grammar_gen<lex_t>;
#endif // #if BOOST_WAVE_SEPARATE_GRAMMAR_INSTANTIATION != 0

View File

@@ -0,0 +1,48 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Sample: Print out the preprocessed tokens returned by the Wave iterator
Explicit instantiation of the lex_functor generation function
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 "cpp_tokens.hpp" // config data
#if BOOST_WAVE_SEPARATE_LEXER_INSTANTIATION != 0
#include <string>
#include <boost/wave/token_ids.hpp>
#include "slex_token.hpp"
#include "slex_iterator.hpp"
///////////////////////////////////////////////////////////////////////////////
// The following file needs to be included only once throughout the whole
// program.
#include "slex/cpp_slex_lexer.hpp"
///////////////////////////////////////////////////////////////////////////////
//
// This instantiates the correct 'new_lexer' function, which generates the
// C++ lexer used in this sample.
//
// This is moved into a separate compilation unit to decouple the compilation
// of the C++ lexer from the compilation of the other modules, which helps to
// reduce compilation time.
//
// The template parameter(s) supplied should be identical to the parameters
// supplied while instantiating the context<> template.
//
///////////////////////////////////////////////////////////////////////////////
template struct boost::wave::cpp_token_sample::new_lexer_gen<
std::string::iterator>;
#endif // BOOST_WAVE_SEPARATE_LEXER_INSTANTIATION != 0

View File

@@ -0,0 +1,657 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
SLex (Spirit Lex) based C++ lexer
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(SLEX_LEXER_HPP_5E8E1DF0_BB41_4938_B7E5_A4BB68222FF6_INCLUDED)
#define SLEX_LEXER_HPP_5E8E1DF0_BB41_4938_B7E5_A4BB68222FF6_INCLUDED
#include <string>
#if defined(BOOST_SPIRIT_DEBUG)
#include <iostream>
#endif // defined(BOOST_SPIRIT_DEBUG)
#include <boost/assert.hpp>
#include <boost/spirit/core.hpp>
#include <boost/wave/wave_config.hpp>
#include <boost/wave/language_support.hpp>
#include <boost/wave/token_ids.hpp>
#include <boost/wave/util/file_position.hpp>
#include <boost/wave/util/time_conversion_helper.hpp>
#include <boost/wave/cpplexer/validate_universal_char.hpp>
#include "../slex_interface.hpp"
#include "../slex_token.hpp"
#include "../slex_iterator.hpp"
#include "lexer.hpp" // "spirit/lexer.hpp"
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace cpp_token_sample {
namespace slex {
///////////////////////////////////////////////////////////////////////////////
//
// encapsulation of the boost::spirit::slex based cpp lexer
//
///////////////////////////////////////////////////////////////////////////////
template <typename IteratorT, typename PositionT>
class lexer
: public boost::spirit::lexer<
boost::wave::util::position_iterator<IteratorT, PositionT> >
{
public:
typedef boost::wave::util::position_iterator<IteratorT, PositionT>
iterator_t;
typedef typename std::iterator_traits<IteratorT>::value_type char_t;
typedef boost::spirit::lexer<iterator_t> base_t;
typedef boost::wave::cpp_token_sample::slex_token<PositionT> token_t;
lexer();
void init_dfa(boost::wave::language_support language);
// get time of last compilation
static std::time_t get_compilation_time()
{ return compilation_time.get_time(); }
private:
// initialization data (regular expressions for the token definitions)
struct lexer_data {
token_id tokenid; // token data
char_t const *tokenregex; // associated token to match
typename base_t::callback_t tokencb; // associated callback function
unsigned int lexerstate; // valid for lexer state
};
static lexer_data const init_data[]; // common patterns
static lexer_data const init_data_cpp[]; // C++ only patterns
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
static lexer_data const init_data_cpp0x[]; // C++0x only patterns
#endif // BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
// helper for calculation of the time of last compilation
static boost::wave::util::time_conversion_helper compilation_time;
};
///////////////////////////////////////////////////////////////////////////////
// data required for initialization of the lexer (token definitions)
#define OR "|"
#define Q(c) "\\" c
#define TRI(c) Q("?") Q("?") c
// definition of some subtoken regexps to simplify the regex definitions
#define BLANK "[ \\t]"
#define CCOMMENT \
Q("/") Q("*") "[^*]*" Q("*") "+" "(" "[^/*][^*]*" Q("*") "+" ")*" Q("/")
#define PPSPACE "(" BLANK OR CCOMMENT ")*"
#define OCTALDIGIT "[0-7]"
#define DIGIT "[0-9]"
#define HEXDIGIT "[0-9a-fA-F]"
#define SIGN "[-+]?"
#define EXPONENT "(" "[eE]" SIGN "[0-9]+" ")"
#define INTEGER_SUFFIX "(" "[uU][lL]?|[lL][uU]?" ")"
#define FLOAT_SUFFIX "(" "[fF][lL]?|[lL][fF]?" ")"
#define CHAR_SPEC "L?"
#define BACKSLASH "(" Q("\\") OR TRI(Q("/")) ")"
#define ESCAPESEQ BACKSLASH "(" \
"[abfnrtv?'\"]" OR \
BACKSLASH OR \
"x" HEXDIGIT "+" OR \
OCTALDIGIT OCTALDIGIT "?" OCTALDIGIT "?" \
")"
#define HEXQUAD HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT
#define UNIVERSALCHAR BACKSLASH "(" \
"u" HEXQUAD OR \
"U" HEXQUAD HEXQUAD \
")"
#define POUNDDEF "(" "#" OR TRI("=") OR Q("%:") ")"
#define NEWLINEDEF "(" "\\n" OR "\\r" OR "\\r\\n" ")"
#if BOOST_WAVE_SUPPORT_INCLUDE_NEXT != 0
#define INCLUDEDEF "(include|include_next)"
#else
#define INCLUDEDEF "include"
#endif
///////////////////////////////////////////////////////////////////////////////
// sexer state constants
#define LEXER_STATE_NORMAL 0
#define LEXER_STATE_PP 1
#define NUM_LEXER_STATES 1
// helper for initializing token data
#define TOKEN_DATA(id, regex) \
{ T_##id, regex, 0, LEXER_STATE_NORMAL }
#define TOKEN_DATA_EX(id, regex, callback) \
{ T_##id, regex, callback, LEXER_STATE_NORMAL }
///////////////////////////////////////////////////////////////////////////////
// common C++/C99 token definitions
template <typename IteratorT, typename PositionT>
typename lexer<IteratorT, PositionT>::lexer_data const
lexer<IteratorT, PositionT>::init_data[] =
{
TOKEN_DATA(AND, "&"),
TOKEN_DATA(ANDAND, "&&"),
TOKEN_DATA(ASSIGN, "="),
TOKEN_DATA(ANDASSIGN, "&="),
TOKEN_DATA(OR, Q("|")),
TOKEN_DATA(OR_TRIGRAPH, TRI("!")),
TOKEN_DATA(ORASSIGN, Q("|=") OR TRI("!=")),
TOKEN_DATA(XOR, Q("^")),
TOKEN_DATA(XOR_TRIGRAPH, TRI("'")),
TOKEN_DATA(XORASSIGN, Q("^=") OR TRI("'=")),
TOKEN_DATA(COMMA, ","),
TOKEN_DATA(COLON, ":"),
TOKEN_DATA(DIVIDE, Q("/")),
TOKEN_DATA(DIVIDEASSIGN, Q("/=")),
TOKEN_DATA(DOT, Q(".")),
TOKEN_DATA(ELLIPSIS, Q(".") Q(".") Q(".")),
TOKEN_DATA(EQUAL, "=="),
TOKEN_DATA(GREATER, ">"),
TOKEN_DATA(GREATEREQUAL, ">="),
TOKEN_DATA(LEFTBRACE, Q("{")),
TOKEN_DATA(LEFTBRACE_ALT, "<" Q("%")),
TOKEN_DATA(LEFTBRACE_TRIGRAPH, TRI("<")),
TOKEN_DATA(LESS, "<"),
TOKEN_DATA(LESSEQUAL, "<="),
TOKEN_DATA(LEFTPAREN, Q("(")),
TOKEN_DATA(LEFTBRACKET, Q("[")),
TOKEN_DATA(LEFTBRACKET_ALT, "<:"),
TOKEN_DATA(LEFTBRACKET_TRIGRAPH, TRI(Q("("))),
TOKEN_DATA(MINUS, Q("-")),
TOKEN_DATA(MINUSASSIGN, Q("-=")),
TOKEN_DATA(MINUSMINUS, Q("-") Q("-")),
TOKEN_DATA(PERCENT, Q("%")),
TOKEN_DATA(PERCENTASSIGN, Q("%=")),
TOKEN_DATA(NOT, "!"),
TOKEN_DATA(NOTEQUAL, "!="),
TOKEN_DATA(OROR, Q("|") Q("|") OR TRI("!") Q("|") OR Q("|") TRI("!") OR
TRI("!") TRI("!")),
TOKEN_DATA(PLUS, Q("+")),
TOKEN_DATA(PLUSASSIGN, Q("+=")),
TOKEN_DATA(PLUSPLUS, Q("+") Q("+")),
TOKEN_DATA(ARROW, Q("->")),
TOKEN_DATA(QUESTION_MARK, Q("?")),
TOKEN_DATA(RIGHTBRACE, Q("}")),
TOKEN_DATA(RIGHTBRACE_ALT, Q("%>")),
TOKEN_DATA(RIGHTBRACE_TRIGRAPH, TRI(">")),
TOKEN_DATA(RIGHTPAREN, Q(")")),
TOKEN_DATA(RIGHTBRACKET, Q("]")),
TOKEN_DATA(RIGHTBRACKET_ALT, ":>"),
TOKEN_DATA(RIGHTBRACKET_TRIGRAPH, TRI(Q(")"))),
TOKEN_DATA(SEMICOLON, ";"),
TOKEN_DATA(SHIFTLEFT, "<<"),
TOKEN_DATA(SHIFTLEFTASSIGN, "<<="),
TOKEN_DATA(SHIFTRIGHT, ">>"),
TOKEN_DATA(SHIFTRIGHTASSIGN, ">>="),
TOKEN_DATA(STAR, Q("*")),
TOKEN_DATA(COMPL, Q("~")),
TOKEN_DATA(COMPL_TRIGRAPH, TRI("-")),
TOKEN_DATA(STARASSIGN, Q("*=")),
TOKEN_DATA(ASM, "asm"),
TOKEN_DATA(AUTO, "auto"),
TOKEN_DATA(BOOL, "bool"),
TOKEN_DATA(FALSE, "false"),
TOKEN_DATA(TRUE, "true"),
TOKEN_DATA(BREAK, "break"),
TOKEN_DATA(CASE, "case"),
TOKEN_DATA(CATCH, "catch"),
TOKEN_DATA(CHAR, "char"),
TOKEN_DATA(CLASS, "class"),
TOKEN_DATA(CONST, "const"),
TOKEN_DATA(CONSTCAST, "const_cast"),
TOKEN_DATA(CONTINUE, "continue"),
TOKEN_DATA(DEFAULT, "default"),
// TOKEN_DATA(DEFINED, "defined"),
TOKEN_DATA(DELETE, "delete"),
TOKEN_DATA(DO, "do"),
TOKEN_DATA(DOUBLE, "double"),
TOKEN_DATA(DYNAMICCAST, "dynamic_cast"),
TOKEN_DATA(ELSE, "else"),
TOKEN_DATA(ENUM, "enum"),
TOKEN_DATA(EXPLICIT, "explicit"),
TOKEN_DATA(EXPORT, "export"),
TOKEN_DATA(EXTERN, "extern"),
TOKEN_DATA(FLOAT, "float"),
TOKEN_DATA(FOR, "for"),
TOKEN_DATA(FRIEND, "friend"),
TOKEN_DATA(GOTO, "goto"),
TOKEN_DATA(IF, "if"),
TOKEN_DATA(INLINE, "inline"),
TOKEN_DATA(INT, "int"),
TOKEN_DATA(LONG, "long"),
TOKEN_DATA(MUTABLE, "mutable"),
TOKEN_DATA(NAMESPACE, "namespace"),
TOKEN_DATA(NEW, "new"),
TOKEN_DATA(OPERATOR, "operator"),
TOKEN_DATA(PRIVATE, "private"),
TOKEN_DATA(PROTECTED, "protected"),
TOKEN_DATA(PUBLIC, "public"),
TOKEN_DATA(REGISTER, "register"),
TOKEN_DATA(REINTERPRETCAST, "reinterpret_cast"),
TOKEN_DATA(RETURN, "return"),
TOKEN_DATA(SHORT, "short"),
TOKEN_DATA(SIGNED, "signed"),
TOKEN_DATA(SIZEOF, "sizeof"),
TOKEN_DATA(STATIC, "static"),
TOKEN_DATA(STATICCAST, "static_cast"),
TOKEN_DATA(STRUCT, "struct"),
TOKEN_DATA(SWITCH, "switch"),
TOKEN_DATA(TEMPLATE, "template"),
TOKEN_DATA(THIS, "this"),
TOKEN_DATA(THROW, "throw"),
TOKEN_DATA(TRY, "try"),
TOKEN_DATA(TYPEDEF, "typedef"),
TOKEN_DATA(TYPEID, "typeid"),
TOKEN_DATA(TYPENAME, "typename"),
TOKEN_DATA(UNION, "union"),
TOKEN_DATA(UNSIGNED, "unsigned"),
TOKEN_DATA(USING, "using"),
TOKEN_DATA(VIRTUAL, "virtual"),
TOKEN_DATA(VOID, "void"),
TOKEN_DATA(VOLATILE, "volatile"),
TOKEN_DATA(WCHART, "wchar_t"),
TOKEN_DATA(WHILE, "while"),
TOKEN_DATA(PP_DEFINE, POUNDDEF PPSPACE "define"),
TOKEN_DATA(PP_IF, POUNDDEF PPSPACE "if"),
TOKEN_DATA(PP_IFDEF, POUNDDEF PPSPACE "ifdef"),
TOKEN_DATA(PP_IFNDEF, POUNDDEF PPSPACE "ifndef"),
TOKEN_DATA(PP_ELSE, POUNDDEF PPSPACE "else"),
TOKEN_DATA(PP_ELIF, POUNDDEF PPSPACE "elif"),
TOKEN_DATA(PP_ENDIF, POUNDDEF PPSPACE "endif"),
TOKEN_DATA(PP_ERROR, POUNDDEF PPSPACE "error"),
TOKEN_DATA(PP_QHEADER, POUNDDEF PPSPACE \
INCLUDEDEF PPSPACE Q("\"") "[^\\n\\r\"]+" Q("\"")),
TOKEN_DATA(PP_HHEADER, POUNDDEF PPSPACE \
INCLUDEDEF PPSPACE "<" "[^\\n\\r>]+" ">"),
TOKEN_DATA(PP_INCLUDE, POUNDDEF PPSPACE \
INCLUDEDEF PPSPACE),
TOKEN_DATA(PP_LINE, POUNDDEF PPSPACE "line"),
TOKEN_DATA(PP_PRAGMA, POUNDDEF PPSPACE "pragma"),
TOKEN_DATA(PP_UNDEF, POUNDDEF PPSPACE "undef"),
TOKEN_DATA(PP_WARNING, POUNDDEF PPSPACE "warning"),
TOKEN_DATA(IDENTIFIER, "([a-zA-Z_]" OR UNIVERSALCHAR ")([a-zA-Z0-9_]" OR UNIVERSALCHAR ")*"),
// TOKEN_DATA(OCTALINT, "0" OCTALDIGIT "*" INTEGER_SUFFIX "?"),
// TOKEN_DATA(DECIMALINT, "[1-9]" DIGIT "*" INTEGER_SUFFIX "?"),
// TOKEN_DATA(HEXAINT, "(0x|0X)" HEXDIGIT "+" INTEGER_SUFFIX "?"),
TOKEN_DATA(INTLIT, "(" "(0x|0X)" HEXDIGIT "+" OR "0" OCTALDIGIT "*" OR \
"[1-9]" DIGIT "*" ")" INTEGER_SUFFIX "?"),
TOKEN_DATA(FLOATLIT,
"(" DIGIT "*" Q(".") DIGIT "+" OR DIGIT "+" Q(".") ")"
EXPONENT "?" FLOAT_SUFFIX "?" OR
DIGIT "+" EXPONENT FLOAT_SUFFIX "?"),
TOKEN_DATA(CCOMMENT, CCOMMENT),
TOKEN_DATA(CPPCOMMENT, Q("/") Q("/[^\\n\\r]*") NEWLINEDEF ),
TOKEN_DATA(CHARLIT, CHAR_SPEC "'"
"(" ESCAPESEQ OR "[^\\n\\r']" OR UNIVERSALCHAR ")+" "'"),
TOKEN_DATA(STRINGLIT, CHAR_SPEC Q("\"")
"(" ESCAPESEQ OR "[^\\n\\r\"]" OR UNIVERSALCHAR ")*" Q("\"")),
TOKEN_DATA(SPACE, BLANK "+"),
TOKEN_DATA(SPACE2, "[\\v\\f]+"),
TOKEN_DATA(CONTLINE, Q("\\") "\\n"),
TOKEN_DATA(NEWLINE, NEWLINEDEF),
TOKEN_DATA(POUND_POUND, "##"),
TOKEN_DATA(POUND_POUND_ALT, Q("%:") Q("%:")),
TOKEN_DATA(POUND_POUND_TRIGRAPH, TRI("=") TRI("=")),
TOKEN_DATA(POUND, "#"),
TOKEN_DATA(POUND_ALT, Q("%:")),
TOKEN_DATA(POUND_TRIGRAPH, TRI("=")),
TOKEN_DATA(ANY, "."),
#if BOOST_WAVE_SUPPORT_MS_EXTENSIONS != 0
TOKEN_DATA(MSEXT_INT8, "__int8"),
TOKEN_DATA(MSEXT_INT16, "__int16"),
TOKEN_DATA(MSEXT_INT32, "__int32"),
TOKEN_DATA(MSEXT_INT64, "__int64"),
TOKEN_DATA(MSEXT_BASED, "_?" "_based"),
TOKEN_DATA(MSEXT_DECLSPEC, "_?" "_declspec"),
TOKEN_DATA(MSEXT_CDECL, "_?" "_cdecl"),
TOKEN_DATA(MSEXT_FASTCALL, "_?" "_fastcall"),
TOKEN_DATA(MSEXT_STDCALL, "_?" "_stdcall"),
TOKEN_DATA(MSEXT_TRY , "__try"),
TOKEN_DATA(MSEXT_EXCEPT, "__except"),
TOKEN_DATA(MSEXT_FINALLY, "__finally"),
TOKEN_DATA(MSEXT_LEAVE, "__leave"),
TOKEN_DATA(MSEXT_INLINE, "_?" "_inline"),
TOKEN_DATA(MSEXT_ASM, "_?" "_asm"),
#endif // BOOST_WAVE_SUPPORT_MS_EXTENSIONS != 0
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
TOKEN_DATA(PP_REGION, POUNDDEF PPSPACE BOOST_WAVE_PP_REGION),
TOKEN_DATA(PP_ENDREGION, POUNDDEF PPSPACE BOOST_WAVE_PP_ENDREGION),
TOKEN_DATA(PP_IMPORT, POUNDDEF PPSPACE BOOST_WAVE_PP_IMPORT),
#endif // BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
{ token_id(0) } // this should be the last entry
};
///////////////////////////////////////////////////////////////////////////////
// C++ only token definitions
template <typename IteratorT, typename PositionT>
typename lexer<IteratorT, PositionT>::lexer_data const
lexer<IteratorT, PositionT>::init_data_cpp[] =
{
TOKEN_DATA(AND_ALT, "bitand"),
TOKEN_DATA(ANDAND_ALT, "and"),
TOKEN_DATA(ANDASSIGN_ALT, "and_eq"),
TOKEN_DATA(OR_ALT, "bitor"),
TOKEN_DATA(ORASSIGN_ALT, "or_eq"),
TOKEN_DATA(OROR_ALT, "or"),
TOKEN_DATA(XOR_ALT, "xor"),
TOKEN_DATA(XORASSIGN_ALT, "xor_eq"),
TOKEN_DATA(NOT_ALT, "not"),
TOKEN_DATA(NOTEQUAL_ALT, "not_eq"),
TOKEN_DATA(COMPL_ALT, "compl"),
TOKEN_DATA(ARROWSTAR, Q("->") Q("*")),
TOKEN_DATA(DOTSTAR, Q(".") Q("*")),
TOKEN_DATA(COLON_COLON, "::"),
{ token_id(0) } // this should be the last entry
};
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
///////////////////////////////////////////////////////////////////////////////
// C++0x only token definitions
template <typename IteratorT, typename PositionT>
typename lexer<IteratorT, PositionT>::lexer_data const
lexer<IteratorT, PositionT>::init_data_cpp0x[] =
{
TOKEN_DATA(COMMA_ALT, "__comma__"),
TOKEN_DATA(LEFTPAREN_ALT, "__lparen__"),
TOKEN_DATA(RIGHTPAREN_ALT, "__rparen__"),
{ token_id(0) } // this should be the last entry
};
#endif // BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
///////////////////////////////////////////////////////////////////////////////
// undefine macros, required for regular expression definitions
#undef INCLUDEDEF
#undef POUNDDEF
#undef CCOMMENT
#undef PPSPACE
#undef DIGIT
#undef OCTALDIGIT
#undef HEXDIGIT
#undef SIGN
#undef EXPONENT
#undef INTEGER_SUFFIX
#undef FLOAT_SUFFIX
#undef CHAR_SPEC
#undef BACKSLASH
#undef ESCAPESEQ
#undef HEXQUAD
#undef UNIVERSALCHAR
#undef Q
#undef TRI
#undef OR
#undef TOKEN_DATA
#undef TOKEN_DATA_EX
///////////////////////////////////////////////////////////////////////////////
// initialize cpp lexer with token data
template <typename IteratorT, typename PositionT>
inline
lexer<IteratorT, PositionT>::lexer()
: base_t(NUM_LEXER_STATES)
{
}
template <typename IteratorT, typename PositionT>
inline void
lexer<IteratorT, PositionT>::init_dfa(boost::wave::language_support lang)
{
// the modes are mutually exclusive
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
BOOST_ASSERT(!boost::wave::need_c99(lang) || !boost::wave::need_cpp0x(lang));
#endif // BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
if (has_compiled_dfa())
return;
for (int i = 0; 0 != init_data[i].tokenid; ++i) {
this->register_regex(init_data[i].tokenregex, init_data[i].tokenid,
init_data[i].tokencb, init_data[i].lexerstate);
}
// if in C99 mode, some of the keywords are not valid
if (!boost::wave::need_c99(lang)) {
for (int j = 0; 0 != init_data_cpp[j].tokenid; ++j) {
this->register_regex(init_data_cpp[j].tokenregex,
init_data_cpp[j].tokenid, init_data_cpp[j].tokencb,
init_data_cpp[j].lexerstate);
}
}
#if BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
// C++0x mode has it's own new keywords
if (boost::wave::need_cpp0x(lang)) {
for (int k = 0; 0 != init_data_cpp0x[k].tokenid; ++k) {
this->register_regex(init_data_cpp0x[k].tokenregex,
init_data_cpp0x[k].tokenid, init_data_cpp0x[k].tokencb,
init_data_cpp0x[k].lexerstate);
}
}
#endif // BOOST_WAVE_ENABLE_CPP0X_EXTENSIONS != 0
}
///////////////////////////////////////////////////////////////////////////////
// get time of last compilation of this file
template <typename IteratorT, typename PositionT>
boost::wave::util::time_conversion_helper
lexer<IteratorT, PositionT>::compilation_time(__DATE__ " " __TIME__);
///////////////////////////////////////////////////////////////////////////////
//
template <typename IteratorT, typename PositionT>
inline void
init_lexer (lexer<IteratorT, PositionT> &lexer,
boost::wave::language_support language, bool force_reinit = false)
{
if (lexer.has_compiled_dfa())
return; // nothing to do
using std::ifstream;
using std::ofstream;
using std::ios;
using std::cerr;
using std::endl;
ifstream dfa_in("wave_slex_lexer.dfa", ios::in|ios::binary);
lexer.init_dfa(language);
if (force_reinit || !dfa_in.is_open() ||
!lexer.load (dfa_in, (long)lexer.get_compilation_time()))
{
#if defined(BOOST_SPIRIT_DEBUG)
cerr << "Compiling regular expressions for slex ...";
#endif // defined(BOOST_SPIRIT_DEBUG)
dfa_in.close();
lexer.create_dfa();
ofstream dfa_out ("wave_slex_lexer.dfa", ios::out|ios::binary|ios::trunc);
if (dfa_out.is_open())
lexer.save (dfa_out, (long)lexer.get_compilation_time());
#if defined(BOOST_SPIRIT_DEBUG)
cerr << " Done." << endl;
#endif // defined(BOOST_SPIRIT_DEBUG)
}
}
///////////////////////////////////////////////////////////////////////////////
//
// lex_functor
//
///////////////////////////////////////////////////////////////////////////////
template <typename IteratorT, typename PositionT = wave::util::file_position_t>
class slex_functor
: public slex_input_interface<typename lexer<IteratorT, PositionT>::token_t>
{
public:
typedef boost::wave::util::position_iterator<IteratorT, PositionT>
iterator_t;
typedef typename std::iterator_traits<IteratorT>::value_type char_t;
typedef BOOST_WAVE_STRINGTYPE string_t;
typedef typename lexer<IteratorT, PositionT>::token_t token_t;
slex_functor(IteratorT const &first_, IteratorT const &last_,
PositionT const &pos_, boost::wave::language_support language)
: first(first_, last_, pos_), at_eof(false)
{
// initialize lexer dfa tables
init_lexer(lexer, language);
}
virtual ~slex_functor() {}
// get the next token from the input stream
token_t get()
{
token_t token;
if (!at_eof) {
do {
// generate and return the next token
std::string value;
PositionT const &pos = first.get_position();
token_id id = token_id(lexer.next_token(first, last, &value));
if ((token_id)(-1) == id)
id = T_EOF; // end of input reached
string_t token_val(value.c_str());
if (T_CONTLINE != id) {
switch (id) {
case T_IDENTIFIER:
// test identifier characters for validity (throws if
// invalid chars found)
using boost::wave::cpplexer::impl::validate_identifier_name;
validate_identifier_name(token_val,
pos.get_line(), pos.get_column(), pos.get_file());
break;
case T_STRINGLIT:
case T_CHARLIT:
// test literal characters for validity (throws if invalid
// chars found)
using boost::wave::cpplexer::impl::validate_literal;
validate_literal(token_val,
pos.get_line(), pos.get_column(), pos.get_file());
break;
#if BOOST_WAVE_SUPPORT_INCLUDE_NEXT != 0
case T_PP_HHEADER:
case T_PP_QHEADER:
case T_PP_INCLUDE:
// convert to the corresponding ..._next token, if appropriate
if (string_t::npos != value.find("include_"))
id = token_id(id | AltTokenType);
break;
#endif // BOOST_WAVE_SUPPORT_INCLUDE_NEXT != 0
case T_EOF:
// T_EOF is returned as a valid token, the next call will
// return T_EOI, i.e. the actual end of input
at_eof = true;
break;
}
return token_t(id, token_val, pos);
}
// skip the T_CONTLINE token
} while (true);
}
return token; // return T_EOI
}
void set_position(PositionT const &pos)
{ first.set_position(pos); }
private:
iterator_t first;
iterator_t last;
static lexer<IteratorT, PositionT> lexer; // needed only once
bool at_eof;
};
template <typename IteratorT, typename PositionT>
lexer<IteratorT, PositionT> slex_functor<IteratorT, PositionT>::lexer;
} // namespace slex
///////////////////////////////////////////////////////////////////////////////
//
// The 'new_lexer' function allows the opaque generation of a new lexer object.
// It is coupled to the iterator type to allow to decouple the lexer/iterator
// configurations at compile time.
//
// This function is declared inside the cpp_slex_token.hpp file, which is
// referenced by the source file calling the lexer and the source file, which
// instantiates the lex_functor. But is is defined here, so it will be
// instantiated only while compiling the source file, which instantiates the
// lex_functor. While the cpp_slex_token.hpp file may be included everywhere,
// this file (cpp_slex_lexer.hpp) should be included only once. This allows
// to decouple the lexer interface from the lexer implementation and reduces
// compilation time.
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//
// The new_lexer_gen<>::new_lexer function (declared in cpp_slex_token.hpp)
// should be defined inline, if the lex_functor shouldn't be instantiated
// separately from the lex_iterator.
//
// Separate (explicit) instantiation helps to reduce compilation time.
//
///////////////////////////////////////////////////////////////////////////////
#if BOOST_WAVE_SEPARATE_LEXER_INSTANTIATION != 0
#define BOOST_WAVE_SLEX_NEW_LEXER_INLINE
#else
#define BOOST_WAVE_SLEX_NEW_LEXER_INLINE inline
#endif
template <typename IteratorT, typename PositionT>
BOOST_WAVE_SLEX_NEW_LEXER_INLINE
slex_input_interface<slex_token<PositionT> > *
new_lexer_gen<IteratorT, PositionT>::new_lexer(IteratorT const &first,
IteratorT const &last, PositionT const &pos,
boost::wave::language_support language)
{
return new slex::slex_functor<IteratorT, PositionT>(first, last, pos,
language);
}
#undef BOOST_WAVE_SLEX_NEW_LEXER_INLINE
///////////////////////////////////////////////////////////////////////////////
} // namespace cpp_token_sample
} // namespace wave
} // namespace boost
#endif // !defined(SLEX_LEXER_HPP_5E8E1DF0_BB41_4938_B7E5_A4BB68222FF6_INCLUDED)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,82 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Definition of the abstract lexer interface
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(SLEX_INTERFACE_HPP_E83F52A4_90AC_4FBE_A9A7_B65F7F94C497_INCLUDED)
#define SLEX_INTERFACE_HPP_E83F52A4_90AC_4FBE_A9A7_B65F7F94C497_INCLUDED
#include <boost/wave/language_support.hpp>
#include <boost/wave/util/file_position.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace cpp_token_sample {
///////////////////////////////////////////////////////////////////////////////
//
// new_lexer_gen: generates a new instance of the required C++ lexer
//
///////////////////////////////////////////////////////////////////////////////
template <typename TokenT> struct slex_input_interface;
template <
typename IteratorT,
typename PositionT = boost::wave::util::file_position_t
>
struct new_lexer_gen
{
// The NewLexer function allows the opaque generation of a new lexer object.
// It is coupled to the token type to allow to decouple the lexer/token
// configurations at compile time.
static slex_input_interface<slex_token<PositionT> > *
new_lexer(IteratorT const &first, IteratorT const &last,
PositionT const &pos, boost::wave::language_support language);
};
///////////////////////////////////////////////////////////////////////////////
//
// The lex_input_interface decouples the lex_iterator_shim from the actual
// lexer. This is done to allow compile time reduction.
// Thanks to JCAB for having this idea.
//
///////////////////////////////////////////////////////////////////////////////
template <typename TokenT>
struct slex_input_interface
{
typedef typename TokenT::position_t position_t;
virtual TokenT get() = 0;
virtual void set_position(position_t const &pos) = 0;
virtual ~slex_input_interface() {}
// The new_lexer function allows the opaque generation of a new lexer object.
// It is coupled to the token type to allow to distinguish different
// lexer/token configurations at compile time.
template <typename IteratorT>
static slex_input_interface *
new_lexer(IteratorT const &first, IteratorT const &last,
position_t const &pos, boost::wave::language_support language)
{
return new_lexer_gen<IteratorT, position_t>::new_lexer (first, last,
pos, language);
}
};
///////////////////////////////////////////////////////////////////////////////
} // namespace cpp_token_sample
} // namespace wave
} // namespace boost
#endif // !defined(SLEX_INTERFACE_HPP_E83F52A4_90AC_4FBE_A9A7_B65F7F94C497_INCLUDED)

View File

@@ -0,0 +1,136 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
Definition of the lexer iterator
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(SLEX_ITERATOR_HPP_AF0C37E3_CBD8_4F33_A225_51CF576FA61F_INCLUDED)
#define SLEX_ITERATOR_HPP_AF0C37E3_CBD8_4F33_A225_51CF576FA61F_INCLUDED
#include <string>
#include <iostream>
#include <boost/assert.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/spirit/iterator/multi_pass.hpp>
#include <boost/wave/language_support.hpp>
#include <boost/wave/util/file_position.hpp>
#include <boost/wave/util/functor_input.hpp>
#include "slex_interface.hpp"
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace cpp_token_sample {
namespace impl {
///////////////////////////////////////////////////////////////////////////////
//
// lex_iterator_functor_shim
//
///////////////////////////////////////////////////////////////////////////////
template <typename TokenT>
class slex_iterator_functor_shim
{
public:
template <typename IteratorT>
slex_iterator_functor_shim(IteratorT const &first, IteratorT const &last,
typename TokenT::position_t const &pos,
boost::wave::language_support language)
: functor_ptr(slex_input_interface<TokenT>
::new_lexer(first, last, pos, language))
{}
// interface to the boost::spirit::multi_pass_policies::functor_input policy
typedef TokenT result_type;
/*static*/ result_type const eof;
result_type operator()()
{
BOOST_ASSERT(0 != functor_ptr.get());
return functor_ptr->get();
}
void set_position(typename TokenT::position_t const &pos)
{
BOOST_ASSERT(0 != functor_ptr.get());
functor_ptr->set_position(pos);
}
private:
boost::shared_ptr<slex_input_interface<TokenT> > functor_ptr;
};
///////////////////////////////////////////////////////////////////////////////
// eof token
//template <typename TokenT>
//typename slex_iterator_functor_shim<TokenT>::result_type const
// slex_iterator_functor_shim<TokenT>::eof =
// typename slex_iterator_functor_shim<TokenT>::result_type();
///////////////////////////////////////////////////////////////////////////////
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
//
// slex_iterator
//
// A generic C++ lexer interface class, which allows to plug in different
// lexer implementations (template parameter LexT). The following
// requirement apply:
//
// - the lexer type should have a function implemented, which returnes
// the next lexed token from the input stream:
// typename LexT::token_t get();
// - at the end of the input stream this function should return the
// eof token equivalent
// - the lexer should implement a constructor taking two iterators
// pointing to the beginning and the end of the input stream and
// a third parameter containing the name of the parsed input file
//
///////////////////////////////////////////////////////////////////////////////
template <typename TokenT>
class slex_iterator
: public boost::spirit::multi_pass<
impl::slex_iterator_functor_shim<TokenT>,
boost::wave::util::functor_input
>
{
typedef impl::slex_iterator_functor_shim<TokenT> input_policy_t;
typedef
boost::spirit::multi_pass<input_policy_t,
boost::wave::util::functor_input>
base_t;
typedef slex_iterator<TokenT> self_t;
public:
typedef TokenT token_t;
slex_iterator()
{}
template <typename IteratorT>
slex_iterator(IteratorT const &first, IteratorT const &last,
typename TokenT::position_t const &pos,
boost::wave::language_support language)
: base_t(input_policy_t(first, last, pos, language))
{}
};
///////////////////////////////////////////////////////////////////////////////
} // namespace cpp_token_sample
} // namespace wave
} // namespace boost
#endif // !defined(SLEX_ITERATOR_HPP_AF0C37E3_CBD8_4F33_A225_51CF576FA61F_INCLUDED)

View File

@@ -0,0 +1,116 @@
/*=============================================================================
Wave: A Standard compliant C++ preprocessor library
A generic C++ lexer token definition
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(SLEX_TOKEN_HPP_53A13BD2_FBAA_444B_9B8B_FCB225C2BBA8_INCLUDED)
#define SLEX_TOKEN_HPP_53A13BD2_FBAA_444B_9B8B_FCB225C2BBA8_INCLUDED
#include <iomanip>
#include <boost/wave/wave_config.hpp>
#include <boost/wave/token_ids.hpp>
#include <boost/wave/language_support.hpp>
#include <boost/wave/util/file_position.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {
namespace cpp_token_sample {
///////////////////////////////////////////////////////////////////////////////
// forward declaration of the token type
template <typename PositionT = boost::wave::util::file_position_t>
class slex_token;
///////////////////////////////////////////////////////////////////////////////
//
// lex_token
//
///////////////////////////////////////////////////////////////////////////////
template <typename PositionT>
class slex_token
{
public:
typedef BOOST_WAVE_STRINGTYPE string_t;
typedef PositionT position_t;
slex_token()
: id(T_EOI)
{}
slex_token(token_id id_, string_t const &value_, PositionT const &pos_)
: id(id_), value(value_), pos(pos_)
{}
// accessors
operator token_id() const { return id; }
string_t const &get_value() const { return value; }
position_t const &get_position() const { return pos; }
void set_token_id (token_id id_) { id = id_; }
void set_value (string_t const &newval) { value = newval; }
void set_position (position_t const &pos_) { pos = pos_; }
// debug support
#if BOOST_WAVE_DUMP_PARSE_TREE != 0
// access functions for the tree_to_xml functionality
static int get_token_id(lex_token const &t)
{ return ID_FROM_TOKEN(token_id(t)); }
static string_t get_token_value(lex_token const &t)
{ return t.get_value(); }
#endif
// print support
void print (std::ostream &stream) const
{
using namespace std;
using namespace boost::wave;
stream << setw(16) << left << boost::wave::get_token_name(id) << " ("
<< "(#" << token_id(ID_FROM_TOKEN(*this))
<< ") at " << get_position().get_file() << " ("
<< setw(3) << right << get_position().get_line() << "/"
<< setw(2) << right << get_position().get_column()
<< "): >";
for (size_t i = 0; i < value.size(); ++i) {
switch (value[i]) {
case '\r': stream << "\\r"; break;
case '\n': stream << "\\n"; break;
case '\t': stream << "\\t"; break;
default:
stream << value[i];
break;
}
}
stream << "<";
}
private:
boost::wave::token_id id; // the token id
string_t value; // the text, which was parsed into this token
PositionT pos; // the original file position
};
template <typename PositionT>
inline std::ostream &
operator<< (std::ostream &stream, slex_token<PositionT> const &object)
{
object.print(stream);
return stream;
}
///////////////////////////////////////////////////////////////////////////////
} // namespace cpp_token_sample
} // namespace wave
} // namespace boost
#endif // !defined(SLEX_TOKEN_HPP_53A13BD2_FBAA_444B_9B8B_FCB225C2BBA8_INCLUDED)

Some files were not shown because too many files have changed in this diff Show More