Skip to content

Commit

Permalink
Implemented #49 Missing __LINE__ and __FILE__ macros
Browse files Browse the repository at this point in the history
  • Loading branch information
X39 committed Mar 28, 2019
1 parent 23014a6 commit 7c67eed
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/parsepreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ namespace {
size_t line;
size_t column;
bool hasargs;
// Special method pointer that may be filled
// to give this macro a special behavior rather
// then a content.
// Gets only applied if pointer is != nullptr
std::string(*callback)(finfo fileinfo, std::vector<std::string> params) = nullptr;
};
class helper
{
Expand Down Expand Up @@ -336,6 +341,10 @@ namespace {
}
return "";
}
if (m.callback)
{
return m.callback(fileinfo, params);
}
std::stringstream sstream;
std::string actual_content = m.content;
bool stringify_required = false;
Expand Down Expand Up @@ -1101,10 +1110,40 @@ namespace {
}

}
std::string line_macro_callback(finfo fileinfo, std::vector<std::string> params)
{
return std::to_string(fileinfo.line);
}
std::string file_macro_callback(finfo fileinfo, std::vector<std::string> params)
{
return '"' + fileinfo.path + '"';
}
std::string sqf::parse::preprocessor::parse(sqf::virtualmachine* vm, std::string input, bool & errflag, std::string filename)
{
helper h;
h.vm = vm;
{
macro line_macro;
line_macro.line = 0;
line_macro.column = 0;
line_macro.content = "";
line_macro.filepath = "";
line_macro.hasargs = false;
line_macro.name = "__LINE__";
line_macro.callback = line_macro_callback;
h.macros.push_back(line_macro);
}
{
macro file_macro;
file_macro.line = 0;
file_macro.column = 0;
file_macro.content = "";
file_macro.filepath = "";
file_macro.hasargs = false;
file_macro.name = "__FILE__";
file_macro.callback = file_macro_callback;
h.macros.push_back(file_macro);
}
finfo fileinfo;
fileinfo.content = input;
fileinfo.path = filename;
Expand Down

0 comments on commit 7c67eed

Please sign in to comment.