testwave_app.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*=============================================================================
  2. Boost.Wave: A Standard compliant C++ preprocessor library
  3. http://www.boost.org/
  4. Copyright (c) 2001-2013 Hartmut Kaiser. Distributed under the Boost
  5. Software License, Version 1.0. (See accompanying file
  6. LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. =============================================================================*/
  8. #if !defined(BOOST_WAVE_LIBS_WAVE_TEST_TESTWAVE_APP_HPP)
  9. #define BOOST_WAVE_LIBS_WAVE_TEST_TESTWAVE_APP_HPP
  10. #include <string>
  11. #include <vector>
  12. // include boost
  13. #include <boost/config.hpp>
  14. #include "cmd_line_utils.hpp"
  15. ///////////////////////////////////////////////////////////////////////////////
  16. class testwave_app
  17. {
  18. public:
  19. testwave_app(boost::program_options::variables_map const& vm);
  20. // Test the given file (i.e. preprocess the file and compare the result
  21. // against the embedded 'R' comments, if an error occurs compare the error
  22. // message against the given 'E' comments).
  23. bool test_a_file(std::string filename);
  24. // print the current version of this program
  25. int print_version();
  26. // print the copyright statement
  27. int print_copyright();
  28. // access the common options used for the command line and the config
  29. // options inside the test files
  30. boost::program_options::options_description const& common_options() const
  31. {
  32. return desc_options;
  33. }
  34. void set_debuglevel(int debuglevel_)
  35. {
  36. debuglevel = debuglevel_;
  37. }
  38. int get_debuglevel() const
  39. {
  40. return debuglevel;
  41. }
  42. protected:
  43. // Read the given file into a string
  44. bool read_file(std::string const& filename, std::string& instr);
  45. // Extract special information from comments marked with the given letter
  46. bool extract_special_information(std::string const& filename,
  47. std::string const& instr, char flag, std::string& content);
  48. // Extract the expected output and expected hooks information from the
  49. // given input data.
  50. // The expected output has to be provided inside of special comments which
  51. // start with a capital 'R' ('H' for the hooks information). All such
  52. // comments are concatenated and returned through the parameter 'expected'
  53. // ('expectedhooks' for hooks information).
  54. bool extract_expected_output(std::string const& filename,
  55. std::string const& instr, std::string& expected,
  56. std::string& expectedhooks);
  57. // Extracts the required preprocessing options from the given input data
  58. // and initializes the given Wave context object accordingly.
  59. // We allow the same (applicable) options to be used as are valid for the
  60. // wave driver executable.
  61. template <typename Context>
  62. bool extract_options(std::string const& filename,
  63. std::string const& instr, Context& ctx, bool single_line,
  64. boost::program_options::variables_map& vm);
  65. // transfers the options collected in the vm parameter into the given
  66. // context
  67. template <typename Context>
  68. bool initialise_options(Context& ctx,
  69. boost::program_options::variables_map const& vm, bool single_line);
  70. // Preprocess the given input data and return the generated output through
  71. // the parameter 'result'.
  72. bool preprocess_file(std::string filename, std::string const& instr,
  73. std::string& result, std::string& error, std::string& hooks,
  74. std::string const& expected_cfg_macro, bool single_line = false);
  75. // Add special predefined macros to the context object
  76. template <typename Context>
  77. bool add_predefined_macros(Context& ctx);
  78. // This function compares the real result and the expected one but first
  79. // replaces all occurrences in the expected result of
  80. // $E: to the result of preprocessing the given expression
  81. // $F: to the passed full filepath
  82. // $P: to the full path
  83. // $R: to the relative path
  84. // $V: to the current Boost version number
  85. bool got_expected_result(std::string const& filename,
  86. std::string const& result, std::string& expected);
  87. // construct a SIZEOF macro definition string and predefine this macro
  88. template <typename Context>
  89. bool add_sizeof_definition(Context& ctx, char const *name, int value);
  90. // construct a MIN macro definition string and predefine this macro
  91. template <typename T, typename Context>
  92. bool add_min_definition(Context& ctx, char const *name);
  93. // construct a MAX macro definition string and predefine this macro
  94. template <typename T, typename Context>
  95. bool add_max_definition(Context& ctx, char const *name);
  96. // Predefine __TESTWAVE_HAS_STRICT_LEXER__
  97. template <typename Context>
  98. bool add_strict_lexer_definition(Context& ctx);
  99. #if BOOST_WAVE_SUPPORT_MS_EXTENSIONS
  100. // Predefine __TESTWAVE_SUPPORT_MS_EXTENSIONS__
  101. template <typename Context>
  102. bool add_support_ms_extensions_definition(Context& ctx);
  103. #endif
  104. private:
  105. int debuglevel;
  106. boost::program_options::options_description desc_options;
  107. boost::program_options::variables_map const& global_vm;
  108. };
  109. #endif // !defined(BOOST_WAVE_LIBS_WAVE_TEST_TESTWAVE_APP_HPP)