From nobody Sat Nov 2 10:20:22 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1490970105373741.6515410197957; Fri, 31 Mar 2017 07:21:45 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 42E0220080308; Fri, 31 Mar 2017 07:21:44 -0700 (PDT) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E0F9A21DFA7B1 for ; Fri, 31 Mar 2017 07:21:42 -0700 (PDT) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Mar 2017 07:21:42 -0700 Received: from shwdeopenpsi168.ccr.corp.intel.com ([10.239.158.121]) by fmsmga005.fm.intel.com with ESMTP; 31 Mar 2017 07:21:41 -0700 X-Original-To: edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1490970102; x=1522506102; h=from:to:cc:subject:date:message-id; bh=wG88ETBHGuxedRGg+6X4XGeIeKZq9UcUZLbe4cmcfQE=; b=jIKtA8fJnpRFqVSqfdbBanWBS08ecn4+LXWyAfAIpBD6glsjZdX6Z/OW jVbBPDYWo3HJKH8Xq3FeEwuEI5q2Mg==; X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,252,1486454400"; d="scan'208";a="82730048" From: Yonghong Zhu To: edk2-devel@lists.01.org Date: Fri, 31 Mar 2017 22:21:38 +0800 Message-Id: <1490970098-52308-1-git-send-email-yonghong.zhu@intel.com> X-Mailer: git-send-email 2.6.1.windows.1 Subject: [edk2] [Patch] BaseTools: Enhance expression to support some more operation X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Enhance expression to support some more operation that allowed in the spec, eg: *, /, %, <<, >>, ~. Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Yonghong Zhu Reviewed-by: Liming Gao --- BaseTools/Source/Python/Common/Expression.py | 28 +++++++++++++++++++++++-= ---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Sourc= e/Python/Common/Expression.py index 7b3030c..6d002f5 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -1,9 +1,9 @@ ## @file # This file is used to parse and evaluate expression in directive or PCD v= alue. # -# Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.
# This program and the accompanying materials # are licensed and made available under the terms and conditions of the BS= D License # which accompanies this distribution. The full text of the license may= be found at # http://opensource.org/licenses/bsd-license.php # @@ -127,11 +127,11 @@ class ValueExpression(object): 'GT' : '>' , 'LT' : '<', 'GE' : '>=3D' , 'LE' : '<=3D', 'IN' : 'in' } =20 - NonLetterOpLst =3D ['+', '-', '&', '|', '^', '!', '=3D', '>', '<'] + NonLetterOpLst =3D ['+', '-', '*', '/', '%', '&', '|', '^', '~', '<<',= '>>', '!', '=3D', '>', '<'] =20 PcdPattern =3D re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-= z_]*$') HexPattern =3D re.compile(r'0[xX][0-9a-fA-F]+$') RegGuidPattern =3D re.compile(r'[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA= -F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}') =20 @@ -160,10 +160,14 @@ class ValueExpression(object): EvalStr =3D '' if Operator in ["!", "NOT", "not"]: if type(Oprand1) =3D=3D type(''): raise BadExpression(ERR_STRING_EXPR % Operator) EvalStr =3D 'not Oprand1' + elif Operator in ["~"]: + if type(Oprand1) =3D=3D type(''): + raise BadExpression(ERR_STRING_EXPR % Operator) + EvalStr =3D '~ Oprand1' else: if Operator in ["+", "-"] and (type(True) in [type(Oprand1), t= ype(Oprand2)]): # Boolean in '+'/'-' will be evaluated but raise warning WrnExp =3D WrnExpression(WRN_BOOL_EXPR) elif type('') in [type(Oprand1), type(Oprand2)] and type(Opran= d1)!=3D type(Oprand2): @@ -351,25 +355,39 @@ class ValueExpression(object): Val =3D Warn.result return Val =20 # A [ > B]* def _RelExpr(self): - return self._ExprFuncTemplate(self._AddExpr, ["<=3D", ">=3D", "<",= ">", "LE", "GE", "LT", "GT"]) + return self._ExprFuncTemplate(self._ShiftExpr, ["<=3D", ">=3D", "<= ", ">", "LE", "GE", "LT", "GT"]) + + def _ShiftExpr(self): + return self._ExprFuncTemplate(self._AddExpr, ["<<", ">>"]) =20 # A [ + B]* def _AddExpr(self): - return self._ExprFuncTemplate(self._UnaryExpr, ["+", "-"]) + return self._ExprFuncTemplate(self._MulExpr, ["+", "-"]) + + # A [ * B]* + def _MulExpr(self): + return self._ExprFuncTemplate(self._UnaryExpr, ["*", "/", "%"]) =20 # [!]*A def _UnaryExpr(self): if self._IsOperator(["!", "NOT", "not"]): Val =3D self._UnaryExpr() try: return self.Eval('not', Val) except WrnExpression, Warn: self._WarnExcept =3D Warn return Warn.result + if self._IsOperator(["~"]): + Val =3D self._UnaryExpr() + try: + return self.Eval('~', Val) + except WrnExpression, Warn: + self._WarnExcept =3D Warn + return Warn.result return self._IdenExpr() =20 # Parse identifier or encapsulated expression def _IdenExpr(self): Tk =3D self._GetToken() @@ -535,11 +553,11 @@ class ValueExpression(object): def _GetToken(self): return self.__GetNList() =20 @staticmethod def __IsIdChar(Ch): - return Ch in '._/:' or Ch.isalnum() + return Ch in '._:' or Ch.isalnum() =20 # Parse operand def _GetSingleToken(self): self.__SkipWS() Expr =3D self._Expr[self._Idx:] --=20 2.6.1.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel