From d5d3f564bbc716d2a9f3d534c97d3baff77dda59 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 14 Mar 2024 02:48:07 -0400 Subject: [PATCH] Remove some shadowed variables --- Makefile | 2 +- builtins/files.c | 4 ++-- builtins/text.c | 6 +++--- compile.c | 30 ++++++++++++++++-------------- environment.c | 5 ----- parse.c | 6 +++--- 6 files changed, 25 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index a5b7d11..6cf1651 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ CCONFIG=-std=c11 -Werror -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -fPIC -I. LTO=-flto=auto -fno-fat-lto-objects -Wl,-flto LDFLAGS=-Wl,-rpath '-Wl,$$ORIGIN' # MAKEFLAGS := --jobs=$(shell nproc) --output-sync=target -CWARN=-Wall -Wextra -Wno-format +CWARN=-Wall -Wextra -Wno-format -Wshadow # -Wpedantic -Wsign-conversion -Wtype-limits -Wunused-result -Wnull-dereference \ # -Waggregate-return -Walloc-zero -Walloca -Warith-conversion -Wcast-align -Wcast-align=strict \ # -Wdangling-else -Wdate-time -Wdisabled-optimization -Wdouble-promotion -Wduplicated-branches \ diff --git a/builtins/files.c b/builtins/files.c index 9fe9b91..1622e0a 100644 --- a/builtins/files.c +++ b/builtins/files.c @@ -297,7 +297,7 @@ public int fprint_span(FILE *out, file_t *file, const char *start, const char *e for (int num = 0; num < digits; num++) printed += fputc(' ', out); printed += fputs(": ", out); - int column = 0; + int col = 0; for (const char *sp = line; *sp && *sp != '\n'; ++sp) { char print_char; if (sp < start) @@ -308,7 +308,7 @@ public int fprint_span(FILE *out, file_t *file, const char *start, const char *e print_char = '-'; else print_char = ' '; - printed += fputc_column(out, *sp, print_char, &column); + printed += fputc_column(out, *sp, print_char, &col); } printed += fputs("\n", out); } diff --git a/builtins/text.c b/builtins/text.c index e443da3..7116c92 100644 --- a/builtins/text.c +++ b/builtins/text.c @@ -248,9 +248,9 @@ public array_t Text__split(CORD str, CORD split) i += non_split; - size_t split = u8_strspn(ustr + i, usplit); - if (split == 0) break; - i += split; + size_t split_span = u8_strspn(ustr + i, usplit); + if (split_span == 0) break; + i += split_span; } return strings; } diff --git a/compile.c b/compile.c index 0a0c4ea..a2d432b 100644 --- a/compile.c +++ b/compile.c @@ -699,7 +699,7 @@ CORD compile(env_t *env, ast_t *ast) if (!array->items) return "(array_t){.length=0}"; - type_t *array_t = get_type(env, ast); + type_t *array_type = get_type(env, ast); int64_t n = 0; for (ast_list_t *item = array->items; item; item = item->next) { @@ -708,17 +708,19 @@ CORD compile(env_t *env, ast_t *ast) goto array_comprehension; } - type_t *item_type = Match(array_t, ArrayType)->item_type; - CORD code = CORD_all("$TypedArrayN(", compile_type(item_type), CORD_asprintf(", %ld", n)); - for (ast_list_t *item = array->items; item; item = item->next) - code = CORD_all(code, ", ", compile(env, item->ast)); - return CORD_cat(code, ")"); + { + type_t *item_type = Match(array_type, ArrayType)->item_type; + CORD code = CORD_all("$TypedArrayN(", compile_type(item_type), CORD_asprintf(", %ld", n)); + for (ast_list_t *item = array->items; item; item = item->next) + code = CORD_all(code, ", ", compile(env, item->ast)); + return CORD_cat(code, ")"); + } array_comprehension: { CORD code = "({ array_t $arr = {};"; env_t *scope = fresh_scope(env); - set_binding(scope, "$arr", new(binding_t, .type=array_t, .code="$arr")); + set_binding(scope, "$arr", new(binding_t, .type=array_type, .code="$arr")); for (ast_list_t *item = array->items; item; item = item->next) { if (item->ast->tag == For) { auto for_ = Match(item->ast, For); @@ -749,9 +751,9 @@ CORD compile(env_t *env, ast_t *ast) return CORD_cat(code, "}"); } - type_t *table_t = get_type(env, ast); - type_t *key_t = Match(table_t, TableType)->key_type; - type_t *value_t = Match(table_t, TableType)->value_type; + type_t *table_type = get_type(env, ast); + type_t *key_t = Match(table_type, TableType)->key_type; + type_t *value_t = Match(table_type, TableType)->value_type; CORD code = CORD_all("$Table(", compile_type(key_t), ", ", compile_type(value_t), ", ", @@ -992,10 +994,10 @@ CORD compile(env_t *env, ast_t *ast) } else code_err(ast, "There is no '%s' method for tables", call->name); } default: { - auto call = Match(ast, MethodCall); - type_t *fn_t = get_method_type(env, call->self, call->name); - arg_ast_t *args = new(arg_ast_t, .value=call->self, .next=call->args); - binding_t *b = get_namespace_binding(env, call->self, call->name); + auto methodcall = Match(ast, MethodCall); + type_t *fn_t = get_method_type(env, methodcall->self, methodcall->name); + arg_ast_t *args = new(arg_ast_t, .value=methodcall->self, .next=methodcall->args); + binding_t *b = get_namespace_binding(env, methodcall->self, methodcall->name); if (!b) code_err(ast, "No such method"); return CORD_all(b->code, "(", compile_arguments(env, ast, Match(fn_t, FunctionType)->args, args), ")"); } diff --git a/environment.c b/environment.c index 3a8ac50..a50d4e3 100644 --- a/environment.c +++ b/environment.c @@ -8,11 +8,6 @@ #include "typecheck.h" #include "builtins/util.h" -typedef struct { - const char *name; - binding_t binding; -} ns_entry_t; - env_t *new_compilation_unit(void) { env_t *env = new(env_t); diff --git a/parse.c b/parse.c index d44afda..68be402 100644 --- a/parse.c +++ b/parse.c @@ -233,14 +233,14 @@ static void expect_str( // Helper for matching closing parens with good error messages // static void expect_closing( - parse_ctx_t *ctx, const char **pos, const char *closing, const char *fmt, ...) { + parse_ctx_t *ctx, const char **pos, const char *close_str, const char *fmt, ...) { const char *start = *pos; spaces(pos); - if (match(pos, closing)) + if (match(pos, close_str)) return; const char *eol = strchr(*pos, '\n'); - const char *next = strstr(*pos, closing); + const char *next = strstr(*pos, close_str); const char *end = eol < next ? eol : next;