Skip to content

Commit

Permalink
Initial support for using clangd (#375)
Browse files Browse the repository at this point in the history
* Add IDE-independent `DECOMP_IDE_FLAG` define

* Generate clangd config when running configure.py

* Fix some errors clangd reports in RVL_SDK

* Move clangd configuration flags into .clangd file

* Fix clangd language cflag issues

* Apply clangd compiler defines in project.py instead of .clangd

* Apply a bunch of IWYU pragmas to stdlib files

* Replace remaining explicit __declspecs with their macro equivalents

* Fix operator new exception specifications

* Couple miscellaneous fixes
  • Loading branch information
TheNathannator authored Oct 10, 2024
1 parent 8de0975 commit f0fdd44
Show file tree
Hide file tree
Showing 83 changed files with 470 additions and 224 deletions.
34 changes: 34 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
CompileFlags:
Add: [
# Remove all built-in definitions
"-undef",

# Indicator for things which shouldn't be processed in IDEs
"-DDECOMP_IDE_FLAG",

# Default to C++03
"--language=c++",
"-std=c++03",

# No standard includes
"-nostdinc",
"-nostdinc++",
"-fno-builtin",

# Target definitions
"--target=ppc32-unknown=linux-eabi",
]
---
# C files
If:
PathMatch: .*\.c
PathExclude: .*/stlport/.* # STLport is not C
CompileFlags:
Remove: [
"--language=",
"-std=",
]
Add: [
"--language=c",
"-std=c99",
]
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ build/
build.ninja
objdiff.json

# clangd
.cache/
compile_commands.json

# Doxygen output
doxygen/

Expand Down
1 change: 1 addition & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"defines": [
"MILO_DEBUG",
"HX_WII",
"DECOMP_IDE_FLAG",
"__MWERKS__=0x4302",
"__PPCBROADWAY__",
"__PPCGECKO__",
Expand Down
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"ms-vscode.cpptools",
"xaver.clang-format",
"akiramiyakoda.cppincludeguard",
"ms-python.black-formatter"
"ms-python.black-formatter",
"llvm-vs-code-extensions.vscode-clangd"
]
}
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
"utility": "cpp",
"valarray": "cpp",
"vector": "cpp",

".clangd": "yaml",
},
"C/C++ Include Guard.Macro Type": "Filepath",
"C/C++ Include Guard.Prefix": "",
Expand Down
8 changes: 2 additions & 6 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,14 @@
"label": "all_source_host",
"type": "shell",
"command": "ninja all_source_host",
"problemMatcher": {
"base": "$gcc"
},
"problemMatcher": [],
"group": "build"
},
{
"label": "current file (host)",
"type": "shell",
"command": "ninja host/${relativeFile}",
"problemMatcher": {
"base": "$gcc"
},
"problemMatcher": [],
"group": "build"
},
{
Expand Down
2 changes: 2 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@
objects_path,
]

config.make_clangd_config = True

# Build flags
flags = json.load(open(config_json_path, "r", encoding="utf-8"))
progress_categories: dict[str, str] = flags["progress_categories"]
Expand Down
4 changes: 2 additions & 2 deletions src/compiler_macros.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef COMPILER_MACROS_H
#define COMPILER_MACROS_H

#if !defined(__MWERKS__) || defined(__VS_CODE__)
#define __option(x)
#if !defined(__MWERKS__) || defined(DECOMP_IDE_FLAG)
#define __option(x) 0
#define __declspec(x)
#define __attribute__(x)
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/decomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
/*
* ASM macros, to prevent IDEs from complaining
*/
#if defined(__MWERKS__) && !defined(__VS_CODE__)
#if defined(__MWERKS__) && !defined(DECOMP_IDE_FLAG)
#define ASM_DECL asm
#define ASM_BLOCK asm
#else
Expand Down
1 change: 1 addition & 0 deletions src/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define ROTATE_LEFT(x, i) (((x) << (i)) | ((x) >> ((sizeof((x)) * 8) - (i))))
#define ROTATE_RIGHT(x, i) (((x) >> (i)) | ((x) << ((sizeof((x)) * 8) - (i))))

#define VARSIZE_ARRAY 1
#define ARRAY_LENGTH(x) (sizeof((x)) / sizeof((x)[0]))

#define null 0
Expand Down
4 changes: 2 additions & 2 deletions src/sdk/PowerPC_EABI_Support/MSL/MSL_C++/new
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace std {

}

void *operator new(std::size_t size);
void *operator new[](std::size_t size);
void *operator new(std::size_t size) throw(std::bad_alloc);
void *operator new[](std::size_t size) throw(std::bad_alloc);
void operator delete(void *ptr) throw();
void operator delete[](void *ptr) throw();

