##\r
# Import Modules\r
#\r
+from __future__ import print_function\r
import re\r
\r
import Fd\r
from Common.BuildToolError import *\r
from Common import EdkLogger\r
from Common.Misc import PathClass\r
-from Common.String import NormPath\r
+from Common.StringUtils import NormPath\r
import Common.GlobalData as GlobalData\r
from Common.Expression import *\r
from Common import GlobalData\r
from Common.DataType import *\r
-from Common.String import ReplaceMacro\r
+from Common.StringUtils import ReplaceMacro\r
import uuid\r
from Common.Misc import tdict\r
from Common.MultipleWorkspace import MultipleWorkspace as mws\r
return ValueExpression(Expression, MacroPcdDict)(True)\r
else:\r
return ValueExpression(Expression, MacroPcdDict)()\r
- except WrnExpression, Excpt:\r
+ except WrnExpression as Excpt:\r
# \r
# Catch expression evaluation warning here. We need to report\r
# the precise number of line and return the evaluation result\r
File=self.FileName, ExtraData=self.__CurrentLine(), \r
Line=Line)\r
return Excpt.result\r
- except Exception, Excpt:\r
+ except Exception as Excpt:\r
if hasattr(Excpt, 'Pcd'):\r
if Excpt.Pcd in GlobalData.gPlatformOtherPcds:\r
Info = GlobalData.gPlatformOtherPcds[Excpt.Pcd]\r
\r
try:\r
self.Preprocess()\r
+ self.__GetError()\r
#\r
# Keep processing sections of the FDF until no new sections or a syntax error is found\r
#\r
while self.__GetFd() or self.__GetFv() or self.__GetFmp() or self.__GetCapsule() or self.__GetVtf() or self.__GetRule() or self.__GetOptionRom():\r
pass\r
\r
- except Warning, X:\r
+ except Warning as X:\r
self.__UndoToken()\r
#'\n\tGot Token: \"%s\" from File %s\n' % (self.__Token, FileLineTuple[0]) + \\r
# At this point, the closest parent would be the included file itself\r
\r
return False\r
\r
+ ##__GetError() method\r
+ def __GetError(self):\r
+ #save the Current information\r
+ CurrentLine = self.CurrentLineNumber\r
+ CurrentOffset = self.CurrentOffsetWithinLine\r
+ while self.__GetNextToken():\r
+ if self.__Token == TAB_ERROR:\r
+ EdkLogger.error('FdfParser', ERROR_STATEMENT, self.__CurrentLine().replace(TAB_ERROR, '', 1), File=self.FileName, Line=self.CurrentLineNumber)\r
+ self.CurrentLineNumber = CurrentLine\r
+ self.CurrentOffsetWithinLine = CurrentOffset\r
+\r
## __GetFd() method\r
#\r
# Get FD section contents and store its data into FD dictionary of self.Profile\r
return long(\r
ValueExpression(Expr,\r
self.__CollectMacroPcd()\r
- )(True),0)\r
+ )(True), 0)\r
except Exception:\r
self.SetFileBufferPos(StartPos)\r
return None\r
if not self.__GetNextHexNumber() and not self.__GetNextDecimalNumber():\r
raise Warning("expected Hex FV extension entry type value At Line ", self.FileName, self.CurrentLineNumber)\r
\r
- FvObj.FvExtEntryTypeValue += [self.__Token]\r
+ FvObj.FvExtEntryTypeValue.append(self.__Token)\r
\r
if not self.__IsToken( "{"):\r
raise Warning("expected '{'", self.FileName, self.CurrentLineNumber)\r
if not self.__IsKeyword ("FILE") and not self.__IsKeyword ("DATA"):\r
raise Warning("expected 'FILE' or 'DATA'", self.FileName, self.CurrentLineNumber)\r
\r
- FvObj.FvExtEntryType += [self.__Token]\r
+ FvObj.FvExtEntryType.append(self.__Token)\r
\r
if self.__Token == 'DATA':\r
\r
raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
\r
DataString = DataString.rstrip(",")\r
- FvObj.FvExtEntryData += [DataString]\r
+ FvObj.FvExtEntryData.append(DataString)\r
\r
if self.__Token == 'FILE':\r
\r
if not self.__GetNextToken():\r
raise Warning("expected FV Extension Entry file path At Line ", self.FileName, self.CurrentLineNumber)\r
\r
- FvObj.FvExtEntryData += [self.__Token]\r
+ FvObj.FvExtEntryData.append(self.__Token)\r
\r
if not self.__IsToken( "}"):\r
raise Warning("expected '}'", self.FileName, self.CurrentLineNumber)\r
while True:\r
AlignValue = None\r
if self.__GetAlignment():\r
- if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",\r
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K", "64K", "128K",\r
"256K", "512K", "1M", "2M", "4M", "8M", "16M"):\r
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
#For FFS, Auto is default option same to ""\r
FfsFileObj.CheckSum = True\r
\r
if self.__GetAlignment():\r
- if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",\r
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K", "64K", "128K",\r
"256K", "512K", "1M", "2M", "4M", "8M", "16M"):\r
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
#For FFS, Auto is default option same to ""\r
\r
AlignValue = None\r
if self.__GetAlignment():\r
- if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",\r
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K", "64K", "128K",\r
"256K", "512K", "1M", "2M", "4M", "8M", "16M"):\r
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
AlignValue = self.__Token\r
\r
AlignValue = None\r
if self.__GetAlignment():\r
- if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",\r
+ if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K", "64K", "128K",\r
"256K", "512K", "1M", "2M", "4M", "8M", "16M"):\r
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
AlignValue = self.__Token\r
AfileName = self.__Token\r
AfileBaseName = os.path.basename(AfileName)\r
\r
- if os.path.splitext(AfileBaseName)[1] not in [".bin",".BIN",".Bin",".dat",".DAT",".Dat",".data",".DATA",".Data"]:\r
+ if os.path.splitext(AfileBaseName)[1] not in [".bin", ".BIN", ".Bin", ".dat", ".DAT", ".Dat", ".data", ".DATA", ".Data"]:\r
raise Warning('invalid binary file type, should be one of "bin",BINARY_FILE_TYPE_BIN,"Bin","dat","DAT","Dat","data","DATA","Data"', \\r
self.FileName, self.CurrentLineNumber)\r
\r
\r
AlignValue = ""\r
if self.__GetAlignment():\r
- if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",\r
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K", "64K", "128K",\r
"256K", "512K", "1M", "2M", "4M", "8M", "16M"):\r
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
#For FFS, Auto is default option same to ""\r
\r
SectAlignment = ""\r
if self.__GetAlignment():\r
- if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",\r
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K", "64K", "128K",\r
"256K", "512K", "1M", "2M", "4M", "8M", "16M"):\r
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
if self.__Token == 'Auto' and (not SectionName == BINARY_FILE_TYPE_PE32) and (not SectionName == BINARY_FILE_TYPE_TE):\r
FvImageSectionObj.FvFileType = self.__Token\r
\r
if self.__GetAlignment():\r
- if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",\r
+ if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K", "64K", "128K",\r
"256K", "512K", "1M", "2M", "4M", "8M", "16M"):\r
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
FvImageSectionObj.Alignment = self.__Token\r
EfiSectionObj.BuildNum = self.__Token\r
\r
if self.__GetAlignment():\r
- if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K",\r
+ if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K", "64K", "128K",\r
"256K", "512K", "1M", "2M", "4M", "8M", "16M"):\r
raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber)\r
if self.__Token == 'Auto' and (not SectionName == BINARY_FILE_TYPE_PE32) and (not SectionName == BINARY_FILE_TYPE_TE):\r
FvInFdList = self.__GetFvInFd(RefFdName)\r
if FvInFdList != []:\r
for FvNameInFd in FvInFdList:\r
- LogStr += "FD %s contains FV %s\n" % (RefFdName,FvNameInFd)\r
+ LogStr += "FD %s contains FV %s\n" % (RefFdName, FvNameInFd)\r
if FvNameInFd not in RefFvStack:\r
RefFvStack.append(FvNameInFd)\r
\r
CapInFdList = self.__GetCapInFd(RefFdName)\r
if CapInFdList != []:\r
for CapNameInFd in CapInFdList:\r
- LogStr += "FD %s contains Capsule %s\n" % (RefFdName,CapNameInFd)\r
+ LogStr += "FD %s contains Capsule %s\n" % (RefFdName, CapNameInFd)\r
if CapNameInFd not in RefCapStack:\r
RefCapStack.append(CapNameInFd)\r
\r
FvInFdList = self.__GetFvInFd(RefFdName)\r
if FvInFdList != []:\r
for FvNameInFd in FvInFdList:\r
- LogStr += "FD %s contains FV %s\n" % (RefFdName,FvNameInFd)\r
+ LogStr += "FD %s contains FV %s\n" % (RefFdName, FvNameInFd)\r
if FvNameInFd not in RefFvList:\r
RefFvList.append(FvNameInFd)\r
\r
import sys\r
try:\r
test_file = sys.argv[1]\r
- except IndexError, v:\r
- print "Usage: %s filename" % sys.argv[0]\r
+ except IndexError as v:\r
+ print("Usage: %s filename" % sys.argv[0])\r
sys.exit(1)\r
\r
parser = FdfParser(test_file)\r
try:\r
parser.ParseFile()\r
parser.CycleReferenceCheck()\r
- except Warning, X:\r
- print str(X)\r
+ except Warning as X:\r
+ print(str(X))\r
else:\r
- print "Success!"\r
+ print("Success!")\r
\r