mirror of
https://github.com/gbdev/rgbds.git
synced 2026-01-21 16:01:52 +00:00
Predef std::pair to two-element std::tuple
This commit is contained in:
@@ -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; }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <memory>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
#include "helpers.hpp" // assume, literal_strlen
|
||||
#include "linkdefs.hpp"
|
||||
@@ -409,7 +409,7 @@ void sdobj_ReadFile(FileStackNode const &src, FILE *file, std::vector<Symbol> &f
|
||||
if (other) {
|
||||
// The same symbol can only be defined twice if neither
|
||||
// definition is in a floating section
|
||||
auto checkSymbol = [](Symbol const &sym) -> std::tuple<Section *, int32_t> {
|
||||
auto checkSymbol = [](Symbol const &sym) -> std::pair<Section *, int32_t> {
|
||||
if (std::holds_alternative<Label>(sym.data)) {
|
||||
Label const &label = std::get<Label>(sym.data);
|
||||
return {label.section, label.offset};
|
||||
|
||||
Reference in New Issue
Block a user