@@ -22,7 +22,7 @@ using namespace boost::wave;
2222using namespace boost ::wave::util;
2323
2424// for including builtins
25- struct load_file_or_builtin_to_string
25+ struct load_to_string
2626{
2727 template <typename IterContextT>
2828 class inner
@@ -33,26 +33,23 @@ struct load_file_or_builtin_to_string
3333 {
3434 using iterator_type = typename IterContextT::iterator_type;
3535
36- std::string filepath (iter_ctx.filename .begin (), iter_ctx.filename .end ());
36+ std::string filepath (iter_ctx.filename .begin (),iter_ctx.filename .end ());
3737 const auto inclFinder = iter_ctx.ctx .get_hooks ().m_includeFinder ;
3838 assert (inclFinder);
3939
4040 std::optional<std::string> result;
4141 system::path requestingSourceDir (iter_ctx.ctx .get_current_directory ().string ());
42- if (iter_ctx.type == IterContextT::base_type::file_type::system_header) // is it a sys include (#include <...>)?
43- result = inclFinder->getIncludeStandard (requestingSourceDir, filepath);
42+ if (iter_ctx.type == IterContextT::base_type::file_type::system_header) // is it a sys include (#include <...>)?
43+ result = inclFinder->getIncludeStandard (requestingSourceDir,filepath);
4444 else // regular #include "..."
45- result = inclFinder->getIncludeRelative (requestingSourceDir, filepath);
45+ result = inclFinder->getIncludeRelative (requestingSourceDir,filepath);
4646
47- if (!result)
48- BOOST_WAVE_THROW_CTX (iter_ctx.ctx , boost::wave::preprocess_exception,
49- bad_include_file, iter_ctx.filename .c_str (), act_pos);
50- auto & res_str = *result;
51- iter_ctx.instring = res_str;
47+ if (result)
48+ iter_ctx.instring = *result;
49+ else
50+ iter_ctx.instring = " #error \" " +filepath+" \" not found\n " ;
5251
53- iter_ctx.first = iterator_type (
54- iter_ctx.instring .begin (), iter_ctx.instring .end (),
55- PositionT (iter_ctx.filename ), language);
52+ iter_ctx.first = iterator_type (iter_ctx.instring .begin (),iter_ctx.instring .end (),PositionT (iter_ctx.filename ),language);
5653 iter_ctx.last = iterator_type ();
5754 }
5855
@@ -62,9 +59,9 @@ struct load_file_or_builtin_to_string
6259};
6360
6461
65- struct custom_preprocessing_hooks : public boost ::wave::context_policies::default_preprocessing_hooks
62+ struct preprocessing_hooks : public boost ::wave::context_policies::default_preprocessing_hooks
6663{
67- custom_preprocessing_hooks (const IShaderCompiler::SPreprocessorOptions& _preprocessOptions)
64+ preprocessing_hooks (const IShaderCompiler::SPreprocessorOptions& _preprocessOptions)
6865 : m_includeFinder(_preprocessOptions.includeFinder), m_logger(_preprocessOptions.logger), m_pragmaStage(IShader::ESS_UNKNOWN) {}
6966
7067 const IShaderCompiler::CIncludeFinder* m_includeFinder;
@@ -75,22 +72,26 @@ struct custom_preprocessing_hooks : public boost::wave::context_policies::defaul
7572 template <typename ContextT>
7673 bool locate_include_file (ContextT& ctx, std::string& file_path, bool is_system, char const * current_name, std::string& dir_path, std::string& native_name)
7774 {
75+ assert (current_name==nullptr );
7876 if (!m_includeFinder)
7977 return false ;
8078
8179 dir_path = ctx.get_current_directory ().string ();
8280 std::optional<std::string> result;
83- if (is_system) {
81+ if (is_system)
82+ {
8483 result = m_includeFinder->getIncludeStandard (dir_path, file_path);
8584 dir_path = " " ;
8685 }
8786 else
8887 result = m_includeFinder->getIncludeRelative (dir_path, file_path);
88+
8989 if (!result)
9090 {
9191 m_logger.log (" Pre-processor error: Bad include file.\n '%s' does not exist." , nbl::system::ILogger::ELL_ERROR, file_path.c_str ());
9292 return false ;
9393 }
94+ // TODO:
9495 native_name = file_path;
9596 return true ;
9697 }
@@ -157,7 +158,7 @@ class include_paths
157158 typedef include_list_type::value_type include_value_type;
158159
159160 public:
160- inline include_paths () : was_sys_include_path(false ), current_dir(), current_rel_dir() {}
161+ inline include_paths () : was_sys_include_path(false ), current_dir() {}
161162
162163 bool add_include_path (char const * path_, bool is_system = false )
163164 {
@@ -178,8 +179,6 @@ class include_paths
178179 namespace fs = nbl::system;
179180 fs::path filepath (path_);
180181 fs::path filename = current_dir.is_absolute () ? filepath : (current_dir / filepath);
181- current_rel_dir.clear ();
182- current_rel_dir = filepath.parent_path ();
183182 current_dir = filename.parent_path ();
184183 }
185184
@@ -193,22 +192,16 @@ class include_paths
193192 include_list_type system_include_paths;
194193 bool was_sys_include_path; // saw a set_sys_include_delimiter()
195194 system::path current_dir;
196- system::path current_rel_dir;
197195};
198196
199197template <
200198 typename IteratorT,
201- typename LexIteratorT = boost::wave::cpplexer::lex_iterator<boost::wave::cpplexer::lex_token<>>,
202- typename InputPolicyT = load_file_or_builtin_to_string,
203- typename HooksT = custom_preprocessing_hooks,
204- typename DerivedT = boost::wave::this_type
199+ typename LexIteratorT = boost::wave::cpplexer::lex_iterator<boost::wave::cpplexer::lex_token<>>
205200>
206201class context : private boost ::noncopyable
207202{
208203 private:
209- typedef typename mpl::if_<
210- boost::is_same<DerivedT, this_type>, context, DerivedT
211- >::type actual_context_type;
204+ using actual_context_type = context;
212205
213206 public:
214207 // public typedefs
@@ -219,14 +212,12 @@ class context : private boost::noncopyable
219212 typedef LexIteratorT lexer_type;
220213 typedef pp_iterator<context> iterator_type;
221214
222- typedef InputPolicyT input_policy_type ;
215+ using input_policy_type = load_to_string ;
223216 typedef typename token_type::position_type position_type;
224217
225218 // type of a token sequence
226219 typedef std::list<token_type, boost::fast_pool_allocator<token_type> >
227220 token_sequence_type;
228- // type of the policies
229- typedef HooksT hook_policy_type;
230221
231222 private:
232223 // stack of shared_ptr's to the pending iteration contexts
@@ -239,8 +230,7 @@ class context : private boost::noncopyable
239230 context* this_ () { return this ; } // avoid warning in constructor
240231
241232 public:
242- context (target_iterator_type const & first_, target_iterator_type const & last_,
243- char const * fname = " <Unknown>" , HooksT const & hooks_ = HooksT())
233+ context (target_iterator_type const & first_, target_iterator_type const & last_, char const * fname, preprocessing_hooks const & hooks_)
244234 : first(first_), last(last_), filename(fname)
245235 , has_been_initialized(false )
246236 , current_relative_filename(fname)
@@ -397,8 +387,8 @@ class context : private boost::noncopyable
397387 }
398388
399389 // access the policies
400- hook_policy_type & get_hooks () { return hooks; }
401- hook_policy_type const & get_hooks () const { return hooks; }
390+ preprocessing_hooks & get_hooks () { return hooks; }
391+ preprocessing_hooks const & get_hooks () const { return hooks; }
402392
403393 // return type of actually used context type (might be the derived type)
404394 actual_context_type& derived ()
@@ -536,30 +526,29 @@ class context : private boost::noncopyable
536526 iteration_context_stack_type iter_ctxs; // iteration contexts
537527 macromap_type macros; // map of defined macros
538528 boost::wave::language_support language; // supported language/extensions
539- hook_policy_type hooks; // hook policy instance
529+ preprocessing_hooks hooks; // hook policy instance
540530};
541531
542532}
543533
544534
545535template <> inline bool boost::wave::impl::pp_iterator_functor<nbl::wave::context<std::string::iterator>>::on_include_helper(char const * f, char const * s, bool is_system, bool include_next)
546536{
537+ assert (!include_next);
547538 namespace fs = boost::filesystem;
548539
549540 // try to locate the given file, searching through the include path lists
550541 std::string file_path (s);
551542 std::string dir_path;
552- char const * current_name = 0 ; // never try to match current file name
553543
554544 // call the 'found_include_directive' hook function
555- if (ctx.get_hooks ().found_include_directive (ctx.derived (), f, include_next))
545+ if (ctx.get_hooks ().found_include_directive (ctx.derived (),f, include_next))
556546 return true ; // client returned false: skip file to include
557547
558548 file_path = util::impl::unescape_lit (file_path);
559549 std::string native_path_str;
560550
561- if (!ctx.get_hooks ().locate_include_file (ctx, file_path, is_system,
562- current_name, dir_path, native_path_str))
551+ if (!ctx.get_hooks ().locate_include_file (ctx, file_path, is_system, nullptr , dir_path, native_path_str))
563552 {
564553 BOOST_WAVE_THROW_CTX (ctx, preprocess_exception, bad_include_file,
565554 file_path.c_str (), act_pos);
0 commit comments