From 5e384049170dcb9e7e8aae5e98729bbc26661f90 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 21 Jun 2024 02:04:37 +0200 Subject: Huge changes to static analysis --- src/parser.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/parser.c') diff --git a/src/parser.c b/src/parser.c index 44888ae..5d9bf9c 100644 --- a/src/parser.c +++ b/src/parser.c @@ -10,6 +10,7 @@ #include "common.h" #include "errors.h" #include "parser.h" +#include "strview.h" #if DEBUG # define AST_DFLT_CAP (8) @@ -114,16 +115,17 @@ idx_t_ parsedecl(struct ast *ast, struct lexemes toks, bool toplvl) { idx_t_ i = astalloc(ast); - ast->lexemes[i] = toksidx; bool pub; - if (toplvl && toks.kinds[toksidx] == LEXIDENT && toks.strs[toksidx].len == 3 - && memcmp("pub", toks.strs[toksidx].p, 3) == 0) + if (toplvl && toks.kinds[toksidx] == LEXIDENT + && strview_eq(SV("pub"), toks.strs[toksidx])) { pub = true; - toksidx++; - } else + ast->lexemes[i] = ++toksidx; + } else { pub = false; + ast->lexemes[i] = toksidx; + } if (toks.kinds[toksidx++] != LEXIDENT) err("parser: Expected identifier"); @@ -230,7 +232,7 @@ parsestmt(struct ast *ast, struct lexemes toks) err("parser: Expected identifier"); struct strview sv = toks.strs[toksidx]; - if (sv.len == 6 && memcmp(sv.p, "return", 6) == 0) { + if (strview_eq(SV("return"), sv)) { i = astalloc(ast); ast->lexemes[i] = toksidx++; ast->kinds[i] = ASTRET; -- cgit v1.2.3