Skip to content

Commit

Permalink
adding include tracking callback
Browse files Browse the repository at this point in the history
  • Loading branch information
X39 committed Sep 27, 2023
1 parent 4eebf1d commit ea17a9f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/parser/preprocessor/default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,9 @@ std::string sqf::parser::preprocessor::impl_default::instance::parse_ppinstructi
output.append(" \"");
output.append(file_context.path.physical);
output.append("\"\n");
if (m_file_included_callback) {
m_file_included_callback(otherfinfo, file_context);
}
return output;
}
catch (const std::runtime_error &ex) {
Expand Down Expand Up @@ -1477,6 +1480,7 @@ std::optional<std::string> sqf::parser::preprocessor::impl_default::preprocess(
fileinfo.content = view;
instance i(this, get_logger(), m_macros);
i.m_macro_resolved_callback = m_macro_resolved_callback;
i.m_file_included_callback = m_file_included_callback;
auto res = i.parse_file(runtime, fileinfo);
if (out_included) {
for (const auto &entry: i.m_visited) {
Expand Down
6 changes: 6 additions & 0 deletions src/parser/preprocessor/default.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace sqf::parser::preprocessor {
&m,
const std::unordered_map<std::string, std::string> &param_map
)> m_macro_resolved_callback;
std::function<void(context & included_fileinfo, context & source_fileinfo)> m_file_included_callback;
struct condition_scope {
bool allow_write{};
::sqf::runtime::diagnostics::diag_info info_if;
Expand All @@ -62,6 +63,7 @@ namespace sqf::parser::preprocessor {
&m,
const std::unordered_map<std::string, std::string> &param_map
)> m_macro_resolved_callback;
std::function<void(context & included_fileinfo, context & source_fileinfo)> m_file_included_callback;

instance(
impl_default *owner,
Expand Down Expand Up @@ -177,6 +179,10 @@ namespace sqf::parser::preprocessor {
assert(m_pragmas.find(std::string(name.begin(), name.end())) != m_pragmas.end());
};

void file_included(std::function<void(context & included_fileinfo, context & source_fileinfo)> callback) {
m_file_included_callback = std::move(callback);
}

void macro_resolved(std::function<void(
macro_resolved_data orig_start,
macro_resolved_data orig_end,
Expand Down

0 comments on commit ea17a9f

Please sign in to comment.