public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
From: Carlos Maniero <carlos@maniero.me>
To: ~johnnyrichard/olang-devel@lists.sr.ht
Cc: Carlos Maniero <carlos@maniero.me>
Subject: [PATCH olang v1 3/3] naming: rename all identifier symbols to id
Date: Mon, 23 Sep 2024 10:11:57 +0000 (UTC)	[thread overview]
Message-ID: <20240923101141.76783-4-carlos@maniero.me> (raw)
In-Reply-To: <20240923101141.76783-1-carlos@maniero.me>

We were already using this pattern but initially we were callig them the
full name.

Signed-off-by: Carlos Maniero <carlos@maniero.me>
---
 src/ast.c                   | 12 ++++++------
 src/ast.h                   | 12 ++++++------
 src/checker.c               |  2 +-
 src/codegen_linux_aarch64.c |  4 ++--
 src/codegen_linux_x86_64.c  |  8 ++++----
 src/lexer.c                 |  4 ++--
 src/lexer.h                 |  2 +-
 src/parser.c                | 12 ++++++------
 src/pretty_print_ast.c      |  6 +++---
 tests/unit/parser_test.c    |  2 +-
 10 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/src/ast.c b/src/ast.c
index a136182..7019316 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -37,7 +37,7 @@ ast_new_program(arena_t *arena, ast_node_t *fn_def)
 }
 
 ast_node_t *
-ast_new_node_fn_def(arena_t *arena, string_view_t identifier, string_view_t return_type, ast_node_t *block)
+ast_new_node_fn_def(arena_t *arena, string_view_t id, string_view_t return_type, ast_node_t *block)
 {
     ast_node_t *node_fn_def = (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t));
     assert(node_fn_def);
