From 5029dc703ee42e4eb2d1fe4a8e97912bec91a69a Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 30 Sep 2022 08:44:28 +0200 Subject: [PATCH] Updated error message. --- src/compiler/llvm_codegen.c | 78 ++++++++++---------- src/compiler/parse_global.c | 8 +- test/test_suite/compile_time/ct_if_fails.c3 | 2 +- test/test_suite/globals/misplaced_const.c3 | 2 +- test/test_suite2/compile_time/ct_if_fails.c3 | 2 +- test/test_suite2/globals/misplaced_const.c3 | 2 +- 6 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/compiler/llvm_codegen.c b/src/compiler/llvm_codegen.c index f6db689e8..bdefe57ac 100644 --- a/src/compiler/llvm_codegen.c +++ b/src/compiler/llvm_codegen.c @@ -992,6 +992,7 @@ LLVMValueRef llvm_get_ref(GenContext *c, Decl *decl) } UNREACHABLE } + void *llvm_gen(Module *module) { if (!vec_size(module->units)) return NULL; @@ -1000,9 +1001,8 @@ void *llvm_gen(Module *module) gencontext_init(gen_context, module); gencontext_begin_module(gen_context); - VECEACH(module->units, j) - { - CompilationUnit *unit = module->units[j]; + FOREACH_BEGIN(CompilationUnit *unit, module->units) + gencontext_init_file_emit(gen_context, unit); gen_context->debug.compile_unit = unit->llvm.debug_compile_unit; gen_context->debug.file = unit->llvm.debug_file; @@ -1010,61 +1010,59 @@ void *llvm_gen(Module *module) FOREACH_BEGIN(Decl *initializer, unit->xxlizers) llvm_emit_xxlizer(gen_context, initializer); FOREACH_END(); - VECEACH(unit->methods, i) - { - llvm_emit_function_decl(gen_context, unit->methods[i]); - } - VECEACH(unit->types, i) - { - llvm_emit_type_decls(gen_context, unit->types[i]); - } - VECEACH(unit->enums, i) - { - llvm_emit_type_decls(gen_context, unit->enums[i]); - } - VECEACH(unit->functions, i) - { - Decl *func = unit->functions[i]; + + FOREACH_BEGIN(Decl *method, unit->methods) + llvm_emit_function_decl(gen_context, method); + FOREACH_END(); + + FOREACH_BEGIN(Decl *type_decl, unit->types) + llvm_emit_type_decls(gen_context, type_decl); + FOREACH_END(); + + FOREACH_BEGIN(Decl *enum_decl, unit->enums) + llvm_emit_type_decls(gen_context, enum_decl); + FOREACH_END(); + + FOREACH_BEGIN(Decl *func, unit->functions) llvm_emit_function_decl(gen_context, func); - } + FOREACH_END(); + if (unit->main_function && unit->main_function->is_synthetic) { llvm_emit_function_decl(gen_context, unit->main_function); } - } - VECEACH(module->units, j) - { - CompilationUnit *unit = module->units[j]; + FOREACH_END(); + + FOREACH_BEGIN(CompilationUnit *unit, module->units) + gen_context->debug.compile_unit = unit->llvm.debug_compile_unit; gen_context->debug.file = unit->llvm.debug_file; - VECEACH(unit->vars, i) - { - llvm_get_ref(gen_context, unit->vars[i]); - } - VECEACH(unit->vars, i) - { - llvm_emit_global_variable_init(gen_context, unit->vars[i]); - } - VECEACH(unit->functions, i) - { - Decl *decl = unit->functions[i]; + FOREACH_BEGIN(Decl *var, unit->vars) + llvm_get_ref(gen_context, var); + FOREACH_END(); + + FOREACH_BEGIN(Decl *var, unit->vars) + llvm_emit_global_variable_init(gen_context, var); + FOREACH_END(); + + FOREACH_BEGIN(Decl *decl, unit->functions) if (decl->func_decl.body) llvm_emit_function_body(gen_context, decl); - } + FOREACH_END(); + if (unit->main_function && unit->main_function->is_synthetic) { llvm_emit_function_body(gen_context, unit->main_function); } - VECEACH(unit->methods, i) - { - Decl *decl = unit->methods[i]; + FOREACH_BEGIN(Decl *decl, unit->methods) if (decl->func_decl.body) llvm_emit_function_body(gen_context, decl); - } + FOREACH_END(); gencontext_end_file_emit(gen_context, unit); - } + + FOREACH_END(); llvm_emit_constructors_and_destructors(gen_context); diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index fdb5881c5..daaa3f391 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -2659,10 +2659,12 @@ Decl *parse_top_level_statement(ParseContext *c) ASSIGN_DECL_OR_RET(decl, parse_global_declaration(c, visibility), poisoned_decl); break; } - default: - SEMA_ERROR_HERE("Expected a top level declaration here."); + case TOKEN_EOS: + SEMA_ERROR_HERE("';' wasn't expected here, try removing it."); + return poisoned_decl; + default: + SEMA_ERROR_HERE("Expected the start of a global declaration here."); return poisoned_decl; - break; } assert(decl); return decl; diff --git a/test/test_suite/compile_time/ct_if_fails.c3 b/test/test_suite/compile_time/ct_if_fails.c3 index 1d582b250..2392071f1 100644 --- a/test/test_suite/compile_time/ct_if_fails.c3 +++ b/test/test_suite/compile_time/ct_if_fails.c3 @@ -12,7 +12,7 @@ $endif; $if (1): $else: -$else: // #error: Expected a top level declaration here. +$else: // #error: Expected the start of a global declaration here $endif; diff --git a/test/test_suite/globals/misplaced_const.c3 b/test/test_suite/globals/misplaced_const.c3 index d8ebafd84..6ea51e0c8 100644 --- a/test/test_suite/globals/misplaced_const.c3 +++ b/test/test_suite/globals/misplaced_const.c3 @@ -3,4 +3,4 @@ int BAR = 4; // #error: This looks like a constant variable, did you forget 'con const BAZ = "ofke"; -FOOBAR; // #error: Expected a top level declaration here. \ No newline at end of file +FOOBAR; // #error: Expected the start of a global declaration here \ No newline at end of file diff --git a/test/test_suite2/compile_time/ct_if_fails.c3 b/test/test_suite2/compile_time/ct_if_fails.c3 index 1d582b250..2392071f1 100644 --- a/test/test_suite2/compile_time/ct_if_fails.c3 +++ b/test/test_suite2/compile_time/ct_if_fails.c3 @@ -12,7 +12,7 @@ $endif; $if (1): $else: -$else: // #error: Expected a top level declaration here. +$else: // #error: Expected the start of a global declaration here $endif; diff --git a/test/test_suite2/globals/misplaced_const.c3 b/test/test_suite2/globals/misplaced_const.c3 index d8ebafd84..6ea51e0c8 100644 --- a/test/test_suite2/globals/misplaced_const.c3 +++ b/test/test_suite2/globals/misplaced_const.c3 @@ -3,4 +3,4 @@ int BAR = 4; // #error: This looks like a constant variable, did you forget 'con const BAZ = "ofke"; -FOOBAR; // #error: Expected a top level declaration here. \ No newline at end of file +FOOBAR; // #error: Expected the start of a global declaration here \ No newline at end of file