@@ -22,7 +22,7 @@ using namespace boost::wave;
22
22
using namespace boost ::wave::util;
23
23
24
24
// for including builtins
25
- struct load_to_string
25
+ struct load_to_string final
26
26
{
27
27
template <typename IterContextT>
28
28
class inner
@@ -44,10 +44,9 @@ struct load_to_string
44
44
else // regular #include "..."
45
45
result = inclFinder->getIncludeRelative (requestingSourceDir,filepath);
46
46
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;
51
50
52
51
iter_ctx.first = iterator_type (iter_ctx.instring .begin (),iter_ctx.instring .end (),PositionT (iter_ctx.filename ),language);
53
52
iter_ctx.last = iterator_type ();
@@ -59,15 +58,11 @@ struct load_to_string
59
58
};
60
59
61
60
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
63
62
{
64
63
preprocessing_hooks (const IShaderCompiler::SPreprocessorOptions& _preprocessOptions)
65
64
: m_includeFinder(_preprocessOptions.includeFinder), m_logger(_preprocessOptions.logger), m_pragmaStage(IShader::ESS_UNKNOWN) {}
66
65
67
- const IShaderCompiler::CIncludeFinder* m_includeFinder;
68
- system::logger_opt_ptr m_logger;
69
- IShader::E_SHADER_STAGE m_pragmaStage;
70
-
71
66
72
67
template <typename ContextT>
73
68
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
79
74
dir_path = ctx.get_current_directory ().string ();
80
75
std::optional<std::string> result;
81
76
if (is_system)
82
- {
83
77
result = m_includeFinder->getIncludeStandard (dir_path, file_path);
84
- dir_path = " " ;
85
- }
86
78
else
87
79
result = m_includeFinder->getIncludeRelative (dir_path, file_path);
88
80
@@ -148,28 +140,19 @@ struct preprocessing_hooks : public boost::wave::context_policies::default_prepr
148
140
m_logger.log (" Pre-processor encountered error directive:\n %s" , nbl::system::ILogger::ELL_ERROR, stream.str ().c_str ());
149
141
return false ;
150
142
}
143
+
144
+
145
+ const IShaderCompiler::CIncludeFinder* m_includeFinder;
146
+ system::logger_opt_ptr m_logger;
147
+ IShader::E_SHADER_STAGE m_pragmaStage;
151
148
};
152
149
153
- class include_paths
150
+ class include_paths final
154
151
{
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
-
160
152
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() {}
172
154
155
+ // Nabla Additions Start
173
156
system::path get_current_directory () const
174
157
{
175
158
return current_dir;
@@ -181,43 +164,30 @@ class include_paths
181
164
fs::path filename = current_dir.is_absolute () ? filepath : (current_dir / filepath);
182
165
current_dir = filename.parent_path ();
183
166
}
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
189
168
190
169
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()
194
170
system::path current_dir;
195
171
};
196
172
197
- template <
198
- typename IteratorT,
199
- typename LexIteratorT = boost::wave::cpplexer::lex_iterator<boost::wave::cpplexer::lex_token<>>
200
- >
201
173
class context : private boost ::noncopyable
202
174
{
203
175
private:
204
176
using actual_context_type = context;
205
177
206
178
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;
210
181
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> ;
213
184
typedef pp_iterator<context> iterator_type;
214
185
215
186
using input_policy_type = load_to_string;
216
- typedef typename token_type::position_type position_type;
187
+ using position_type = token_type::position_type;
217
188
218
189
// 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>>;
221
191
222
192
private:
223
193
// stack of shared_ptr's to the pending iteration contexts
@@ -266,15 +236,6 @@ class context : private boost::noncopyable
266
236
}
267
237
268
238
// 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 (); }
278
239
typename iteration_context_stack_type::size_type get_iteration_depth () const
279
240
{
280
241
return iter_ctxs.size ();
@@ -400,11 +361,13 @@ class context : private boost::noncopyable
400
361
return *static_cast <actual_context_type const *>(this );
401
362
}
402
363
364
+ // Nabla Additions Start
403
365
// return the directory of the currently preprocessed file
404
- nbl:: system::path get_current_directory () const
366
+ system::path get_current_directory () const
405
367
{
406
368
return includes.get_current_directory ();
407
369
}
370
+ // Nabla Additions End
408
371
409
372
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
410
373
protected:
@@ -416,15 +379,12 @@ class context : private boost::noncopyable
416
379
// make sure the context has been initialized
417
380
void init_context ()
418
381
{
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
428
388
}
429
389
430
390
template <typename IteratorT2>
@@ -507,12 +467,6 @@ class context : private boost::noncopyable
507
467
return current_relative_filename;
508
468
}
509
469
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
-
516
470
private:
517
471
// the main input stream
518
472
target_iterator_type first; // underlying input stream
@@ -532,7 +486,7 @@ class context : private boost::noncopyable
532
486
}
533
487
534
488
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)
536
490
{
537
491
assert (!include_next);
538
492
namespace fs = boost::filesystem;
@@ -547,11 +501,9 @@ template<> inline bool boost::wave::impl::pp_iterator_functor<nbl::wave::context
547
501
548
502
file_path = util::impl::unescape_lit (file_path);
549
503
std::string native_path_str;
550
-
551
504
if (!ctx.get_hooks ().locate_include_file (ctx, file_path, is_system, nullptr , dir_path, native_path_str))
552
505
{
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);
555
507
return false ;
556
508
}
557
509
@@ -568,8 +520,7 @@ template<> inline bool boost::wave::impl::pp_iterator_functor<nbl::wave::context
568
520
base_iteration_context_type::user_header));
569
521
570
522
// 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);
573
524
574
525
// store current file position
575
526
iter_ctx->real_relative_filename = ctx.get_current_relative_filename ().c_str ();
0 commit comments