From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F7EEC11F64 for ; Thu, 1 Jul 2021 06:17:11 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F269A61461 for ; Thu, 1 Jul 2021 06:17:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F269A61461 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B5D668321C; Thu, 1 Jul 2021 08:16:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ZNayrIIq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8325383271; Thu, 1 Jul 2021 08:16:30 +0200 (CEST) Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7CF9D8321E for ; Thu, 1 Jul 2021 08:16:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qt1-x833.google.com with SMTP id c13so3356280qtb.12 for ; Wed, 30 Jun 2021 23:16:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yjms/r4TRyD7PnAT/kUWqC3GJwb1jt5iMV+Y6BStEps=; b=ZNayrIIqkYDl+CMNZXxziYKi3LpMDMS7GRrDban1xzqZqOIiIdjiTLC5m80II6zlm/ Ng9pv/UbrkaUgZ78aGI1f0NhHhNmeE7oReOx4FOSx32Uebr+0m4HxAQQWeMDbFH1ybgx lhtHWNpp1N3I+cSTKu/aGcydmSV2eqOUeyGxY2HdaSrjck/xQfMjfS1Bhs6lQComq5wr qkTuPyNYRL8Bi4D1Z5oekA6BmFiceB3mqNfx2OMWq5D5VhJEqEViPoTPvRIx0HGTfi95 lLBfMmiVrGELYBTHpHjcT8J3wKunVuedFGHd/v6wG8raSsCVPHaSOS6yQOFLNenMM4qe PHMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yjms/r4TRyD7PnAT/kUWqC3GJwb1jt5iMV+Y6BStEps=; b=N7d/kf1kiOnaCGLKwfR/RE+vP3QzR9cyTC8Fl1Nq4ATSYwVfN0LC4Kg0/mEh9EOGZd CDetsg3SYGlWvz0m2RsOigZ45UILBm85MU+BAbz4mtK8nGhqTpgw0iNMLZtdrnVOIZpK DLJmYavTwMJe6V3JfirZwiUtGJ23bVD3zQ7KjTG4Asn8Yad3SVHjG3NqcKB30O5ibVdB n7Z26CNXwnhd0vP3xI12qHnzNJxJPxoHfaoou1s6b0r+a7dXk88V3uAc4F9fUcSKTHAv 9GJXrvzUswU3VpxXnEJfmOFUySz0MGiuV2Bhz0Jux0j36X7QqnR0OBxZ84h4UaIFcA93 bWNA== X-Gm-Message-State: AOAM533DxwMQigeATM98FyrToL4sS8er23iUUZvHQZma8Kfk/U0a+827 ngJcOBaoRe0EsDvP9JuHLu6PQVApB7A= X-Google-Smtp-Source: ABdhPJxRF+JCwa8rFgqddudESiYJ23gTIvEoV3kuVnreWFsakjnAuJY5kr6qfWhyVI3eGPsYVBtLvQ== X-Received: by 2002:a05:622a:394:: with SMTP id j20mr5400372qtx.270.1625120179178; Wed, 30 Jun 2021 23:16:19 -0700 (PDT) Received: from godwin.fios-router.home (pool-74-96-87-9.washdc.fios.verizon.net. [74.96.87.9]) by smtp.gmail.com with ESMTPSA id g21sm1684673qts.90.2021.06.30.23.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Jun 2021 23:16:18 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de, Tom Rini Cc: =?UTF-8?q?Marek=20Beh=C3=BAn?= , Wolfgang Denk , Simon Glass , Roland Gaudig , Heinrich Schuchardt , Kostas Michalopoulos , Sean Anderson Subject: [RFC PATCH 06/28] cli: lil: Convert some defines to enums Date: Thu, 1 Jul 2021 02:15:49 -0400 Message-Id: <20210701061611.957918-7-seanga2@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210701061611.957918-1-seanga2@gmail.com> References: <20210701061611.957918-1-seanga2@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean This converts some defines to enums. This allows them to be documented more easily, and helps the compiler give better errors for switch statements. Signed-off-by: Sean Anderson --- common/cli_lil.c | 44 +++++++++++++++++++++++--------------------- include/cli_lil.h | 12 +++++++----- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/common/cli_lil.c b/common/cli_lil.c index a6c77ee19c..3d1e6181f9 100644 --- a/common/cli_lil.c +++ b/common/cli_lil.c @@ -24,10 +24,6 @@ * overflows and is also useful when running through an automated fuzzer like AFL */ /*#define LIL_ENABLE_RECLIMIT 10000*/ -#define ERROR_NOERROR 0 -#define ERROR_DEFAULT 1 -#define ERROR_FIXHEAD 2 - #define CALLBACKS 8 #define HASHMAP_CELLS 256 #define HASHMAP_CELLMASK 0xFF @@ -97,7 +93,11 @@ struct lil { struct lil_env *rootenv; struct lil_env *downenv; struct lil_value *empty; - int error; + enum { + ERROR_NOERROR = 0, + ERROR_DEFAULT, + ERROR_FIXHEAD, + } error; size_t err_head; char *err_msg; lil_callback_proc_t callback[CALLBACKS]; @@ -108,7 +108,12 @@ struct expreval { const char *code; size_t len, head; ssize_t ival; - int error; + enum { + EERR_NO_ERROR = 0, + EERR_SYNTAX_ERROR, + EERR_DIVISION_BY_ZERO, + EERR_INVALID_EXPRESSION, + } error; }; static struct lil_value *next_word(struct lil *lil); @@ -645,7 +650,7 @@ int lil_register(struct lil *lil, const char *name, lil_func_proc_t proc) } struct lil_var *lil_set_var(struct lil *lil, const char *name, - struct lil_value *val, int local) + struct lil_value *val, enum lil_setvar local) { struct lil_var **nvar; struct lil_env *env = @@ -1222,11 +1227,6 @@ int lil_error(struct lil *lil, const char **msg, size_t *pos) return 1; } -#define EERR_NO_ERROR 0 -#define EERR_SYNTAX_ERROR 1 -#define EERR_DIVISION_BY_ZERO 3 -#define EERR_INVALID_EXPRESSION 4 - static void ee_expr(struct expreval *ee); static int ee_invalidpunct(int ch) @@ -1673,16 +1673,18 @@ struct lil_value *lil_eval_expr(struct lil *lil, struct lil_value *code) ee_expr(&ee); lil_free_value(code); - if (ee.error) { - switch (ee.error) { - case EERR_DIVISION_BY_ZERO: - lil_set_error(lil, "division by zero in expression"); - break; - case EERR_SYNTAX_ERROR: - lil_set_error(lil, "expression syntax error"); - break; - } + switch (ee.error) { + case EERR_DIVISION_BY_ZERO: + lil_set_error(lil, "division by zero in expression"); return NULL; + case EERR_SYNTAX_ERROR: + lil_set_error(lil, "expression syntax error"); + return NULL; + case EERR_INVALID_EXPRESSION: + lil_set_error(lil, "invalid expression"); + return NULL; + case EERR_NO_ERROR: + break; } return lil_alloc_integer(ee.ival); } diff --git a/include/cli_lil.h b/include/cli_lil.h index c72977ea5c..48735e0605 100644 --- a/include/cli_lil.h +++ b/include/cli_lil.h @@ -13,10 +13,12 @@ #define LIL_VERSION_STRING "0.1" -#define LIL_SETVAR_GLOBAL 0 -#define LIL_SETVAR_LOCAL 1 -#define LIL_SETVAR_LOCAL_NEW 2 -#define LIL_SETVAR_LOCAL_ONLY 3 +enum lil_setvar { + LIL_SETVAR_GLOBAL = 0, + LIL_SETVAR_LOCAL, + LIL_SETVAR_LOCAL_NEW, + LIL_SETVAR_LOCAL_ONLY, +}; #define LIL_CALLBACK_EXIT 0 #define LIL_CALLBACK_WRITE 1 @@ -98,7 +100,7 @@ struct lil_env *lil_push_env(struct lil *lil); void lil_pop_env(struct lil *lil); struct lil_var *lil_set_var(struct lil *lil, const char *name, - struct lil_value *val, int local); + struct lil_value *val, enum lil_setvar local); struct lil_value *lil_get_var(struct lil *lil, const char *name); struct lil_value *lil_get_var_or(struct lil *lil, const char *name, struct lil_value *defvalue); -- 2.32.0