From 15b92955f41f5b0053e6cddb97d7f4c9e9554c1d Mon Sep 17 00:00:00 2001 From: fedi-nabli Date: Sat, 6 Apr 2024 13:47:13 +0100 Subject: [PATCH] Implementing includes - Part 3 --- Makefile | 19 ++++++++++++++----- .../preprocessor}/.keep | 0 build/preprocessor/static-includes/.keep | 0 preprocessor/preprocessor.c | 9 ++++++++- preprocessor/preprocessor.h | 2 ++ preprocessor/static-include.c | 19 +++++++++++++++++++ preprocessor/static-includes/stdarg.c | 7 +++++++ preprocessor/static-includes/stddef.c | 7 +++++++ test.c | 1 + 9 files changed, 58 insertions(+), 6 deletions(-) rename {preprocessor/static-includes => build/preprocessor}/.keep (100%) create mode 100644 build/preprocessor/static-includes/.keep create mode 100644 preprocessor/static-include.c create mode 100644 preprocessor/static-includes/stdarg.c create mode 100644 preprocessor/static-includes/stddef.c diff --git a/Makefile b/Makefile index 37ddac0..ff2d990 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -OBJECTS = ./build/compiler.o ./build/cprocess.o ./build/lexer.o ./build/lex_process.o ./build/token.o ./build/parser.o ./build/node.o ./build/expressionable.o ./build/datatype.o ./build/scope.o ./build/symresolver.o ./build/array.o ./build/fixup.o ./build/codegen.o ./build/stackframe.o ./build/resolver.o ./build/rdefault.o ./build/helper.o ./build/preprocessor.o ./build/native.o ./build/helpers/buffer.o ./build/helpers/vector.o +OBJECTS = ./build/compiler.o ./build/cprocess.o ./build/lexer.o ./build/lex_process.o ./build/token.o ./build/parser.o ./build/node.o ./build/expressionable.o ./build/datatype.o ./build/scope.o ./build/symresolver.o ./build/array.o ./build/fixup.o ./build/codegen.o ./build/stackframe.o ./build/resolver.o ./build/rdefault.o ./build/helper.o ./build/preprocessor/preprocessor.o ./build/preprocessor/native.o ./build/preprocessor/static-include.o ./build/preprocessor/static-includes/stdarg.o ./build/preprocessor/static-includes/stddef.o ./build/helpers/buffer.o ./build/helpers/vector.o INCLUDES = -I./ all: ${OBJECTS} @@ -58,11 +58,20 @@ all: ${OBJECTS} ./build/helper.o: ./helper.c gcc ./helper.c ${INCLUDES} -g -c -o ./build/helper.o -./build/preprocessor.o: ./preprocessor/preprocessor.c - gcc ./preprocessor/preprocessor.c ${INCLUDES} -g -c -o ./build/preprocessor.o +./build/preprocessor/preprocessor.o: ./preprocessor/preprocessor.c + gcc ./preprocessor/preprocessor.c ${INCLUDES} -g -c -o ./build/preprocessor/preprocessor.o -./build/native.o: ./preprocessor/native.c - gcc ./preprocessor/native.c ${INCLUDES} -g -c -o ./build/native.o +./build/preprocessor/native.o: ./preprocessor/native.c + gcc ./preprocessor/native.c ${INCLUDES} -g -c -o ./build/preprocessor/native.o + +./build/preprocessor/static-include.o: ./preprocessor/static-include.c + gcc ./preprocessor/static-include.c ${INCLUDES} -g -c -o ./build/preprocessor/static-include.o + +./build/preprocessor/static-includes/stdarg.o: ./preprocessor/static-includes/stdarg.c + gcc ./preprocessor/static-includes/stdarg.c ${INCLUDES} -g -c -o ./build/preprocessor/static-includes/stdarg.o + +./build/preprocessor/static-includes/stddef.o: ./preprocessor/static-includes/stddef.c + gcc ./preprocessor/static-includes/stddef.c ${INCLUDES} -g -c -o ./build/preprocessor/static-includes/stddef.o ./build/helpers/buffer.o: ./helpers/buffer.c gcc ./helpers/buffer.c -o ./build/helpers/buffer.o -g -c diff --git a/preprocessor/static-includes/.keep b/build/preprocessor/.keep similarity index 100% rename from preprocessor/static-includes/.keep rename to build/preprocessor/.keep diff --git a/build/preprocessor/static-includes/.keep b/build/preprocessor/static-includes/.keep new file mode 100644 index 0000000..e69de29 diff --git a/preprocessor/preprocessor.c b/preprocessor/preprocessor.c index 936d5fc..bc05d16 100644 --- a/preprocessor/preprocessor.c +++ b/preprocessor/preprocessor.c @@ -1700,7 +1700,14 @@ void preprocessor_handle_include_token(struct compile_process* compiler) struct compile_process* new_compile_process = compile_include(file_path_token->sval, compiler); if (!new_compile_process) { - #warning "Check for static includes" + PREPROCESSOR_STATIC_INCLUDE_HANDLER_POST_CREATION handler = preprocessor_static_include_handler_for(file_path_token->sval); + if (handler) + { + // Handle it + preprocessor_create_static_include(compiler->preprocessor, file_path_token->sval, handler); + return; + } + compiler_error(compiler, "The file provided does not exist, unable to include %s\n", file_path_token->sval); } diff --git a/preprocessor/preprocessor.h b/preprocessor/preprocessor.h index 3390621..7b3bb12 100644 --- a/preprocessor/preprocessor.h +++ b/preprocessor/preprocessor.h @@ -108,4 +108,6 @@ struct token* preprocessor_previous_token(struct compile_process* compiler); struct vector* preprocessor_build_value_vector_for_integer(int value); struct preprocessor_definition* preprocessor_definition_create_native(struct preprocessor* preprocessor, const char* name, PREPROCESSOR_DEFINITION_NATIVE_CALL_EVALUATION evaluate, PREPROCESSOR_DEFINITION_NATIVE_CALL_VALUE value); +PREPROCESSOR_STATIC_INCLUDE_HANDLER_POST_CREATION preprocessor_static_include_handler_for(const char* filename); + #endif \ No newline at end of file diff --git a/preprocessor/static-include.c b/preprocessor/static-include.c new file mode 100644 index 0000000..532c015 --- /dev/null +++ b/preprocessor/static-include.c @@ -0,0 +1,19 @@ +#include "compiler.h" +#include "preprocessor/preprocessor.h" + +void preprocessor_stddef_internal_include(struct preprocessor* preprocessor, struct preprocessor_included_file* file); +void preprocessor_stdarg_internal_include(struct preprocessor* preprocessor, struct preprocessor_included_file* file); + +PREPROCESSOR_STATIC_INCLUDE_HANDLER_POST_CREATION preprocessor_static_include_handler_for(const char* filename) +{ + if (S_EQ(filename, "stddef-internal.h")) + { + return preprocessor_stddef_internal_include; + } + else if (S_EQ(filename, "stdarg-internal.h")) + { + return preprocessor_stdarg_internal_include; + } + + return NULL; +} \ No newline at end of file diff --git a/preprocessor/static-includes/stdarg.c b/preprocessor/static-includes/stdarg.c new file mode 100644 index 0000000..53171eb --- /dev/null +++ b/preprocessor/static-includes/stdarg.c @@ -0,0 +1,7 @@ +#include "compiler.h" +#include "preprocessor/preprocessor.h" + +void preprocessor_stdarg_internal_include(struct preprocessor* preprocessor, struct preprocessor_included_file* file) +{ + #warning "Create VALIST" +} \ No newline at end of file diff --git a/preprocessor/static-includes/stddef.c b/preprocessor/static-includes/stddef.c new file mode 100644 index 0000000..42d75bf --- /dev/null +++ b/preprocessor/static-includes/stddef.c @@ -0,0 +1,7 @@ +#include "compiler.h" +#include "preprocessor/preprocessor.h" + +void preprocessor_stddef_internal_include(struct preproecssor* preprocessor, struct preprocessor_included_file* file) +{ + #warning "Implement stddef" +} \ No newline at end of file diff --git a/test.c b/test.c index ecba0ad..89ba7c2 100644 --- a/test.c +++ b/test.c @@ -1,4 +1,5 @@ #include "test.h" +#include int main() {