diff options
author | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2024-09-25 19:47:29 +0330 |
---|---|---|
committer | A404M <ahmadmahmoudiprogrammer@gmail.com> | 2024-09-25 19:47:29 +0330 |
commit | c409b8aaf6b6f63bd68a3356e146ab80b2ec8c4b (patch) | |
tree | 65ea5801fd910fc6bcff3f2e8f06b5fd7d249c78 /src/compiler/error_helper/error_helper.c | |
parent | f79290084948f3cf140395c270c07cf29ca58e8d (diff) |
fixed multiple variable definition bug
tried to implement import
Diffstat (limited to 'src/compiler/error_helper/error_helper.c')
-rw-r--r-- | src/compiler/error_helper/error_helper.c | 22 |
1 files changed, 18 insertions, 4 deletions
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 <stdarg.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> -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) { |