File: fstack.hpp

package info (click to toggle)
rgbds 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,164 kB
  • sloc: cpp: 19,048; asm: 6,208; yacc: 2,405; sh: 1,784; makefile: 213; ansic: 14
file content (38 lines) | stat: -rw-r--r-- 1,191 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// SPDX-License-Identifier: MIT

#ifndef RGBDS_LINK_FSTACK_HPP
#define RGBDS_LINK_FSTACK_HPP

#include <stdint.h>
#include <stdio.h>
#include <string>
#include <variant>
#include <vector>

#include "linkdefs.hpp"

struct FileStackNode {
	FileStackNodeType type;
	std::variant<
	    std::monostate,        // Default constructed; `.type` and `.data` must be set manually
	    std::vector<uint32_t>, // NODE_REPT
	    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
	uint32_t lineNo;

	// REPT iteration counts since last named node, in reverse depth order
	std::vector<uint32_t> &iters() { return std::get<std::vector<uint32_t>>(data); }
	std::vector<uint32_t> const &iters() const { return std::get<std::vector<uint32_t>>(data); }
	// File name for files, file::macro name for macros
	std::string &name() { return std::get<std::string>(data); }
	std::string const &name() const { return std::get<std::string>(data); }

	void printBacktrace(uint32_t curLineNo) const;
};

#endif // RGBDS_LINK_FSTACK_HPP