From 37217cf1b921a2a6e128b6134518912f0bd57f62 Mon Sep 17 00:00:00 2001 From: Mel Date: Mon, 30 Jun 2025 23:15:23 +0200 Subject: Factor out translation unit includes to seperate header This allows both the usual build compiler and an LSP server like `clangd` to correctly locate symbols throughout every subunit. Signed-off-by: Mel --- boot/catboot.c | 6 +----- boot/catboot.h | 20 ++++++++++++++++++++ boot/common.c | 4 ++++ boot/lex.c | 4 ++++ boot/parse.c | 4 ++++ boot/tree.c | 4 ++++ boot/visit.c | 4 ++++ 7 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 boot/catboot.h (limited to 'boot') diff --git a/boot/catboot.c b/boot/catboot.c index f716e4f..fac6273 100644 --- a/boot/catboot.c +++ b/boot/catboot.c @@ -24,11 +24,7 @@ #include #include -#include "common.c" -#include "lex.c" -#include "tree.c" -#include "parse.c" -#include "visit.c" +#include "catboot.h" const ascii* read_file(const ascii* path) diff --git a/boot/catboot.h b/boot/catboot.h new file mode 100644 index 0000000..4c40676 --- /dev/null +++ b/boot/catboot.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025, Mel G. + * + * SPDX-License-Identifier: MPL-2.0 + */ + +#pragma once + +// include all partial translation units, for correct language server behaviour +// despite the fact that single translation units are not yet supported. + +// when included in the root of the translation unit, this will compile the whole project, +// however if included in a partial subunit, the `#pragma once` in the subunit will prevent +// multiple inclusions of the itself, only adding other files, thus allowing for an LSP like `clang` +// to find the definitions of all other functions and types in the project. +#include "common.c" +#include "lex.c" +#include "tree.c" +#include "parse.c" +#include "visit.c" diff --git a/boot/common.c b/boot/common.c index 22ee50a..cf9aa46 100644 --- a/boot/common.c +++ b/boot/common.c @@ -8,6 +8,10 @@ * SPDX-License-Identifier: MPL-2.0 */ +#pragma once + +#include "catboot.h" + #include #include #include diff --git a/boot/lex.c b/boot/lex.c index 5b91187..f450798 100644 --- a/boot/lex.c +++ b/boot/lex.c @@ -7,6 +7,10 @@ * SPDX-License-Identifier: MPL-2.0 */ +#pragma once + +#include "catboot.h" + #define MAX_CHAR_BUFFER_SIZE 256 // byte position within a file. diff --git a/boot/parse.c b/boot/parse.c index 6aa61f7..d410476 100644 --- a/boot/parse.c +++ b/boot/parse.c @@ -7,6 +7,10 @@ * SPDX-License-Identifier: MPL-2.0 */ +#pragma once + +#include "catboot.h" + #define PARSER_LOOKAHEAD 2 #define CHECK(parse) \ diff --git a/boot/tree.c b/boot/tree.c index cb5fd2a..1eb19a8 100644 --- a/boot/tree.c +++ b/boot/tree.c @@ -6,6 +6,10 @@ * SPDX-License-Identifier: MPL-2.0 */ +#pragma once + +#include "catboot.h" + enum Unary_Operation { UNARY_NONE, diff --git a/boot/visit.c b/boot/visit.c index 24f033a..c297fb4 100644 --- a/boot/visit.c +++ b/boot/visit.c @@ -9,6 +9,10 @@ * SPDX-License-Identifier: MPL-2.0 */ +#pragma once + +#include "catboot.h" + struct Visit { struct Visit_Table* table; -- cgit 1.4.1