Skip to content

Commit

Permalink
fix dev function calls and hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
ate47 committed Jun 18, 2024
1 parent f61420a commit 3b3b2f5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
5 changes: 4 additions & 1 deletion config/common_hashes/path.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6551,4 +6551,7 @@ scripts/core_common/stealth/debug.gsc
scripts/core_common/stealth/threat_sight.gsc
scripts/core_common/stealth/utility.gsc
leaderboards/mp_leaderboards_reset.csv
gamedata/tables/common/countrytable.csv
gamedata/tables/common/countrytable.csv
scripts/core_common/encounters/wave_manager.gsc
scripts/core_common/ai/systems/ai_interactables.gsc
scripts/core_common/ai/systems/ai_interactables.csc
32 changes: 20 additions & 12 deletions src/acts/compiler/gsc_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,7 @@ namespace acts::compiler {

class CompileObject {
public:
size_t devBlockDepth;
GscCompilerOption& opt;
InputInfo& info;
GscFileType type;
Expand Down Expand Up @@ -1248,16 +1249,16 @@ namespace acts::compiler {
}

void AddHash(const std::string& str) {
hashes.insert(str);
const char* strc{ str.c_str() };
if (!hash::HashPattern(strc)) {
hashes.insert(str);
hashutils::Add(strc);
}
}

void AddHash(const char* str) {
hashes.insert(str);
if (!hash::HashPattern(str)) {
hashes.insert(str);
hashutils::Add(str);
}
}
Expand Down Expand Up @@ -1384,7 +1385,7 @@ namespace acts::compiler {
return true;
}
default:
info.PrintLineMessage(alogs::LVL_ERROR, hashNode, "Not a hash expression, only strings or hash node available");
info.PrintLineMessage(alogs::LVL_ERROR, hashNode, "Not a hash expression, only string or hash node available");
return false;
}
}
Expand Down Expand Up @@ -1824,6 +1825,11 @@ namespace acts::compiler {
// link by the game, but we write it for test
Located located{ funcNspHash, funcHash };

if (devBlockDepth) {
// dev call
importFlags |= tool::gsc::T8GSCImportFlags::DEV_CALL;
}

auto& impList = imports[located];

auto it = std::find_if(impList.begin(), impList.end(), [importFlags](const auto& e) { return e.flags == importFlags; });
Expand Down Expand Up @@ -2811,13 +2817,15 @@ namespace acts::compiler {
AscmNode* djmp = new AscmNodeJump(endBlock, OPCODE_DevblockBegin);
obj.m_devBlocks.push_back(djmp);
fobj.AddNode(rule->children[0], djmp);
obj.devBlockDepth++;
for (size_t i = 1; i < rule->children.size() - 1; i++) {
ParseTree* stmt = rule->children[i];

if (!ParseExpressionNode(stmt, parser, obj, fobj, false)) {
ok = false;
}
}
obj.devBlockDepth--;
fobj.AddNode(rule->children[rule->children.size() - 1], endBlock);
return ok;
}
Expand Down Expand Up @@ -4081,7 +4089,7 @@ namespace acts::compiler {
return false;
}

bool ParseFunction(RuleContext* func, gscParser& parser, CompileObject& obj, bool devFunction) {
bool ParseFunction(RuleContext* func, gscParser& parser, CompileObject& obj) {
bool hasName = func->children.size() > 4 && IS_IDF(func->children[(size_t)(func->children.size() - 5)]);

auto* paramsRule = func->children[(size_t)(func->children.size() - 3)];
Expand Down Expand Up @@ -4330,7 +4338,7 @@ namespace acts::compiler {

exp.PopBreakNode();

if (devFunction) {
if (obj.devBlockDepth) {
// add a dev block from start to begin
AscmNode* djmp = new AscmNodeJump(endNode, OPCODE_DevblockBegin);
obj.m_devBlocks.push_back(djmp);
Expand Down Expand Up @@ -4449,7 +4457,7 @@ namespace acts::compiler {
}
}

size_t devBlockDepth{};
obj.devBlockDepth = 0;
for (auto& es : prog->children) {
if (es == eof) {
break; // done
Expand All @@ -4459,15 +4467,15 @@ namespace acts::compiler {
std::string txt{ es->getText() };

if (txt == "/#") {
devBlockDepth++;
obj.devBlockDepth++;
}
else if (txt == "#/") {
if (!devBlockDepth) {
if (!obj.devBlockDepth) {
obj.info.PrintLineMessage(alogs::LVL_ERROR, es, "Usage of #/ with no starting /#");
return false;
}
else {
devBlockDepth--;
obj.devBlockDepth--;
}
}
else {
Expand Down Expand Up @@ -4497,7 +4505,7 @@ namespace acts::compiler {
}
break;
case gscParser::RuleFunction:
if (!ParseFunction(rule, parser, obj, devBlockDepth > 0)) {
if (!ParseFunction(rule, parser, obj)) {
return false;
}
break;
Expand All @@ -4507,8 +4515,8 @@ namespace acts::compiler {
}
}

if (devBlockDepth > 0) {
obj.info.PrintLineMessage(alogs::LVL_ERROR, prog, std::format("Missing {} #/", devBlockDepth));
if (obj.devBlockDepth > 0) {
obj.info.PrintLineMessage(alogs::LVL_ERROR, prog, std::format("Missing {} #/", obj.devBlockDepth));
return false;
}

Expand Down

0 comments on commit 3b3b2f5

Please sign in to comment.