Run clang-format on everything (#1332)

This commit is contained in:
Sylvie
2024-03-04 14:22:49 -05:00
committed by GitHub
parent b004648a13
commit e74073e480
66 changed files with 6091 additions and 4957 deletions

View File

@@ -3,6 +3,7 @@
#ifndef RGBDS_FORMAT_SPEC_H
#define RGBDS_FORMAT_SPEC_H
#include <stddef.h>
#include <stdint.h>
enum FormatState {
@@ -30,7 +31,7 @@ class FormatSpec {
public:
bool isEmpty() const { return !state; }
bool isValid() const { return valid || state == FORMAT_DONE; }
bool isFinished() const { return state >= FORMAT_DONE;}
bool isFinished() const { return state >= FORMAT_DONE; }
void useCharacter(int c);
void finishCharacters();

View File

@@ -11,24 +11,25 @@
#include <variant>
#include <vector>
#include "asm/lexer.hpp"
#include "linkdefs.hpp"
#include "asm/lexer.hpp"
struct FileStackNode {
FileStackNode *parent; // Pointer to parent node, for error reporting
// Line at which the parent context was exited; meaningless for the root level
uint32_t lineNo;
bool referenced; // If referenced by a Symbol, Section, or Patch's `src`, don't `delete`!
uint32_t ID; // Set only if referenced: ID within the object file, -1 if not output yet
uint32_t ID; // Set only if referenced: ID within the object file, -1 if not output yet
enum 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;
std::monostate, // Default constructed; `.type` and `.data` must be set manually
std::vector<uint32_t>, // NODE_REPT
std::string // NODE_FILE, NODE_MACRO
>
data;
// REPT iteration counts since last named node, in reverse depth order
std::vector<uint32_t> &iters();
@@ -62,8 +63,15 @@ bool yywrap();
void fstk_RunInclude(char const *path);
void fstk_RunMacro(char const *macroName, MacroArgs &args);
void fstk_RunRept(uint32_t count, int32_t reptLineNo, char const *body, size_t size);
void fstk_RunFor(char const *symName, int32_t start, int32_t stop, int32_t step,
int32_t reptLineNo, char const *body, size_t size);
void fstk_RunFor(
char const *symName,
int32_t start,
int32_t stop,
int32_t step,
int32_t reptLineNo,
char const *body,
size_t size
);
void fstk_StopRept();
bool fstk_Break();

View File

@@ -34,13 +34,13 @@ struct Expansion {
char const *unowned;
char *owned; // Non-`const` only so it can be `delete []`d
} contents;
size_t size; // Length of the contents
size_t size; // Length of the contents
size_t offset; // Cursor into the contents
bool owned; // Whether or not to free contents when this expansion is freed
bool owned; // Whether or not to free contents when this expansion is freed
};
struct IfStackEntry {
bool ranIfBlock; // Whether an IF/ELIF/ELSE block ran already
bool ranIfBlock; // Whether an IF/ELIF/ELSE block ran already
bool reachedElseBlock; // Whether an ELSE block ran already
};
@@ -59,9 +59,9 @@ struct ViewedLexerState {
struct BufferedLexerState {
int fd;
size_t index; // Read index into the buffer
size_t index; // Read index into the buffer
char buf[LEXER_BUF_SIZE]; // Circular buffer
size_t nbChars; // Number of "fresh" chars in the buffer
size_t nbChars; // Number of "fresh" chars in the buffer
};
struct LexerState {
@@ -75,8 +75,8 @@ struct LexerState {
std::deque<IfStackEntry> ifStack;
bool capturing; // Whether the text being lexed should be captured
size_t captureSize; // Amount of text captured
bool capturing; // Whether the text being lexed should be captured
size_t captureSize; // Amount of text captured
std::vector<char> *captureBuf; // Buffer to send the captured text to if non-null
bool disableMacroArgs;
@@ -85,38 +85,29 @@ struct LexerState {
bool expandStrings;
std::deque<Expansion> expansions; // Front is the innermost current expansion
std::variant<
std::monostate,
MmappedLexerState,
ViewedLexerState,
BufferedLexerState
> content;
std::variant<std::monostate, MmappedLexerState, ViewedLexerState, BufferedLexerState> content;
};
extern LexerState *lexerState;
extern LexerState *lexerStateEOL;
static inline void lexer_SetState(LexerState *state)
{
static inline void lexer_SetState(LexerState *state) {
lexerState = state;
}
static inline void lexer_SetStateAtEOL(LexerState *state)
{
static inline void lexer_SetStateAtEOL(LexerState *state) {
lexerStateEOL = state;
}
extern char binDigits[2];
extern char gfxDigits[4];
static inline void lexer_SetBinDigits(char const digits[2])
{
static inline void lexer_SetBinDigits(char const digits[2]) {
binDigits[0] = digits[0];
binDigits[1] = digits[1];
}
static inline void lexer_SetGfxDigits(char const digits[4])
{
static inline void lexer_SetGfxDigits(char const digits[4]) {
gfxDigits[0] = digits[0];
gfxDigits[1] = digits[1];
gfxDigits[2] = digits[2];
@@ -125,8 +116,9 @@ static inline void lexer_SetGfxDigits(char const digits[4])
// `path` is referenced, but not held onto..!
bool lexer_OpenFile(LexerState &state, char const *path);
void lexer_OpenFileView(LexerState &state, char const *path, char const *buf, size_t size,
uint32_t lineNo);
void lexer_OpenFileView(
LexerState &state, char const *path, char const *buf, size_t size, uint32_t lineNo
);
void lexer_RestartRept(uint32_t lineNo);
void lexer_CleanupState(LexerState &state);
void lexer_Init();

View File

@@ -8,10 +8,10 @@
#include <string>
#include <vector>
#include "asm/warning.hpp"
#include "helpers.hpp"
#include "asm/warning.hpp"
struct MacroArgs {
unsigned int shift;
std::vector<std::string> args;

View File

@@ -16,7 +16,9 @@ void out_RegisterNode(FileStackNode *node);
void out_ReplaceNode(FileStackNode *node);
void out_SetFileName(char *s);
void out_CreatePatch(uint32_t type, Expression const &expr, uint32_t ofs, uint32_t pcShift);
void out_CreateAssert(enum AssertionType type, Expression const &expr, char const *message, uint32_t ofs);
void out_CreateAssert(
enum AssertionType type, Expression const &expr, char const *message, uint32_t ofs
);
void out_WriteObject();
#endif // RGBDS_ASM_OUTPUT_H

View File

@@ -5,18 +5,19 @@
#include <stdint.h>
#include <string>
#include <vector>
#include "linkdefs.hpp"
struct Symbol;
struct Expression {
int32_t val; // If the expression's value is known, it's here
int32_t val; // If the expression's value is known, it's here
std::string *reason; // Why the expression is not known, if it isn't
bool isKnown; // Whether the expression's value is known at assembly time
bool isSymbol; // Whether the expression represents a symbol suitable for const diffing
bool isKnown; // Whether the expression's value is known at assembly time
bool isSymbol; // Whether the expression represents a symbol suitable for const diffing
std::vector<uint8_t> *rpn; // Bytes serializing the RPN expression
uint32_t rpnPatchSize; // Size the expression will take in the object file
uint32_t rpnPatchSize; // Size the expression will take in the object file
int32_t getConstVal() const;
Symbol const *symbolOf() const;
@@ -26,7 +27,9 @@ struct Expression {
void rpn_Number(Expression &expr, uint32_t val);
void rpn_Symbol(Expression &expr, char const *symName);
void rpn_LOGNOT(Expression &expr, const Expression &src);
void rpn_BinaryOp(enum RPNCommand op, Expression &expr, const Expression &src1, const Expression &src2);
void rpn_BinaryOp(
enum RPNCommand op, Expression &expr, const Expression &src1, const Expression &src2
);
void rpn_HIGH(Expression &expr, const Expression &src);
void rpn_LOW(Expression &expr, const Expression &src);
void rpn_ISCONST(Expression &expr, const Expression &src);

View File

@@ -30,7 +30,7 @@ struct Section {
enum SectionType type;
enum SectionModifier modifier;
FileStackNode const *src; // Where the section was defined
uint32_t fileLine; // Line where the section was defined
uint32_t fileLine; // Line where the section was defined
uint32_t size;
uint32_t org;
uint32_t bank;
@@ -52,10 +52,20 @@ extern std::deque<Section> sectionList;
extern Section *currentSection;
Section *sect_FindSectionByName(char const *name);
void sect_NewSection(char const *name, enum SectionType type, uint32_t org,
SectionSpec const &attrs, enum SectionModifier mod);
void sect_SetLoadSection(char const *name, enum SectionType type, uint32_t org,
SectionSpec const &attrs, enum SectionModifier mod);
void sect_NewSection(
char const *name,
enum SectionType type,
uint32_t org,
SectionSpec const &attrs,
enum SectionModifier mod
);
void sect_SetLoadSection(
char const *name,
enum SectionType type,
uint32_t org,
SectionSpec const &attrs,
enum SectionModifier mod
);
void sect_EndLoadSection();
Section *sect_GetSymbolSection();

View File

@@ -4,8 +4,8 @@
#define RGBDS_SYMBOL_H
#include <stdint.h>
#include <string>
#include <string.h>
#include <string>
#include <string_view>
#include <time.h>
#include <variant>
@@ -23,7 +23,7 @@ enum SymbolType {
SYM_REF // Forward reference to a label
};
struct Symbol; // For the `sym_IsPC` forward declaration
struct Symbol; // For the `sym_IsPC` forward declaration
bool sym_IsPC(Symbol const *sym); // For the inline `getSection` method
struct Symbol {
@@ -33,14 +33,15 @@ struct Symbol {
bool isBuiltin; // Whether the symbol is a built-in
Section *section;
FileStackNode *src; // Where the symbol was defined
uint32_t fileLine; // Line where the symbol was defined
uint32_t fileLine; // Line where the symbol was defined
std::variant<
int32_t, // If isNumeric()
int32_t (*)(), // If isNumeric() and has a callback
std::string_view *, // For SYM_MACRO
std::string * // For SYM_EQUS
> data;
int32_t, // If isNumeric()
int32_t (*)(), // If isNumeric() and has a callback
std::string_view *, // For SYM_MACRO
std::string * // For SYM_EQUS
>
data;
uint32_t ID; // ID of the symbol in the object file (-1 if none)

View File

@@ -7,34 +7,29 @@
extern unsigned int nbErrors, maxErrors;
enum WarningState {
WARNING_DEFAULT,
WARNING_DISABLED,
WARNING_ENABLED,
WARNING_ERROR
};
enum WarningState { WARNING_DEFAULT, WARNING_DISABLED, WARNING_ENABLED, WARNING_ERROR };
enum WarningID {
WARNING_ASSERT, // Assertions
WARNING_BACKWARDS_FOR, // `for` loop with backwards range
WARNING_BUILTIN_ARG, // Invalid args to builtins
WARNING_CHARMAP_REDEF, // Charmap entry re-definition
WARNING_DIV, // Division undefined behavior
WARNING_ASSERT, // Assertions
WARNING_BACKWARDS_FOR, // `for` loop with backwards range
WARNING_BUILTIN_ARG, // Invalid args to builtins
WARNING_CHARMAP_REDEF, // Charmap entry re-definition
WARNING_DIV, // Division undefined behavior
WARNING_EMPTY_DATA_DIRECTIVE, // `db`, `dw` or `dl` directive without data in ROM
WARNING_EMPTY_MACRO_ARG, // Empty macro argument
WARNING_EMPTY_STRRPL, // Empty second argument in `STRRPL`
WARNING_LARGE_CONSTANT, // Constants too large
WARNING_LONG_STR, // String too long for internal buffers
WARNING_MACRO_SHIFT, // Shift past available arguments in macro
WARNING_NESTED_COMMENT, // Comment-start delimiter in a block comment
WARNING_OBSOLETE, // Obsolete things
WARNING_SHIFT, // Shifting undefined behavior
WARNING_SHIFT_AMOUNT, // Strange shift amount
WARNING_USER, // User warnings
WARNING_EMPTY_STRRPL, // Empty second argument in `STRRPL`
WARNING_LARGE_CONSTANT, // Constants too large
WARNING_LONG_STR, // String too long for internal buffers
WARNING_MACRO_SHIFT, // Shift past available arguments in macro
WARNING_NESTED_COMMENT, // Comment-start delimiter in a block comment
WARNING_OBSOLETE, // Obsolete things
WARNING_SHIFT, // Shifting undefined behavior
WARNING_SHIFT_AMOUNT, // Strange shift amount
WARNING_USER, // User warnings
NB_PLAIN_WARNINGS,
// Warnings past this point are "parametric" warnings, only mapping to a single flag
// Warnings past this point are "parametric" warnings, only mapping to a single flag
#define PARAM_WARNINGS_START NB_PLAIN_WARNINGS
// Treating string as number may lose some bits
WARNING_NUMERIC_STRING_1 = PARAM_WARNINGS_START,
@@ -49,7 +44,7 @@ enum WarningID {
NB_PLAIN_AND_PARAM_WARNINGS,
#define NB_PARAM_WARNINGS (NB_PLAIN_AND_PARAM_WARNINGS - PARAM_WARNINGS_START)
// Warnings past this point are "meta" warnings
// Warnings past this point are "meta" warnings
#define META_WARNINGS_START NB_PLAIN_AND_PARAM_WARNINGS
WARNING_ALL = META_WARNINGS_START,
WARNING_EXTRA,