From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 7902A2279CF07 for ; Fri, 27 Apr 2018 15:33:03 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Apr 2018 15:33:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,336,1520924400"; d="scan'208";a="54252898" Received: from jcarsey-desk1.amr.corp.intel.com ([10.7.159.144]) by orsmga002.jf.intel.com with ESMTP; 27 Apr 2018 15:33:01 -0700 From: Jaben Carsey To: edk2-devel@lists.01.org Cc: Liming Gao , Yonghong Zhu Date: Fri, 27 Apr 2018 15:32:56 -0700 Message-Id: <7054250a55c4d83d0ca4962c37a83646170d495d.1524868035.git.jaben.carsey@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: References: In-Reply-To: References: Subject: [PATCH v1 42/42] BaseTools: use set instead of list X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Apr 2018 22:33:04 -0000 as we only do membership (in) testing for this, set is better Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- BaseTools/Source/Python/Common/Expression.py | 68 ++++++++++---------- BaseTools/Source/Python/Common/RangeExpression.py | 14 ++-- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py index b5f76d860773..de691ccaa612 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -171,7 +171,7 @@ def ReplaceExprMacro(String, Macros, ExceptionList = None): RetStr += '0' elif not InQuote: Tklst = RetStr.split() - if Tklst and Tklst[-1] in ['IN', 'in'] and ExceptionList and Macro not in ExceptionList: + if Tklst and Tklst[-1] in {'IN', 'in'} and ExceptionList and Macro not in ExceptionList: raise BadExpression(ERR_IN_OPERAND) # Make sure the macro in exception list is encapsulated by double quote # For example: DEFINE ARCH = IA32 X64 @@ -243,10 +243,10 @@ class ValueExpression(BaseExpression): def Eval(Operator, Oprand1, Oprand2 = None): WrnExp = None - if Operator not in ["==", "!=", ">=", "<=", ">", "<", "in", "not in"] and \ + if Operator not in {"==", "!=", ">=", "<=", ">", "<", "in", "not in"} and \ (type(Oprand1) == type('') or type(Oprand2) == type('')): raise BadExpression(ERR_STRING_EXPR % Operator) - if Operator in ['in', 'not in']: + if Operator in {'in', 'not in'}: if type(Oprand1) != type(''): Oprand1 = IntToStr(Oprand1) if type(Oprand2) != type(''): @@ -259,19 +259,19 @@ class ValueExpression(BaseExpression): } EvalStr = '' - if Operator in ["!", "NOT", "not"]: + if Operator in {"!", "NOT", "not"}: if type(Oprand1) == type(''): raise BadExpression(ERR_STRING_EXPR % Operator) EvalStr = 'not Oprand1' - elif Operator in ["~"]: + elif Operator in {"~"}: if type(Oprand1) == type(''): raise BadExpression(ERR_STRING_EXPR % Operator) EvalStr = '~ Oprand1' else: - if Operator in ["+", "-"] and (type(True) in [type(Oprand1), type(Oprand2)]): + if Operator in {"+", "-"} and (type(True) in {type(Oprand1), type(Oprand2)}): # Boolean in '+'/'-' will be evaluated but raise warning WrnExp = WrnExpression(WRN_BOOL_EXPR) - elif type('') in [type(Oprand1), type(Oprand2)] and type(Oprand1)!= type(Oprand2): + elif type('') in {type(Oprand1), type(Oprand2)} and type(Oprand1)!= type(Oprand2): # == between string and number/boolean will always return False, != return True if Operator == "==": WrnExp = WrnExpression(WRN_EQCMP_STR_OTHERS) @@ -284,10 +284,10 @@ class ValueExpression(BaseExpression): else: raise BadExpression(ERR_RELCMP_STR_OTHERS % Operator) elif TypeDict[type(Oprand1)] != TypeDict[type(Oprand2)]: - if Operator in ["==", "!=", ">=", "<=", ">", "<"] and set((TypeDict[type(Oprand1)], TypeDict[type(Oprand2)])) == set((TypeDict[type(True)], TypeDict[type(0)])): + if Operator in {"==", "!=", ">=", "<=", ">", "<"} and set((TypeDict[type(Oprand1)], TypeDict[type(Oprand2)])) == set((TypeDict[type(True)], TypeDict[type(0)])): # comparison between number and boolean is allowed pass - elif Operator in ['&', '|', '^', "and", "or"] and set((TypeDict[type(Oprand1)], TypeDict[type(Oprand2)])) == set((TypeDict[type(True)], TypeDict[type(0)])): + elif Operator in {'&', '|', '^', "and", "or"} and set((TypeDict[type(Oprand1)], TypeDict[type(Oprand2)])) == set((TypeDict[type(True)], TypeDict[type(0)])): # bitwise and logical operation between number and boolean is allowed pass else: @@ -310,7 +310,7 @@ class ValueExpression(BaseExpression): except Exception, Excpt: raise BadExpression(str(Excpt)) - if Operator in ['and', 'or']: + if Operator in {'and', 'or'}: if Val: Val = True else: @@ -410,13 +410,13 @@ class ValueExpression(BaseExpression): # Template function to parse binary operators which have same precedence # Expr [Operator Expr]* - def _ExprFuncTemplate(self, EvalFunc, OpLst): + def _ExprFuncTemplate(self, EvalFunc, OpSet): Val = EvalFunc() - while self._IsOperator(OpLst): + while self._IsOperator(OpSet): Op = self._Token if Op == '?': Val2 = EvalFunc() - if self._IsOperator(':'): + if self._IsOperator({':'}): Val3 = EvalFunc() if Val: Val = Val2 @@ -431,35 +431,35 @@ class ValueExpression(BaseExpression): return Val # A [? B]* def _ConExpr(self): - return self._ExprFuncTemplate(self._OrExpr, ['?', ':']) + return self._ExprFuncTemplate(self._OrExpr, {'?', ':'}) # A [|| B]* def _OrExpr(self): - return self._ExprFuncTemplate(self._AndExpr, ["OR", "or", "||"]) + return self._ExprFuncTemplate(self._AndExpr, {"OR", "or", "||"}) # A [&& B]* def _AndExpr(self): - return self._ExprFuncTemplate(self._BitOr, ["AND", "and", "&&"]) + return self._ExprFuncTemplate(self._BitOr, {"AND", "and", "&&"}) # A [ | B]* def _BitOr(self): - return self._ExprFuncTemplate(self._BitXor, ["|"]) + return self._ExprFuncTemplate(self._BitXor, {"|"}) # A [ ^ B]* def _BitXor(self): - return self._ExprFuncTemplate(self._BitAnd, ["XOR", "xor", "^"]) + return self._ExprFuncTemplate(self._BitAnd, {"XOR", "xor", "^"}) # A [ & B]* def _BitAnd(self): - return self._ExprFuncTemplate(self._EqExpr, ["&"]) + return self._ExprFuncTemplate(self._EqExpr, {"&"}) # A [ == B]* def _EqExpr(self): Val = self._RelExpr() - while self._IsOperator(["==", "!=", "EQ", "NE", "IN", "in", "!", "NOT", "not"]): + while self._IsOperator({"==", "!=", "EQ", "NE", "IN", "in", "!", "NOT", "not"}): Op = self._Token - if Op in ["!", "NOT", "not"]: - if not self._IsOperator(["IN", "in"]): + if Op in {"!", "NOT", "not"}: + if not self._IsOperator({"IN", "in"}): raise BadExpression(ERR_REL_NOT_IN) Op += ' ' + self._Token try: @@ -471,29 +471,29 @@ class ValueExpression(BaseExpression): # A [ > B]* def _RelExpr(self): - return self._ExprFuncTemplate(self._ShiftExpr, ["<=", ">=", "<", ">", "LE", "GE", "LT", "GT"]) + return self._ExprFuncTemplate(self._ShiftExpr, {"<=", ">=", "<", ">", "LE", "GE", "LT", "GT"}) def _ShiftExpr(self): - return self._ExprFuncTemplate(self._AddExpr, ["<<", ">>"]) + return self._ExprFuncTemplate(self._AddExpr, {"<<", ">>"}) # A [ + B]* def _AddExpr(self): - return self._ExprFuncTemplate(self._MulExpr, ["+", "-"]) + return self._ExprFuncTemplate(self._MulExpr, {"+", "-"}) # A [ * B]* def _MulExpr(self): - return self._ExprFuncTemplate(self._UnaryExpr, ["*", "/", "%"]) + return self._ExprFuncTemplate(self._UnaryExpr, {"*", "/", "%"}) # [!]*A def _UnaryExpr(self): - if self._IsOperator(["!", "NOT", "not"]): + if self._IsOperator({"!", "NOT", "not"}): Val = self._UnaryExpr() try: return self.Eval('not', Val) except WrnExpression, Warn: self._WarnExcept = Warn return Warn.result - if self._IsOperator(["~"]): + if self._IsOperator({"~"}): Val = self._UnaryExpr() try: return self.Eval('~', Val) @@ -531,7 +531,7 @@ class ValueExpression(BaseExpression): if self._Token.startswith('"') or self._Token.startswith('L"'): Flag = 0 for Index in range(len(self._Token)): - if self._Token[Index] in ['"']: + if self._Token[Index] in {'"'}: if self._Token[Index - 1] == '\\': continue Flag += 1 @@ -540,7 +540,7 @@ class ValueExpression(BaseExpression): if self._Token.startswith("'") or self._Token.startswith("L'"): Flag = 0 for Index in range(len(self._Token)): - if self._Token[Index] in ["'"]: + if self._Token[Index] in {"'"}: if self._Token[Index - 1] == '\\': continue Flag += 1 @@ -645,9 +645,9 @@ class ValueExpression(BaseExpression): if self._Token.startswith('"'): self._Token = self._Token[1:-1] - elif self._Token in ["FALSE", "false", "False"]: + elif self._Token in {"FALSE", "false", "False"}: self._Token = False - elif self._Token in ["TRUE", "true", "True"]: + elif self._Token in {"TRUE", "true", "True"}: self._Token = True else: self.__IsNumberToken() @@ -841,7 +841,7 @@ class ValueExpressionEx(ValueExpression): elif Item.startswith(TAB_UINT64): ItemSize = 8 ValueType = TAB_UINT64 - elif Item[0] in ['"',"'",'L']: + elif Item[0] in {'"',"'",'L'}: ItemSize = 0 ValueType = TAB_VOID else: @@ -998,7 +998,7 @@ class ValueExpressionEx(ValueExpression): Item = '0x%x' % TmpValue if type(TmpValue) != type('') else TmpValue if ItemSize == 0: ItemValue, ItemSize = ParseFieldValue(Item) - if Item[0] not in ['"','L','{'] and ItemSize > 1: + if Item[0] not in {'"','L','{'} and ItemSize > 1: raise BadExpression("Byte array number %s should less than 0xFF." % Item) else: ItemValue = ParseFieldValue(Item)[0] diff --git a/BaseTools/Source/Python/Common/RangeExpression.py b/BaseTools/Source/Python/Common/RangeExpression.py index a37d0ca70d87..53bb11b8cc9b 100644 --- a/BaseTools/Source/Python/Common/RangeExpression.py +++ b/BaseTools/Source/Python/Common/RangeExpression.py @@ -416,9 +416,9 @@ class RangeExpression(BaseExpression): # Template function to parse binary operators which have same precedence # Expr [Operator Expr]* - def _ExprFuncTemplate(self, EvalFunc, OpLst): + def _ExprFuncTemplate(self, EvalFunc, OpSet): Val = EvalFunc() - while self._IsOperator(OpLst): + while self._IsOperator(OpSet): Op = self._Token try: Val = self.Eval(Op, Val, EvalFunc()) @@ -429,18 +429,18 @@ class RangeExpression(BaseExpression): # A [|| B]* def _OrExpr(self): - return self._ExprFuncTemplate(self._AndExpr, ["OR", "or"]) + return self._ExprFuncTemplate(self._AndExpr, {"OR", "or"}) # A [&& B]* def _AndExpr(self): - return self._ExprFuncTemplate(self._NeExpr, ["AND", "and"]) + return self._ExprFuncTemplate(self._NeExpr, {"AND", "and"}) def _NeExpr(self): Val = self._RelExpr() - while self._IsOperator([ "!=", "NOT", "not"]): + while self._IsOperator({"!=", "NOT", "not"}): Op = self._Token if Op in ["!", "NOT", "not"]: - if not self._IsOperator(["IN", "in"]): + if not self._IsOperator({"IN", "in"}): raise BadExpression(ERR_REL_NOT_IN) Op += ' ' + self._Token try: @@ -452,7 +452,7 @@ class RangeExpression(BaseExpression): # [!]*A def _RelExpr(self): - if self._IsOperator(["NOT" , "LE", "GE", "LT", "GT", "EQ", "XOR"]): + if self._IsOperator({"NOT" , "LE", "GE", "LT", "GT", "EQ", "XOR"}): Token = self._Token Val = self._NeExpr() try: -- 2.16.2.windows.1