X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FGenFds%2FFdfParser.py;h=6b4f724f6d9ca6aec7828a606855874be9a1b004;hp=8a9296c49d1d1faeeaf09a4e61284e0206f72415;hb=72443dd25014a8b6209895640af36dec33da51e0;hpb=053cd183c9f25929f056239a173e0106b2322d17 diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py index 8a9296c49d..6b4f724f6d 100644 --- a/BaseTools/Source/Python/GenFds/FdfParser.py +++ b/BaseTools/Source/Python/GenFds/FdfParser.py @@ -16,6 +16,7 @@ ## # Import Modules # +from __future__ import print_function import re import Fd @@ -48,12 +49,12 @@ from GenFdsGlobalVariable import GenFdsGlobalVariable from Common.BuildToolError import * from Common import EdkLogger from Common.Misc import PathClass -from Common.String import NormPath +from Common.StringUtils import NormPath import Common.GlobalData as GlobalData from Common.Expression import * from Common import GlobalData from Common.DataType import * -from Common.String import ReplaceMacro +from Common.StringUtils import ReplaceMacro import uuid from Common.Misc import tdict from Common.MultipleWorkspace import MultipleWorkspace as mws @@ -914,7 +915,6 @@ class FdfParser: return MacroDict def __EvaluateConditional(self, Expression, Line, Op = None, Value = None): - FileLineTuple = GetRealFileLine(self.FileName, Line) MacroPcdDict = self.__CollectMacroPcd() if Op == 'eval': try: @@ -922,7 +922,7 @@ class FdfParser: return ValueExpression(Expression, MacroPcdDict)(True) else: return ValueExpression(Expression, MacroPcdDict)() - except WrnExpression, Excpt: + except WrnExpression as Excpt: # # Catch expression evaluation warning here. We need to report # the precise number of line and return the evaluation result @@ -931,7 +931,7 @@ class FdfParser: File=self.FileName, ExtraData=self.__CurrentLine(), Line=Line) return Excpt.result - except Exception, Excpt: + except Exception as Excpt: if hasattr(Excpt, 'Pcd'): if Excpt.Pcd in GlobalData.gPlatformOtherPcds: Info = GlobalData.gPlatformOtherPcds[Excpt.Pcd] @@ -939,12 +939,12 @@ class FdfParser: " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section" " of the DSC file (%s), and it is currently defined in this section:" " %s, line #: %d." % (Excpt.Pcd, GlobalData.gPlatformOtherPcds['DSCFILE'], Info[0], Info[1]), - *FileLineTuple) + self.FileName, Line) else: raise Warning("PCD (%s) is not defined in DSC file (%s)" % (Excpt.Pcd, GlobalData.gPlatformOtherPcds['DSCFILE']), - *FileLineTuple) + self.FileName, Line) else: - raise Warning(str(Excpt), *FileLineTuple) + raise Warning(str(Excpt), self.FileName, Line) else: if Expression.startswith('$(') and Expression[-1] == ')': Expression = Expression[2:-1] @@ -1362,13 +1362,14 @@ class FdfParser: try: self.Preprocess() + self.__GetError() # # Keep processing sections of the FDF until no new sections or a syntax error is found # while self.__GetFd() or self.__GetFv() or self.__GetFmp() or self.__GetCapsule() or self.__GetVtf() or self.__GetRule() or self.__GetOptionRom(): pass - except Warning, X: + except Warning as X: self.__UndoToken() #'\n\tGot Token: \"%s\" from File %s\n' % (self.__Token, FileLineTuple[0]) + \ # At this point, the closest parent would be the included file itself @@ -1442,6 +1443,17 @@ class FdfParser: return False + ##__GetError() method + def __GetError(self): + #save the Current information + CurrentLine = self.CurrentLineNumber + CurrentOffset = self.CurrentOffsetWithinLine + while self.__GetNextToken(): + if self.__Token == TAB_ERROR: + EdkLogger.error('FdfParser', ERROR_STATEMENT, self.__CurrentLine().replace(TAB_ERROR, '', 1), File=self.FileName, Line=self.CurrentLineNumber) + self.CurrentLineNumber = CurrentLine + self.CurrentOffsetWithinLine = CurrentOffset + ## __GetFd() method # # Get FD section contents and store its data into FD dictionary of self.Profile @@ -2329,7 +2341,7 @@ class FdfParser: if not self.__GetNextHexNumber() and not self.__GetNextDecimalNumber(): raise Warning("expected Hex FV extension entry type value At Line ", self.FileName, self.CurrentLineNumber) - FvObj.FvExtEntryTypeValue += [self.__Token] + FvObj.FvExtEntryTypeValue.append(self.__Token) if not self.__IsToken( "{"): raise Warning("expected '{'", self.FileName, self.CurrentLineNumber) @@ -2337,7 +2349,7 @@ class FdfParser: if not self.__IsKeyword ("FILE") and not self.__IsKeyword ("DATA"): raise Warning("expected 'FILE' or 'DATA'", self.FileName, self.CurrentLineNumber) - FvObj.FvExtEntryType += [self.__Token] + FvObj.FvExtEntryType.append(self.__Token) if self.__Token == 'DATA': @@ -2371,7 +2383,7 @@ class FdfParser: raise Warning("expected '}'", self.FileName, self.CurrentLineNumber) DataString = DataString.rstrip(",") - FvObj.FvExtEntryData += [DataString] + FvObj.FvExtEntryData.append(DataString) if self.__Token == 'FILE': @@ -2381,7 +2393,7 @@ class FdfParser: if not self.__GetNextToken(): raise Warning("expected FV Extension Entry file path At Line ", self.FileName, self.CurrentLineNumber) - FvObj.FvExtEntryData += [self.__Token] + FvObj.FvExtEntryData.append(self.__Token) if not self.__IsToken( "}"): raise Warning("expected '}'", self.FileName, self.CurrentLineNumber) @@ -4765,16 +4777,16 @@ if __name__ == "__main__": import sys try: test_file = sys.argv[1] - except IndexError, v: - print "Usage: %s filename" % sys.argv[0] + except IndexError as v: + print("Usage: %s filename" % sys.argv[0]) sys.exit(1) parser = FdfParser(test_file) try: parser.ParseFile() parser.CycleReferenceCheck() - except Warning, X: - print str(X) + except Warning as X: + print(str(X)) else: - print "Success!" + print("Success!")