From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 2ItuD/lYCWe/hAAA62LTzQ:P1 (envelope-from ) for ; Fri, 11 Oct 2024 18:57:29 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id 2ItuD/lYCWe/hAAA62LTzQ (envelope-from ) for ; Fri, 11 Oct 2024 18:57:29 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=GZgAxn1Z; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=GSnOWiot; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; arc=pass ("mailchannels.net:s=arc-2022:i=1"); dmarc=pass (policy=none) header.from=maniero.me ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1728665849; 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=UL91YGi8zll393Gy1IjlePnMHwk6yIVyulu19uOorJQ=; b=KYR9vStWsucle0nlH0aeyCGZx7me4va36XIAmTdpgaGn9lEMIPzFljritIL3wawm6bJ2XO 1bwtpbMRqpzpguodb0qwzaENZHK0NyVMVc5YYffm0GHpAZqCO8EGtD4TUWg1paCmTx204z 0agXdGYYXP62Q6ArWJzC7qLl1cuywRWt/LD9w9WFopiVCC+9tUBIRiD3Pmm3Vk5lxv7hVj UW++SjNke8nI6l+lAXDTYP4S/OTv8q5arKvDjOJbx6fbg0kimrN6zVXqhFmXmDOVSb9F5j R7zXnkvSod3Ou92qKsGqNQ3NSaIQgbk5LExWjVnxtyiBMSQ48IxkULlxKSrx/g== ARC-Seal: i=2; s=key1; d=johnnyrichard.com; t=1728665849; a=rsa-sha256; cv=pass; b=XbBk7GVYJSwYw9NbrUXb67zuUTUDUOuZRSsJZqq6D/f2PDeYPAfiilbT3KRYb2ozdeVTFQ CEiD4k6OTLLSLIH9j40dpqNPMHebTbEyyAeXN/ygIBFtus0M1n+0mkOD/gMKM+oxPXOecf v9mZe9Zsw8Os/99vVu7EMJn1EC3Lzk7mxVXKZd42qeZVV/gu9Cp6uS28L364lqg6jVATnm ceFzjCiFdXWVF/4UILl/NQJc+Es+rtLpKYz+GDkFLBBM1YBQWKyyIBaQgb3BTAlF3KM5wJ kcFdNlS/X/yVZC+As6gz/o1uAbxb7VHGbGvnY391n4BuDHYq3il4hM0s6p5C1A== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=GZgAxn1Z; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=GSnOWiot; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; arc=pass ("mailchannels.net:s=arc-2022:i=1"); dmarc=pass (policy=none) header.from=maniero.me 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 2511070B9 for ; Fri, 11 Oct 2024 18:57:29 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=kJW6MxLPGEV7K2vi6VQ9oVSVFruoNYH/CtxoQVNGorQ=; 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=1728665849; v=1; b=GZgAxn1Zul+7PmcICRTnbSYNyV1QMpUVQe9C2tWep81nmNTYU9s0jPBH7my0wGK7ACA2eSsj q4ZxzfXa6HRKXh87rHyWJtWNhA+02SzIp7Xj16+zKnHk0rkB5eqhL+qppKPaHpu+mbvFINnp99m 2sKao1ccMvckUwKI3Duoyt1gGMW1cqLD4zJdXqpOV+0pzg998CS8rbLneseBRQWMnuUGqn3zKo2 a/wFVJT1tMPl8QarugYOo0H2IPl5HBV/ek5522ZBENLjUSE/5viabRJmRP6lDPzwcfT5bxmR1jv IjGUW9w64DRoX5gvmfCzUsl8oPRqRh/GJCu8ivuTGGOng== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 085CD2029D for ; Fri, 11 Oct 2024 16:57:29 +0000 (UTC) Received: from dog.ash.relay.mailchannels.net (dog.ash.relay.mailchannels.net [23.83.222.48]) by mail-a.sr.ht (Postfix) with ESMTPS id 0030020294 for <~johnnyrichard/olang-devel@lists.sr.ht>; Fri, 11 Oct 2024 16:57:27 +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 33D3A902CBF for <~johnnyrichard/olang-devel@lists.sr.ht>; Fri, 11 Oct 2024 16:57:26 +0000 (UTC) Received: from uk-fast-smtpout10.hostinger.io (100-98-223-68.trex-nlb.outbound.svc.cluster.local [100.98.223.68]) (Authenticated sender: hostingeremail) by relay.mailchannels.net (Postfix) with ESMTPA id 66C2A902B16 for <~johnnyrichard/olang-devel@lists.sr.ht>; Fri, 11 Oct 2024 16:57:25 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1728665845; a=rsa-sha256; cv=none; b=1GjVYZcjC63qKM4KTWahXxfbF+JAkpceUIkL4wdGVFXfHwBXNWwqxPXq7m0x7uqN3+LnDq Fue4DlAIRyqY0KEmmawH+4bnnDFSX08aYU38cmwN3qnFWJQ+oVlmADoevf1UClhIpfLc24 GRe2fjjYXXbzCkq9Dw3bDUHvgsDnxTNCXOfQOTPOqu2hrVRwowEM48Y0jlrcUHhX6S11Ic bHn/077CbkfRHAC5c0F1AJPHcgfDoXOpWRVDAb4AF6ly8WKHIkU55a7AOhp6B+2zmCbPkL Oqvn8w/zmViD+z10fDopDAPG2/KHmC0cN4KiPtPvP5n/cIalmcEcPIM8DQ/BgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1728665845; 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=UL91YGi8zll393Gy1IjlePnMHwk6yIVyulu19uOorJQ=; b=y1QtbegPa3gVS2Bb6zo9aBmawYXKikKd1JIzvT2htZzeVv+tkHnyXAXxpL3pdM3MuGSNV7 0n/JSQ3GY2olgRJAF/P4CgL0AeyumxLQIMbxTCZTWatDN604+NX3/LkBdIZkIMToq04QZl O0RvaUxOKL3l54top9GbhuXdDH1wHPllIWyHTf33VNDJzzm2OsnLg6DnPMQ5q0ZH/uTrnF KgzUgnH3vlMpFkXvmyR8DpKjFrU2tKnhGJTolC9Cr06i7n21kgn2Ql9EvmwB9ci5coVbJl 9RGeD+Nz9ZbGGnQ6EQ0iOQTXHKYcT+ndQm7Fhhz/xJ12nkp/jmRbuSqHwOa6mg== ARC-Authentication-Results: i=1; rspamd-667df746d9-lfdfr; 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-Inform-Snatch: 26053906139776a5_1728665845922_1436499319 X-MC-Loop-Signature: 1728665845922:4052107266 X-MC-Ingress-Time: 1728665845922 Received: from uk-fast-smtpout10.hostinger.io (uk-fast-smtpout10.hostinger.io [145.14.155.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.98.223.68 (trex/7.0.2); Fri, 11 Oct 2024 16:57:25 +0000 From: Carlos Maniero DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maniero.me; s=hostingermail1; t=1728665843; 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=UL91YGi8zll393Gy1IjlePnMHwk6yIVyulu19uOorJQ=; b=GSnOWiot5mJfhMC10jebWTF2O9BX/9Tx25bQ3lzESCHqT7KRJVsA7+Kdur6IAIUOe1xMxO Z7Cwn4sCba+harwZtLAgdX1LSkD9MgoNraC8arMcw3UEgBNsZOtFXUawQNa8sn9Ip0IQ1k lQgqUDxU0kxSNbf66xeBeVZDnhfPTl4T3RPqE1R6tETFtGVU+4alYXQVVI2urnZPqiyluh ASPkcmpbreFqFtpGWFqhDF7i3gJAfyWrq0rbTHwX4dekwHWhLQNpEyyJod/tohCWZQ0Wpf vkd8eL0VvEZegl9wOFcuVoxwBLX/T/pw4Y/yxe2kcX2rbU7cSkVFxXizY69oUQ== To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Carlos Maniero Subject: [PATCH olang v2 3/4] codestyle: add trailing comma on struct initializer Message-ID: <20241011165708.553265-4-carlos@maniero.me> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241011165708.553265-1-carlos@maniero.me> References: <20241011165708.553265-1-carlos@maniero.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Date: Fri, 11 Oct 2024 16:57:23 +0000 (UTC) X-CM-Envelope: MS4xfJURiLC2ApJa9dXvNYc/StPOQf/+lhw6UAGtMz3ZZhEufrLQfLGTB4x01Uz41pdJ0PfuvvMdsaCAGvgBSIndFaono57NrCulRMIsCMdsQfSeL6/KQQDB 3oZ+i9PnpUX3aUIeq9Vi3L1xDdNLW6GkzkcLJyp1mM7pj8tMA0kz98uboh+7fMCUhw98/iuC/zX7gicHcqzOidwKPXH62jDtEAPB9WZfoAI5w8PPKiVjAHk+ X-CM-Analysis: v=2.4 cv=TcnEtgQh c=1 sm=1 tr=0 ts=670958f3 a=WwxFCuf3mf1fs3oSi6/dng==:117 a=WwxFCuf3mf1fs3oSi6/dng==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=rgKBkb8WActE3e0zLjgA:9 a=BXDaF_L80NY05PYiAFlV:22 X-AuthUser: carlos@maniero.me X-Sourcehut-Patchset-Status: UNKNOWN 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-Flow: FLOW_IN X-Migadu-Country: NL X-Migadu-Spam-Score: -4.87 X-Spam-Score: -4.87 X-Migadu-Queue-Id: 2511070B9 X-Migadu-Scanner: mx13.migadu.com X-TUID: X0SJ2qnJGS5K 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 9d0f875..d6b69e1 100644 --- a/src/cli.c +++ b/src/cli.c @@ -35,7 +35,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 c4f645c..03763de 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -90,8 +90,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; @@ -403,22 +405,52 @@ _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 @@ -473,7 +505,10 @@ 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 d1c76e3..aa09f34 100644 --- a/src/main.c +++ b/src/main.c @@ -238,7 +238,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 a6bc3a3..42801b0 100644 --- a/src/map.c +++ b/src/map.c @@ -86,7 +86,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; } @@ -97,7 +102,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 b4d4103..13d359c 100644 --- a/src/string_view.c +++ b/src/string_view.c @@ -24,7 +24,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 7a6776c..d85f19b 100644 --- a/tests/unit/string_view_test.c +++ b/tests/unit/string_view_test.c @@ -26,14 +26,20 @@ string_view_eq_to_cstr_test(const MunitParameter params[], void *user_data_or_fi { 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; @@ -44,11 +50,17 @@ string_view_to_u32_test(const MunitParameter params[], void *user_data_or_fixtur { 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.1