poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Allow arrays of size zero


From: John Darrington
Subject: [PATCH] Allow arrays of size zero
Date: Sun, 17 Nov 2019 14:51:16 +0100

        * src/pkl-typify.c (PKL_PHRASE_BEGIN_HANDLER): Change bound to accept 
zero sized arrays.
        Also, adjust the error message and correct the spelling.
        * testsuite/array-type-diag-2.pk: Adjust test accordingly.
---
 src/pkl-typify.c                        | 6 +++---
 testsuite/poke.map/maps-int-51.pk       | 5 +++++
 testsuite/poke.pkl/array-type-1.pk      | 3 +++
 testsuite/poke.pkl/array-type-diag-2.pk | 3 ---
 4 files changed, 11 insertions(+), 6 deletions(-)
 create mode 100644 testsuite/poke.map/maps-int-51.pk
 create mode 100644 testsuite/poke.pkl/array-type-1.pk
 delete mode 100644 testsuite/poke.pkl/array-type-diag-2.pk

diff --git a/src/pkl-typify.c b/src/pkl-typify.c
index 86dc651..1beeb39 100644
--- a/src/pkl-typify.c
+++ b/src/pkl-typify.c
@@ -2205,7 +2205,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify2_ps_type)
 }
 PKL_PHASE_END_HANDLER
 
-/* Static array indexes should be bigger than 0.  */
+/* Static array indexes should be non-negative.  */
 
 PKL_PHASE_BEGIN_HANDLER (pkl_typify2_ps_type_array)
 {
@@ -2218,10 +2218,10 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify2_ps_type_array)
 
       if (PKL_AST_TYPE_CODE (bound_type) == PKL_TYPE_INTEGRAL
           && PKL_AST_CODE (bound) == PKL_AST_INTEGER
-          && ((int64_t) PKL_AST_INTEGER_VALUE (bound)) <= 0)
+          && ((int64_t) PKL_AST_INTEGER_VALUE (bound)) < 0)
         {
           PKL_ERROR (PKL_AST_LOC (bound),
-                     "array dimentions should be > 0");
+                     "array dimensions may not be negative");
           PKL_TYPIFY_PAYLOAD->errors++;
           PKL_PASS_ERROR;
         }
diff --git a/testsuite/poke.map/maps-int-51.pk 
b/testsuite/poke.map/maps-int-51.pk
new file mode 100644
index 0000000..2836f8d
--- /dev/null
+++ b/testsuite/poke.map/maps-int-51.pk
@@ -0,0 +1,5 @@
+/* { dg-do run } */
+/* { dg-data {c*} {0x10 0x20 0x30 0x40  0x50 0x60 0x70 0x80   0x90 0xa0 0xb0 
0xc0} } */
+
+/* { dg-command { int[0] @ 0#B } } */
+/* { dg-output "\\\[\\\]" } */
diff --git a/testsuite/poke.pkl/array-type-1.pk 
b/testsuite/poke.pkl/array-type-1.pk
new file mode 100644
index 0000000..87325e0
--- /dev/null
+++ b/testsuite/poke.pkl/array-type-1.pk
@@ -0,0 +1,3 @@
+/* { dg-do compile } */
+
+deftype foo = int[0];
diff --git a/testsuite/poke.pkl/array-type-diag-2.pk 
b/testsuite/poke.pkl/array-type-diag-2.pk
deleted file mode 100644
index 4be1d21..0000000
--- a/testsuite/poke.pkl/array-type-diag-2.pk
+++ /dev/null
@@ -1,3 +0,0 @@
-/* { dg-do compile } */
-
-deftype foo = int[0];  /* { dg-error "" } */
-- 
2.11.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]