]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Common/FdfParserLite.py
BaseTools: make static functions when self is not needed
[mirror_edk2.git] / BaseTools / Source / Python / Common / FdfParserLite.py
index 255ca9633aa180abe4fd2603bc23ebee109fe08e..dd822505d3d3dfaa0d7c570a562a922adb020fbc 100644 (file)
@@ -23,6 +23,7 @@ from Common.LongFilePathSupport import OpenLongFilePath as open
 from Common.MultipleWorkspace import MultipleWorkspace as mws\r
 from Common.RangeExpression import RangeExpression\r
 from Common.GlobalData import *\r
+import string\r
 \r
 ##define T_CHAR_SPACE                ' '\r
 ##define T_CHAR_NULL                 '\0'\r
@@ -183,21 +184,6 @@ class FdfParser(object):
         \r
         self.__WipeOffArea = []\r
 \r
-    ## __IsWhiteSpace() method\r
-    #\r
-    #   Whether char at current FileBufferPos is whitespace\r
-    #\r
-    #   @param  self        The object pointer\r
-    #   @param  Char        The char to test\r
-    #   @retval True        The char is a kind of white space\r
-    #   @retval False       The char is NOT a kind of white space\r
-    #\r
-    def __IsWhiteSpace(self, Char):\r
-        if Char in (T_CHAR_NULL, T_CHAR_CR, T_CHAR_SPACE, T_CHAR_TAB, T_CHAR_LF):\r
-            return True\r
-        else:\r
-            return False\r
-\r
     ## __SkipWhiteSpace() method\r
     #\r
     #   Skip white spaces from current char, return number of chars skipped\r
@@ -975,32 +961,13 @@ class FdfParser(object):
             \r
         self.__GetOneChar()\r
     \r
-    ## __HexDigit() method\r
-    #\r
-    #   Whether char input is a Hex data bit\r
-    #\r
-    #   @param  self        The object pointer\r
-    #   @param  TempChar    The char to test\r
-    #   @retval True        The char is a Hex data bit\r
-    #   @retval False       The char is NOT a Hex data bit\r
-    #\r
-    def __HexDigit(self, TempChar):\r
-        if (TempChar >= 'a' and TempChar <= 'f') or (TempChar >= 'A' and TempChar <= 'F') \\r
-                or (TempChar >= '0' and TempChar <= '9'):\r
-                    return True\r
-        else:\r
-            return False\r
-    \r
     def __IsHex(self, HexStr):\r
         if not HexStr.upper().startswith("0X"):\r
             return False\r
         if len(self.__Token) <= 2:\r
             return False\r
-        charList = [c for c in HexStr[2 : ] if not self.__HexDigit( c)]\r
-        if len(charList) == 0:\r
-            return True\r
-        else:\r
-            return False    \r
+        return True if all(x in string.hexdigits for x in HexStr[2:]) else False\r
+\r
     ## __GetNextHexNumber() method\r
     #\r
     #   Get next HEX data before a seperator\r
@@ -2163,13 +2130,12 @@ class FdfParser(object):
     #\r
     #   Check whether reloc strip flag can be set for a file type.\r
     #\r
-    #   @param  self        The object pointer\r
     #   @param  FileType    The file type to check with\r
     #   @retval True        This type could have relocation strip flag\r
     #   @retval False       No way to have it\r
     #\r
-    \r
-    def __FileCouldHaveRelocFlag (self, FileType):\r
+    @staticmethod\r
+    def __FileCouldHaveRelocFlag (FileType):\r
         if FileType in ('SEC', 'PEI_CORE', 'PEIM', 'PEI_DXE_COMBO'):\r
             return True\r
         else:\r
@@ -2179,13 +2145,12 @@ class FdfParser(object):
     #\r
     #   Check whether reloc strip flag can be set for a section type.\r
     #\r
-    #   @param  self        The object pointer\r
     #   @param  SectionType The section type to check with\r
     #   @retval True        This type could have relocation strip flag\r
     #   @retval False       No way to have it\r
     #\r
-    \r
-    def __SectionCouldHaveRelocFlag (self, SectionType):\r
+    @staticmethod\r
+    def __SectionCouldHaveRelocFlag (SectionType):\r
         if SectionType in ('TE', 'PE32'):\r
             return True\r
         else:\r
@@ -3185,12 +3150,12 @@ class FdfParser(object):
     #\r
     #   Get whether a section could be optional\r
     #\r
-    #   @param  self        The object pointer\r
     #   @param  SectionType The section type to check\r
     #   @retval True        section could be optional\r
     #   @retval False       section never optional\r
     #\r
-    def __RuleSectionCouldBeOptional(self, SectionType):\r
+    @staticmethod\r
+    def __RuleSectionCouldBeOptional(SectionType):\r
         if SectionType in ("DXE_DEPEX", "UI", "VERSION", "PEI_DEPEX", "RAW", "SMM_DEPEX"):\r
             return True\r
         else:\r
@@ -3200,12 +3165,12 @@ class FdfParser(object):
     #\r
     #   Get whether a section could have build number information\r
     #\r
-    #   @param  self        The object pointer\r
     #   @param  SectionType The section type to check\r
     #   @retval True        section could have build number information\r
     #   @retval False       section never have build number information\r
     #\r
-    def __RuleSectionCouldHaveBuildNum(self, SectionType):\r
+    @staticmethod\r
+    def __RuleSectionCouldHaveBuildNum(SectionType):\r
         if SectionType in ("VERSION"):\r
             return True\r
         else:\r
@@ -3215,12 +3180,12 @@ class FdfParser(object):
     #\r
     #   Get whether a section could have string\r
     #\r
-    #   @param  self        The object pointer\r
     #   @param  SectionType The section type to check\r
     #   @retval True        section could have string\r
     #   @retval False       section never have string\r
     #\r
-    def __RuleSectionCouldHaveString(self, SectionType):\r
+    @staticmethod\r
+    def __RuleSectionCouldHaveString(SectionType):\r
         if SectionType in ("UI", "VERSION"):\r
             return True\r
         else:\r
@@ -3455,7 +3420,7 @@ class FdfParser(object):
             raise Warning("expected Component type At Line ", self.FileName, self.CurrentLineNumber)\r
         if self.__Token not in ("FIT", "PAL_B", "PAL_A", "OEM"):\r
             if not self.__Token.startswith("0x") or len(self.__Token) < 3 or len(self.__Token) > 4 or \\r
-                not self.__HexDigit(self.__Token[2]) or not self.__HexDigit(self.__Token[-1]):\r
+                not self.__Token[2] in string.hexdigits or not self.__Token[-1] in string.hexdigits:\r
                 raise Warning("Unknown location type At line ", self.FileName, self.CurrentLineNumber)\r
         CompStatementObj.CompType = self.__Token\r
         \r