X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FCommon%2FFdfParserLite.py;h=0e35eb484b9a0370953a2d8a7cfa961e1bb8242b;hp=806fdd8aa5bb487cdbb23da1ffc5ecea51927e44;hb=cfbe3c3500a64e218e7d357dacb18d8b95eddfec;hpb=4d603daa3a2276d98ac6749d1db8e327ff7c1f5f diff --git a/BaseTools/Source/Python/Common/FdfParserLite.py b/BaseTools/Source/Python/Common/FdfParserLite.py index 806fdd8aa5..0e35eb484b 100644 --- a/BaseTools/Source/Python/Common/FdfParserLite.py +++ b/BaseTools/Source/Python/Common/FdfParserLite.py @@ -22,6 +22,8 @@ import CommonDataClass.FdfClass 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' @@ -48,6 +50,7 @@ InputMacroDict = {} AllMacroList = [] FileExtensionPattern = re.compile(r'([a-zA-Z][a-zA-Z0-9]*)') +TokenFindPattern = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)') def GetRealFileLine (File, Line): @@ -355,7 +358,7 @@ class FdfParser(object): if Profile.FileName == File and Profile.MacroName == Name and Profile.DefinedAtLine <= Line: Value = Profile.MacroValue - if Value != None: + if Value is not None: Str = Str.replace('$(' + Name + ')', Value) MacroEnd = MacroStart + len(Value) @@ -678,8 +681,8 @@ class FdfParser(object): FileLineTuple = GetRealFileLine(self.FileName, Line) if Name in InputMacroDict: MacroValue = InputMacroDict[Name] - if Op == None: - if Value == 'Bool' and MacroValue == None or MacroValue.upper() == 'FALSE': + if Op is None: + if Value == 'Bool' and MacroValue is None or MacroValue.upper() == 'FALSE': return False return True elif Op == '!=': @@ -693,7 +696,7 @@ class FdfParser(object): else: return False else: - if (self.__IsHex(Value) or Value.isdigit()) and (self.__IsHex(MacroValue) or (MacroValue != None and MacroValue.isdigit())): + if (self.__IsHex(Value) or Value.isdigit()) and (self.__IsHex(MacroValue) or (MacroValue is not None and MacroValue.isdigit())): InputVal = long(Value, 0) MacroVal = long(MacroValue, 0) if Op == '>': @@ -723,8 +726,8 @@ class FdfParser(object): for Profile in AllMacroList: if Profile.FileName == FileLineTuple[0] and Profile.MacroName == Name and Profile.DefinedAtLine <= FileLineTuple[1]: - if Op == None: - if Value == 'Bool' and Profile.MacroValue == None or Profile.MacroValue.upper() == 'FALSE': + if Op is None: + if Value == 'Bool' and Profile.MacroValue is None or Profile.MacroValue.upper() == 'FALSE': return False return True elif Op == '!=': @@ -738,7 +741,7 @@ class FdfParser(object): else: return False else: - if (self.__IsHex(Value) or Value.isdigit()) and (self.__IsHex(Profile.MacroValue) or (Profile.MacroValue != None and Profile.MacroValue.isdigit())): + if (self.__IsHex(Value) or Value.isdigit()) and (self.__IsHex(Profile.MacroValue) or (Profile.MacroValue is not None and Profile.MacroValue.isdigit())): InputVal = long(Value, 0) MacroVal = long(Profile.MacroValue, 0) if Op == '>': @@ -934,7 +937,7 @@ class FdfParser(object): if not self.__GetNextToken(): return False - if RangeExpression.RegGuidPattern.match(self.__Token) != None: + if gGuidPattern.match(self.__Token) is not None: return True else: self.__UndoToken() @@ -973,32 +976,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 @@ -1453,7 +1437,7 @@ class FdfParser(object): pass for Item in Obj.BlockSizeList: - if Item[0] == None or Item[1] == None: + if Item[0] is None or Item[1] is None: raise Warning("expected block statement for Fd Section", self.FileName, self.CurrentLineNumber) return True @@ -2093,8 +2077,7 @@ class FdfParser(object): if self.__GetNextToken(): - p = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)') - if p.match(self.__Token): + if TokenFindPattern.match(self.__Token): FfsInfObj.KeyStringList.append(self.__Token) if not self.__IsToken(","): return @@ -2103,7 +2086,7 @@ class FdfParser(object): return while self.__GetNextToken(): - if not p.match(self.__Token): + if not TokenFindPattern.match(self.__Token): raise Warning("expected KeyString \"Target_Tag_Arch\" At Line ", self.FileName, self.CurrentLineNumber) FfsInfObj.KeyStringList.append(self.__Token) @@ -2251,12 +2234,11 @@ class FdfParser(object): def __GetFileOpts(self, FfsFileObj): if self.__GetNextToken(): - Pattern = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)') - if Pattern.match(self.__Token): + if TokenFindPattern.match(self.__Token): FfsFileObj.KeyStringList.append(self.__Token) if self.__IsToken(","): while self.__GetNextToken(): - if not Pattern.match(self.__Token): + if not TokenFindPattern.match(self.__Token): raise Warning("expected KeyString \"Target_Tag_Arch\" At Line ", self.FileName, self.CurrentLineNumber) FfsFileObj.KeyStringList.append(self.__Token) @@ -2422,7 +2404,7 @@ class FdfParser(object): FvImageSectionObj = CommonDataClass.FdfClass.FvImageSectionClassObject() FvImageSectionObj.Alignment = AlignValue - if FvObj != None: + if FvObj is not None: FvImageSectionObj.Fv = FvObj FvImageSectionObj.FvName = None else: @@ -2901,12 +2883,11 @@ class FdfParser(object): KeyStringList = [] if self.__GetNextToken(): - Pattern = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)') - if Pattern.match(self.__Token): + if TokenFindPattern.match(self.__Token): KeyStringList.append(self.__Token) if self.__IsToken(","): while self.__GetNextToken(): - if not Pattern.match(self.__Token): + if not TokenFindPattern.match(self.__Token): raise Warning("expected KeyString \"Target_Tag_Arch\" At Line ", self.FileName, self.CurrentLineNumber) KeyStringList.append(self.__Token) @@ -2941,7 +2922,7 @@ class FdfParser(object): Rule.CheckSum = CheckSum Rule.Fixed = Fixed Rule.KeyStringList = KeyStringList - if KeepReloc != None: + if KeepReloc is not None: Rule.KeepReloc = KeepReloc while True: @@ -2968,7 +2949,7 @@ class FdfParser(object): Rule.Fixed = Fixed Rule.FileExtension = Ext Rule.KeyStringList = KeyStringList - if KeepReloc != None: + if KeepReloc is not None: Rule.KeepReloc = KeepReloc return Rule @@ -3011,7 +2992,7 @@ class FdfParser(object): Rule.Fixed = Fixed Rule.FileName = self.__Token Rule.KeyStringList = KeyStringList - if KeepReloc != None: + if KeepReloc is not None: Rule.KeepReloc = KeepReloc return Rule @@ -3148,7 +3129,7 @@ class FdfParser(object): EfiSectionObj.KeepReloc = False else: EfiSectionObj.KeepReloc = True - if Obj.KeepReloc != None and Obj.KeepReloc != EfiSectionObj.KeepReloc: + if Obj.KeepReloc is not None and Obj.KeepReloc != EfiSectionObj.KeepReloc: raise Warning("Section type %s has reloc strip flag conflict with Rule At Line %d" % (EfiSectionObj.SectionType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber) else: raise Warning("Section type %s could not have reloc strip flag At Line %d" % (EfiSectionObj.SectionType, self.CurrentLineNumber), self.FileName, self.CurrentLineNumber) @@ -3456,7 +3437,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 @@ -3470,7 +3451,7 @@ class FdfParser(object): raise Warning("expected Component version At Line ", self.FileName, self.CurrentLineNumber) Pattern = re.compile('-$|[0-9]{0,1}[0-9]{1}\.[0-9]{0,1}[0-9]{1}') - if Pattern.match(self.__Token) == None: + if Pattern.match(self.__Token) is None: raise Warning("Unknown version format At line ", self.FileName, self.CurrentLineNumber) CompStatementObj.CompVer = self.__Token @@ -3543,7 +3524,7 @@ class FdfParser(object): for elementRegion in FdObj.RegionList: if elementRegion.RegionType == 'FV': for elementRegionData in elementRegion.RegionDataList: - if elementRegionData != None and elementRegionData.upper() not in FvList: + if elementRegionData is not None and elementRegionData.upper() not in FvList: FvList.append(elementRegionData.upper()) return FvList @@ -3560,9 +3541,9 @@ class FdfParser(object): for FfsObj in FvObj.FfsList: if isinstance(FfsObj, FfsFileStatement.FileStatement): - if FfsObj.FvName != None and FfsObj.FvName.upper() not in RefFvList: + if FfsObj.FvName is not None and FfsObj.FvName.upper() not in RefFvList: RefFvList.append(FfsObj.FvName.upper()) - elif FfsObj.FdName != None and FfsObj.FdName.upper() not in RefFdList: + elif FfsObj.FdName is not None and FfsObj.FdName.upper() not in RefFdList: RefFdList.append(FfsObj.FdName.upper()) else: self.__GetReferencedFdFvTupleFromSection(FfsObj, RefFdList, RefFvList) @@ -3583,9 +3564,9 @@ class FdfParser(object): while SectionStack != []: SectionObj = SectionStack.pop() if isinstance(SectionObj, FvImageSection.FvImageSection): - if SectionObj.FvName != None and SectionObj.FvName.upper() not in FvList: + if SectionObj.FvName is not None and SectionObj.FvName.upper() not in FvList: FvList.append(SectionObj.FvName.upper()) - if SectionObj.Fv != None and SectionObj.Fv.UiFvName != None and SectionObj.Fv.UiFvName.upper() not in FvList: + if SectionObj.Fv is not None and SectionObj.Fv.UiFvName is not None and SectionObj.Fv.UiFvName.upper() not in FvList: FvList.append(SectionObj.Fv.UiFvName.upper()) self.__GetReferencedFdFvTuple(SectionObj.Fv, FdList, FvList)