diff --git a/cc_core.c b/cc_core.c index 328cd9a..c2ce6b9 100644 --- a/cc_core.c +++ b/cc_core.c @@ -97,13 +97,18 @@ struct token_list* sym_lookup(char *s, struct token_list* symbol_list) return NULL; } +void line_error_token(struct token_list *token) +{ + require(NULL != token, "EOF reached inside of line_error\n"); + file_print(token->filename, stderr); + file_print(":", stderr); + file_print(numerate_number(token->linenumber), stderr); + file_print(":", stderr); +} + void line_error() { - require(NULL != global_token, "EOF reached inside of line_error\n"); - file_print(global_token->filename, stderr); - file_print(":", stderr); - file_print(numerate_number(global_token->linenumber), stderr); - file_print(":", stderr); + line_error_token(global_token); } void require_match(char* message, char* required) diff --git a/cc_macro.c b/cc_macro.c index 1d7dfb4..150f9bc 100644 --- a/cc_macro.c +++ b/cc_macro.c @@ -19,6 +19,7 @@ void require(int bool, char* error); int numerate_string(char *a); +void line_error_token(struct token_list *); struct conditional_inclusion { struct conditional_inclusion* prev; @@ -270,6 +271,12 @@ void macro_directive() } else if (match("#endif", macro_token->s)) { + if (NULL == conditional_inclusion_top) + { + line_error_token(macro_token); + file_print("unexpected #endif\n", stderr); + exit(EXIT_FAILURE); + } eat_current_token(); /* pop conditional inclusion */ t = conditional_inclusion_top; diff --git a/test/test.answers b/test/test.answers index 228be68..54138c6 100644 --- a/test/test.answers +++ b/test/test.answers @@ -169,8 +169,8 @@ a2a83f42119e646b389b98647cf6cf2aa9597185997c9453db746178c8c4c0bf test/results/t 698853b79efb30865a663c4863c050639eb21c7400008f7840830503928973d4 test/results/test0106-knight-native-binary 45c2ba61dc209d7ffa39de9ff0f0a7f8f3ea4d7e38598c72f982fcaf9a05c84a test/results/test0106-knight-posix-binary 944580ff4aae38aafac139faf6eed5bfe4ff68b01a7a3adfa346de8803101182 test/results/test0106-x86-binary -5d0a41c3ec339d6413167ab9e87d8d3444863d1dc12883592ad23669654cb7ce test/results/test1000-aarch64-binary -37952a1f53e7859408bee89a5521cb3ef818363fa4bda682a3696c24fe7ff645 test/results/test1000-amd64-binary -8cf345632079de545b1fac3158c7a2d048fa64ec0fed927c4b1bbffabdef5b3f test/results/test1000-armv7l-binary -f761471e800c86dcbaa1be532a7a0ccd3f6100e76852891331adb171c64bc932 test/results/test1000-knight-posix-binary -f5662f155218f9e73d92cfa28bab8d12c6ed407a5662cf583299ac4f5ec71f95 test/results/test1000-x86-binary +05da67e8b98c17fe19028b926f8f4a56fd162b6de54711cb2ae260632c129f0c test/results/test1000-aarch64-binary +211f04faefb5dd1f162e519641bed7e055f9147a0e3ef37ec86b84d4e1847664 test/results/test1000-amd64-binary +c38946118ad95309cd628f0e1b108507556f1c733b2ccb95a8235f9e99b18788 test/results/test1000-armv7l-binary +6417efad2ab83ea297e319b2ee4d9ba78bae0e6c18eed78115f4a8ae93eb1419 test/results/test1000-knight-posix-binary +0565d906bf7f962df0bb3b7c5020fb8f4f47aad0654279f8937c08815445e9f0 test/results/test1000-x86-binary diff --git a/test/test1000/proof.answer b/test/test1000/proof.answer index 7d87551..633bfa7 100644 --- a/test/test1000/proof.answer +++ b/test/test1000/proof.answer @@ -1 +1 @@ -cb2ed985d814d493cd376d89ef5471d66cfd76d78a7bb22fffbb076df44e0aa9 test/test1000/proof +3e0fb1cf49b0f2a14f4f0dbd213d5b8c5a46d4372a409924fa4996d84bd5d3f8 test/test1000/proof