Implement ? suffix to "quiet" a context and exclude it from backtraces (#1800)

This commit is contained in:
Rangi
2025-08-18 21:34:58 -04:00
committed by GitHub
parent 77a105e189
commit b7e0783ae7
32 changed files with 392 additions and 139 deletions

View File

@@ -24,6 +24,7 @@ struct FileStackNode {
std::string // NODE_FILE, NODE_MACRO
>
data;
bool isQuiet; // Whether to omit this node from error reporting
std::shared_ptr<FileStackNode> parent; // Pointer to parent node, for error reporting
// Line at which the parent context was exited
@@ -40,8 +41,12 @@ struct FileStackNode {
std::string &name() { return std::get<std::string>(data); }
std::string const &name() const { return std::get<std::string>(data); }
FileStackNode(FileStackNodeType type_, std::variant<std::vector<uint32_t>, std::string> data_)
: type(type_), data(data_) {}
FileStackNode(
FileStackNodeType type_,
std::variant<std::vector<uint32_t>, std::string> data_,
bool isQuiet_
)
: type(type_), data(data_), isQuiet(isQuiet_) {}
void printBacktrace(uint32_t curLineNo) const;
};
@@ -62,16 +67,19 @@ bool fstk_FileError(std::string const &path, char const *functionName);
bool fstk_FailedOnMissingInclude();
bool yywrap();
bool fstk_RunInclude(std::string const &path);
void fstk_RunMacro(std::string const &macroName, std::shared_ptr<MacroArgs> macroArgs);
void fstk_RunRept(uint32_t count, int32_t reptLineNo, ContentSpan const &span);
bool fstk_RunInclude(std::string const &path, bool isQuiet);
void fstk_RunMacro(
std::string const &macroName, std::shared_ptr<MacroArgs> macroArgs, bool isQuiet
);
void fstk_RunRept(uint32_t count, int32_t reptLineNo, ContentSpan const &span, bool isQuiet);
void fstk_RunFor(
std::string const &symName,
int32_t start,
int32_t stop,
int32_t step,
int32_t reptLineNo,
ContentSpan const &span
ContentSpan const &span,
bool isQuiet
);
bool fstk_Break();

View File

@@ -30,8 +30,9 @@ bool sym_IsPC(Symbol const *sym); // Forward declaration for `getSection`
struct Symbol {
std::string name;
SymbolType type;
bool isExported; // Whether the symbol is to be exported
bool isBuiltin; // Whether the symbol is a built-in
bool isBuiltin;
bool isExported; // Not relevant for SYM_MACRO or SYM_EQUS
bool isQuiet; // Only relevant for SYM_MACRO
Section *section;
std::shared_ptr<FileStackNode> src; // Where the symbol was defined
uint32_t fileLine; // Line where the symbol was defined
@@ -88,7 +89,9 @@ Symbol *sym_FindScopedSymbol(std::string const &symName);
// Find a scoped symbol by name; do not return `@` or `_NARG` when they have no value
Symbol *sym_FindScopedValidSymbol(std::string const &symName);
Symbol const *sym_GetPC();
Symbol *sym_AddMacro(std::string const &symName, int32_t defLineNo, ContentSpan const &span);
Symbol *sym_AddMacro(
std::string const &symName, int32_t defLineNo, ContentSpan const &span, bool isQuiet
);
Symbol *sym_Ref(std::string const &symName);
Symbol *sym_AddString(std::string const &symName, std::shared_ptr<std::string> value);
Symbol *sym_RedefString(std::string const &symName, std::shared_ptr<std::string> value);

View File

@@ -11,58 +11,74 @@
#include "style.hpp"
static constexpr uint64_t TRACE_COLLAPSE = UINT64_MAX;
struct Tracing {
uint64_t depth = 0;
bool collapse = false;
bool loud = false;
};
extern uint64_t traceDepth;
extern Tracing tracing;
bool trace_ParseTraceDepth(char const *arg);
template<typename T, typename M, typename N>
void trace_PrintBacktrace(std::vector<T> const &stack, M getName, N getLineNo) {
auto printLocation = [&](T const &item) {
size_t n = stack.size();
if (n == 0) {
return; // LCOV_EXCL_LINE
}
auto printLocation = [&](size_t i) {
T const &item = stack[n - i - 1];
style_Reset(stderr);
if (!tracing.collapse) {
fputs(" ", stderr); // Just three spaces; the fourth will be printed next
}
fprintf(stderr, " %s ", i == 0 ? "at" : "<-");
style_Set(stderr, STYLE_CYAN, true);
fputs(getName(item), stderr);
style_Set(stderr, STYLE_CYAN, false);
fprintf(stderr, "(%" PRIu32 ")", getLineNo(item));
if (!tracing.collapse) {
putc('\n', stderr);
}
};
size_t n = stack.size();
if (traceDepth == TRACE_COLLAPSE) {
if (tracing.collapse) {
fputs(" ", stderr); // Just three spaces; the fourth will be handled by the loop
}
if (tracing.depth == 0 || static_cast<size_t>(tracing.depth) >= n) {
for (size_t i = 0; i < n; ++i) {
style_Reset(stderr);
fprintf(stderr, " %s ", i == 0 ? "at" : "<-");
printLocation(stack[n - i - 1]);
}
putc('\n', stderr);
} else if (traceDepth == 0 || static_cast<size_t>(traceDepth) >= n) {
for (size_t i = 0; i < n; ++i) {
style_Reset(stderr);
fprintf(stderr, " %s ", i == 0 ? "at" : "<-");
printLocation(stack[n - i - 1]);
putc('\n', stderr);
printLocation(i);
}
} else {
size_t last = traceDepth / 2;
size_t first = traceDepth - last;
size_t skipped = n - traceDepth;
size_t last = tracing.depth / 2;
size_t first = tracing.depth - last;
size_t skipped = n - tracing.depth;
for (size_t i = 0; i < first; ++i) {
style_Reset(stderr);
fprintf(stderr, " %s ", i == 0 ? "at" : "<-");
printLocation(stack[n - i - 1]);
putc('\n', stderr);
printLocation(i);
}
style_Reset(stderr);
fprintf(stderr, " ...%zu more%s\n", skipped, last ? "..." : "");
for (size_t i = n - last; i < n; ++i) {
style_Reset(stderr);
fputs(" <- ", stderr);
printLocation(stack[n - i - 1]);
if (tracing.collapse) {
fputs(" <-", stderr);
} else {
fputs(" ", stderr); // Just three spaces; the fourth will be printed next
}
fprintf(stderr, " ...%zu more%s", skipped, last ? "..." : "");
if (!tracing.collapse) {
putc('\n', stderr);
}
for (size_t i = n - last; i < n; ++i) {
printLocation(i);
}
}
if (tracing.collapse) {
putc('\n', stderr);
}
style_Reset(stderr);
}

View File

@@ -19,6 +19,7 @@ struct FileStackNode {
std::string // NODE_FILE, NODE_MACRO
>
data;
bool isQuiet; // Whether to omit this node from error reporting
FileStackNode *parent;
// Line at which the parent context was exited; meaningless for the root level

View File

@@ -9,7 +9,7 @@
#include "helpers.hpp" // assume
#define RGBDS_OBJECT_VERSION_STRING "RGB9"
#define RGBDS_OBJECT_REV 12U
#define RGBDS_OBJECT_REV 13U
enum AssertionType { ASSERT_WARN, ASSERT_ERROR, ASSERT_FATAL };
@@ -78,12 +78,18 @@ enum SectionType {
SECTTYPE_INVALID
};
static constexpr uint8_t SECTTYPE_TYPE_MASK = 0b111;
static constexpr uint8_t SECTTYPE_UNION_BIT = 7;
static constexpr uint8_t SECTTYPE_FRAGMENT_BIT = 6;
enum FileStackNodeType {
NODE_REPT,
NODE_FILE,
NODE_MACRO,
};
static constexpr uint8_t FSTACKNODE_QUIET_BIT = 7;
// Nont-`const` members may be patched in RGBLINK depending on CLI flags
extern struct SectionTypeInfo {
std::string const name;