Skip to content

Commit

Permalink
Implementing includes - Part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
fedi-nabli committed Apr 6, 2024
1 parent 665fa79 commit 15b9295
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 6 deletions.
19 changes: 14 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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}
Expand Down Expand Up @@ -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
Expand Down
File renamed without changes.
Empty file.
9 changes: 8 additions & 1 deletion preprocessor/preprocessor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions preprocessor/preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 19 additions & 0 deletions preprocessor/static-include.c
Original file line number Diff line number Diff line change
@@ -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;
}
7 changes: 7 additions & 0 deletions preprocessor/static-includes/stdarg.c
Original file line number Diff line number Diff line change
@@ -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"
}
7 changes: 7 additions & 0 deletions preprocessor/static-includes/stddef.c
Original file line number Diff line number Diff line change
@@ -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"
}
1 change: 1 addition & 0 deletions test.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "test.h"
#include <stdarg-internal.h>

int main()
{
Expand Down

0 comments on commit 15b9295

Please sign in to comment.