zsh-workers
 help / color / mirror / code / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: zsh-workers@zsh.org
Cc: Bart Schaefer <schaefer@brasslantern.com>,
	Felipe Contreras <felipe.contreras@gmail.com>
Subject: [PATCH] First try of null typeset
Date: Tue,  1 Dec 2020 03:13:42 -0600	[thread overview]
Message-ID: <20201201091342.310763-1-felipe.contreras@gmail.com> (raw)

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---

This achieves most of what Bart Schaefer's version achieves, except no extra hacks are needed, and
integer and floats are not changed.

This most definetly is not close to the final solution, but shows what can be achieved by narrowing
down the functional changes to two functions.

In my opinion a separate concept of "null" variable will be needed, and should be separate from
PM_UNSET, since that changes a lot of behavior.

Also, I don't think $empty[(i)] should return nothing, so probably paramsubst() would need to be
tuned, not simply set vunset=1.

Addtionally, this patch doesn't change the behavior of the private module.

 Src/params.c | 23 ++++++++++++++++++++++-
 Src/subst.c  |  2 +-
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/Src/params.c b/Src/params.c
index 122f5da7d..7dbe67bd1 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -3697,6 +3697,27 @@ unsetparam_pm(Param pm, int altflag, int exp)
     return 0;
 }
 
+/**/
+mod_export int
+isnull(Param pm)
+{
+    switch (PM_TYPE(pm->node.flags)) {
+    case PM_SCALAR:
+	if (pm->gsu.s->getfn == strgetfn && !pm->u.str)
+	    return 1;
+	break;
+    case PM_ARRAY:
+	if (pm->gsu.a->getfn == arrgetfn && !pm->u.arr)
+	    return 1;
+	break;
+    case PM_HASHED:
+	if (pm->gsu.h->getfn == hashgetfn && !pm->u.hash)
+	    return 1;
+	break;
+    }
+    return 0;
+}
+
 /* Standard function to unset a parameter.  This is mostly delegated to *
  * the specific set function.
  *
@@ -5955,7 +5976,7 @@ printparamnode(HashNode hn, int printflags)
 	}
     }
 
-    if ((printflags & PRINT_NAMEONLY) ||
+    if ((printflags & PRINT_NAMEONLY) || isnull(p) ||
 	((p->node.flags & PM_HIDEVAL) && !(printflags & PRINT_INCLUDEVALUE)))
 	quotedzputs(p->node.nam, stdout);
     else {
diff --git a/Src/subst.c b/Src/subst.c
index 8f5bd355e..42d18d58d 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -2532,7 +2532,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
 			     (wantt ? -1 :
 			      ((unset(KSHARRAYS) || inbrace) ? 1 : -1)),
 			     scanflags)) ||
-	    (v->pm && (v->pm->node.flags & PM_UNSET)) ||
+	    (v->pm && (v->pm->node.flags & PM_UNSET || isnull(v->pm))) ||
 	    (v->flags & VALFLAG_EMPTY))
 	    vunset = 1;
 
-- 
2.29.2



             reply	other threads:[~2020-12-01  9:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-01  9:13 Felipe Contreras [this message]
2020-12-02 18:47 ` Bart Schaefer
2020-12-02 21:59   ` Felipe Contreras
2020-12-03  8:44     ` Roman Perepelitsa
2020-12-03  9:18       ` Felipe Contreras

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201201091342.310763-1-felipe.contreras@gmail.com \
    --to=felipe.contreras@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).