Skip to content

Commit

Permalink
fix(vscode): some more CONST_ASSERT issues
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyV99 authored and connorjclark committed Aug 6, 2023
1 parent db0bc50 commit d5d3c1d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 20 deletions.
23 changes: 16 additions & 7 deletions src/parser/CompileError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,20 +291,29 @@ string CompileError::toString() const
return oss.str();
}

void CompileError::print() const
BasicCompileError::BasicCompileError(CompileError const& err)
{
if(isStrict())
zconsole_error("%s",toString().c_str());
errmsg = err.toString();
id = *(err.getId());
strict = err.isStrict();
}
void BasicCompileError::print() const
{
std::string s = errmsg;
char const* ptr = s.c_str();
while(ptr[0]==' '||ptr[0]=='\r'||ptr[0]=='\n') ++ptr;
if(strict)
zconsole_error("%s",ptr);
else
zconsole_warn("%s",toString().c_str());
zconsole_warn("%s",ptr);
}
extern bool zscript_error_out;
extern uint32_t zscript_failcode;
void CompileError::handle() const
void BasicCompileError::handle() const
{
print();
if(!zscript_failcode && isStrict())
zscript_failcode = *getId();
if(!zscript_failcode && strict)
zscript_failcode = id;
zscript_error_out = true;
}

Expand Down
14 changes: 11 additions & 3 deletions src/parser/CompileError.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,23 @@ namespace ZScript
// Get if strict (an error), or not (a warning).
bool isStrict() const;
std::string toString() const;
void print() const;
void handle() const;

private:
CompileError(Impl*);

Impl* pimpl_;
};


class BasicCompileError
{
public:
std::string errmsg;
bool strict;
CompileError::Id id;
BasicCompileError(CompileError const& err);
void print() const;
void handle() const;
};
void log_error(CompileError const&);
void logDebugMessage(const char* msg);

Expand Down
17 changes: 12 additions & 5 deletions src/parser/ScriptParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ void ScriptParser::initialize()
extern uint32_t zscript_failcode;
extern bool zscript_error_out;
extern bool delay_asserts, ignore_asserts;
vector<ZScript::CompileError> casserts;
unique_ptr<ScriptsData> ZScript::compile(string const& filename)
vector<ZScript::BasicCompileError> casserts;
static unique_ptr<ScriptsData> _compile_helper(string const& filename)
{
using namespace ZScript;
zscript_failcode = 0;
zscript_error_out = false;
ScriptParser::initialize();
Expand Down Expand Up @@ -121,9 +122,7 @@ unique_ptr<ScriptsData> ZScript::compile(string const& filename)
ScriptParser::assemble(id.get());

unique_ptr<ScriptsData> result(new ScriptsData(program));
if(!ignore_asserts)
for(CompileError const& error : casserts)
error.handle();
if(!ignore_asserts && casserts.size()) return nullptr;
if(zscript_error_out) return nullptr;

zconsole_info("%s", "Success!");
Expand Down Expand Up @@ -153,6 +152,14 @@ unique_ptr<ScriptsData> ZScript::compile(string const& filename)
}
#endif
}
unique_ptr<ScriptsData> ZScript::compile(string const& filename)
{
auto ret = _compile_helper(filename);
if(!ignore_asserts)
for(BasicCompileError const& error : casserts)
error.handle();
return ret;
}

int32_t ScriptParser::vid = 0;
int32_t ScriptParser::fid = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/parser/SemanticAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ void SemanticAnalyzer::caseImportCondDecl(ASTImportCondDecl& host, void* param)
RecursiveVisitor::caseImportCondDecl(host, param);
}

extern vector<CompileError> casserts;
extern vector<BasicCompileError> casserts;
extern bool delay_asserts;
void SemanticAnalyzer::caseAssert(ASTAssert& host, void* param)
{
Expand All @@ -1108,7 +1108,7 @@ void SemanticAnalyzer::caseAssert(ASTAssert& host, void* param)
? CompileError::AssertFail(&host, str->getValue().c_str())
: CompileError::AssertFail(&host, "");
if(delay_asserts)
casserts.push_back(cassert);
casserts.emplace_back(cassert);
else handleError(cassert);
}
}
Expand Down
6 changes: 3 additions & 3 deletions vscode-extension/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ async function processScript(textDocument: TextDocument): Promise<void> {
});
}

const tmpInput = `${globalTmpDir}/tmp2.zs`;
const tmpScript = `${globalTmpDir}/tmp.zs`;
const tmpInput = cleanupFile(`${globalTmpDir}/tmp2.zs`);
const tmpScript = cleanupFile(`${globalTmpDir}/tmp.zs`);
includeText += `#include "${tmpScript}"\n`;
let stdout = '';
let success = false;
Expand All @@ -191,8 +191,8 @@ async function processScript(textDocument: TextDocument): Promise<void> {
try {
const args = [
'-unlinked',
'-delay_cassert',
'-input', tmpInput,
'-delay_cassert'
];
if (settings.ignoreConstAssert)
args.push('-ignore_cassert');
Expand Down

0 comments on commit d5d3c1d

Please sign in to comment.