aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/preprocess.c10
-rw-r--r--src/token.c12
-rw-r--r--tests/057.sh2
-rw-r--r--tests/059.sh2
-rw-r--r--tests/110.sh15
5 files changed, 27 insertions, 14 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);
}
diff --git a/tests/057.sh b/tests/057.sh
index 291030c..3649588 100644
--- a/tests/057.sh
+++ b/tests/057.sh
@@ -1,5 +1,5 @@
cat <<'EOF' > expected
-cannot open include file: ./nonexistent.h
+main.c:1: cannot open include file: "nonexistent.h"
EOF
test_compile_error <<'EOF'
diff --git a/tests/059.sh b/tests/059.sh
index 189ff5e..a7b92d0 100644
--- a/tests/059.sh
+++ b/tests/059.sh
@@ -7,7 +7,7 @@ int main() }
EOF
cat <<'EOF' > expected
-main.c:1: expected '{', but got '123 (<integer>)'
+main.c:1: expected '{', but got '123'
EOF
test_compile_error <<'EOF'
diff --git a/tests/110.sh b/tests/110.sh
new file mode 100644
index 0000000..4d48752
--- /dev/null
+++ b/tests/110.sh
@@ -0,0 +1,15 @@
+cat <<'EOF' > expected
+main.c:1: cannot open include file: "hoge.h"
+EOF
+
+test_compile_error <<'EOF'
+#include "hoge.h"
+EOF
+
+cat <<'EOF' > expected
+main.c:1: cannot resolve include file name: <hoge.h>
+EOF
+
+test_compile_error <<'EOF'
+#include <hoge.h>
+EOF