Skip to content

Commit

Permalink
adding additional data to macro_resolved callback
Browse files Browse the repository at this point in the history
  • Loading branch information
X39 committed Aug 28, 2023
1 parent c54b4cf commit 92e9fc5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 30 deletions.
24 changes: 20 additions & 4 deletions src/parser/preprocessor/default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,11 @@ std::string sqf::parser::preprocessor::impl_default::instance::parse_file(
if (m.has_value()) {
file_context.move_back();
assert(file_context.file_offset >= word.length());
auto macro_offset_start = file_context.file_offset - word.length();
macro_resolved_data macro_offset_start {
file_context.line,
file_context.col - word.length(),
file_context.file_offset - word.length(),
};
std::vector<const ::sqf::runtime::parser::macro *> macro_stack;
auto res = handle_macro(
runtime,
Expand All @@ -1210,7 +1214,11 @@ std::string sqf::parser::preprocessor::impl_default::instance::parse_file(
if (m_errflag) {
return res;
}
auto macro_offset_end = file_context.file_offset;
macro_resolved_data macro_offset_end {
file_context.line,
file_context.col - word.length(),
file_context.file_offset - word.length(),
};
auto replacement_offset_start = sstream.tellp();
sstream << res;
auto replacement_offset_end = sstream.tellp();
Expand Down Expand Up @@ -1314,13 +1322,21 @@ std::string sqf::parser::preprocessor::impl_default::instance::parse_file(
if (m.has_value()) {
file_context.move_back();
assert(file_context.file_offset >= word.length());
auto macro_offset_start = file_context.file_offset - word.length();
macro_resolved_data macro_offset_start {
file_context.line,
file_context.col - word.length(),
file_context.file_offset - word.length(),
};
std::vector<const ::sqf::runtime::parser::macro *> macro_stack;
auto res = handle_macro(runtime, file_context, file_context, m.value(), empty_parammap, macro_stack);
if (m_errflag) {
return res;
}
auto macro_offset_end = file_context.file_offset;
macro_resolved_data macro_offset_end {
file_context.line,
file_context.col - word.length(),
file_context.file_offset - word.length(),
};
auto replacement_offset_start = sstream.tellp();
sstream << res;
auto replacement_offset_end = sstream.tellp();
Expand Down
59 changes: 33 additions & 26 deletions src/parser/preprocessor/default.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,27 @@

namespace sqf::parser::preprocessor {
class impl_default : public ::sqf::runtime::parser::preprocessor, public CanLog {
public:
struct macro_resolved_data {
size_t line;
size_t column;
size_t offset;
};

private:
std::unordered_map<std::string, ::sqf::runtime::parser::macro> m_macros;
std::unordered_map<std::string, ::sqf::runtime::parser::pragma> m_pragmas;
std::function<void(
size_t orig_start,
size_t orig_end,
macro_resolved_data orig_start,
macro_resolved_data orig_end,
size_t pp_start,
size_t pp_end,
::sqf::runtime::runtime & runtime,
context & local_fileinfo,
context & original_fileinfo,
const ::sqf::runtime::parser::macro
&m,
const std::unordered_map<std::string, std::string> &param_map
::sqf::runtime::runtime &runtime,
context &local_fileinfo,
context &original_fileinfo,
const ::sqf::runtime::parser::macro
&m,
const std::unordered_map<std::string, std::string> &param_map
)> m_macro_resolved_callback;
struct condition_scope {
bool allow_write{};
Expand All @@ -45,16 +51,16 @@ namespace sqf::parser::preprocessor {
class instance : public CanLog {
public:
std::function<void(
size_t orig_start,
size_t orig_end,
macro_resolved_data orig_start,
macro_resolved_data orig_end,
size_t pp_start,
size_t pp_end,
::sqf::runtime::runtime & runtime,
context & local_fileinfo,
context & original_fileinfo,
const ::sqf::runtime::parser::macro
&m,
const std::unordered_map<std::string, std::string> &param_map
::sqf::runtime::runtime &runtime,
context &local_fileinfo,
context &original_fileinfo,
const ::sqf::runtime::parser::macro
&m,
const std::unordered_map<std::string, std::string> &param_map
)> m_macro_resolved_callback;

instance(
Expand Down Expand Up @@ -147,6 +153,7 @@ namespace sqf::parser::preprocessor {
};

public:

explicit impl_default(Logger &logger);

std::optional<std::string> preprocess(
Expand All @@ -170,16 +177,16 @@ namespace sqf::parser::preprocessor {
assert(m_pragmas.find(std::string(name.begin(), name.end())) != m_pragmas.end());
};

void macro_resolved(std::function< void(
size_t orig_start,
size_t orig_end,
size_t pp_start,
size_t pp_end,
::sqf::runtime::runtime &runtime,
context &local_fileinfo,
context &original_fileinfo,
const ::sqf::runtime::parser::macro &m,
const std::unordered_map<std::string, std::string> &param_map)
void macro_resolved(std::function<void(
macro_resolved_data orig_start,
macro_resolved_data orig_end,
size_t pp_start,
size_t pp_end,
::sqf::runtime::runtime &runtime,
context &local_fileinfo,
context &original_fileinfo,
const ::sqf::runtime::parser::macro &m,
const std::unordered_map<std::string, std::string> &param_map)

> callback) {
m_macro_resolved_callback = std::move(callback);
Expand Down

0 comments on commit 92e9fc5

Please sign in to comment.