@@ -45,7 +45,7 @@ ast_new_node_fn_def(arena_t *arena, string_view_t identifier, string_view_t retu
     node_fn_def->kind = AST_NODE_FN_DEF;
     ast_fn_definition_t *fn_def = &node_fn_def->as_fn_def;
 
-    fn_def->identifier = identifier;
+    fn_def->id = id;
     fn_def->return_type = return_type;
     fn_def->block = block;
 
@@ -53,7 +53,7 @@ ast_new_node_fn_def(arena_t *arena, string_view_t identifier, string_view_t retu
 }
 
 ast_node_t *
-ast_new_node_var_def(arena_t *arena, string_view_t identifier, string_view_t type, ast_node_t *value)
+ast_new_node_var_def(arena_t *arena, string_view_t id, string_view_t type, ast_node_t *value)
 {
     ast_node_t *node_var_def = (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t));
     assert(node_var_def);
@@ -61,7 +61,7 @@ ast_new_node_var_def(arena_t *arena, string_view_t identifier, string_view_t typ
     node_var_def->kind = AST_NODE_VAR_DEF;
     ast_var_definition_t *var_def = &node_var_def->as_var_def;
 
-    var_def->identifier = identifier;
+    var_def->id = id;
     var_def->type = type;
     var_def->value = value;
 
@@ -96,13 +96,13 @@ ast_new_node_literal_u32(arena_t *arena, uint32_t value)
 }
 
 ast_node_t *
-ast_new_node_ref(arena_t *arena, string_view_t identifier)
+ast_new_node_ref(arena_t *arena, string_view_t id)
 {
     ast_node_t *node_ref = (ast_node_t *)arena_alloc(arena, sizeof(ast_node_t));
     assert(node_ref);
 
     node_ref->kind = AST_NODE_REF;
-    node_ref->as_ref.identifier = identifier;
+    node_ref->as_ref.id = id;
 
     return node_ref;
 }
diff --git a/src/ast.h b/src/ast.h
index e618314..df65e59 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -53,7 +53,7 @@ typedef struct ast_program
 
 typedef struct ast_fn_definition
 {
-    string_view_t identifier;
+    string_view_t id;
     string_view_t return_type;
     ast_node_t *block;
     scope_t *scope;
@@ -61,7 +61,7 @@ typedef struct ast_fn_definition
 
 typedef struct ast_var_definition
 {
-    string_view_t identifier;
+    string_view_t id;
     string_view_t type;
     ast_node_t *value;
     scope_t *scope;
@@ -83,7 +83,7 @@ typedef struct ast_literal
 
 typedef struct ast_ref
 {
-    string_view_t identifier;
+    string_view_t id;
     scope_t *scope;
 } ast_ref_t;
 
@@ -149,10 +149,10 @@ ast_node_t *
 ast_new_program(arena_t *arena, ast_node_t *fn_def);
 
 ast_node_t *
-ast_new_node_fn_def(arena_t *arena, string_view_t identifier, string_view_t return_type, ast_node_t *block);
+ast_new_node_fn_def(arena_t *arena, string_view_t id, string_view_t return_type, ast_node_t *block);
 
 ast_node_t *
-ast_new_node_var_def(arena_t *arena, string_view_t identifier, string_view_t type, ast_node_t *value);
+ast_new_node_var_def(arena_t *arena, string_view_t id, string_view_t type, ast_node_t *value);
 
 ast_node_t *
 ast_new_node_bin_op(arena_t *arena, ast_binary_op_kind_t kind, ast_node_t *lhs, ast_node_t *rhs);
@@ -161,7 +161,7 @@ ast_node_t *
 ast_new_node_literal_u32(arena_t *arena, uint32_t value);
 
 ast_node_t *
-ast_new_node_ref(arena_t *arena, string_view_t identifier);
+ast_new_node_ref(arena_t *arena, string_view_t id);
 
 ast_node_t *
 ast_new_node_return_stmt(arena_t *arena, ast_node_t *expr);
diff --git a/src/checker.c b/src/checker.c
index def7e86..090920c 100644
--- a/src/checker.c
+++ b/src/checker.c
@@ -106,7 +106,7 @@ populate_scope(checker_t *checker, scope_t *scope, ast_node_t *ast)
         }
 
         case AST_NODE_VAR_DEF: {
-            string_view_t id = ast->as_var_def.identifier;
+            string_view_t id = ast->as_var_def.id;
 
             symbol_t *symbol = symbol_new(checker->arena, id, type_from_id(ast->as_var_def.type));
 
diff --git a/src/codegen_linux_aarch64.c b/src/codegen_linux_aarch64.c
index 18173ce..93dde4f 100644
--- a/src/codegen_linux_aarch64.c
+++ b/src/codegen_linux_aarch64.c
@@ -51,7 +51,7 @@ codegen_linux_aarch64_emit_program(FILE *out, ast_node_t *node)
 
     ast_fn_definition_t fn = program.fn->as_fn_def;
 
-    assert(string_view_eq_to_cstr(fn.identifier, "main"));
+    assert(string_view_eq_to_cstr(fn.id, "main"));
     codegen_linux_aarch64_emit_function(out, &fn);
 }
 
@@ -88,7 +88,7 @@ codegen_linux_aarch64_emit_function(FILE *out, ast_fn_definition_t *fn)
     assert(literal_u32.kind == AST_LITERAL_U32);
     uint32_t exit_code = literal_u32.as_u32;
 
-    fprintf(out, "" SV_FMT ":\n", SV_ARG(fn->identifier));
+    fprintf(out, "" SV_FMT ":\n", SV_ARG(fn->id));
     fprintf(out, "    mov x0, #%d\n", exit_code);
     fprintf(out, "    ret\n");
 }
diff --git a/src/codegen_linux_x86_64.c b/src/codegen_linux_x86_64.c
index 2e329ca..a0d9d97 100644
--- a/src/codegen_linux_x86_64.c
+++ b/src/codegen_linux_x86_64.c
@@ -65,7 +65,7 @@ codegen_linux_x86_64_emit_program(codegen_x86_64_t *codegen, ast_node_t *node)
 
     ast_fn_definition_t fn = program.fn->as_fn_def;
 
-    assert(string_view_eq_to_cstr(fn.identifier, "main"));
+    assert(string_view_eq_to_cstr(fn.id, "main"));
     codegen_linux_x86_64_emit_function(codegen, &fn);
 }
 
