From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id AEqmBUlq92YoiwAAqHPOHw:P1 (envelope-from ) for ; Sat, 28 Sep 2024 04:30:33 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id AEqmBUlq92YoiwAAqHPOHw (envelope-from ) for ; Sat, 28 Sep 2024 04:30:33 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; none 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 08E8B196AD for ; Sat, 28 Sep 2024 04:30:30 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=UXSdfClbInJ/rZHYLnK2Wm4HBoX6SWS6dJGLwAOvzQI=; c=simple/simple; d=lists.sr.ht; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Unsubscribe:List-Subscribe:List-Archive:List-Post:List-ID; q=dns/txt; s=20240113; t=1727490629; v=1; b=c8C8BExD527PfPIMgHNW2kj27kyQRWEdkz/qTwd78oeLNTNUCyfm6slLHFsS9Lpd1DvhoYV8 OGt1XY8ExaHbHZILy7LJ0bACg1l4FJhdCdt1pQiawSaXqYJWqnWbemmw42b7piv2CIK73wfYIkd DGrHbdc/2JkE9OncoKP0+MiscqzZeyVgArTs0Izzqe5Cwphmq+eP5zqvD0kiL4xsWgqBHEzumVP GmYY8HeAACGWpOfsQDjwcoi+3Wx55v7uOClT8M8BBveaGRR3qsXr/oPpLxWRSlQ/KnQ1gm4a3qZ 0BPdYEpMgqkQVHLRPM2Csvg3ULjuH+VRargqxpzKUcpfQ== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 65AE520327 for ; Sat, 28 Sep 2024 02:30:29 +0000 (UTC) Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) by mail-a.sr.ht (Postfix) with ESMTPS id 5CDD7202E2 for <~johnnyrichard/olang-devel@lists.sr.ht>; Sat, 28 Sep 2024 02:30:28 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1727490627; 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=JpyUOX+Skz1To03tsWTsj9cNP+WcboY2atbCUJNnCPU=; b=uj53tQLHG0jkujmfEjjXSFBI3E1kqfFt4SAFqJC4efG1MOz2aN8lJfMDrAiPH/RzHUEh8J QFE/OTSvZpL++MXpseaKCfDVVxQx4MC5IKHnp7AxdDK3jN1SBLTuLLwqUt/opU33U0+JWL 6GXTZHFaiOTT24tWtlr0qk3+l5NHdFMWw5TWQ3hIq23SuTE/sdOhBrq6yI+3/HLkJIGlkn 5T/RY9+L86o7/ayVJiZ54q2l2DxKG+IuDMyItnVFCm0mCOuOi3Wj8p/C2Ye50Pgg+7gxBJ rqcA3Gcs6COGne/qMIsAyof+15L0hceCmJoyu+GJQmQwJ4JF9k/xV7mDEKuZ1Q== From: Johnny Richard To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Johnny Richard Subject: [PATCH olang v1 1/2] ast: remove anonymous union on ast_node_t Date: Sat, 28 Sep 2024 06:29:27 +0200 Message-ID: <20240928043016.104228-2-johnny@johnnyrichard.com> In-Reply-To: <20240928043016.104228-1-johnny@johnnyrichard.com> References: <20240928043016.104228-1-johnny@johnnyrichard.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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-Scanner: mx12.migadu.com X-Migadu-Spam-Score: -4.00 X-Spam-Score: -4.00 X-Migadu-Queue-Id: 08E8B196AD X-TUID: WSX2uSvYwGSs Signed-off-by: Johnny Richard --- src/ast.h | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/ast.h b/src/ast.h index 66c626d..4791d6b 100644 --- a/src/ast.h +++ b/src/ast.h @@ -25,7 +25,7 @@ #include "string_view.h" #include "type.h" -typedef struct ast_node ast_node_t; +typedef union ast_node ast_node_t; typedef enum { @@ -44,11 +44,13 @@ typedef enum typedef struct ast_block { + ast_node_kind_t node_kind; list_t *nodes; } ast_block_t; typedef struct ast_translation_unit { + ast_node_kind_t node_kind; list_t *decls; } ast_translation_unit_t; @@ -60,6 +62,7 @@ typedef struct ast_fn_param typedef struct ast_fn_definition { + ast_node_kind_t node_kind; string_view_t id; list_t *params; string_view_t return_type; @@ -69,6 +72,7 @@ typedef struct ast_fn_definition typedef struct ast_fn_call { + ast_node_kind_t node_kind; string_view_t id; list_t *args; scope_t *scope; @@ -76,6 +80,7 @@ typedef struct ast_fn_call typedef struct ast_var_definition { + ast_node_kind_t node_kind; string_view_t id; string_view_t type; ast_node_t *value; @@ -89,6 +94,7 @@ typedef enum typedef struct ast_literal { + ast_node_kind_t node_kind; ast_literal_kind_t kind; union { @@ -98,6 +104,7 @@ typedef struct ast_literal typedef struct ast_ref { + ast_node_kind_t node_kind; string_view_t id; scope_t *scope; } ast_ref_t; @@ -126,6 +133,7 @@ typedef enum ast_binary_op_kind typedef struct ast_binary_op { + ast_node_kind_t node_kind; ast_binary_op_kind_t kind; ast_node_t *lhs; ast_node_t *rhs; @@ -133,32 +141,31 @@ typedef struct ast_binary_op typedef struct ast_return_stmt { + ast_node_kind_t node_kind; ast_node_t *expr; } ast_return_stmt_t; typedef struct ast_if_stmt { + ast_node_kind_t node_kind; ast_node_t *cond; ast_node_t *then; ast_node_t *_else; } ast_if_stmt_t; -typedef struct ast_node +typedef union ast_node { ast_node_kind_t kind; - union - { - ast_translation_unit_t as_translation_unit; - ast_fn_definition_t as_fn_def; - ast_fn_call_t as_fn_call; - ast_var_definition_t as_var_def; - ast_binary_op_t as_bin_op; - ast_literal_t as_literal; - ast_ref_t as_ref; - ast_block_t as_block; - ast_return_stmt_t as_return_stmt; - ast_if_stmt_t as_if_stmt; - }; + ast_translation_unit_t as_translation_unit; + ast_fn_definition_t as_fn_def; + ast_fn_call_t as_fn_call; + ast_var_definition_t as_var_def; + ast_binary_op_t as_bin_op; + ast_literal_t as_literal; + ast_ref_t as_ref; + ast_block_t as_block; + ast_return_stmt_t as_return_stmt; + ast_if_stmt_t as_if_stmt; } ast_node_t; ast_node_t * -- 2.46.0