Predef std::pair to two-element std::tuple

This commit is contained in:
Rangi42
2025-08-13 20:48:54 -04:00
parent 2bdf61da70
commit ea1358bbe6
8 changed files with 54 additions and 59 deletions

View File

@@ -1,39 +1,40 @@
#include "link/fstack.hpp"
#include <inttypes.h>
#include <utility>
#include "backtrace.hpp"
#include "link/warning.hpp"
std::vector<std::pair<std::string, uint32_t>> FileStackNode::backtrace(uint32_t curLineNo) const {
if (std::holds_alternative<std::vector<uint32_t>>(data)) {
assume(parent); // REPT nodes use their parent's name
std::vector<std::pair<std::string, uint32_t>> nodes = parent->backtrace(lineNo);
assume(!nodes.empty());
std::string reptChain = nodes.back().first;
for (uint32_t iter : iters()) {
using TraceNode = std::pair<std::string, uint32_t>;
static std::vector<TraceNode> backtrace(FileStackNode const &node, uint32_t curLineNo) {
if (!node.parent) {
assume(node.type != NODE_REPT && std::holds_alternative<std::string>(node.data));
return {
{node.name(), curLineNo}
};
}
std::vector<TraceNode> traceNodes = backtrace(*node.parent, node.lineNo);
if (std::holds_alternative<std::vector<uint32_t>>(node.data)) {
assume(!traceNodes.empty()); // REPT nodes use their parent's name
std::string reptChain = traceNodes.back().first;
for (uint32_t iter : node.iters()) {
reptChain.append("::REPT~");
reptChain.append(std::to_string(iter));
}
nodes.emplace_back(reptChain, curLineNo);
return nodes;
} else if (parent) {
std::vector<std::pair<std::string, uint32_t>> nodes = parent->backtrace(lineNo);
nodes.emplace_back(name(), curLineNo);
return nodes;
traceNodes.emplace_back(reptChain, curLineNo);
} else {
return {
{name(), curLineNo}
};
traceNodes.emplace_back(node.name(), curLineNo);
}
return traceNodes;
}
void FileStackNode::printBacktrace(uint32_t curLineNo) const {
trace_PrintBacktrace(
backtrace(curLineNo),
[](std::pair<std::string, uint32_t> const &node) { return node.first.c_str(); },
[](std::pair<std::string, uint32_t> const &node) { return node.second; }
backtrace(*this, curLineNo),
[](TraceNode const &node) { return node.first.c_str(); },
[](TraceNode const &node) { return node.second; }
);
}