All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 1/4] builtin: extract eval_args() from arguments_choose()
Date: Sat, 17 Feb 2018 15:56:31 +0100	[thread overview]
Message-ID: <20180217145634.53616-2-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20180217145634.53616-1-luc.vanoostenryck@gmail.com>

Almost the same code is needed for others builtins, only
with another function name a arguments number.

So, extract this into a generic helper.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 builtin.c | 49 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 19 deletions(-)

diff --git a/builtin.c b/builtin.c
index f5ea06ab9..9aa109d15 100644
--- a/builtin.c
+++ b/builtin.c
@@ -51,6 +51,35 @@ static int evaluate_pure_unop(struct expression *expr)
 	return 1;
 }
 
+/*
+ * eval_args - check the number of arguments and evaluate them.
+ */
+static int eval_args(struct expression *expr, int n)
+{
+	struct expression *arg;
+	struct symbol *sym;
+	const char *msg;
+	int rc = 1;
+
+	FOR_EACH_PTR(expr->args, arg) {
+		if (n-- == 0) {
+			msg = "too many arguments";
+			goto error;
+		}
+		if (!evaluate_expression(arg))
+			rc = 0;
+	} END_FOR_EACH_PTR(arg);
+	if (n > 0) {
+		msg = "not enough arguments";
+		goto error;
+	}
+	return rc;
+
+error:
+	sym = expr->fn->ctype;
+	expression_error(expr, "%s for %s", msg, show_ident(sym->ident));
+	return 0;
+}
 
 static int evaluate_expect(struct expression *expr)
 {
@@ -61,25 +90,7 @@ static int evaluate_expect(struct expression *expr)
 
 static int arguments_choose(struct expression *expr)
 {
-	struct expression_list *arglist = expr->args;
-	struct expression *arg;
-	int i = 0;

  reply	other threads:[~2018-02-17 14:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-17 14:56 [PATCH 0/4] expansion of builtin FP predicates (isinf(), ...) Luc Van Oostenryck
2018-02-17 14:56 ` Luc Van Oostenryck [this message]
2018-02-17 14:56 ` [PATCH 2/4] builtin: add typechecking of isnan(), isinf(), Luc Van Oostenryck
2018-02-17 14:56 ` [PATCH 3/4] builtin: add testcases for expansion of special FP constants Luc Van Oostenryck
2018-02-17 14:56 ` [PATCH 4/4] builtin: add testcases for expansion of FP classification Luc Van Oostenryck

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=20180217145634.53616-2-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.