🐛 fix error report bug in import.cpp

This commit is contained in:
ValKmjolnir 2023-10-24 00:16:48 +08:00
parent f7f4a38b47
commit 9f7484596a
5 changed files with 21 additions and 13 deletions

View File

@ -8,6 +8,7 @@
#include <iostream>
#include <fstream>
#include <cstring>
#include <sstream>
#include <cmath>
// abbreviation of some useful basic type

View File

@ -198,8 +198,10 @@ code_block* linker::import_regular_file(call_expr* node) {
return new code_block({0, 0, 0, 0, filename});
}
if (check_self_import(filename)) {
err.err("link", "self-referenced module <" + filename + ">:\n" +
" reference path: " + generate_self_import_path(filename));
err.err("link",
"self-referenced module <" + filename + ">:\n" +
" reference path: " + generate_self_import_path(filename)
);
return new code_block({0, 0, 0, 0, filename});
}
exist(filename);
@ -208,16 +210,19 @@ code_block* linker::import_regular_file(call_expr* node) {
// start importing...
if (lex.scan(filename).geterr()) {
err.err("link", "error occurred when analysing <" + filename + ">");
return new code_block({0, 0, 0, 0, filename});
}
if (par.compile(lex).geterr()) {
err.err("link", "error occurred when analysing <" + filename + ">");
return new code_block({0, 0, 0, 0, filename});
}
auto tmp = par.swap(nullptr);
// check if tmp has 'import'
auto res = load(tmp, find(filename));
auto parse_result = par.swap(nullptr);
// check if parse result has 'import'
auto result = load(parse_result, find(filename));
module_load_stack.pop_back();
return res;
return result;
}
code_block* linker::import_nasal_lib() {
@ -239,16 +244,18 @@ code_block* linker::import_nasal_lib() {
err.err("link",
"error occurred when analysing library <" + filename + ">"
);
return new code_block({0, 0, 0, 0, filename});
}
if (par.compile(lex).geterr()) {
err.err("link",
"error occurred when analysing library <" + filename + ">"
);
return new code_block({0, 0, 0, 0, filename});
}
auto tmp = par.swap(nullptr);
// check if tmp has 'import'
return load(tmp, find(filename));
auto parse_result = par.swap(nullptr);
// check if library has 'import' (in fact it should not)
return load(parse_result, find(filename));
}
std::string linker::generate_module_name(const std::string& file_path) {