public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Jaben Carsey <jaben.carsey@intel.com>
To: edk2-devel@lists.01.org
Cc: Liming Gao <liming.gao@intel.com>, Yonghong Zhu <yonghong.zhu@intel.com>
Subject: [PATCH v1 42/42] BaseTools: use set instead of list
Date: Fri, 27 Apr 2018 15:32:56 -0700	[thread overview]
Message-ID: <7054250a55c4d83d0ca4962c37a83646170d495d.1524868035.git.jaben.carsey@intel.com> (raw)
In-Reply-To: <cover.1524868033.git.jaben.carsey@intel.com>
In-Reply-To: <cover.1524868033.git.jaben.carsey@intel.com>

as we only do membership (in) testing for this, set is better

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
---
 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



  parent reply	other threads:[~2018-04-27 22:33 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-27 22:32 [PATCH v1 00/42] BaseTools: refactoring patches Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 01/42] BaseTools: FdfParser - update to remove duplicate constant value Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 02/42] BaseTools: AutoGen " Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 03/42] BaseTools: check before accessing members in __eq__ Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 04/42] BaseTools: this function has no purpose Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 05/42] BaseTools: AutoGen - refactor assemble_variable Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 06/42] BaseTools: AutoGen - refactor dictionary access Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 07/42] BaseTools: AutoGen - GenVar refactor static methods Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 08/42] BaseTools: AutoGen - share StripComments API Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 09/42] BaseTools: AutoGen - refactor class factory Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 10/42] BaseTools: Eot - remove unused lists Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 11/42] BaseTools: Eot - refactor global data Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 12/42] BaseTools: AutoGen - remove global line Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 13/42] BaseTools: AutoGen - UniClassObject refactor static methods Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 14/42] BaseTools: refactor to use list not dict Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 15/42] BaseTools: eliminate {} from dictionary contructor call Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 16/42] BaseTools: remove Compound statements Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 17/42] BaseTools: Workspace - refactor a dict Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 18/42] BaseTools: move PCD size calculation functions to PcdClassObject Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 19/42] BaseTools: AutoGen - refactor out functions only called in __init__ Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 20/42] BaseTools: AutoGen - refactor out a list Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 21/42] BaseTools: AutoGen - refactor out a useless class Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 22/42] BaseTools: AutoGen - no need to recompute Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 23/42] BaseTools: refactor __init__ functions to not compute temporary variable Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 24/42] BaseTools: AutoGen - remove function no one calls Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 25/42] BaseTools: AutoGen - move function to clean file namespace Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 26/42] BaseTools: AutoGen - remove another function no one calls Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 27/42] BaseTools: Refactor to share GUID packing function Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 28/42] BaseTools: AutoGen - refactor function to remove extra variables Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 29/42] BaseTools: AutoGen - refactor more functions only called in __init__ Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 30/42] BaseTools: remove unused member variable Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 31/42] BaseTools: remove redundant content in InfSectionParser Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 32/42] BaseTools: trim whitespace Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 33/42] BaseTools: AutoGen - add Opcode constants Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 34/42] BaseTools: standardize GUID and pack size Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 35/42] BaseTools: remove unused variable Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 36/42] BaseTools: GenFds - use existing shared string Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 37/42] BaseTools: missed a copyright update Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 38/42] BaseTools: Remove lists form set construction Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 39/42] BaseTools: refactor Depex optomization Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 40/42] BaseTools: dont make iterator into list if not needed Jaben Carsey
2018-04-27 22:32 ` [PATCH v1 41/42] BaseTools: create base expression class Jaben Carsey
2018-04-27 22:32 ` Jaben Carsey [this message]
2018-05-04  4:33 ` [PATCH v1 00/42] BaseTools: refactoring patches Zhu, Yonghong

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-list 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=7054250a55c4d83d0ca4962c37a83646170d495d.1524868035.git.jaben.carsey@intel.com \
    --to=devel@edk2.groups.io \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox