diff --git a/.clangd b/.clangd new file mode 100644 index 00000000..c654ac92 --- /dev/null +++ b/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Add: [-D__CLANGD__] diff --git a/include/decomp.h b/include/decomp.h index 3ad73a47..e0511da1 100644 --- a/include/decomp.h +++ b/include/decomp.h @@ -25,7 +25,8 @@ typedef struct ps_f32 { SECTION_GARBAGE static void __garbage_ordering_hints(void) #define order_hint_access(var) (void)(var) -#elif defined (__INTELLISENSE__) +#elif defined (__EDITOR_CHECKING__) +// dummy implementations for editor tooling #define sdata_ps_f32 ps_f32 #define sdata2_ps_f32 ps_f32 @@ -35,9 +36,7 @@ typedef struct ps_f32 { #define SECTION_GARBAGE #define static_order_hints #define order_hint_access(var) (void)(var) - -#endif - -#ifdef __clang__ -#define __cntlzw(x) __builtin_clz(x) +// TODO(KooShnoo): is builtin preferred? +#define __cntlzw(x) (x) +// #define __cntlzw(x) __builtin_clz(x) #endif diff --git a/include/macros.h b/include/macros.h index 083688c5..829bd902 100644 --- a/include/macros.h +++ b/include/macros.h @@ -24,16 +24,21 @@ #define DECLTYPE(x) __decltype__(x) -// https://github.com/DarkRTA/rb3/blob/235050f88a263fec0387b7c618dda76a8bb24d2c/src/sdk/RVL_SDK/revolution/os/OSUtils.h#L13-L17 -#if defined(__CWCC__) && !defined(__INTELLISENSE__) -#define AT_ADDRESS(addr) : (addr) -#else -#define AT_ADDRESS(addr) +#if defined(__INTELLISENSE__) || defined(__CLANGD__) +// TODO(KooShnoo): are we happy with this name? +#define __EDITOR_CHECKING__ #endif -// For VSCode -#ifdef __INTELLISENSE__ +#ifdef __CWCC__ +// codewarrior-specific syntax +#define AT_ADDRESS(addr) : (addr) +#elif defined(__EDITOR_CHECKING__) +// dummy implementations for editor tooling +#define AT_ADDRESS(addr) #define asm #define __attribute__(x) #define __declspec(x) +#else +// building with a non-codewarrior compiler is not supported yet +#error "workarounds for codewarrior's language extensions unimplemented" #endif diff --git a/include/rk_types.h b/include/rk_types.h index 0a9b36b2..6185ea2d 100644 --- a/include/rk_types.h +++ b/include/rk_types.h @@ -111,7 +111,7 @@ class NonCopyable { // Main static assert macro -#if defined(__INTELLISENSE__) +#ifdef __EDITOR_CHECKING__ #if !__has_extension(c_static_assert) #error "language server lacks `_Static_assert` support" #endif diff --git a/lib/MSL/include/math.h b/lib/MSL/include/math.h index 9b7a51f6..ee393646 100644 --- a/lib/MSL/include/math.h +++ b/lib/MSL/include/math.h @@ -25,9 +25,12 @@ inline f32 sqrtf(f32 x) { return (f32)sqrt(x); } f64 acos(f64); inline f32 acosf(f32 x) { return (f32)acos(x); } -#ifdef __INTELLISENSE__ -#define __fabsf(x) x -#define __fabs(x) x +#ifdef __CWCC__ +// when using the codewarrior compiler, __fabs and __fabsf are builtin intrinsics. +#elif defined(__EDITOR_CHECKING__) +// dummy implementation for editor tooling +#define __fabsf(x) (x) +#define __fabs(x) (x) #endif f32 fabsf(f32); diff --git a/lib/MSL/include/stddef.h b/lib/MSL/include/stddef.h index a719e004..810d1e29 100644 --- a/lib/MSL/include/stddef.h +++ b/lib/MSL/include/stddef.h @@ -1,6 +1,8 @@ #pragma once -#ifdef __INTELLISENSE__ +#include "macros.h" + +#ifdef __EDITOR_CHECKING__ #define offsetof(type, m) __builtin_offsetof(type,m) #else #define offsetof(type, m) ((size_t) & (((type*)0)->m)) diff --git a/lib/MSL/include/stdlib.h b/lib/MSL/include/stdlib.h index 41697608..8848bef7 100644 --- a/lib/MSL/include/stdlib.h +++ b/lib/MSL/include/stdlib.h @@ -1,5 +1,7 @@ #pragma once +#include "macros.h" + #ifndef SIZE_T_DEFINE #define SIZE_T_DEFINE typedef unsigned long size_t; @@ -9,11 +11,10 @@ typedef unsigned long size_t; #ifdef __CWCC__ #define abs(x) __abs(x) #define labs(x) __labs(x) -#elif defined(__clang__) -#define abs(x) __builtin_abs(x) -#define labs(x) __builtin_labs(x) -#else -#error compiler has no instrinsic abs support, please do some sit ups. +#elif defined(__EDITOR_CHECKING__) +// dummy implementation for editor tooling +#define abs(x) (x) +#define labs(x) (x) #endif long strtol(const char* restrict nptr, char** restrict endptr, int base); diff --git a/src/system/CourseMap.hpp b/src/system/CourseMap.hpp index d02748fe..c1e90153 100644 --- a/src/system/CourseMap.hpp +++ b/src/system/CourseMap.hpp @@ -453,9 +453,11 @@ class MapdataAreaAccessor { MapdataAreaBase** byPriority; }; static_assert(sizeof(MapdataAreaAccessor) == 0x14); +#ifndef __EDITOR_CHECKING__ // Ensure the vtable does not exist at offset 0x0 // (It should exist at offset 0x8) static_assert(offsetof(MapdataAreaAccessor, entries) == 0x0); +#endif class MapdataCameraAccessor : public MapdataAccessorBase {