Skip to content

Commit b717c7f

Browse files
committed
added do-preprocess to the debugger
1 parent a741a9a commit b717c7f

File tree

5 files changed

+79
-1
lines changed

5 files changed

+79
-1
lines changed

docs/Debugger/README.MD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [set-breakpoint](set-breakpoint.md)
77
* [parse-sqf](parse-sqf.md)
88
* [load-sqf](load-sqf.md)
9+
* [do-preprocess](do-preprocess.md)
910

1011
# Server-Modes
1112
* [callstack](get-callstack.md)
@@ -14,3 +15,4 @@
1415
* [status](get-status.md)
1516
* [variables](get-variables.md)
1617
* [position](position.md)
18+
* [preprocess](do-preprocess.md)

docs/Debugger/do-preprocess.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Request Schema
2+
{
3+
"mode": "do-preprocess",
4+
"data": { "path": "string", "content": "string" }
5+
}
6+
* **mode** - `do-preprocess` - always set, tells the receiving end that this is a do-preprocess action in the `data` field
7+
* **data** - `STRING` - always set, contains either the `path` to an existing file or a `content` field. If both are provided, path takes priority.
8+
## Response Schema
9+
{
10+
"mode": "preprocess",
11+
"data": "string"
12+
}
13+
* **mode** - `preprocess` - always set, tells the receiving end that this is a preprocess-string in the `data` field
14+
* **data** - `STRING` - always set, contains the preprocessed data from the server.
15+
16+
Tells the server to preprocess a file or contents.

src/debugger.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "value.h"
99
#include "instruction.h"
1010
#include "fileio.h"
11+
#include "parsepreprocessor.h"
1112
#include <sstream>
1213

1314
namespace {
@@ -257,6 +258,62 @@ void sqf::debugger::check(virtualmachine * vm)
257258
auto data = json["data"];
258259
_server->push_message(variablemsg(vm, vm->stack(), data));
259260
}
261+
else if (mode == "preprocess")
262+
{
263+
auto data = json["data"];
264+
auto res = data.find("path");
265+
if (res != data.end())
266+
{
267+
std::string path = *res;
268+
path = vm->get_filesystem().sanitize(path);
269+
auto phys = vm->get_filesystem().try_get_physical_path(path);
270+
if (phys.has_value())
271+
{
272+
auto filecontents = load_file(phys.value());
273+
bool errflag = false;
274+
auto ppres = sqf::parse::preprocessor::parse(vm, filecontents, errflag, path);
275+
if (errflag)
276+
{
277+
auto err = vm->err().str();
278+
vm->err_clear();
279+
_server->push_message(errormsg(err));
280+
}
281+
else
282+
{
283+
nlohmann::json json = {
284+
{ "mode", "message" },
285+
{ "data", ppres }
286+
};
287+
_server->push_message(json.dump());
288+
}
289+
}
290+
else
291+
{
292+
_server->push_message(errormsg("Path not found."));
293+
}
294+
}
295+
else
296+
{
297+
std::string content = data["content"];
298+
auto filecontents = load_file(content);
299+
bool errflag = false;
300+
auto ppres = sqf::parse::preprocessor::parse(vm, filecontents, errflag, "__debugger.sqf");
301+
if (errflag)
302+
{
303+
auto err = vm->err().str();
304+
vm->err_clear();
305+
_server->push_message(errormsg(err));
306+
}
307+
else
308+
{
309+
nlohmann::json json = {
310+
{ "mode", "message" },
311+
{ "data", ppres }
312+
};
313+
_server->push_message(json.dump());
314+
}
315+
}
316+
}
260317
else if (mode == "parse-sqf")
261318
{
262319
auto data = json["data"];

src/parsepreprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ namespace {
696696
sstream << "#line 0" << std::endl;
697697
sstream << parse_file(h, otherfinfo) << std::endl;
698698
sstream << "#file " << fileinfo.path << std::endl;
699-
sstream << "#line " << fileinfo.line << std::endl;
699+
sstream << "#line " << fileinfo.line - 1 << std::endl;
700700
return sstream.str();
701701
}
702702
else if (inst == "DEFINE")

src/virtualmachine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,13 @@ namespace sqf
7575
std::stringstream& wrn() { /* on purpose */static_cast<virtualmachine*>(this)->mwrnflag = true; return mwrn_buff; }
7676
void out(std::basic_ostream<char, std::char_traits<char>>* strm) { mout = strm; }
7777
void out_buffprint() { (*mout) << mout_buff.str(); mout_buff.str(std::string()); }
78+
void out_clear() { mout_buff.str(""); moutflag = false; }
7879
void err(std::basic_ostream<char, std::char_traits<char>>* strm) { merr = strm; }
7980
void err_buffprint() { (*merr) << merr_buff.str(); merr_buff.str(std::string()); }
81+
void err_clear() { merr_buff.str(""); merrflag = false; }
8082
void wrn(std::basic_ostream<char, std::char_traits<char>>* strm) { mwrn = strm; }
8183
void wrn_buffprint() { (*mwrn) << mwrn_buff.str(); mwrn_buff.str(std::string()); }
84+
void wrn_clear() { mwrn_buff.str(""); mwrnflag = false; }
8285
virtualmachine() : virtualmachine(0) {};
8386
virtualmachine(unsigned long long maxinst);
8487
void execute();

0 commit comments

Comments
 (0)