@@ -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_file_or_builtin_to_string
25
+ struct load_to_string
26
26
{
27
27
template <typename IterContextT>
28
28
class inner
@@ -33,26 +33,23 @@ struct load_file_or_builtin_to_string
33
33
{
34
34
using iterator_type = typename IterContextT::iterator_type;
35
35
36
- std::string filepath (iter_ctx.filename .begin (), iter_ctx.filename .end ());
36
+ std::string filepath (iter_ctx.filename .begin (),iter_ctx.filename .end ());
37
37
const auto inclFinder = iter_ctx.ctx .get_hooks ().m_includeFinder ;
38
38
assert (inclFinder);
39
39
40
40
std::optional<std::string> result;
41
41
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);
44
44
else // regular #include "..."
45
- result = inclFinder->getIncludeRelative (requestingSourceDir, filepath);
45
+ result = inclFinder->getIncludeRelative (requestingSourceDir,filepath);
46
46
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 " ;
52
51
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);
56
53
iter_ctx.last = iterator_type ();
57
54
}
58
55
@@ -62,9 +59,9 @@ struct load_file_or_builtin_to_string
62
59
};
63
60
64
61
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
66
63
{
67
- custom_preprocessing_hooks (const IShaderCompiler::SPreprocessorOptions& _preprocessOptions)
64
+ preprocessing_hooks (const IShaderCompiler::SPreprocessorOptions& _preprocessOptions)
68
65
: m_includeFinder(_preprocessOptions.includeFinder), m_logger(_preprocessOptions.logger), m_pragmaStage(IShader::ESS_UNKNOWN) {}
69
66
70
67
const IShaderCompiler::CIncludeFinder* m_includeFinder;
@@ -75,22 +72,26 @@ struct custom_preprocessing_hooks : public boost::wave::context_policies::defaul
75
72
template <typename ContextT>
76
73
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)
77
74
{
75
+ assert (current_name==nullptr );
78
76
if (!m_includeFinder)
79
77
return false ;
80
78
81
79
dir_path = ctx.get_current_directory ().string ();
82
80
std::optional<std::string> result;
83
- if (is_system) {
81
+ if (is_system)
82
+ {
84
83
result = m_includeFinder->getIncludeStandard (dir_path, file_path);
85
84
dir_path = " " ;
86
85
}
87
86
else
88
87
result = m_includeFinder->getIncludeRelative (dir_path, file_path);
88
+
89
89
if (!result)
90
90
{
91
91
m_logger.log (" Pre-processor error: Bad include file.\n '%s' does not exist." , nbl::system::ILogger::ELL_ERROR, file_path.c_str ());
92
92
return false ;
93
93
}
94
+ // TODO:
94
95
native_name = file_path;
95
96
return true ;
96
97
}
@@ -157,7 +158,7 @@ class include_paths
157
158
typedef include_list_type::value_type include_value_type;
158
159
159
160
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() {}
161
162
162
163
bool add_include_path (char const * path_, bool is_system = false )
163
164
{
@@ -178,8 +179,6 @@ class include_paths
178
179
namespace fs = nbl::system;
179
180
fs::path filepath (path_);
180
181
fs::path filename = current_dir.is_absolute () ? filepath : (current_dir / filepath);
181
- current_rel_dir.clear ();
182
- current_rel_dir = filepath.parent_path ();
183
182
current_dir = filename.parent_path ();
184
183
}
185
184
@@ -193,22 +192,16 @@ class include_paths
193
192
include_list_type system_include_paths;
194
193
bool was_sys_include_path; // saw a set_sys_include_delimiter()
195
194
system::path current_dir;
196
- system::path current_rel_dir;
197
195
};
198
196
199
197
template <
200
198
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<>>
205
200
>
206
201
class context : private boost ::noncopyable
207
202
{
208
203
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;
212
205
213
206
public:
214
207
// public typedefs
@@ -219,14 +212,12 @@ class context : private boost::noncopyable
219
212
typedef LexIteratorT lexer_type;
220
213
typedef pp_iterator<context> iterator_type;
221
214
222
- typedef InputPolicyT input_policy_type ;
215
+ using input_policy_type = load_to_string ;
223
216
typedef typename token_type::position_type position_type;
224
217
225
218
// type of a token sequence
226
219
typedef std::list<token_type, boost::fast_pool_allocator<token_type> >
227
220
token_sequence_type;
228
- // type of the policies
229
- typedef HooksT hook_policy_type;
230
221
231
222
private:
232
223
// stack of shared_ptr's to the pending iteration contexts
@@ -239,8 +230,7 @@ class context : private boost::noncopyable
239
230
context* this_ () { return this ; } // avoid warning in constructor
240
231
241
232
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_)
244
234
: first(first_), last(last_), filename(fname)
245
235
, has_been_initialized(false )
246
236
, current_relative_filename(fname)
@@ -397,8 +387,8 @@ class context : private boost::noncopyable
397
387
}
398
388
399
389
// 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; }
402
392
403
393
// return type of actually used context type (might be the derived type)
404
394
actual_context_type& derived ()
@@ -536,30 +526,29 @@ class context : private boost::noncopyable
536
526
iteration_context_stack_type iter_ctxs; // iteration contexts
537
527
macromap_type macros; // map of defined macros
538
528
boost::wave::language_support language; // supported language/extensions
539
- hook_policy_type hooks; // hook policy instance
529
+ preprocessing_hooks hooks; // hook policy instance
540
530
};
541
531
542
532
}
543
533
544
534
545
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)
546
536
{
537
+ assert (!include_next);
547
538
namespace fs = boost::filesystem;
548
539
549
540
// try to locate the given file, searching through the include path lists
550
541
std::string file_path (s);
551
542
std::string dir_path;
552
- char const * current_name = 0 ; // never try to match current file name
553
543
554
544
// 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))
556
546
return true ; // client returned false: skip file to include
557
547
558
548
file_path = util::impl::unescape_lit (file_path);
559
549
std::string native_path_str;
560
550
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))
563
552
{
564
553
BOOST_WAVE_THROW_CTX (ctx, preprocess_exception, bad_include_file,
565
554
file_path.c_str (), act_pos);
0 commit comments