@@ -22,7 +22,7 @@ using namespace boost::wave;
2222using namespace boost ::wave::util;
2323
2424// for including builtins
25- struct load_to_string
25+ struct load_to_string final
2626{
2727 template <typename IterContextT>
2828 class inner
@@ -44,10 +44,9 @@ struct load_to_string
4444 else // regular #include "..."
4545 result = inclFinder->getIncludeRelative (requestingSourceDir,filepath);
4646
47- if (result)
48- iter_ctx.instring = *result;
49- else
50- iter_ctx.instring = " #error \" " +filepath+" \" not found\n " ;
47+ // If located then must be possible to open!
48+ assert (result);
49+ iter_ctx.instring = *result;
5150
5251 iter_ctx.first = iterator_type (iter_ctx.instring .begin (),iter_ctx.instring .end (),PositionT (iter_ctx.filename ),language);
5352 iter_ctx.last = iterator_type ();
@@ -59,15 +58,11 @@ struct load_to_string
5958};
6059
6160
62- struct preprocessing_hooks : public boost ::wave::context_policies::default_preprocessing_hooks
61+ struct preprocessing_hooks final : public boost::wave::context_policies::default_preprocessing_hooks
6362{
6463 preprocessing_hooks (const IShaderCompiler::SPreprocessorOptions& _preprocessOptions)
6564 : m_includeFinder(_preprocessOptions.includeFinder), m_logger(_preprocessOptions.logger), m_pragmaStage(IShader::ESS_UNKNOWN) {}
6665
67- const IShaderCompiler::CIncludeFinder* m_includeFinder;
68- system::logger_opt_ptr m_logger;
69- IShader::E_SHADER_STAGE m_pragmaStage;
70-
7166
7267 template <typename ContextT>
7368 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)
@@ -79,10 +74,7 @@ struct preprocessing_hooks : public boost::wave::context_policies::default_prepr
7974 dir_path = ctx.get_current_directory ().string ();
8075 std::optional<std::string> result;
8176 if (is_system)
82- {
8377 result = m_includeFinder->getIncludeStandard (dir_path, file_path);
84- dir_path = " " ;
85- }
8678 else
8779 result = m_includeFinder->getIncludeRelative (dir_path, file_path);
8880
@@ -148,28 +140,19 @@ struct preprocessing_hooks : public boost::wave::context_policies::default_prepr
148140 m_logger.log (" Pre-processor encountered error directive:\n %s" , nbl::system::ILogger::ELL_ERROR, stream.str ().c_str ());
149141 return false ;
150142 }
143+
144+
145+ const IShaderCompiler::CIncludeFinder* m_includeFinder;
146+ system::logger_opt_ptr m_logger;
147+ IShader::E_SHADER_STAGE m_pragmaStage;
151148};
152149
153- class include_paths
150+ class include_paths final
154151{
155- private:
156- typedef std::list<std::pair<system::path, std::string> >
157- include_list_type;
158- typedef include_list_type::value_type include_value_type;
159-
160152 public:
161- inline include_paths () : was_sys_include_path(false ), current_dir() {}
162-
163- bool add_include_path (char const * path_, bool is_system = false )
164- {
165- return add_include_path (path_, (is_system || was_sys_include_path) ?
166- system_include_paths : user_include_paths);
167- }
168-
169- void set_sys_include_delimiter () { was_sys_include_path = true ; }
170-
171- bool find_include_file (std::string& s, std::string& dir, bool is_system, char const * current_file) const ;
153+ inline include_paths () : current_dir() {}
172154
155+ // Nabla Additions Start
173156 system::path get_current_directory () const
174157 {
175158 return current_dir;
@@ -181,43 +164,30 @@ class include_paths
181164 fs::path filename = current_dir.is_absolute () ? filepath : (current_dir / filepath);
182165 current_dir = filename.parent_path ();
183166 }
184-
185- protected:
186- bool find_include_file (std::string& s, std::string& dir,
187- include_list_type const & pathes, char const *) const ;
188- bool add_include_path (char const * path_, include_list_type& pathes_);
167+ // Nabla Additions End
189168
190169 private:
191- include_list_type user_include_paths;
192- include_list_type system_include_paths;
193- bool was_sys_include_path; // saw a set_sys_include_delimiter()
194170 system::path current_dir;
195171};
196172
197- template <
198- typename IteratorT,
199- typename LexIteratorT = boost::wave::cpplexer::lex_iterator<boost::wave::cpplexer::lex_token<>>
200- >
201173class context : private boost ::noncopyable
202174{
203175 private:
204176 using actual_context_type = context;
205177
206178 public:
207- // public typedefs
208- typedef typename LexIteratorT::token_type token_type;
209- typedef typename token_type::string_type string_type;
179+ using token_type = boost::wave::cpplexer::lex_token<>;
180+ using string_type = token_type::string_type;
210181
211- typedef IteratorT target_iterator_type ;
212- typedef LexIteratorT lexer_type ;
182+ using target_iterator_type = core::string::iterator ;
183+ using lexer_type = boost::wave::cpplexer::lex_iterator<token_type> ;
213184 typedef pp_iterator<context> iterator_type;
214185
215186 using input_policy_type = load_to_string;
216- typedef typename token_type::position_type position_type;
187+ using position_type = token_type::position_type;
217188
218189 // type of a token sequence
219- typedef std::list<token_type, boost::fast_pool_allocator<token_type> >
220- token_sequence_type;
190+ using token_sequence_type = std::list<token_type,boost::fast_pool_allocator<token_type>>;
221191
222192 private:
223193 // stack of shared_ptr's to the pending iteration contexts
@@ -266,15 +236,6 @@ class context : private boost::noncopyable
266236 }
267237
268238 // maintain include paths
269- bool add_include_path (char const * path_)
270- {
271- return includes.add_include_path (path_, false );
272- }
273- bool add_sysinclude_path (char const * path_)
274- {
275- return includes.add_include_path (path_, true );
276- }
277- void set_sysinclude_delimiter () { includes.set_sys_include_delimiter (); }
278239 typename iteration_context_stack_type::size_type get_iteration_depth () const
279240 {
280241 return iter_ctxs.size ();
@@ -400,11 +361,13 @@ class context : private boost::noncopyable
400361 return *static_cast <actual_context_type const *>(this );
401362 }
402363
364+ // Nabla Additions Start
403365 // return the directory of the currently preprocessed file
404- nbl:: system::path get_current_directory () const
366+ system::path get_current_directory () const
405367 {
406368 return includes.get_current_directory ();
407369 }
370+ // Nabla Additions End
408371
409372#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
410373 protected:
@@ -416,15 +379,12 @@ class context : private boost::noncopyable
416379 // make sure the context has been initialized
417380 void init_context ()
418381 {
419- if (!has_been_initialized) {
420- std::string fname (filename);
421- if (filename != " <Unknown>" && filename != " <stdin>" ) {
422- nbl::system::path fpath (filename);
423- fname = fpath.string ();
424- includes.set_current_directory (fname.c_str ());
425- }
426- has_been_initialized = true ; // execute once
427- }
382+ if (has_been_initialized)
383+ return ;
384+
385+ nbl::system::path fpath (filename);
386+ includes.set_current_directory (fpath.string ().c_str ());
387+ has_been_initialized = true ; // execute once
428388 }
429389
430390 template <typename IteratorT2>
@@ -507,12 +467,6 @@ class context : private boost::noncopyable
507467 return current_relative_filename;
508468 }
509469
510- bool find_include_file (std::string& s, std::string& d, bool is_system,
511- char const * current_file) const
512- {
513- return includes.find_include_file (s, d, is_system, current_file);
514- }
515-
516470 private:
517471 // the main input stream
518472 target_iterator_type first; // underlying input stream
@@ -532,7 +486,7 @@ class context : private boost::noncopyable
532486}
533487
534488
535- template <> 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)
489+ template <> inline bool boost::wave::impl::pp_iterator_functor<nbl::wave::context>::on_include_helper(char const * f, char const * s, bool is_system, bool include_next)
536490{
537491 assert (!include_next);
538492 namespace fs = boost::filesystem;
@@ -547,11 +501,9 @@ template<> inline bool boost::wave::impl::pp_iterator_functor<nbl::wave::context
547501
548502 file_path = util::impl::unescape_lit (file_path);
549503 std::string native_path_str;
550-
551504 if (!ctx.get_hooks ().locate_include_file (ctx, file_path, is_system, nullptr , dir_path, native_path_str))
552505 {
553- BOOST_WAVE_THROW_CTX (ctx, preprocess_exception, bad_include_file,
554- file_path.c_str (), act_pos);
506+ BOOST_WAVE_THROW_CTX (ctx, preprocess_exception, bad_include_file, file_path.c_str (), act_pos);
555507 return false ;
556508 }
557509
@@ -568,8 +520,7 @@ template<> inline bool boost::wave::impl::pp_iterator_functor<nbl::wave::context
568520 base_iteration_context_type::user_header));
569521
570522 // call the include policy trace function
571- ctx.get_hooks ().opened_include_file (ctx.derived (), dir_path, file_path,
572- is_system);
523+ ctx.get_hooks ().opened_include_file (ctx.derived (), dir_path, file_path, is_system);
573524
574525 // store current file position
575526 iter_ctx->real_relative_filename = ctx.get_current_relative_filename ().c_str ();
0 commit comments