cpp_lex_interface_generator.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*=============================================================================
  2. Boost.Wave: A Standard compliant C++ preprocessor library
  3. Definition of the abstract lexer interface
  4. http://www.boost.org/
  5. Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
  6. Software License, Version 1.0. (See accompanying file
  7. LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  8. =============================================================================*/
  9. #if !defined(BOOST_WAVE_LEX_INTERFACE_GENERATOR_HPP_INCLUDED)
  10. #define BOOST_WAVE_LEX_INTERFACE_GENERATOR_HPP_INCLUDED
  11. #include <boost/wave/wave_config.hpp>
  12. #include <boost/wave/util/file_position.hpp>
  13. #include <boost/wave/language_support.hpp>
  14. #include <boost/wave/cpplexer/cpp_lex_interface.hpp>
  15. #include <boost/wave/cpplexer/cpp_lex_token.hpp> // lex_token
  16. // this must occur after all of the includes and before any code appears
  17. #ifdef BOOST_HAS_ABI_HEADERS
  18. #include BOOST_ABI_PREFIX
  19. #endif
  20. // suppress warnings about dependent classes not being exported from the dll
  21. #ifdef BOOST_MSVC
  22. #pragma warning(push)
  23. #pragma warning(disable : 4251 4231 4660)
  24. #endif
  25. ///////////////////////////////////////////////////////////////////////////////
  26. namespace boost {
  27. namespace wave {
  28. namespace cpplexer {
  29. #if BOOST_WAVE_SEPARATE_LEXER_INSTANTIATION != 0
  30. #define BOOST_WAVE_NEW_LEXER_DECL BOOST_WAVE_DECL
  31. #else
  32. #define BOOST_WAVE_NEW_LEXER_DECL
  33. #endif
  34. ///////////////////////////////////////////////////////////////////////////////
  35. //
  36. // new_lexer_gen: generates a new instance of the required C++ lexer
  37. //
  38. ///////////////////////////////////////////////////////////////////////////////
  39. template <
  40. typename IteratorT,
  41. typename PositionT = boost::wave::util::file_position_type,
  42. typename TokenT = lex_token<PositionT>
  43. >
  44. struct BOOST_WAVE_NEW_LEXER_DECL new_lexer_gen
  45. {
  46. // The NewLexer function allows the opaque generation of a new lexer object.
  47. // It is coupled to the token type to allow to decouple the lexer/token
  48. // configurations at compile time.
  49. static lex_input_interface<TokenT> *
  50. new_lexer(IteratorT const &first, IteratorT const &last,
  51. PositionT const &pos, boost::wave::language_support language);
  52. };
  53. #undef BOOST_WAVE_NEW_LEXER_DECL
  54. ///////////////////////////////////////////////////////////////////////////////
  55. //
  56. // The lex_input_interface_generator helps to instantiate a concrete lexer
  57. // to be used by the Wave preprocessor module.
  58. // This is done to allow compile time reduction.
  59. //
  60. ///////////////////////////////////////////////////////////////////////////////
  61. template <typename TokenT>
  62. struct lex_input_interface_generator
  63. : lex_input_interface<TokenT>
  64. {
  65. typedef typename lex_input_interface<TokenT>::position_type position_type;
  66. lex_input_interface_generator() {}
  67. ~lex_input_interface_generator() {}
  68. // The new_lexer function allows the opaque generation of a new lexer object.
  69. // It is coupled to the token type to allow to distinguish different
  70. // lexer/token configurations at compile time.
  71. template <typename IteratorT>
  72. static lex_input_interface<TokenT> *
  73. new_lexer(IteratorT const &first, IteratorT const &last,
  74. position_type const &pos, boost::wave::language_support language)
  75. {
  76. return new_lexer_gen<IteratorT, position_type, TokenT>::new_lexer (
  77. first, last, pos, language);
  78. }
  79. };
  80. ///////////////////////////////////////////////////////////////////////////////
  81. } // namespace cpplexer
  82. } // namespace wave
  83. } // namespace boost
  84. #ifdef BOOST_MSVC
  85. #pragma warning(pop)
  86. #endif
  87. // the suffix header occurs after all of the code
  88. #ifdef BOOST_HAS_ABI_HEADERS
  89. #include BOOST_ABI_SUFFIX
  90. #endif
  91. #endif // !defined(BOOST_WAVE_LEX_INTERFACE_GENERATOR_HPP_INCLUDED)