[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[COMMITTED] libpoke: add an `foptionals' field to Pk_Type
From: |
Jose E. Marchesi |
Subject: |
[COMMITTED] libpoke: add an `foptionals' field to Pk_Type |
Date: |
Mon, 16 Sep 2024 20:17:02 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
This commit adds an `foptional' field to the Pk_Type struct to denote
whether each field in the struct is optional or not.
2024-09-16 Jose E. Marchesi <jemarch@gnu.org>
* libpoke/pkl-rt.pk: New field `foptional'.
* libpoke/pkl-gen.pks (struct_typifier): Initialize the value of
foptional in Pk_Type struct.
* testsuite/poke.pkl/typeof-struct-5.pk: New test.
* testsuite/Makefile.am (EXTRA_DIST): Add new test.
---
ChangeLog | 8 ++++++++
libpoke/pkl-gen.pks | 18 ++++++++++++++++++
libpoke/pkl-rt.pk | 1 +
testsuite/Makefile.am | 1 +
testsuite/poke.pkl/typeof-struct-5.pk | 13 +++++++++++++
5 files changed, 41 insertions(+)
create mode 100644 testsuite/poke.pkl/typeof-struct-5.pk
diff --git a/ChangeLog b/ChangeLog
index e8371efd..eeba2f5a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-09-16 Jose E. Marchesi <jemarch@gnu.org>
+
+ * libpoke/pkl-rt.pk: New field `foptional'.
+ * libpoke/pkl-gen.pks (struct_typifier): Initialize the value of
+ foptional in Pk_Type struct.
+ * testsuite/poke.pkl/typeof-struct-5.pk: New test.
+ * testsuite/Makefile.am (EXTRA_DIST): Add new test.
+
2024-09-09 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
* pickles/Makefile.am (dist_pickles_DATA): Add `crc16.pk'.
diff --git a/libpoke/pkl-gen.pks b/libpoke/pkl-gen.pks
index f857c22c..66cdaa80 100644
--- a/libpoke/pkl-gen.pks
+++ b/libpoke/pkl-gen.pks
@@ -3420,6 +3420,24 @@
sel ; ... ARR SEL
push #field_type_str ; ... ARR SEL STR
ains ; ... ARR
+ .c }
+ drop ; SCT(Type) SCT(sct)
+ ;; Whether fields are optional.
+ push "foptional"
+ sref
+ nip ; SCT(Type) SCT(sct) ARR
+ .c for (@field = PKL_AST_TYPE_S_ELEMS (@type);
+ .c @field;
+ .c @field = PKL_AST_CHAIN (@field))
+ .c {
+ .c if (PKL_AST_CODE (@field) != PKL_AST_STRUCT_TYPE_FIELD)
+ .c continue;
+ sel ; ... ARR SEL
+ .c if (PKL_AST_STRUCT_TYPE_FIELD_OPTIONAL_P (@field))
+ push int<32>1 ; ... ARR SEL OPTIONAL_P
+ .c else
+ push int<32>0 ; ... ARR SEL OPTIONAL_P
+ ains ; ... ARR
.c }
drop ; SCT(Type) SCT(sct)
;; Methods names.
diff --git a/libpoke/pkl-rt.pk b/libpoke/pkl-rt.pk
index 7dd0f026..4f28849d 100644
--- a/libpoke/pkl-rt.pk
+++ b/libpoke/pkl-rt.pk
@@ -693,6 +693,7 @@ immutable type Pk_Type =
string[] fnames if code == PK_TYPE_STRUCT;
int<32>[] fcomputed if code == PK_TYPE_STRUCT;
string[] ftypes if code == PK_TYPE_STRUCT;
+ int<32>[] foptional if code == PK_TYPE_STRUCT;
string[] mnames if code == PK_TYPE_STRUCT;
string[] mtypes if code == PK_TYPE_STRUCT;
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index 9f5a9138..60794a6b 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -2776,6 +2776,7 @@ EXTRA_DIST = \
poke.pkl/typeof-struct-2.pk \
poke.pkl/typeof-struct-3.pk \
poke.pkl/typeof-struct-4.pk \
+ poke.pkl/typeof-struct-5.pk \
poke.pkl/union-1.pk \
poke.pkl/union-constraint-1.pk \
poke.pkl/union-constraint-2.pk \
diff --git a/testsuite/poke.pkl/typeof-struct-5.pk
b/testsuite/poke.pkl/typeof-struct-5.pk
new file mode 100644
index 00000000..9e6e429d
--- /dev/null
+++ b/testsuite/poke.pkl/typeof-struct-5.pk
@@ -0,0 +1,13 @@
+/* { dg-do run } */
+
+type Foo =
+ struct
+ {
+ int i;
+ long l if i > 0;
+ if (i == 0) int z;
+ if (i > 10) int w if i % 2;
+ };
+
+/* { dg-command {typeof (Foo).foptional} } */
+/* { dg-output "\\\[0,1,1,1\\\]" } */
--
2.30.2
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [COMMITTED] libpoke: add an `foptionals' field to Pk_Type,
Jose E. Marchesi <=