Remove C++ pseudo support

This commit is contained in:
Abdelrahman Said 2025-05-05 02:48:35 +01:00
parent 0d4aa7a9c2
commit 98a802e3eb
30 changed files with 20 additions and 251 deletions

View File

@ -246,10 +246,7 @@ class CHeader(CFile):
name_upper = self.name.upper()
header_guard_name = f"{name_upper}_H"
header_guard_open = f"#ifndef {header_guard_name}\n#define {header_guard_name}\n\n"
header_guard_close = f"#endif // !{header_guard_name}\n"
c_linkage_open = "#ifdef WAPP_PLATFORM_CPP\nBEGIN_C_LINKAGE\n#endif // !WAPP_PLATFORM_CPP\n\n"
c_linkage_close = "\n#ifdef WAPP_PLATFORM_CPP\nEND_C_LINKAGE\n#endif // !WAPP_PLATFORM_CPP\n\n"
header_guard_close = f"\n#endif // !{header_guard_name}\n"
includes = _get_includes_string(self.includes)
@ -277,12 +274,10 @@ class CHeader(CFile):
super().__str__() +
header_guard_open +
includes +
c_linkage_open +
macros +
forward_declarations +
types +
funcs +
c_linkage_close +
header_guard_close
)

View File

@ -4,9 +4,22 @@
#include "../platform/platform.h"
#include <stdint.h>
#define c8 uint8_t
#define c16 uint16_t
#define c32 uint32_t
#if WAPP_PLATFORM_C_VERSION >= WAPP_PLATFORM_C11_VERSION
#include <uchar.h>
#if WAPP_PLATFORM_C_VERSION >= WAPP_PLATFORM_C23_VERSION
#define c8 char8_t
#else
#define c8 uint8_t
#endif // !WAPP_PLATFORM_C23_VERSION
#define c16 char16_t
#define c32 char32_t
#else
#define c8 uint8_t
#define c16 uint16_t
#define c32 uint32_t
#endif // !WAPP_PLATFORM_C11_VERSION
#define u8 uint8_t
#define u16 uint16_t
@ -29,10 +42,4 @@
#define internal static
#define persistent static
#ifdef WAPP_PLATFORM_CPP
#define class_mem static
#define BEGIN_C_LINKAGE extern "C" {
#define END_C_LINKAGE }
#endif // WAPP_PLATFORM_CPP
#endif // !ALIASES_H

View File

@ -59,30 +59,7 @@
#endif
#ifdef __cplusplus
#define WAPP_PLATFORM_CPP
#define WAPP_PLATFORM_CPP_VERSION __cplusplus
#define WAPP_PLATFORM_CPP98_VERSION 199711L
#define WAPP_PLATFORM_CPP11_VERSION 201103L
#define WAPP_PLATFORM_CPP14_VERSION 201402L
#define WAPP_PLATFORM_CPP17_VERSION 201703L
#define WAPP_PLATFORM_CPP20_VERSION 202002L
#define WAPP_PLATFORM_CPP23_VERSION 202302L
#if WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP98_VERSION
#define WAPP_PLATFORM_CPP98
#elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP11_VERSION
#define WAPP_PLATFORM_CPP11
#elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP14_VERSION
#define WAPP_PLATFORM_CPP14
#elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP17_VERSION
#define WAPP_PLATFORM_CPP17
#elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP20_VERSION
#define WAPP_PLATFORM_CPP20
#elif WAPP_PLATFORM_CPP_VERSION == WAPP_PLATFORM_CPP23_VERSION
#define WAPP_PLATFORM_CPP23
#else
#error "Unrecognised C++ version"
#endif
#error "WAPP is a C only library"
#else
#define WAPP_PLATFORM_C

View File

