✨ add check for generated module name
This commit is contained in:
parent
d479f13a5c
commit
25e202fbaf
|
@ -139,12 +139,7 @@ void execute(
|
|||
gen.print(std::cout);
|
||||
}
|
||||
if (cmd&VM_SYMINFO) {
|
||||
for(const auto& domain : gen.get_experimental_namespace()) {
|
||||
std::cout << domain.first << ":\n";
|
||||
for(const auto& i : domain.second) {
|
||||
std::cout << " [" << domain.first << "]@" << i << "\n";
|
||||
}
|
||||
}
|
||||
gen.symbol_dump(std::cout);
|
||||
}
|
||||
|
||||
// run
|
||||
|
|
|
@ -1196,3 +1196,13 @@ void codegen::print(std::ostream& out) {
|
|||
out << " " << codestream(c,i) << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void codegen::symbol_dump(std::ostream& out) const {
|
||||
for(const auto& domain : experimental_namespace) {
|
||||
out << "<" << domain.first << ">\n";
|
||||
for(const auto& i : domain.second) {
|
||||
out << " " << i << ": 0x";
|
||||
out << std::hex << global.at(i) << std::dec << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,4 +108,5 @@ public:
|
|||
codegen(): fileindex(0) {}
|
||||
const error& compile(parse&, linker&);
|
||||
void print(std::ostream&);
|
||||
void symbol_dump(std::ostream&) const;
|
||||
};
|
||||
|
|
|
@ -95,6 +95,10 @@ void error::err(const std::string& stage, const std::string& info) {
|
|||
std::cerr << red << stage << ": " << white << info << reset << "\n\n";
|
||||
}
|
||||
|
||||
void error::warn(const std::string& stage, const std::string& info) {
|
||||
std::clog << orange << stage << ": " << white << info << reset << "\n\n";
|
||||
}
|
||||
|
||||
void error::err(
|
||||
const std::string& stage, const span& loc, const std::string& info) {
|
||||
// load error occurred file into string lines
|
||||
|
|
|
@ -53,6 +53,7 @@ public:
|
|||
error():cnt(0) {}
|
||||
void fatal(const std::string&, const std::string&);
|
||||
void err(const std::string&, const std::string&);
|
||||
void warn(const std::string&, const std::string&);
|
||||
void err(const std::string&, const span&, const std::string&);
|
||||
|
||||
void chkerr() const {
|
||||
|
|
|
@ -58,8 +58,8 @@ std::string linker::find_file(
|
|||
if (!show_path) {
|
||||
err.err("link",
|
||||
"in <" + location.file + ">: " +
|
||||
"cannot find file <" + filename + ">\n");
|
||||
err.err("link", "use <-d> to get detail search path");
|
||||
"cannot find file <" + filename + ">, " +
|
||||
"use <-d> to get detail search path");
|
||||
return "";
|
||||
}
|
||||
std::string paths = "";
|
||||
|
@ -215,10 +215,22 @@ std::string linker::generate_module_name(const std::string& filename) {
|
|||
if (split_pos==std::string::npos) {
|
||||
split_pos = filename.find_last_of("\\");
|
||||
}
|
||||
if (split_pos==std::string::npos) {
|
||||
return error_name;
|
||||
auto res = split_pos==std::string::npos?
|
||||
filename.substr(0, pos + 1):
|
||||
filename.substr(split_pos + 1, pos - split_pos);
|
||||
if (!res.length()) {
|
||||
err.warn("link", "get empty module name from <" + filename + ">, " +
|
||||
"will not be easily accessed.");
|
||||
}
|
||||
return filename.substr(split_pos + 1, pos - split_pos);
|
||||
if (res.length() && '0' <= res[0] && res[0] <= '9') {
|
||||
err.warn("link", "get module <" + res + "> from <" + filename + ">, " +
|
||||
"will not be easily accessed.");
|
||||
}
|
||||
if (res.length() && res.find(".")!=std::string::npos) {
|
||||
err.warn("link", "get module <" + res + "> from <" + filename + ">, " +
|
||||
"will not be easily accessed.");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
return_expr* linker::generate_module_return(code_block* block) {
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
import.std.file;
|
||||
import.std.sort;
|
||||
|
||||
if (size(arg)!=1) {
|
||||
println("need a key string to search files.");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
var needle = arg[0];
|
||||
|
||||
var do_flat = func(vec) {
|
||||
var flat = [];
|
||||
var bfs = [vec];
|
||||
while(size(bfs)) {
|
||||
var d = pop(bfs);
|
||||
foreach(var f;d.files) {
|
||||
if (ishash(f)) {
|
||||
append(bfs,f);
|
||||
continue;
|
||||
}
|
||||
append(flat, d.dir~"/"~f);
|
||||
}
|
||||
}
|
||||
sort.sort(flat, func(a,b){return cmp(a,b)<0});
|
||||
return flat;
|
||||
}
|
||||
|
||||
var count = 0;
|
||||
foreach(var f;do_flat(file.recursive_find_files("."))) {
|
||||
var pos = find(needle, f);
|
||||
if (pos == -1) {
|
||||
continue;
|
||||
}
|
||||
count += 1;
|
||||
var begin = substr(f, 0, pos);
|
||||
var end = pos+size(needle)>=size(f)? "":substr(f, pos+size(needle), size(f));
|
||||
println(begin, "\e[95;1m", needle, "\e[0m", end);
|
||||
}
|
||||
|
||||
println("\n", count, " result(s).");
|
Loading…
Reference in New Issue