Expand Down
2 changes: 1 addition & 1 deletion src/sdk/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/arith.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
extern "C" {
#endif

#if !defined(__MWERKS__) || defined(__VS_CODE__)
#ifdef DECOMP_IDE_FLAG
#define __abs(x) abs(x)
#define __labs(x) labs(x)
#endif
Expand Down
8 changes: 5 additions & 3 deletions src/sdk/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/float.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#ifndef MSL_COMMON_FLOAT_H
#define MSL_COMMON_FLOAT_H

#include "compiler_macros.h"

#ifdef __cplusplus
extern "C" {
#endif

__declspec(section ".data") extern int __float_nan;
__declspec(section ".data") extern float __float_huge;
__declspec(section ".data") extern double __double_huge;
DECL_SECTION(".data") extern int __float_nan;
DECL_SECTION(".data") extern float __float_huge;
DECL_SECTION(".data") extern double __double_huge;

#define INFINITY (__float_huge)
#define NAN (*(float *)&__float_nan)
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/PowerPC_EABI_Support/MSL/MSL_C/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
extern "C" {
#endif

#include "MSL_Common/assert_api.h"
#include "MSL_Common/assert_api.h" /* IWYU pragma: export */

#ifdef NDEBUG
#define assert(condition) ((void)0)
Expand Down
4 changes: 2 additions & 2 deletions src/sdk/PowerPC_EABI_Support/MSL/MSL_C/ctype.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef _CTYPE_H
#define _CTYPE_H

#include "MSL_Common/locale_def.h"
#include "MSL_Common/ctype_api.h"
#include "MSL_Common/locale_def.h" /* IWYU pragma: export */
#include "MSL_Common/ctype_api.h" /* IWYU pragma: export */

#ifdef __cplusplus
extern "C" {
Expand Down
4 changes: 3 additions & 1 deletion src/sdk/PowerPC_EABI_Support/MSL/MSL_C/errno.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef _ERRNO_H
#define _ERRNO_H

#include "compiler_macros.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -53,7 +55,7 @@ extern "C" {
#define EUNKNOWN 99
/* clang-format on */

__declspec(section ".sdata") extern int errno;
DECL_SECTION(".sdata") extern int errno;

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/PowerPC_EABI_Support/MSL/MSL_C/inttypes.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _INTTYPES_H
#define _INTTYPES_H

#include "MSL_Common/imaxdiv_def.h"
#include "MSL_Common/imaxdiv_def.h" /* IWYU pragma: export */

#ifdef __cplusplus
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/PowerPC_EABI_Support/MSL/MSL_C/locale.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _LOCALE_H
#define _LOCALE_H

#include "MSL_Common/locale_def.h"
#include "MSL_Common/locale_def.h" /* IWYU pragma: export */

#ifdef __cplusplus
extern "C" {
Expand Down
8 changes: 4 additions & 4 deletions src/sdk/PowerPC_EABI_Support/MSL/MSL_C/math.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#ifndef _MATH_H
#define _MATH_H

#include "MSL_Common/math_api.h"
#include "MSL_Common/float.h"
#include "MSL_Common_Embedded/Math/Double_precision/fdlibm.h"
#include "MSL_Common/math_api.h" /* IWYU pragma: export */
#include "MSL_Common/float.h" /* IWYU pragma: export */
#include "MSL_Common_Embedded/Math/Double_precision/fdlibm.h" /* IWYU pragma: export */

#ifdef __cplusplus
extern "C" {
#endif

#if !defined(__MWERKS__) || defined(__VS_CODE__)
#ifdef DECOMP_IDE_FLAG
/* Get clangd to shut up about __fabs being undefined. */
#define __fabs(x) fabs(x)
#define __frsqrte(x) (x)
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/PowerPC_EABI_Support/MSL/MSL_C/setjmp.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _SETJMP_H
#define _SETJMP_H

#include "PowerPC_EABI_Support/Runtime/Gecko_setjmp.h"
#include "PowerPC_EABI_Support/Runtime/Gecko_setjmp.h" /* IWYU pragma: export */

#ifdef __cplusplus
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/PowerPC_EABI_Support/MSL/MSL_C/stdarg.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef _STDARG_H_
#define _STDARG_H_

#include "MSL_Common/va_list_def.h"
#include "MSL_Common/va_list_def.h" /* IWYU pragma: export */

#endif
2 changes: 1 addition & 1 deletion src/sdk/PowerPC_EABI_Support/MSL/MSL_C/stdbool.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef _STDBOOL_H_
#define _STDBOOL_H_

#include "MSL_Common/bool_def.h"
#include "MSL_Common/bool_def.h" /* IWYU pragma: export */

#endif
6 changes: 3 additions & 3 deletions src/sdk/PowerPC_EABI_Support/MSL/MSL_C/stddef.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef _STDDEF_H
#define _STDDEF_H

#include "MSL_Common/intptr_def.h"
#include "MSL_Common/null_def.h"
#include "MSL_Common/size_def.h"
#include "MSL_Common/intptr_def.h" /* IWYU pragma: export */
#include "MSL_Common/null_def.h" /* IWYU pragma: export */
#include "MSL_Common/size_def.h" /* IWYU pragma: export */

#ifdef __cplusplus
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/PowerPC_EABI_Support/MSL/MSL_C/stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _STDINT_H

#include <limits.h>
#include "MSL_Common/intmax_def.h"
#include "MSL_Common/intmax_def.h" /* IWYU pragma: export */

#ifdef __cplusplus
extern "C" {
Expand Down
10 changes: 5 additions & 5 deletions src/sdk/PowerPC_EABI_Support/MSL/MSL_C/stdio.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef _STDIO_H
#define _STDIO_H

#include "MSL_Common/stdio_api.h"
#include "MSL_Common/FILE_POS.h"
#include "MSL_Common/file_io.h"
#include "MSL_Common/printf.h"
#include "MSL_Common/scanf.h"
#include "MSL_Common/stdio_api.h" /* IWYU pragma: export */
#include "MSL_Common/FILE_POS.h" /* IWYU pragma: export */
#include "MSL_Common/file_io.h" /* IWYU pragma: export */
#include "MSL_Common/printf.h" /* IWYU pragma: export */
#include "MSL_Common/scanf.h" /* IWYU pragma: export */

#ifdef __cplusplus
extern "C" {
Expand Down
12 changes: 6 additions & 6 deletions src/sdk/PowerPC_EABI_Support/MSL/MSL_C/stdlib.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef _STDLIB_H
#define _STDLIB_H

#include "MSL_Common/alloc.h"
#include "MSL_Common/arith.h"
#include "MSL_Common/mbstring.h"
#include "MSL_Common/rand.h"
#include "MSL_Common/strtold.h"
#include "MSL_Common/strtoul.h"
#include "MSL_Common/alloc.h" /* IWYU pragma: export */
#include "MSL_Common/arith.h" /* IWYU pragma: export */
#include "MSL_Common/mbstring.h" /* IWYU pragma: export */
#include "MSL_Common/rand.h" /* IWYU pragma: export */
#include "MSL_Common/strtold.h" /* IWYU pragma: export */
#include "MSL_Common/strtoul.h" /* IWYU pragma: export */

#ifdef __cplusplus
extern "C" {
Expand Down
7 changes: 4 additions & 3 deletions src/sdk/PowerPC_EABI_Support/MSL/MSL_C/string.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#ifndef _STRING_H
#define _STRING_H

#include "PowerPC_EABI_Support/Runtime/__mem.h"
#include "MSL_Common/restrict_def.h"
#include "MSL_Common/string_api.h"
#include "MSL_Common/extras.h"

#include "PowerPC_EABI_Support/Runtime/__mem.h" /* IWYU pragma: export */
#include "MSL_Common/string_api.h" /* IWYU pragma: export */
#include "MSL_Common/extras.h" /* IWYU pragma: export */

#ifdef __cplusplus
extern "C" {
Expand Down
5 changes: 3 additions & 2 deletions src/sdk/PowerPC_EABI_Support/MSL/MSL_C/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
#define _TIME_H

#include "MSL_Common/restrict_def.h"
#include "MSL_Common/size_def.h"
#include "MSL_Common/time_def.h"

#include "MSL_Common/size_def.h" /* IWYU pragma: export */
#include "MSL_Common/time_def.h" /* IWYU pragma: export */

#ifdef __cplusplus
extern "C" {
Expand Down
22 changes: 11 additions & 11 deletions src/sdk/PowerPC_EABI_Support/MSL/MSL_C/wchar.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#ifndef _WCHAR_H
#define _WCHAR_H

#include "MSL_Common/wchar_def.h"
#include "MSL_Common/wchar_io.h"
#include "MSL_Common/wchar_time.h"
#include "MSL_Common/wchar_sizes.h"
#include "MSL_Common/wcstoul.h"
#include "MSL_Common/wint_def.h"
#include "MSL_Common/wmem.h"
#include "MSL_Common/wprintf.h"
#include "MSL_Common/wscanf.h"
#include "MSL_Common/wstring.h"
#include "MSL_Common/mbconvert.h"
#include "MSL_Common/wchar_def.h" /* IWYU pragma: export */
#include "MSL_Common/wchar_io.h" /* IWYU pragma: export */
#include "MSL_Common/wchar_time.h" /* IWYU pragma: export */
#include "MSL_Common/wchar_sizes.h" /* IWYU pragma: export */
#include "MSL_Common/wcstoul.h" /* IWYU pragma: export */
#include "MSL_Common/wint_def.h" /* IWYU pragma: export */
#include "MSL_Common/wmem.h" /* IWYU pragma: export */
#include "MSL_Common/wprintf.h" /* IWYU pragma: export */
#include "MSL_Common/wscanf.h" /* IWYU pragma: export */
#include "MSL_Common/wstring.h" /* IWYU pragma: export */
#include "MSL_Common/mbconvert.h" /* IWYU pragma: export */

#endif
6 changes: 3 additions & 3 deletions src/sdk/PowerPC_EABI_Support/MSL/MSL_C/wctype.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef _WCTYPE_H
#define _WCTYPE_H

#include "MSL_Common/locale_def.h"
#include "MSL_Common/wctype_api.h"
#include "MSL_Common/wint_def.h"
#include "MSL_Common/locale_def.h" /* IWYU pragma: export */
#include "MSL_Common/wctype_api.h" /* IWYU pragma: export */
#include "MSL_Common/wint_def.h" /* IWYU pragma: export */

#ifdef __cplusplus
extern "C" {
Expand Down
Loading

0 comments on commit f0fdd44

Please sign in to comment.