@@ -49,33 +49,13 @@ struct preprocessing_hooks final : public boost::wave::context_policies::default
49
49
preprocessing_hooks (const IShaderCompiler::SPreprocessorOptions& _preprocessOptions)
50
50
: m_includeFinder(_preprocessOptions.includeFinder), m_logger(_preprocessOptions.logger), m_pragmaStage(IShader::ESS_UNKNOWN) {}
51
51
52
-
53
52
template <typename ContextT>
54
- 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)
53
+ 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)
55
54
{
56
- assert (current_name==nullptr );
57
- if (!m_includeFinder)
58
- return false ;
59
-
60
- dir_path = ctx.get_current_directory ().string ();
61
- std::optional<std::string> result;
62
- if (is_system)
63
- result = m_includeFinder->getIncludeStandard (dir_path, file_path);
64
- else
65
- result = m_includeFinder->getIncludeRelative (dir_path, file_path);
66
-
67
- if (!result)
68
- {
69
- m_logger.log (" Pre-processor error: Bad include file.\n '%s' does not exist." , nbl::system::ILogger::ELL_ERROR, file_path.c_str ());
70
- return false ;
71
- }
72
- ctx.set_located_include_content (std::move (*result));
73
- // TODO:
74
- native_name = file_path;
75
- return true ;
55
+ assert (false ); // should never be called
56
+ return false ;
76
57
}
77
58
78
-
79
59
// interpretation of #pragma's of the form 'wave option[(value)]'
80
60
template <typename ContextT, typename ContainerT>
81
61
bool interpret_pragma (
@@ -172,8 +152,9 @@ class context : private boost::noncopyable
172
152
, current_relative_filename(fname)
173
153
, macros(*this_ ())
174
154
, language(language_support(
175
- support_cpp
155
+ support_cpp20
176
156
| support_option_convert_trigraphs
157
+ | support_option_preserve_comments
177
158
| support_option_emit_line_directives
178
159
| support_option_emit_pragma_directives
179
160
| support_option_insert_whitespace
@@ -291,13 +272,6 @@ class context : private boost::noncopyable
291
272
}
292
273
293
274
// access current language options
294
- void set_language (boost::wave::language_support language_,
295
- bool reset_macros = true )
296
- {
297
- language = language_;
298
- if (reset_macros)
299
- reset_macro_definitions ();
300
- }
301
275
boost::wave::language_support get_language () const { return language; }
302
276
303
277
position_type& get_main_pos () { return macros.get_main_pos (); }
@@ -328,20 +302,13 @@ class context : private boost::noncopyable
328
302
}
329
303
330
304
// Nabla Additions Start
331
- system::path get_current_directory () const
305
+ const system::path& get_current_directory () const
332
306
{
333
307
return current_dir;
334
308
}
335
- void set_current_directory (char const * path_)
336
- {
337
- namespace fs = nbl::system;
338
- fs::path filepath (path_);
339
- fs::path filename = current_dir.is_absolute () ? filepath : (current_dir / filepath);
340
- current_dir = filename.parent_path ();
341
- }
342
- void set_located_include_content (core::string&& content)
309
+ void set_current_directory (const system::path& filepath)
343
310
{
344
- located_include_content = std::move (content );
311
+ current_dir = filepath. parent_path ( );
345
312
}
346
313
const core::string& get_located_include_content () const
347
314
{
@@ -362,8 +329,7 @@ class context : private boost::noncopyable
362
329
if (has_been_initialized)
363
330
return ;
364
331
365
- nbl::system::path fpath (filename);
366
- set_current_directory (fpath.string ().c_str ());
332
+ set_current_directory (system::path (filename));
367
333
has_been_initialized = true ; // execute once
368
334
}
369
335
@@ -445,8 +411,9 @@ class context : private boost::noncopyable
445
411
// the main input stream
446
412
target_iterator_type first; // underlying input stream
447
413
target_iterator_type last;
448
- std::string filename; // associated main filename
414
+ const std::string filename; // associated main filename
449
415
bool has_been_initialized; // set cwd once
416
+
450
417
std::string current_relative_filename; // real relative name of current preprocessed file
451
418
452
419
// Nabla Additions Start
@@ -458,7 +425,7 @@ class context : private boost::noncopyable
458
425
boost::wave::util::if_block_stack ifblocks; // conditional compilation contexts
459
426
iteration_context_stack_type iter_ctxs; // iteration contexts
460
427
macromap_type macros; // map of defined macros
461
- boost::wave::language_support language; // supported language/extensions
428
+ const boost::wave::language_support language; // supported language/extensions
462
429
preprocessing_hooks hooks; // hook policy instance
463
430
};
464
431
@@ -472,34 +439,45 @@ template<> inline bool boost::wave::impl::pp_iterator_functor<nbl::wave::context
472
439
473
440
// try to locate the given file, searching through the include path lists
474
441
std::string file_path (s);
475
- std::string dir_path;
476
442
477
443
// call the 'found_include_directive' hook function
478
444
if (ctx.get_hooks ().found_include_directive (ctx.derived (),f,include_next))
479
445
return true ; // client returned false: skip file to include
480
-
481
446
file_path = util::impl::unescape_lit (file_path);
482
- std::string native_path_str;
483
- if (!ctx.get_hooks ().locate_include_file (ctx, file_path, is_system, nullptr , dir_path, native_path_str))
447
+
448
+ std::optional<std::string> result;
449
+ auto * includeFinder = ctx.get_hooks ().m_includeFinder ;
450
+ if (includeFinder)
451
+ {
452
+ if (is_system)
453
+ result = includeFinder->getIncludeStandard (ctx.get_current_directory (),file_path);
454
+ else
455
+ result = includeFinder->getIncludeRelative (ctx.get_current_directory (),file_path);
456
+ }
457
+
458
+ if (!result)
484
459
{
460
+ ctx.get_hooks ().m_logger .log (" Pre-processor error: Bad include file.\n '%s' does not exist." , nbl::system::ILogger::ELL_ERROR, file_path.c_str ());
485
461
BOOST_WAVE_THROW_CTX (ctx, preprocess_exception, bad_include_file, file_path.c_str (), act_pos);
486
462
return false ;
487
463
}
488
464
489
- // test, if this file is known through a #pragma once directive
490
- {
491
- // the new include file determines the actual current directory
492
- ctx.set_current_directory (native_path_str.c_str ());
465
+ ctx.located_include_content = std::move (*result);
466
+ // the new include file determines the actual current directory
467
+ // TODO: the found file can be in a completely different place
468
+ nbl::system::path abs_path = ctx.get_current_directory ()/file_path;
469
+ ctx.set_current_directory (abs_path);
493
470
471
+ {
494
472
// preprocess the opened file
495
473
boost::shared_ptr<base_iteration_context_type> new_iter_ctx (
496
- new iteration_context_type (ctx, native_path_str. c_str (), act_pos,
474
+ new iteration_context_type (ctx,abs_path. string (). c_str (),act_pos,
497
475
boost::wave::enable_prefer_pp_numbers (ctx.get_language ()),
498
476
is_system ? base_iteration_context_type::system_header :
499
477
base_iteration_context_type::user_header));
500
478
501
479
// call the include policy trace function
502
- ctx.get_hooks ().opened_include_file (ctx.derived (), dir_path, file_path , is_system);
480
+ ctx.get_hooks ().opened_include_file (ctx.derived (), file_path, abs_path. string () , is_system);
503
481
504
482
// store current file position
505
483
iter_ctx->real_relative_filename = ctx.get_current_relative_filename ().c_str ();
@@ -516,12 +494,13 @@ template<> inline bool boost::wave::impl::pp_iterator_functor<nbl::wave::context
516
494
517
495
act_pos.set_file (iter_ctx->filename ); // initialize file position
518
496
519
- ctx.set_current_relative_filename (dir_path .c_str ());
520
- iter_ctx->real_relative_filename = dir_path .c_str ();
497
+ ctx.set_current_relative_filename (file_path .c_str ());
498
+ iter_ctx->real_relative_filename = file_path .c_str ();
521
499
522
500
act_pos.set_line (iter_ctx->line );
523
501
act_pos.set_column (0 );
524
502
}
503
+
525
504
return true ;
526
505
}
527
506
#endif
0 commit comments