Skip to content

Commit daea09e

Browse files
now I've managed to make this significantly less complicated!
1 parent ac21de5 commit daea09e

File tree

1 file changed

+26
-49
lines changed

1 file changed

+26
-49
lines changed

src/nbl/asset/utils/waveContext.h

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,9 @@ struct load_to_string final
3131
template <typename PositionT>
3232
static void init_iterators(IterContextT& iter_ctx, PositionT const& act_pos, boost::wave::language_support language)
3333
{
34-
using iterator_type = typename IterContextT::iterator_type;
35-
36-
std::string filepath(iter_ctx.filename.begin(),iter_ctx.filename.end());
37-
const auto inclFinder = iter_ctx.ctx.get_hooks().m_includeFinder;
38-
assert(inclFinder);
39-
40-
std::optional<std::string> result;
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);
44-
else // regular #include "..."
45-
result = inclFinder->getIncludeRelative(requestingSourceDir,filepath);
46-
47-
// If located then must be possible to open!
48-
assert(result);
49-
iter_ctx.instring = *result;
34+
iter_ctx.instring = iter_ctx.ctx.get_located_include_content();
5035

36+
using iterator_type = IterContextT::iterator_type;
5137
iter_ctx.first = iterator_type(iter_ctx.instring.begin(),iter_ctx.instring.end(),PositionT(iter_ctx.filename),language);
5238
iter_ctx.last = iterator_type();
5339
}
@@ -83,6 +69,7 @@ struct preprocessing_hooks final : public boost::wave::context_policies::default
8369
m_logger.log("Pre-processor error: Bad include file.\n'%s' does not exist.", nbl::system::ILogger::ELL_ERROR, file_path.c_str());
8470
return false;
8571
}
72+
ctx.set_located_include_content(std::move(*result));
8673
// TODO:
8774
native_name = file_path;
8875
return true;
@@ -149,29 +136,6 @@ struct preprocessing_hooks final : public boost::wave::context_policies::default
149136
IShader::E_SHADER_STAGE m_pragmaStage;
150137
};
151138

152-
class include_paths final
153-
{
154-
public:
155-
inline include_paths() : current_dir() {}
156-
157-
// Nabla Additions Start
158-
system::path get_current_directory() const
159-
{
160-
return current_dir;
161-
}
162-
void set_current_directory(char const* path_)
163-
{
164-
namespace fs = nbl::system;
165-
fs::path filepath(path_);
166-
fs::path filename = current_dir.is_absolute() ? filepath : (current_dir / filepath);
167-
current_dir = filename.parent_path();
168-
}
169-
// Nabla Additions End
170-
171-
private:
172-
system::path current_dir;
173-
};
174-
175139
class context : private boost::noncopyable
176140
{
177141
private:
@@ -364,10 +328,24 @@ class context : private boost::noncopyable
364328
}
365329

366330
// Nabla Additions Start
367-
// return the directory of the currently preprocessed file
368331
system::path get_current_directory() const
369332
{
370-
return includes.get_current_directory();
333+
return current_dir;
334+
}
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)
343+
{
344+
located_include_content = std::move(content);
345+
}
346+
const core::string& get_located_include_content() const
347+
{
348+
return located_include_content;
371349
}
372350
// Nabla Additions End
373351

@@ -385,7 +363,7 @@ class context : private boost::noncopyable
385363
return;
386364

387365
nbl::system::path fpath(filename);
388-
includes.set_current_directory(fpath.string().c_str());
366+
set_current_directory(fpath.string().c_str());
389367
has_been_initialized = true; // execute once
390368
}
391369

@@ -395,12 +373,6 @@ class context : private boost::noncopyable
395373
return macros.is_defined(begin, end);
396374
}
397375

398-
// maintain include paths (helper functions)
399-
void set_current_directory(char const* path_)
400-
{
401-
includes.set_current_directory(path_);
402-
}
403-
404376
// conditional compilation contexts
405377
bool get_if_block_status() const { return ifblocks.get_status(); }
406378
bool get_if_block_some_part_status() const
@@ -477,8 +449,13 @@ class context : private boost::noncopyable
477449
bool has_been_initialized; // set cwd once
478450
std::string current_relative_filename; // real relative name of current preprocessed file
479451

452+
// Nabla Additions Start
453+
// these are temporaries!
454+
system::path current_dir;
455+
core::string located_include_content;
456+
// Nabla Additions End
457+
480458
boost::wave::util::if_block_stack ifblocks; // conditional compilation contexts
481-
include_paths includes; // lists of include directories to search
482459
iteration_context_stack_type iter_ctxs; // iteration contexts
483460
macromap_type macros; // map of defined macros
484461
boost::wave::language_support language; // supported language/extensions

0 commit comments

Comments
 (0)