diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-08-31 00:11:36 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-08-31 00:16:04 +0900 |
| commit | a5ee9d944edf665c814bbfeded2849f2bb980ed8 (patch) | |
| tree | 81c111c54d47e11a90e928edaeef6e1a1eba1e57 /src | |
| parent | 76b0c6bb6bbc339789943ada1f79ec1eba52239f (diff) | |
| download | ducc-a5ee9d944edf665c814bbfeded2849f2bb980ed8.tar.gz ducc-a5ee9d944edf665c814bbfeded2849f2bb980ed8.tar.zst ducc-a5ee9d944edf665c814bbfeded2849f2bb980ed8.zip | |
fix: error message when included file is not found
Diffstat (limited to 'src')
| -rw-r--r-- | src/preprocess.c | 10 | ||||
| -rw-r--r-- | src/token.c | 12 |
2 files changed, 10 insertions, 12 deletions
diff --git a/src/preprocess.c b/src/preprocess.c index c2dd3a8..284a633 100644 --- a/src/preprocess.c +++ b/src/preprocess.c @@ -738,10 +738,11 @@ static void replace_single_pp_token(Preprocessor* pp, int dest, Token* source_to replace_pp_tokens(pp, dest, dest + 1, &tokens); } -static void expand_include_directive(Preprocessor* pp, const char* include_name) { +static void expand_include_directive(Preprocessor* pp, const char* include_name, Token* original_include_name_tok) { InFile* include_source = infile_open(include_name); if (!include_source) { - fatal_error("cannot open include file: %s", include_name); + fatal_error("%s:%d: cannot open include file: %s", original_include_name_tok->loc.filename, + original_include_name_tok->loc.line, token_stringify(original_include_name_tok)); } TokenArray* include_pp_tokens = do_preprocess(include_source, pp->include_depth + 1, pp->macros); @@ -1115,11 +1116,12 @@ static void preprocess_include_directive(Preprocessor* pp) { Token* include_name = read_include_header_name(pp); const char* include_name_resolved = resolve_include_name(pp, include_name); if (include_name_resolved == NULL) { - fatal_error("cannot resolve include file name: %s", include_name); + fatal_error("%s:%d: cannot resolve include file name: %s", include_name->loc.filename, include_name->loc.line, + token_stringify(include_name)); } skip_whitespaces(pp); expect_pp_token(pp, TokenKind_newline); - expand_include_directive(pp, include_name_resolved); + expand_include_directive(pp, include_name_resolved, include_name); } static void preprocess_embed_directive(Preprocessor* pp) { diff --git a/src/token.c b/src/token.c index 6b06b16..82e728f 100644 --- a/src/token.c +++ b/src/token.c @@ -291,16 +291,12 @@ const char* token_stringify(Token* tok) { sprintf(buf, "#%s", tok->value.string); return buf; } else if (k == TokenKind_literal_int) { - const char* kind_str = token_kind_stringify(k); - char* buf = calloc(10 + strlen(kind_str) + 3 + 1, sizeof(char)); - sprintf(buf, "%d (%s)", tok->value.integer, kind_str); + char* buf = calloc(10, sizeof(char)); + sprintf(buf, "%d", tok->value.integer); return buf; } else if (k == TokenKind_other || k == TokenKind_character_constant || k == TokenKind_ident || - k == TokenKind_literal_str) { - const char* kind_str = token_kind_stringify(k); - char* buf = calloc(strlen(tok->value.string) + strlen(kind_str) + 3 + 1, sizeof(char)); - sprintf(buf, "%s (%s)", tok->value.string, kind_str); - return buf; + k == TokenKind_literal_str || k == TokenKind_header_name) { + return tok->value.string; } else { return token_kind_stringify(k); } |
