Preface 前言

During the last time many new features have been developed as additions to the Spirit [4] 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 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.  So we had the idea to implement a C++ preprocessor to fit this needs - Wave was born.
在過去的時間裡,有許多新的功能被作為 Spirit [4] 分析器構建框架的附加特性被開發出來,我們越來越覺得,如果有一個'真實世界'的例子可以用作測試某種功能的可用性的沙盤,將會非常有用。此外,在 Boost郵件列表上最近的討論顯示,廣大開發者對於一個現代的、開源的C++預處理器庫懷有興趣。因此我們有了這個想法,實現一個C++預處理器來適應 這一需求 - 於是就有了 Wave

The Wave C++ preprocessor library uses the Spirit[4] parser construction library to implement a C++ lexer with ISO/ANSI Standards 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).
Wave C++預處理器庫使用了 Spirit[4] 分析器構建框架來實現一個符合ISO/ANSI標準預處理功能的C++ lexer。它提供一個迭代器接口,從輸入流返回當前的預處理單詞。當你對預處理器迭代器序列(用STL的術語來說,這個迭代器是前向迭代器)進行迭代時,預處理單詞是就地生成的。

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 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:

 Inclusion of header files 包含頭文件
 Macro expansion 宏展開
 Conditional compilation 條件編譯
 Line control 行控制

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 [7] 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.
如今這些功能被大大地低估了,甚至長期以來預處理器都被是不被贊成的,直至幾年前 Boost preprocessor 庫[7]誕生之前,它的用途都沒有被有效推廣。直到現在,我們才開始明白,預處理器生成的元程序和C++中的模板元編程相結合,是迄今為止所有語言所支持的編譯期反射/元編程工具中最為強大的之一。

The C++ Standard [2] was adopted back in 1998, but there is still no (known to me) commercial C++ compiler, which has a bugfree implementation of the rather simple preprocessor requirements mandated therein. This may be a result of the mentioned underestimation or even banning of the preprocessor from good programming style during the last few years or may stem from the somewhat awkward standardese dialect of English used to describe it. Two open source projects are exceptions of this: gcc and Clang (a subproject of LLVM), both providing preprocessors with very good standards conformance.
C++標準[2]是 在上1998年通過的,但是直到現在仍然沒有(就我所知)一個商業C++編譯器,對於那怕是簡單的預處理要求,具有無錯的實現。這可能是上述對預處理器的 低估所導致的,也可能是源於最近幾年的優良編程風格對預處理器的抗拒,也可能是由於標準中使用了有點笨拙的英語方言來描述它。有兩個開源項目是例外: gcc 和 Clang (LLVM的一個子項目),它們都提供了具有非常好的標準符合性的預處理器。

So the main goals for the Wave project are:
因此,Wave 項目的主要目標是:

 full conformance with the C++ standard (ISO/IEC 14882:1998) [1] and with the C99 standard (INCITS/ISO/IEC 9899:1999) [2]
完全符合C++標準(ISO/IEC 14882:1998) [1] 和C99標準(INCITS/ISO/IEC 9899:1999) [2]
 usage of Spirit[4] for the parsing parts of the game (certainly :-)
使用 Spirit[4] 作為分析部分(這是當然的 :-)
 maximal usage of STL and/or Boost libraries (for compactness and maintainability)
最大可能地使用 STL 和/或 Boost 庫(為了簡潔性和可維護性)
 straightforward extendability for the implementation of additional features
 building a flexible library for different C++ lexing and preprocessing needs
為不同的 C++ lexing 和預處理需要構建一個靈活的庫

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 works as expected and is usable as a reference implementation, for instance for testing of other preprocessor oriented libraries as the Boost Preprocessor library [7] Nevertheless recent work has lead to surprising performance enhancements (if compared with earlier versions). Wave is still somewhat slower as for instance EDG based preprocessors (Intel, Comeau) on simple input files, however, as complexity increases, time dilates expontentially on EDG. Preprocessing time dilates linearly under Wave, which causes it to easily outperform EDG based preprocessors when complexity increases.
首先,我們並不打算將它實現為一個非常高性能或非常小的C++預處理器。如果你正在尋找這樣的東西,那麼你可能要換個地方找找。雖然我們的C++預處理迭代器可以如預期地工作,也可作為參考實現,例如用於測試象 Boost Preprocessor 庫[7]這 樣的面向預處理器的庫。但是近期的工作取得了令人驚訝的性能提升(與早期版本相比)。對於簡單的輸入文件,Wave依然要比基於EDG的預處理器 (Intel, Comeau)慢一點,不過隨著複雜性的增加,EDG的時間是以指數方式增加。在Wave下的預處理時間則是線性增加的,所以在複雜性增加時,它可以輕易 勝過基於EDG的預處理器。

As tests showed, the Wave 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).
正如測試結果所顯示的,Wave 庫非常符合C++標準,例如它編譯了幾個嚴格符合性的宏定義,這些宏甚至不能與基於EDG的預處理器(如 Comeau 或 Intel)相兼容。