@ -6,10 +6,6 @@
#include "../../os/mem/mem_os.h"
#include <stdbool.h>
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
typedef struct arena Arena;
#define wapp_mem_arena_init(arena_dptr, base_capacity) \
@ -34,8 +30,4 @@ void *wapp_mem_arena_realloc_aligned(Arena *arena, void *ptr, u64 old_size, u64
void wapp_mem_arena_clear(Arena *arena);
void wapp_mem_arena_destroy(Arena **arena);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !MEM_ARENA_H

View File

@ -7,10 +7,6 @@
#include "../../os/mem/mem_os.h"
#include <stdbool.h>
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#define wapp_mem_arena_allocator_init(base_capacity) \
(wapp_mem_arena_allocator_init_custom(base_capacity, WAPP_MEM_ALLOC_RESERVE, false))
#define wapp_mem_arena_allocator_init_commit(base_capacity) \
@ -35,8 +31,4 @@ Allocator wapp_mem_arena_allocator_init_custom(u64 base_capacity, MemAllocFlags
void wapp_mem_arena_allocator_clear(Allocator *allocator);
void wapp_mem_arena_allocator_destroy(Allocator *allocator);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !MEM_ARENA_ALLOCATOR_H

View File

@ -4,14 +4,6 @@
#include "../../../common/aliases/aliases.h"
#include "../../../common/platform/platform.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
void *wapp_mem_util_align_forward(void *ptr, u64 alignment);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !MEM_UTILS_H

View File

@ -6,10 +6,6 @@
#include "../../../primitives/mem_allocator/mem_allocator.h"
#include "../../../primitives/strings/str8/str8.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#ifdef WAPP_PLATFORM_POSIX
#define PATH_SEP '/'
#elif defined(WAPP_PLATFORM_WINDOWS)
@ -31,8 +27,4 @@ enum {
u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts);
Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !CPATH_H

View File

@ -4,10 +4,6 @@
#include "../../../common/aliases/aliases.h"
#include "../../../common/platform/platform.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#include "mem_os_ops.h"
#if defined(WAPP_PLATFORM_WINDOWS)
@ -25,8 +21,4 @@ void wapp_mem_util_free(void *ptr, u64 size);
external void *mem_util_allocate(void *addr, u64 size, MemAccess access, MemAllocFlags flags, MemInitType type);
external void mem_util_free(void *ptr, u64 size);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !MEM_OS_H

View File

@ -3,10 +3,6 @@
#include "../../../common/platform/platform.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
typedef enum mem_access {
WAPP_MEM_ACCESS_NONE,
WAPP_MEM_ACCESS_READ_ONLY,
@ -21,8 +17,4 @@ typedef enum mem_init_type {
WAPP_MEM_INIT_INITIALISED,
} MemInitType;
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !MEM_OS_OPS_H

View File

@ -3,10 +3,6 @@
#include "../../../../common/platform/platform.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#ifdef WAPP_PLATFORM_POSIX
#include <sys/mman.h>
@ -26,8 +22,4 @@ typedef enum mem_alloc_flags {
#endif // !WAPP_PLATFORM_POSIX
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#endif // !MEM_OS_POSIX_H

View File

@ -3,10 +3,6 @@
#include "../../../../common/platform/platform.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#ifdef WAPP_PLATFORM_WINDOWS
#define WIN32_LEAN_AND_MEAN
@ -20,8 +16,4 @@ typedef enum mem_alloc_flags {
#endif // !WAPP_PLATFORM_WINDOWS
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#endif // !MEM_OS_WIN_H

View File

@ -9,18 +9,10 @@
#include <stdio.h>
#include <stdlib.h>
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#define CMD_NO_EXIT(ERR) ((CMDResult){.exited = false, .exit_code = EXIT_FAILURE, .error = ERR})
CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_buf, const Str8List *cmd);
external CMDError get_output_status(FILE *fp, i32 *status_out);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !COMMANDER_H

View File

@ -5,10 +5,6 @@
#include "../../../../common/platform/platform.h"
#include <stdbool.h>
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
typedef enum {
SHELL_OUTPUT_DISCARD,
SHELL_OUTPUT_PRINT,
@ -36,8 +32,4 @@ struct commander_result {
#endif // !WAPP_PLATFORM_WINDOWS
};
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !COMMANDER_OUTPUT_H

View File

@ -6,17 +6,9 @@
#include "../../../../common/platform/platform.h"
#include "../../../../primitives/strings/str8/str8.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
void wapp_shell_termcolour_print_text(Str8RO *text, TerminalColour colour);
void wapp_shell_termcolour_clear_colour(void);
external void print_coloured_text(Str8RO *text, TerminalColour colour);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TERM_COLOUR_H

View File

@ -3,10 +3,6 @@
#include "../../../../common/platform/platform.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
typedef enum {
WAPP_TERM_COLOUR_FG_BLACK,
WAPP_TERM_COLOUR_FG_RED,
@ -29,8 +25,4 @@ typedef enum {
COUNT_TERM_COLOUR,
} TerminalColour;
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TERMINAL_COLOURS_H

View File

@ -12,10 +12,6 @@
#include "../../common/platform/platform.h"
#include <stdbool.h>
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#define wapp_str8_array(...) ((Str8Array){ \
.items = (Str8[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(Str8, __VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = wapp_misc_utils_va_args_count(Str8, __VA_ARGS__), \
@ -498,8 +494,4 @@ UptrArray *wapp_uptr_array_append_alloc(const Allocator *allocator, UptrArray *a
UptrArray *wapp_uptr_array_extend_alloc(const Allocator *allocator, UptrArray *array, const UptrArray *other);
UptrArray *wapp_uptr_array_copy_alloc(const Allocator *allocator, const UptrArray *src, UptrArray *dst);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#endif // !ARRAY_H

View File

@ -9,10 +9,6 @@
#include "../../common/platform/platform.h"
#include <stdbool.h>
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#define wapp_str8_list_node(ITEM_PTR) ((Str8Node){.item = ITEM_PTR})
#define wapp_void_ptr_list_node(ITEM_PTR) ((VoidPNode){.item = ITEM_PTR})
#define wapp_bool_list_node(ITEM_PTR) ((BoolNode){.item = ITEM_PTR})
@ -477,8 +473,4 @@ UptrNode *wapp_uptr_list_pop_back(UptrList *list);
UptrNode *wapp_uptr_list_remove(UptrList *list, u64 index);
void wapp_uptr_list_empty(UptrList *list);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#endif // !DBL_LIST_H

View File

@ -5,17 +5,12 @@
#include "../../common/platform/platform.h"
#include <string.h>
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
typedef void *(MemAllocFunc)(u64 size, void *alloc_obj);
typedef void *(MemAllocAlignedFunc)(u64 size, u64 alignment, void *alloc_obj);
typedef void *(MemReallocFunc)(void *ptr, u64 old_size, u64 new_size, void *alloc_obj);
typedef void *(MemReallocAlignedFunc)(void *ptr, u64 old_size, u64 new_size, u64 alignment, void *alloc_obj);
typedef void (MemFreeFunc)(void **ptr, u64 size, void *alloc_obj);
typedef struct allocator Allocator;
struct allocator {
void *obj;
@ -28,7 +23,6 @@ struct allocator {
#define wapp_mem_allocator_invalid(ALLOCATOR) (memcmp(ALLOCATOR, &((Allocator){0}), sizeof(Allocator)) == 0)
void *wapp_mem_allocator_alloc(const Allocator *allocator, u64 size);
void *wapp_mem_allocator_alloc_aligned(const Allocator *allocator, u64 size, u64 alignment);
void *wapp_mem_allocator_realloc(const Allocator *allocator, void *ptr, u64 old_size, u64 new_size);
@ -36,8 +30,4 @@ void *wapp_mem_allocator_realloc_aligned(const Allocator *allocator, void *ptr,
u64 new_size, u64 alignment);
void wapp_mem_allocator_free(const Allocator *allocator, void **ptr, u64 size);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !MEM_ALLOCATOR_H

View File

@ -8,10 +8,6 @@
#include <string.h>
#include <stdbool.h>
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
typedef struct str8 Str8;
struct str8 {
u64 capacity;
@ -96,8 +92,4 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8R
#define wapp_str8_node_from_str8(STRING) wapp_str8_list_node(&(STRING))
u64 wapp_str8_list_total_size(const Str8List *list);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#endif // !STR8_H

View File

@ -88,7 +88,7 @@ internal u64 split_mix_64(SplitMix64State *state) {
return result ^ (result >> 31);
}
#if defined(WAPP_PLATFORM_CPP) || (defined(WAPP_PLATFORM_C) && WAPP_PLATFORM_C_VERSION >= WAPP_PLATFORM_C11_VERSION)
#if defined(WAPP_PLATFORM_C) && WAPP_PLATFORM_C_VERSION >= WAPP_PLATFORM_C11_VERSION
#ifdef WAPP_PLATFORM_POSIX
internal void seed_os_generator(void) {
struct timespec ts = {0};
@ -131,4 +131,4 @@ internal u64 generate_random_number(void) {
return (((u64)n1) << 32 | (u64)n2);
}
#endif // !WAPP_PLATFORM_CPP
#endif // !WAPP_PLATFORM_C

View File

@ -4,10 +4,6 @@
#include "../../common/aliases/aliases.h"
#include "../../common/platform/platform.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
typedef struct xor_256_state XOR256State;
struct xor_256_state {
u64 x;
@ -21,8 +17,4 @@ u64 wapp_prng_xorshift_256(XOR256State *state);
u64 wapp_prng_xorshift_256ss(XOR256State *state);
u64 wapp_prng_xorshift_256p(XOR256State *state);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !XORSHIFT_H

View File

@ -6,10 +6,6 @@
#include "../../primitives/strings/str8/str8.h"
#include <stdbool.h>
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#define wapp_tester_result(PASSED) ((TestFuncResult){.name = wapp_str8_lit_ro(__func__), .passed = PASSED})
#define wapp_tester_run_tests(...) run_tests(__VA_ARGS__, NULL)
@ -27,8 +23,4 @@ typedef TestFuncResult(TestFunc)(void);
void run_tests(TestFunc *func1, ...);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TESTER_H

View File

@ -5,10 +5,6 @@
#include "../common/platform/platform.h"
#include "../primitives/strings/str8/str8.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#define UUID_BUF_LENGTH 48
#define WAPP_UUID_SPEC WAPP_STR8_SPEC
#define wapp_uuid_varg(UUID) wapp_str8_varg((UUID).uuid)
@ -28,8 +24,4 @@ struct uuid {
// If the pointer is NULL, it skips initialisation.
UUID *wapp_uuid_init_uuid4(UUID *uuid);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !UUID_H

View File

@ -3,14 +3,6 @@
#include "wapp.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_arena_allocator(void);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_ALLOCATOR_H

View File

@ -3,10 +3,6 @@
#include "wapp.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_arena_init(void);
TestFuncResult test_arena_init_succeeds_when_reserving_very_large_size(void);
TestFuncResult test_arena_alloc_succeeds_when_within_capacity(void);
@ -16,8 +12,4 @@ TestFuncResult test_arena_realloc_smaller_size(void);
TestFuncResult test_arena_clear(void);
TestFuncResult test_arena_destroy(void);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_ARENA_H

View File

@ -3,10 +3,6 @@
#include "wapp.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_i32_array(void);
TestFuncResult test_i32_array_with_capacity(void);
TestFuncResult test_i32_array_get(void);
@ -21,8 +17,4 @@ TestFuncResult test_i32_array_append_alloc(void);
TestFuncResult test_i32_array_extend_alloc(void);
TestFuncResult test_i32_array_copy_alloc(void);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_INT_ARRAY_H

View File

@ -3,16 +3,8 @@
#include "wapp.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_cpath_join_path(void);
TestFuncResult test_cpath_dirname(void);
TestFuncResult test_cpath_dirup(void);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_CPATH_H

View File

@ -3,17 +3,9 @@
#include "wapp.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_commander_cmd_success(void);
TestFuncResult test_commander_cmd_failure(void);
TestFuncResult test_commander_cmd_out_buf_success(void);
TestFuncResult test_commander_cmd_out_buf_failure(void);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_SHELL_COMMANDER_H

View File

@ -3,10 +3,6 @@
#include "wapp.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_str8_lit(void);
TestFuncResult test_str8_lit_ro(void);
TestFuncResult test_str8_buf(void);
@ -33,8 +29,4 @@ TestFuncResult test_str8_rsplit(void);
TestFuncResult test_str8_rsplit_with_max(void);
TestFuncResult test_str8_join(void);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_STR8_H

View File

@ -3,10 +3,6 @@
#include "wapp.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
TestFuncResult test_str8_list_get(void);
TestFuncResult test_str8_list_push_front(void);
TestFuncResult test_str8_list_push_back(void);
@ -16,8 +12,4 @@ TestFuncResult test_str8_list_pop_back(void);
TestFuncResult test_str8_list_remove(void);
TestFuncResult test_str8_list_empty(void);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // WAPP_PLATFORM_CPP
#endif // !TEST_STR8_LIST_H