diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-08-18 22:19:34 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-08-18 22:20:25 +0900 |
| commit | db57dd8732d4dccbf1884ad97f87a3f22a2aef9c (patch) | |
| tree | ae07ae8e13b8230faaf350b4b9df94bbd79ab3cb | |
| parent | 1748294579492712d2b928a34329370fa3378a07 (diff) | |
| download | ducc-db57dd8732d4dccbf1884ad97f87a3f22a2aef9c.tar.gz ducc-db57dd8732d4dccbf1884ad97f87a3f22a2aef9c.tar.zst ducc-db57dd8732d4dccbf1884ad97f87a3f22a2aef9c.zip | |
refactor: make temporary variables anonymous to avoid unintentional name collision
| -rw-r--r-- | parse.c | 15 |
1 files changed, 2 insertions, 13 deletions
@@ -151,21 +151,10 @@ int add_lvar(Parser* p, const char* name, Type* ty, BOOL is_param) { return stack_offset; } -char* generate_temporary_lvar_name(Parser* p) { - char* buf = calloc(256, sizeof(char)); - for (int i = 1;; ++i) { - sprintf(buf, "__%d", i); - if (find_lvar(p, buf) == -1) { - return buf; - } - } -} - AstNode* generate_temporary_lvar(Parser* p, Type* ty) { - const char* name = generate_temporary_lvar_name(p); - int stack_offset = add_lvar(p, name, ty, FALSE); + int stack_offset = add_lvar(p, NULL, ty, FALSE); AstNode* lvar = ast_new(AstNodeKind_lvar); - lvar->name = name; + lvar->name = NULL; lvar->node_stack_offset = stack_offset; lvar->ty = ty; return lvar; |
