diff --git a/v0/include.mk b/v0/include.mk index 766f1a6..5185d04 100644 --- a/v0/include.mk +++ b/v0/include.mk @@ -11,7 +11,7 @@ V0_TEST_OBJ := $(patsubst v0/%.c,v0/bin/%.o,$(V0_TEST)) V0_SRC_DEPS := $(V0_SRC_OBJ:.o=.d) V0_TEST_DEPS := $(V0_TEST_OBJ:.o=.d) -CFLAGS += -Werror -Wall -pedantic -std=c89 +CFLAGS += -Werror -Wall -pedantic -std=c11 v0/bin/c2: $(V0_SRC_OBJ) $(CC) $(CFLAGS) -o $@ $^ diff --git a/v0/parser.c b/v0/parser.c index 5459bc5..089c692 100644 --- a/v0/parser.c +++ b/v0/parser.c @@ -5,13 +5,7 @@ #include Module* parser_parse(TokenStream* ts) { - /* Declarations first for C89 */ - Token t; - Module* module; - ImportDeclaration* new_imports; - int is_public; - - t = tokenstream_next(ts); + Token t = tokenstream_next(ts); if (t.token != TOKEN_MODULE) { log_on_line(&t.location, t.location.column_end, "expected 'module' keyword"); return NULL; @@ -23,7 +17,7 @@ Module* parser_parse(TokenStream* ts) { return NULL; } - module = (Module*)malloc(sizeof(Module)); + Module* module = (Module*)malloc(sizeof(Module)); if (module == NULL) { fprintf(stderr, "Out of memory\n"); exit(1); @@ -41,16 +35,13 @@ Module* parser_parse(TokenStream* ts) { return NULL; } - module->imports = NULL; - module->import_count = 0; - while (1) { t = tokenstream_next(ts); if (t.token != TOKEN_IMPORT) { break; } - new_imports = realloc(module->imports, (module->import_count + 1) * sizeof(ImportDeclaration)); + ImportDeclaration* new_imports = realloc(module->imports, (module->import_count + 1) * sizeof(ImportDeclaration)); if (!new_imports) { fprintf(stderr, "Out of memory\n"); exit(1); @@ -58,9 +49,9 @@ Module* parser_parse(TokenStream* ts) { module->imports = new_imports; t = tokenstream_next(ts); - is_public = 0; + bool is_public = false; if (t.token == TOKEN_IDENTIFIER && strncmp(t.text.data, "public", t.text.length) == 0) { - is_public = 1; + is_public = true; t = tokenstream_next(ts); } @@ -70,8 +61,7 @@ Module* parser_parse(TokenStream* ts) { return NULL; } - module->imports[module->import_count].module_name = t; - module->imports[module->import_count].is_public = (bool)is_public; + module->imports[module->import_count] = (ImportDeclaration){ .module_name = t, .is_public = is_public }; module->import_count++; t = tokenstream_next(ts);