1 #ifndef SH_PREPROCESSOR_H 2 #define SH_PREPROCESSOR_H 3 4 #include <string> 5 #include <vector> 6 7 #include <cstdio> 8 #include <ostream> 9 #include <string> 10 #include <algorithm> 11 12 #include <boost/assert.hpp> 13 #include <boost/config.hpp> 14 15 #include <boost/wave/cpp_throw.hpp> 16 #include <boost/wave/cpp_exceptions.hpp> 17 #include <boost/wave/token_ids.hpp> 18 #include <boost/wave/util/macro_helpers.hpp> 19 #include <boost/wave/preprocessing_hooks.hpp> 20 21 namespace sh 22 { 23 /** 24 * @brief A simple interface for the boost::wave preprocessor 25 */ 26 class Preprocessor 27 { 28 public: 29 /** 30 * @brief Run a shader source string through the preprocessor 31 * @param source source string 32 * @param includePath path to search for includes (that are included with #include) 33 * @param definitions macros to predefine (vector of strings of the format MACRO=value, or just MACRO to define it as 1) 34 * @param name name to use for error messages 35 * @return processed string 36 */ 37 static std::string preprocess (std::string source, const std::string& includePath, std::vector<std::string> definitions, const std::string& name); 38 }; 39 40 41 42 class emit_custom_line_directives_hooks 43 : public boost::wave::context_policies::default_preprocessing_hooks 44 { 45 public: 46 47 template <typename ContextT, typename ContainerT> 48 bool emit_line_directive(ContextT const & ctx,ContainerT & pending,typename ContextT::token_type const & act_token)49 emit_line_directive(ContextT const& ctx, ContainerT &pending, 50 typename ContextT::token_type const& act_token) 51 { 52 // emit a #line directive showing the relative filename instead 53 typename ContextT::position_type pos = act_token.get_position(); 54 unsigned int column = 1; 55 56 typedef typename ContextT::token_type result_type; 57 58 // no line directives for now 59 pos.set_column(column); 60 pending.push_back(result_type(boost::wave::T_GENERATEDNEWLINE, "\n", pos)); 61 62 return true; 63 } 64 }; 65 66 67 } 68 69 #endif 70