mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Suggest DEF when undefined macros look like definitions
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "backtrace.hpp"
|
||||
#include "helpers.hpp"
|
||||
#include "linkdefs.hpp"
|
||||
#include "platform.hpp" // strncasecmp
|
||||
#include "verbosity.hpp"
|
||||
|
||||
#include "asm/lexer.hpp"
|
||||
@@ -381,6 +382,26 @@ bool fstk_RunInclude(std::string const &path, bool isQuiet) {
|
||||
return fstk_FileError(path, "INCLUDE");
|
||||
}
|
||||
|
||||
static char const *suggestDef(std::shared_ptr<MacroArgs> const macroArgs) {
|
||||
std::shared_ptr<std::string> arg = macroArgs->getArg(1);
|
||||
if (!arg) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
char const *str = arg->c_str();
|
||||
static char const *types[] = {"EQUS", "EQU", "RB", "RW", "RL", "="};
|
||||
for (size_t i = 0; i < std::size(types); ++i) {
|
||||
if (char const *type = types[i]; strncasecmp(str, type, strlen(type)) == 0) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
if (strncasecmp(str, "SET", literal_strlen("SET")) == 0) {
|
||||
return "=";
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void fstk_RunMacro(
|
||||
std::string const ¯oName, std::shared_ptr<MacroArgs> macroArgs, bool isQuiet
|
||||
) {
|
||||
@@ -389,6 +410,13 @@ void fstk_RunMacro(
|
||||
if (!macro) {
|
||||
if (sym_IsPurgedExact(macroName)) {
|
||||
error("Undefined macro `%s`; it was purged", macroName.c_str());
|
||||
} else if (char const *defType = suggestDef(macroArgs); defType) {
|
||||
error(
|
||||
"Undefined macro `%s` (did you mean \"DEF %s %s ...\"?)",
|
||||
macroName.c_str(),
|
||||
macroName.c_str(),
|
||||
defType
|
||||
);
|
||||
} else {
|
||||
error("Undefined macro `%s`", macroName.c_str());
|
||||
}
|
||||
|
||||
8
test/asm/suggest-def.asm
Normal file
8
test/asm/suggest-def.asm
Normal file
@@ -0,0 +1,8 @@
|
||||
section "test", rom0
|
||||
constant equ 1
|
||||
variable = 2
|
||||
variable set 3
|
||||
string equs "four"
|
||||
byte rb 1
|
||||
word rw 1
|
||||
long rl 1
|
||||
15
test/asm/suggest-def.err
Normal file
15
test/asm/suggest-def.err
Normal file
@@ -0,0 +1,15 @@
|
||||
error: Undefined macro `constant` (did you mean "DEF constant EQU ..."?)
|
||||
at suggest-def.asm(2)
|
||||
error: Undefined macro `variable` (did you mean "DEF variable = ..."?)
|
||||
at suggest-def.asm(3)
|
||||
error: Undefined macro `variable` (did you mean "DEF variable = ..."?)
|
||||
at suggest-def.asm(4)
|
||||
error: Undefined macro `string` (did you mean "DEF string EQUS ..."?)
|
||||
at suggest-def.asm(5)
|
||||
error: Undefined macro `byte` (did you mean "DEF byte RB ..."?)
|
||||
at suggest-def.asm(6)
|
||||
error: Undefined macro `word` (did you mean "DEF word RW ..."?)
|
||||
at suggest-def.asm(7)
|
||||
error: Undefined macro `long` (did you mean "DEF long RL ..."?)
|
||||
at suggest-def.asm(8)
|
||||
Assembly aborted with 7 errors!
|
||||
Reference in New Issue
Block a user