Bugfix for directive parsing
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 9 Jul 2020 18:25:11 +0000 (13:25 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 9 Jul 2020 18:25:11 +0000 (13:25 -0500)
include/onyxmsgs.h
onyx
src/onyxchecker.c
src/onyxmsgs.c
src/onyxparser.c

index 8490bd066bbcff4ef549329a144da5e5a928eb42..9c23a1a42d214cbd9320452da0d501eeb788ab49 100644 (file)
@@ -16,6 +16,8 @@ typedef enum OnyxMessageType {
     ONYX_MESSAGE_TYPE_NOT_LVAL,
     ONYX_MESSAGE_TYPE_ASSIGN_CONST,
     ONYX_MESSAGE_TYPE_UNKNOWN_SYMBOL,
+    ONYX_MESSAGE_TYPE_UNKNOWN_DIRECTIVE,
+
     ONYX_MESSAGE_TYPE_CONFLICTING_GLOBALS,
     ONYX_MESSAGE_TYPE_BINOP_MISMATCH_TYPE,
     ONYX_MESSAGE_TYPE_ASSIGNMENT_TYPE_MISMATCH,
diff --git a/onyx b/onyx
index c96373e52331992eb241a71850623ece26fa74f4..aeaff62dad6084b1132b65650cf6ecd9d46eebae 100755 (executable)
Binary files a/onyx and b/onyx differ
index b63ae843421314c8787a9a41aeb467245e7c6a36..1361d78af6a84c2e3fb15da7e7aefd88998556b5 100644 (file)
@@ -194,7 +194,7 @@ static void check_call(OnyxSemPassState* state, AstNodeCall* call) {
         if (formal_param->base.type != actual_param->base.type) {
             onyx_message_add(state->msgs,
                     ONYX_MESSAGE_TYPE_FUNCTION_PARAM_TYPE_MISMATCH,
-                    call->base.token->pos,
+                    actual_param->value->token->pos,
                     callee->base.token->text, callee->base.token->length,
                     formal_param->base.type->name, arg_pos,
                     actual_param->base.type->name);
index 959c7969edabd6cb62c414e75422116689859d7a..4ef2848c7597dd814ca6978186d6d09af18cc543 100644 (file)
@@ -10,6 +10,8 @@ static const char* msg_formats[] = {
     "expected lval '%b'",
     "attempt to assign to constant '%b'",
     "unknown symbol '%s'",
+    "unknown directive '%b'",
+
     "conflicting declarations of global '%s'",
     "mismatched types for binary operator, '%s', '%s'",
     "mismatched types on assignment, expected '%s', got '%s'",
@@ -63,7 +65,7 @@ void onyx_message_print(OnyxMessages* msgs) {
     OnyxMessage* msg = msgs->first;
     i32 msg_count = 3;
 
-    while (msg && msg_count--) {
+    while (msg && msg_count-- > 0) {
         if (msg->pos.filename) {
             bh_file_contents* fc = &bh_table_get(bh_file_contents, *msgs->file_contents, (char *) msg->pos.filename);
 
index b286f4c2fd7341fd43704a68dd4942147ababeb8..260217a7cc0a47f6bebe191fbbee77e2c95ffba0 100644 (file)
@@ -688,7 +688,12 @@ static b32 parse_possible_directive(OnyxParser* parser, const char* dir) {
     expect(parser, '#');
     OnyxToken* sym = expect(parser, TOKEN_TYPE_SYMBOL);
 
-    return strncmp(dir, sym->text, sym->length) == 0;
+    b32 match = (strlen(dir) == sym->length) && (strncmp(dir, sym->text, sym->length) == 0);
+    if (!match) {
+        parser_prev_token(parser);
+        parser_prev_token(parser);
+    }
+    return match;
 }
 
 static AstNodeFunction* parse_function_definition(OnyxParser* parser) {
@@ -704,6 +709,16 @@ static AstNodeFunction* parse_function_definition(OnyxParser* parser) {
         else if (parse_possible_directive(parser, "inline")) {
             func_def->base.flags |= ONYX_AST_FLAG_INLINE;
         }
+
+        else {
+            OnyxToken* directive_token = expect(parser, '#');
+            OnyxToken* symbol_token = expect(parser, TOKEN_TYPE_SYMBOL);
+
+            onyx_message_add(parser->msgs,
+                    ONYX_MESSAGE_TYPE_UNKNOWN_DIRECTIVE,
+                    directive_token->pos,
+                    symbol_token->text, symbol_token->length);
+        }
     }
 
     AstNodeLocal* params = parse_function_params(parser);