Build everything as C++ (#1176)

This commit is contained in:
Rangi
2023-11-07 15:45:56 -05:00
committed by GitHub
parent 78d83be2b2
commit 1e70e703a7
84 changed files with 667 additions and 663 deletions

View File

@@ -9,9 +9,9 @@
#include <stdint.h>
#include <stdio.h>
#include "asm/lexer.h"
#include "asm/lexer.hpp"
#include "linkdefs.h"
#include "linkdefs.hpp"
struct FileStackNode {
struct FileStackNode *parent; // Pointer to parent node, for error reporting

View File

@@ -7,9 +7,9 @@
#include <stdbool.h>
#include <stdlib.h>
#include "asm/warning.h"
#include "asm/warning.hpp"
#include "helpers.h"
#include "helpers.hpp"
struct MacroArgs;

View File

@@ -7,7 +7,7 @@
#include <stdint.h>
#include <stdio.h>
#include "helpers.h"
#include "helpers.hpp"
extern bool haltNop;
extern bool warnOnHaltNop;

View File

@@ -5,7 +5,7 @@
#include <stdint.h>
#include "linkdefs.h"
#include "linkdefs.hpp"
struct Expression;
struct FileStackNode;

View File

@@ -6,7 +6,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "linkdefs.h"
#include "linkdefs.hpp"
#define MAXRPNLEN 1048576

View File

@@ -6,8 +6,8 @@
#include <stdint.h>
#include <stdbool.h>
#include "linkdefs.h"
#include "platform.h" // NONNULL
#include "linkdefs.hpp"
#include "platform.hpp" // NONNULL
extern uint8_t fillByte;

View File

@@ -8,9 +8,9 @@
#include <string.h>
#include <time.h>
#include "asm/section.h"
#include "asm/section.hpp"
#include "platform.h" // MIN_NB_ELMS
#include "platform.hpp" // MIN_NB_ELMS
#define MAXSYMLEN 255

View File

@@ -3,7 +3,7 @@
#ifndef WARNING_H
#define WARNING_H
#include "helpers.h"
#include "helpers.hpp"
extern unsigned int nbErrors;
@@ -77,7 +77,7 @@ void warning(enum WarningID id, char const *fmt, ...) format_(printf, 2, 3);
* It is also used when the assembler goes into an invalid state (for example,
* when it fails to allocate memory).
*/
_Noreturn void fatalerror(char const *fmt, ...) format_(printf, 1, 2);
[[noreturn]] void fatalerror(char const *fmt, ...) format_(printf, 1, 2);
/*
* Used for errors that make it impossible to assemble correctly, but don't

View File

@@ -3,21 +3,17 @@
#ifndef RGBDS_ERROR_H
#define RGBDS_ERROR_H
#include "helpers.h"
#include "platform.h"
#include "helpers.hpp"
#include "platform.hpp"
#ifdef __cplusplus
extern "C" {
#endif
void warn(char const NONNULL(fmt), ...) format_(printf, 1, 2);
void warnx(char const NONNULL(fmt), ...) format_(printf, 1, 2);
_Noreturn void err(char const NONNULL(fmt), ...) format_(printf, 1, 2);
_Noreturn void errx(char const NONNULL(fmt), ...) format_(printf, 1, 2);
[[noreturn]] void err(char const NONNULL(fmt), ...) format_(printf, 1, 2);
[[noreturn]] void errx(char const NONNULL(fmt), ...) format_(printf, 1, 2);
#ifdef __cplusplus
}
#endif
#endif // RGBDS_ERROR_H

View File

@@ -26,9 +26,7 @@
#ifndef RGBDS_EXTERN_GETOPT_H
#define RGBDS_EXTERN_GETOPT_H
#ifdef __cplusplus
extern "C" {
#endif
extern char *musl_optarg;
extern int musl_optind, musl_opterr, musl_optopt, musl_optreset;
@@ -47,8 +45,6 @@ int musl_getopt_long_only(int argc, char **argv, char const *optstring,
#define required_argument 1
#define optional_argument 2
#ifdef __cplusplus
} // extern "C"
#endif
#endif

View File

@@ -16,8 +16,8 @@
#include <string_view>
#include <variant>
#include "helpers.h"
#include "platform.h"
#include "helpers.hpp"
#include "platform.hpp"
#include "gfx/main.hpp"

View File

@@ -10,7 +10,7 @@
#include <utility>
#include <vector>
#include "helpers.h"
#include "helpers.hpp"
#include "gfx/rgba.hpp"

View File

@@ -3,11 +3,6 @@
#ifndef HELPERS_H
#define HELPERS_H
// Of course, MSVC does not support C11, so no _Noreturn there...
#ifdef _MSC_VER
#define _Noreturn __declspec(noreturn)
#endif
// Ideally, we'd use `__has_attribute` and `__has_builtin`, but these were only introduced in GCC 9
#ifdef __GNUC__ // GCC or compatible
#define format_(archetype, str_index, first_arg) \
@@ -24,8 +19,8 @@
#define format_(archetype, str_index, first_arg)
#define attr_(...)
// This seems to generate similar code to __builtin_unreachable, despite different semantics
// Note that executing this is undefined behavior (declared _Noreturn, but does return)
static inline _Noreturn void unreachable_(void) {}
// Note that executing this is undefined behavior (declared [[noreturn]], but does return)
[[noreturn]] static inline void unreachable_(void) {}
#endif
// Use builtins whenever possible, and shim them otherwise

View File

@@ -6,7 +6,7 @@
#include <tuple>
#include <utility>
#include "platform.h" // __PRETTY_FUNCTION__
#include "platform.hpp" // __PRETTY_FUNCTION__
template<typename... Ts>
static inline void report() {

View File

@@ -8,8 +8,8 @@
#include <stdbool.h>
#include <stdio.h>
#include "helpers.h"
#include "linkdefs.h"
#include "helpers.hpp"
#include "linkdefs.hpp"
// Variables related to CLI options
extern bool isDmgMode;
@@ -61,7 +61,7 @@ void warning(struct FileStackNode const *where, uint32_t lineNo,
void error(struct FileStackNode const *where, uint32_t lineNo,
char const *fmt, ...) format_(printf, 3, 4);
_Noreturn void fatal(struct FileStackNode const *where, uint32_t lineNo,
[[noreturn]] void fatal(struct FileStackNode const *where, uint32_t lineNo,
char const *fmt, ...) format_(printf, 3, 4);
/*

View File

@@ -6,7 +6,7 @@
#include <stdint.h>
#include "link/section.h"
#include "link/section.hpp"
/*
* Registers a section for output.

View File

@@ -7,9 +7,9 @@
#include <stdbool.h>
#include <stdint.h>
#include "link/section.h"
#include "link/section.hpp"
#include "linkdefs.h"
#include "linkdefs.hpp"
struct Assertion {
struct Patch patch;

View File

@@ -6,7 +6,7 @@
#include <stdint.h>
#include "linkdefs.h"
#include "linkdefs.hpp"
extern FILE * linkerScript;

View File

@@ -9,9 +9,9 @@
#include <stdint.h>
#include <stdbool.h>
#include "link/main.h"
#include "link/main.hpp"
#include "linkdefs.h"
#include "linkdefs.hpp"
struct FileStackNode;
struct Section;

View File

@@ -8,7 +8,7 @@
#include <stdint.h>
#include "linkdefs.h"
#include "linkdefs.hpp"
struct FileStackNode;

View File

@@ -49,15 +49,17 @@
# include <unistd.h>
#endif
// MSVC doesn't support `[static N]` for array arguments from C99 or C11
#ifdef _MSC_VER
# define MIN_NB_ELMS(N)
# define ARR_QUALS(...)
# define NONNULL(ptr) *ptr
// C++ doesn't support `[static N]` for array arguments from C99 or C11
#define MIN_NB_ELMS(N) // static (N)
#define ARR_QUALS(...) // __VA_ARGS__
#define NONNULL(ptr) *ptr // ptr[static 1]
#define restrict
// C++ doesn't support designated array initializers, but they're a gcc extension
#ifdef __GNUC__
# define AT(index) [index] =
#else
# define MIN_NB_ELMS(N) static (N)
# define ARR_QUALS(...) __VA_ARGS__
# define NONNULL(ptr) ptr[static 1]
# define AT(index)
#endif
// MSVC uses a different name for O_RDWR, and needs an additional _O_BINARY flag

View File

@@ -3,9 +3,7 @@
#ifndef EXTERN_VERSION_H
#define EXTERN_VERSION_H
#ifdef __cplusplus
extern "C" {
#endif
#define PACKAGE_VERSION_MAJOR 0
#define PACKAGE_VERSION_MINOR 6
@@ -13,8 +11,6 @@ extern "C" {
char const *get_package_version_string(void);
#ifdef __cplusplus
}
#endif
#endif // EXTERN_VERSION_H