From: Carlos Maniero <carlos@maniero.me>
To: ~johnnyrichard/olang-devel@lists.sr.ht
Cc: Carlos Maniero <carlos@maniero.me>
Subject: [PATCH olang v1 5/6] codestyle: add trailing comma on struct initializer
Date: Thu, 10 Oct 2024 01:33:44 +0000 (UTC) [thread overview]
Message-ID: <20241010013318.222905-6-carlos@maniero.me> (raw)
In-Reply-To: <20241010013318.222905-1-carlos@maniero.me>
It makes the struct to be formatted that way:
{
.a = 1,
.b = 2,
}
Instead of:
{ .a = 1,
.b = 2 }
Unfortunately, there is no config on clang-format to enforce this.
Signed-off-by: Carlos Maniero <carlos@maniero.me>
---
src/cli.c | 5 +++-
src/lexer.c | 51 +++++++++++++++++++++++++++++------
src/main.c | 5 +++-
src/map.c | 14 ++++++++--
src/string_view.c | 5 +++-
tests/unit/string_view_test.c | 20 +++++++++++---
6 files changed, 83 insertions(+), 17 deletions(-)
diff --git a/src/cli.c b/src/cli.c
index d57945a..1f30ea3 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -34,7 +34,10 @@ cli_opts_parse_sysroot(cli_opts_t *opts, cli_args_t *args);
cli_opts_t
cli_parse_args(int argc, char **argv) {
- cli_args_t args = { .argc = argc, .argv = argv };
+ cli_args_t args = {
+ .argc = argc,
+ .argv = argv,
+ };
cli_opts_t opts = { 0 };
opts.compiler_path = cli_args_shift(&args);
diff --git a/src/lexer.c b/src/lexer.c
index 352f979..c11bacf 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -88,8 +88,10 @@ lexer_next_token(lexer_t *lexer, token_t *token) {
current_char = lexer_current_char(lexer);
}
- string_view_t text = { .chars = lexer->src.code.chars + start_cur.offset,
- .size = lexer->cur.offset - start_cur.offset };
+ string_view_t text = {
+ .chars = lexer->src.code.chars + start_cur.offset,
+ .size = lexer->cur.offset - start_cur.offset,
+ };
lexer_init_str_value_token(lexer, token, lexer_str_to_token_kind(text), start_cur);
return;
@@ -392,20 +394,50 @@ _isspace(char c) {
static void
lexer_init_char_value_token(lexer_t *lexer, token_t *token, token_kind_t kind) {
- string_view_t str = { .chars = lexer->src.code.chars + lexer->cur.offset, .size = 1 };
- *token = (token_t){ .kind = kind, .value = str, .loc = (token_loc_t){ .src = lexer->src, .cur = lexer->cur } };
+ string_view_t str = {
+ .chars = lexer->src.code.chars + lexer->cur.offset,
+ .size = 1,
+ };
+ *token = (token_t){
+ .kind = kind,
+ .value = str,
+ .loc =
+ (token_loc_t){
+ .src = lexer->src,
+ .cur = lexer->cur,
+ },
+ };
}
static void
lexer_init_str_value_token(lexer_t *lexer, token_t *token, token_kind_t kind, lexer_cursor_t cur) {
- string_view_t str = { .chars = lexer->src.code.chars + cur.offset, .size = lexer->cur.offset - cur.offset };
- *token = (token_t){ .kind = kind, .value = str, .loc = (token_loc_t){ .src = lexer->src, .cur = cur } };
+ string_view_t str = {
+ .chars = lexer->src.code.chars + cur.offset,
+ .size = lexer->cur.offset - cur.offset,
+ };
+ *token = (token_t){
+ .kind = kind,
+ .value = str,
+ .loc =
+ (token_loc_t){
+ .src = lexer->src,
+ .cur = cur,
+ },
+ };
}
static void
lexer_init_eof_token(lexer_t *lexer, token_t *token) {
string_view_t str = { 0 };
- *token = (token_t){ .kind = TOKEN_EOF, .value = str, .loc = (token_loc_t){ .src = lexer->src, .cur = lexer->cur } };
+ *token = (token_t){
+ .kind = TOKEN_EOF,
+ .value = str,
+ .loc =
+ (token_loc_t){
+ .src = lexer->src,
+ .cur = lexer->cur,
+ },
+ };
}
static token_kind_t
@@ -456,7 +488,10 @@ lexer_lookahead(lexer_t *lexer, token_t *token, size_t n) {
string_view_t
token_loc_to_line(token_loc_t loc) {
size_t offset = loc.cur.bol;
- string_view_t line = { .chars = loc.src.code.chars + offset, .size = 0 };
+ string_view_t line = {
+ .chars = loc.src.code.chars + offset,
+ .size = 0,
+ };
while ((line.size + offset) < loc.src.code.size && line.chars[line.size] != '\n' && line.chars[line.size] != 0) {
++line.size;
diff --git a/src/main.c b/src/main.c
index bb0e451..0e174a1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -235,7 +235,10 @@ read_entire_file(char *filepath, arena_t *arena) {
fclose(stream);
- return (source_code_t){ .filepath = filepath, .code = code };
+ return (source_code_t){
+ .filepath = filepath,
+ .code = code,
+ };
}
static void
diff --git a/src/map.c b/src/map.c
index 9109eaa..31100b4 100644
--- a/src/map.c
+++ b/src/map.c
@@ -82,7 +82,12 @@ map_put(map_t *map, char *key, void *value) {
map_entry_t *entry = map->entries + map_get_index(map, hash);
if (entry->key == NULL) {
- *entry = (map_entry_t){ .key = _strdup(key, map->arena), .hash = hash, .value = value, .next = NULL };
+ *entry = (map_entry_t){
+ .key = _strdup(key, map->arena),
+ .hash = hash,
+ .value = value,
+ .next = NULL,
+ };
return true;
}
@@ -93,7 +98,12 @@ map_put(map_t *map, char *key, void *value) {
}
if (entry->next == NULL) {
entry->next = (map_entry_t *)arena_alloc(map->arena, sizeof(map_entry_t));
- *entry->next = (map_entry_t){ .key = _strdup(key, map->arena), .hash = hash, .value = value, .next = NULL };
+ *entry->next = (map_entry_t){
+ .key = _strdup(key, map->arena),
+ .hash = hash,
+ .value = value,
+ .next = NULL,
+ };
break;
}
diff --git a/src/string_view.c b/src/string_view.c
index 22cb61e..438174c 100644
--- a/src/string_view.c
+++ b/src/string_view.c
@@ -23,7 +23,10 @@
string_view_t
string_view_from_cstr(char *cstr) {
- return (string_view_t){ .chars = cstr, .size = strlen(cstr) };
+ return (string_view_t){
+ .chars = cstr,
+ .size = strlen(cstr),
+ };
}
bool
diff --git a/tests/unit/string_view_test.c b/tests/unit/string_view_test.c
index f8ca792..6f42e0c 100644
--- a/tests/unit/string_view_test.c
+++ b/tests/unit/string_view_test.c
@@ -25,14 +25,20 @@ static MunitResult
string_view_eq_to_cstr_test(const MunitParameter params[], void *user_data_or_fixture) {
char *name = "John Doe";
- string_view_t str = { .chars = name, .size = strlen(name) };
+ string_view_t str = {
+ .chars = name,
+ .size = strlen(name),
+ };
assert_true(string_view_eq_to_cstr(str, "John Doe"));
assert_false(string_view_eq_to_cstr(str, "Doe"));
char *return_stmt = "return EXIT_SUCCESS;";
- str = (string_view_t){ .chars = return_stmt + 7, .size = 12 };
+ str = (string_view_t){
+ .chars = return_stmt + 7,
+ .size = 12,
+ };
assert_true(string_view_eq_to_cstr(str, "EXIT_SUCCESS"));
return MUNIT_OK;
@@ -42,11 +48,17 @@ static MunitResult
string_view_to_u32_test(const MunitParameter params[], void *user_data_or_fixture) {
char *number = "69";
- string_view_t str = { .chars = number, .size = strlen(number) };
+ string_view_t str = {
+ .chars = number,
+ .size = strlen(number),
+ };
assert_uint32(string_view_to_u32(str), ==, 69);
- str = (string_view_t){ .chars = "39;", .size = 2 };
+ str = (string_view_t){
+ .chars = "39;",
+ .size = 2,
+ };
assert_uint32(string_view_to_u32(str), ==, 39);
--
2.46.0
next prev parent reply other threads:[~2024-10-10 1:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-10 1:33 [PATCH olang 0/6] Suggestions in code style Carlos Maniero
2024-10-10 1:33 ` [PATCH olang v1 1/6] codestyle: change AlignAfterOpenBracket to BlockIndent Carlos Maniero
2024-10-10 1:33 ` [PATCH olang v1 2/6] codestyle: never BreakBeforeBraces Carlos Maniero
2024-10-10 1:33 ` [PATCH olang v1 3/6] codestyle: prevent extra empty lines at EOF Carlos Maniero
2024-10-10 1:33 ` [PATCH olang v1 4/6] codestyle: do not allow single line enums Carlos Maniero
2024-10-10 1:33 ` Carlos Maniero [this message]
2024-10-10 1:34 ` [olang/patches/.build.yml] build success builds.sr.ht
2024-10-10 1:33 ` [PATCH olang v1 6/6] codestyle: limit the code to 80 characters Carlos Maniero
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=20241010013318.222905-6-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