From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 6IXMCwYvB2f4VAAAqHPOHw:P1 (envelope-from ) for ; Thu, 10 Oct 2024 03:33:58 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id 6IXMCwYvB2f4VAAAqHPOHw (envelope-from ) for ; Thu, 10 Oct 2024 03:33:58 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=SxGb67pp; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=c0b2mig6; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; dmarc=pass (policy=none) header.from=maniero.me; arc=pass ("mailchannels.net:s=arc-2022:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1728524038; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=IesMUswt6Yqa9UboSU5RyqXkNGiBz9CmSzeESJcoh+w=; b=PXlyfotWI6lcuXY7cHTK3EiDS8CbwSMrfh0tiTaH9+AosjyH8TC4uhNu0GDz74fWUqq8Ap bf6OY60JTXEFb8PRDWEeCS8D5Guzig8k0UoKHfQmzIg8h8fWVAs/N4xv8hkw4Q1DW/2d3O pFWra7jO/7Oc5DQpunhLhdRvP7BrB7j/SBn6u2mPremwH7P1/vGpAS7zMQbqVsY3Mbq/lX tUs7ibQlg5JUDhQUBI7E7uOxjCsn3+ZUxKG+PXUiu+ZSPJgUUIPjPQY4HSA+1p2qjbjwGd Wf12E/yDMJ44G/FAApn8PJCxQNyOWrqel8vpMLn012fElW8050rEnoxgN0ghrA== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=SxGb67pp; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=c0b2mig6; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; dmarc=pass (policy=none) header.from=maniero.me; arc=pass ("mailchannels.net:s=arc-2022:i=1") ARC-Seal: i=2; s=key1; d=johnnyrichard.com; t=1728524038; a=rsa-sha256; cv=pass; b=nnrWui/bOy9YIfpfqgDSQBvrduIDajvpBIayf6PEQYpohPMOmHu+rFTBQ/oeASgCwECBc/ s8zVnjJSfJ1jD/GeL0E20n7xLd0GgVFHZ533YIHZdAeeeOS9C1QHTDcwC/Imeg8bYlO2SZ Ckpof7oB4TuyXE6Bh7bTNbJF9UydNhDCfJIydO5ESOwcEP3C516Bfmh8BcmzljWVK+A+zl MhjePmVe2uZXVaSkP6F00TY+Wt61MLFJZrGgOGJFkGNHNR7Fnx9GqWd6gx+YZPc0ZJxNWI zFekAtrrORQMEGrqIxrtrlXvghnBu4BT/qDt19fjPKXqXeGa65jde7HpQo67rQ== Received: from mail-a.sr.ht (mail-a.sr.ht [46.23.81.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 1B5FC86FCB for ; Thu, 10 Oct 2024 03:33:58 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=lhGC+s3c0jepaunSzSzLsZB4s6EtdM/HYRnzfGuVqPs=; c=simple/simple; d=lists.sr.ht; h=From:To:Cc:Subject:In-Reply-To:References:Date:List-Unsubscribe:List-Subscribe:List-Archive:List-Post:List-ID; q=dns/txt; s=20240113; t=1728524037; v=1; b=SxGb67ppBcu+yAqYFkhn8ka/Ari99rDuswQLgYllOYbioJ5FL2GIGm8BGGVbJbKul5WiBWb0 Oett1KWJpabxypoLgCarzT0LQZxhvZW9Fuq6Cdpc1OevmHowd0RU70DF/S3grD89qjx4/z82fhl ZCrIgdkOlDYOY56ty1QlSyRu5klv6BgT9N+ILM7vV8KIWGZYsgXJPEPA24b+MtjNKMBgZcFRiCr K5skYBTatI6Kc0c0pLvUdgVYTws3nTbNbEAmPB8FYFlOA4Cv4rBuOJF3VidTaZSOATTHdMRNjea S1w36qbki55ezR/ZOk3UYBfTvetk8W2PcHCx/OCgVi7DA== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id DC7BF20202 for ; Thu, 10 Oct 2024 01:33:57 +0000 (UTC) Received: from rusty.tulip.relay.mailchannels.net (rusty.tulip.relay.mailchannels.net [23.83.218.252]) by mail-a.sr.ht (Postfix) with ESMTPS id 920AE201E1 for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 10 Oct 2024 01:33:53 +0000 (UTC) X-Sender-Id: hostingeremail|x-authuser|carlos@maniero.me Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 2B6A2183E4D for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 10 Oct 2024 01:33:47 +0000 (UTC) Received: from fr-int-smtpout5.hostinger.io (trex-9.trex.outbound.svc.cluster.local [100.96.88.42]) (Authenticated sender: hostingeremail) by relay.mailchannels.net (Postfix) with ESMTPA id 6B08F183F05 for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 10 Oct 2024 01:33:46 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1728524026; a=rsa-sha256; cv=none; b=dIcfC2riIYEgMNu9fiVDUxYWaPz7o0+VKVlTnn50x1ewsOvFc7PA7S1TuV/85b4Puhc85g EZYLrXoZKOK5K/IWxoIErR24shnhH8RJZb1YddpUWEs18I+WNVnXhUm7d3/wu4OHkR3DGZ xZZS1N55h4gYmTAUezp9X9XAntlKcEkYRZRBFg30uXtbwij16bKOWtmC+4pRCmr5qpVF/k RM5a1eJ3sG6zCFuyZNU09IwpxIPR63hrfpquPZbYajFuYRO5TEQ9C2samiOm1kvm8R2KkC UgN3wb2EUiuYowgoMn6Ef/nWkuwt2w34zaygQUKw2asILf5FsVxvL+VbZHcz1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1728524026; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IesMUswt6Yqa9UboSU5RyqXkNGiBz9CmSzeESJcoh+w=; b=9E8lvOevs3KPNMFZTQpUGxYY1++TXECzWGYpXWCmL4YoOx8t36NWFWZ/LeQNAtm8VGMCq6 SLfXr5EQ+K4xgsxD4HQ/sd0JRVhG/tvUDq6ZmjFH2DNMSvbLnEWRaC/5LKDINdbWqo0bJs M+AjBycZmTWlxLcLGd/xeViFUWz5Klj097cJIQS4yMZSBp6ufYrHwXsZDeM4ctAXFtwufW iHFSYhg6teELBNuZg95t67g+N8ue+ElLDOfBFr+EXasLbziNUlp3Tp4vwsxBLVdSDAoZYm TQ+OS91qL35blD3DT6z8+nd0AKNTeL92Y5KNJ5UwnRkBXN6JDkwTkEmFJydt7Q== ARC-Authentication-Results: i=1; rspamd-5fcd6bf96c-bc64j; auth=pass smtp.auth=hostingeremail smtp.mailfrom=carlos@maniero.me X-Sender-Id: hostingeremail|x-authuser|carlos@maniero.me X-MC-Relay: Neutral X-MailChannels-SenderId: hostingeremail|x-authuser|carlos@maniero.me X-MailChannels-Auth-Id: hostingeremail X-Language-White: 51f5ecb805f94fdd_1728524027075_3107180613 X-MC-Loop-Signature: 1728524027075:3463519793 X-MC-Ingress-Time: 1728524027075 Received: from fr-int-smtpout5.hostinger.io (fr-int-smtpout5.hostinger.io [89.116.146.168]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.96.88.42 (trex/7.0.2); Thu, 10 Oct 2024 01:33:47 +0000 From: Carlos Maniero DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maniero.me; s=hostingermail1; t=1728524024; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IesMUswt6Yqa9UboSU5RyqXkNGiBz9CmSzeESJcoh+w=; b=c0b2mig6tYcIKfDF1EY5TRKY3pfULgJWj4xWIrNJ4HnPF2ElpkAqJtynLWZyNViyWojcYH 3rtOL6fcie91PXY3GGbXvGW0bJDGRPylpUaILy0XNQVsmQhERTKR9WyuZPDbV6dp5af2rU ykbCrmSPD9jG101TSv0dGuCCgzltOajaSoLsy2VWPGBL0UAcJJrMxv376aq+Crjgt+LT/q apM40+wH2zx36oxhsvNYPIImn9AcX5mKdZre+PtEhI5BO0A00EvD96HTPftv8TcezfJdYq rdaOAK3Wbza7xFQvMy9JVojEUSLD1Yjp2aa9KCJgYaviKTL/lBOtuZikr2n0vg== To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Carlos Maniero Subject: [PATCH olang v1 5/6] codestyle: add trailing comma on struct initializer Message-ID: <20241010013318.222905-6-carlos@maniero.me> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241010013318.222905-1-carlos@maniero.me> References: <20241010013318.222905-1-carlos@maniero.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Date: Thu, 10 Oct 2024 01:33:44 +0000 (UTC) X-CM-Analysis: v=2.4 cv=Z6G+H2RA c=1 sm=1 tr=0 ts=67072ef8 a=WwxFCuf3mf1fs3oSi6/dng==:117 a=WwxFCuf3mf1fs3oSi6/dng==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=hgg136lakQ4gt5yPiEUA:9 a=BXDaF_L80NY05PYiAFlV:22 X-CM-Envelope: MS4xfL2sG8reWay4z8FZ1z2vyGcNQM5gm+/Ie2TMO+Rw9He1xDHQEnnlGHf7h61R0yi2ZbNpyrZfVFygeXTudLGO3WDDoxj8hA6as1TV9LEtAlIMt9c+FriP OocxAT+4vJK0QGexXhorf8uVjj00iz6z/wXuRQfU7nMUd9U3cla3o719j/bz9A4cC2inLB6sy9xqsaZU6C8+z7D0kByPntWfIkVjZqSSp/g5eq18bIwLax9c X-AuthUser: carlos@maniero.me X-Sourcehut-Patchset-Status: PROPOSED List-Unsubscribe: List-Subscribe: List-Archive: Archived-At: List-Post: List-ID: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel.lists.sr.ht> Sender: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel@lists.sr.ht> X-Migadu-Country: NL X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx11.migadu.com X-Migadu-Spam-Score: -1.60 X-Spam-Score: -1.60 X-Migadu-Queue-Id: 1B5FC86FCB X-TUID: IpmPWR8bFTst 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 --- 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