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