@@ -103,7 +103,7 @@ codegen_linux_x86_64_emit_expression(codegen_x86_64_t *codegen, ast_node_t *expr
         case AST_NODE_REF: {
             ast_ref_t ref = expr_node->as_ref;
 
-            symbol_t *symbol = scope_lookup(ref.scope, ref.identifier);
+            symbol_t *symbol = scope_lookup(ref.scope, ref.id);
             assert(symbol);
 
             char symbol_ptr[PTR_HEX_CSTR_SIZE];
@@ -366,7 +366,7 @@ codegen_linux_x86_64_emit_block(codegen_x86_64_t *codegen, ast_block_t *block)
                 ast_var_definition_t var_def = node->as_var_def;
                 scope_t *scope = var_def.scope;
 
-                symbol_t *symbol = scope_lookup(scope, var_def.identifier);
+                symbol_t *symbol = scope_lookup(scope, var_def.id);
                 assert(symbol);
 
                 char symbol_ptr[PTR_HEX_CSTR_SIZE];
@@ -486,7 +486,7 @@ codegen_linux_x86_64_emit_function(codegen_x86_64_t *codegen, ast_fn_definition_
     codegen->base_offset = X86_CALL_EIP_STACK_OFFSET;
 
     ast_node_t *block_node = fn->block;
-    fprintf(codegen->out, "" SV_FMT ":\n", SV_ARG(fn->identifier));
+    fprintf(codegen->out, "" SV_FMT ":\n", SV_ARG(fn->id));
 
     fprintf(codegen->out, "    mov %%rsp, %%rbp\n");
 
diff --git a/src/lexer.c b/src/lexer.c
index 12b4719..ebc21b7 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -278,7 +278,7 @@ lexer_next_token(lexer_t *lexer, token_t *token)
 
 static char *token_kind_str_table[] = {
     [TOKEN_UNKNOWN] = "unknown",
-    [TOKEN_IDENTIFIER] = "identifier",
+    [TOKEN_ID] = "identifier",
     [TOKEN_NUMBER] = "number",
     [TOKEN_FN] = "fn",
     [TOKEN_RETURN] = "return",
@@ -432,7 +432,7 @@ lexer_str_to_token_kind(string_view_t text)
         return TOKEN_FN;
     }
 
-    return TOKEN_IDENTIFIER;
+    return TOKEN_ID;
 }
 
 void
diff --git a/src/lexer.h b/src/lexer.h
index 4a0e2e1..717d21d 100644
--- a/src/lexer.h
+++ b/src/lexer.h
@@ -32,7 +32,7 @@ typedef struct lexer
 typedef enum token_kind
 {
     TOKEN_UNKNOWN,
-    TOKEN_IDENTIFIER,
+    TOKEN_ID,
     TOKEN_NUMBER,
 
     // Keywords
diff --git a/src/parser.c b/src/parser.c
index a63a724..3cae763 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -236,7 +236,7 @@ parser_parse_factor(parser_t *parser)
         case TOKEN_NUMBER:
             return ast_new_node_literal_u32(parser->arena, string_view_to_u32(token.value));
 
-        case TOKEN_IDENTIFIER:
+        case TOKEN_ID:
             return ast_new_node_ref(parser->arena, token.value);
 
         case TOKEN_OPAREN: {
@@ -269,7 +269,7 @@ parser_parse_fn_definition(parser_t *parser)
 
     token_t fn_name_token;
 
-    if (!expected_next_token(parser, &fn_name_token, TOKEN_IDENTIFIER)) {
+    if (!expected_next_token(parser, &fn_name_token, TOKEN_ID)) {
         return NULL;
     }
 
@@ -313,7 +313,7 @@ parser_parse_type(parser_t *parser, string_view_t *type)
 
     token_t token;
 
-    if (!expected_next_token(parser, &token, TOKEN_IDENTIFIER)) {
+    if (!expected_next_token(parser, &token, TOKEN_ID)) {
         return false;
     }
 
@@ -459,8 +459,8 @@ parser_parse_var_def(parser_t *parser)
         return NULL;
     }
 
-    token_t identifier_token;
-    if (!expected_next_token(parser, &identifier_token, TOKEN_IDENTIFIER)) {
+    token_t id_token;
+    if (!expected_next_token(parser, &id_token, TOKEN_ID)) {
         return NULL;
     }
 
@@ -479,7 +479,7 @@ parser_parse_var_def(parser_t *parser)
         return NULL;
     }
 
-    ast_node_t *var_node = ast_new_node_var_def(parser->arena, identifier_token.value, var_type, expr);
+    ast_node_t *var_node = ast_new_node_var_def(parser->arena, id_token.value, var_type, expr);
 
     skip_line_feeds(parser->lexer);
 
diff --git a/src/pretty_print_ast.c b/src/pretty_print_ast.c
index a7c75e8..1d5576d 100644
--- a/src/pretty_print_ast.c
+++ b/src/pretty_print_ast.c
@@ -127,7 +127,7 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena)
             char name[256];
             sprintf(name,
                     "Function_Definition <name:" SV_FMT "> <return:" SV_FMT ">",
-                    SV_ARG(fn_def.identifier),
+                    SV_ARG(fn_def.id),
                     SV_ARG(fn_def.return_type));
             node->name = (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1));
             strcpy(node->name, name);
@@ -203,7 +203,7 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena)
             ast_var_definition_t var = ast->as_var_def;
 
             char name[256];
-            sprintf(name, "Var_Definition <name:" SV_FMT "> <kind:u32>", SV_ARG(var.identifier));
+            sprintf(name, "Var_Definition <name:" SV_FMT "> <kind:u32>", SV_ARG(var.id));
             node->name = (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1));
             strcpy(node->name, name);
 
@@ -217,7 +217,7 @@ ast_node_to_pretty_print_node(ast_node_t *ast, arena_t *arena)
             ast_ref_t ref = ast->as_ref;
 
             char name[256];
-            sprintf(name, "Reference <name:" SV_FMT ">", SV_ARG(ref.identifier));
+            sprintf(name, "Reference <name:" SV_FMT ">", SV_ARG(ref.id));
             node->name = (char *)arena_alloc(arena, sizeof(char) * (strlen(name) + 1));
             strcpy(node->name, name);
 
diff --git a/tests/unit/parser_test.c b/tests/unit/parser_test.c
index ccec460..8ad16b5 100644
--- a/tests/unit/parser_test.c
+++ b/tests/unit/parser_test.c
@@ -50,7 +50,7 @@ parse_program_test(const MunitParameter params[], void *user_data_or_fixture)
     assert_uint(program.fn->kind, ==, AST_NODE_FN_DEF);
 
     ast_fn_definition_t fn = program.fn->as_fn_def;
-    assert_memory_equal(fn.identifier.size, fn.identifier.chars, "main");
+    assert_memory_equal(fn.id.size, fn.id.chars, "main");
     assert_memory_equal(fn.return_type.size, fn.return_type.chars, "u32");
 
     ast_node_t *block = fn.block;
-- 
2.34.1


  parent reply	other threads:[~2024-09-23 10:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-23 10:11 [PATCH olang v1 0/3] Housekeeping: resolve a few FIXMEs related to code style Carlos Maniero
2024-09-23 10:11 ` [PATCH olang v1 1/3] ast: return_stmt rename expr field and add it to the factory fn Carlos Maniero
2024-09-23 11:02   ` Johnny Richard
2024-09-23 11:47     ` Carlos Maniero
2024-09-23 10:11 ` [PATCH olang v1 2/3] codegen: move label_index global variable to the codegen scope Carlos Maniero
2024-09-23 10:11 ` Carlos Maniero [this message]
2024-09-23 10:12   ` [olang/patches/.build.yml] build success builds.sr.ht
2024-09-23 11:08 ` [PATCH olang v1 0/3] Housekeeping: resolve a few FIXMEs related to code style Johnny Richard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240923101141.76783-4-carlos@maniero.me \
    --to=carlos@maniero.me \
    --cc=~johnnyrichard/olang-devel@lists.sr.ht \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.johnnyrichard.com/olang.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox