From c409b8aaf6b6f63bd68a3356e146ab80b2ec8c4b Mon Sep 17 00:00:00 2001 From: A404M Date: Wed, 25 Sep 2024 19:47:29 +0330 Subject: fixed multiple variable definition bug tried to implement import --- src/compiler/error_helper/error_helper.c | 22 ++++++++++++++++++---- src/compiler/error_helper/error_helper.h | 3 ++- 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'src/compiler/error_helper') diff --git a/src/compiler/error_helper/error_helper.c b/src/compiler/error_helper/error_helper.c index fd648e4..2a9b209 100644 --- a/src/compiler/error_helper/error_helper.c +++ b/src/compiler/error_helper/error_helper.c @@ -3,18 +3,32 @@ #include #include #include +#include -void printError(char const *error, SourceCode code, char const *begin, +void printError(char const *error, SourceCode *sourceCode, char const *begin, char const *end, ...) { va_list args; va_start(args, end); char *errorStr; vasprintf(&errorStr, error, args); - char const *lineBegin = code; + const Code *code = NULL; + + for (size_t i = 0; i < sourceCode->size; ++i) { + const Code *source = sourceCode->codes[i]; + if (source->code <= begin && strlen(source->code)+source->code >= end) { + code = source; + } + } + if (code == NULL) { + fprintf(stderr, "Bad Error: the error is in no source code"); + return; + } + + char const *lineBegin = code->code; int line = 1; - char const *iter = code; + char const *iter = code->code; for (; iter < begin; ++iter) { const char c = *iter; switch (c) { @@ -54,7 +68,7 @@ void printError(char const *error, SourceCode code, char const *begin, } AFTER_LOOP: - fprintf(stderr, "Error: %s at line %d\n", errorStr, line); + fprintf(stderr, "Error: %s at %s:%d\n", errorStr, code->filePath, line); int printed = 0; for (iter = lineBegin; iter < lineEnd; ++iter) { diff --git a/src/compiler/error_helper/error_helper.h b/src/compiler/error_helper/error_helper.h index 3a78c7c..c118fa9 100644 --- a/src/compiler/error_helper/error_helper.h +++ b/src/compiler/error_helper/error_helper.h @@ -1,6 +1,7 @@ #pragma once +#include #include -extern void printError(char const *error, SourceCode code, char const *begin, +extern void printError(char const *error, SourceCode *code, char const *begin, char const *end, ...); -- cgit v1.2.3