]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/FdfParser.py
BaseTools: Adjust the spaces around commas and colons
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FdfParser.py
index 8a9296c49d1d1faeeaf09a4e61284e0206f72415..74785e0a93fea036809820272a9763467211d8c2 100644 (file)
@@ -16,6 +16,7 @@
 ##\r
 # Import Modules\r
 #\r
+from __future__ import print_function\r
 import re\r
 \r
 import Fd\r
@@ -48,12 +49,12 @@ from GenFdsGlobalVariable import GenFdsGlobalVariable
 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
@@ -914,7 +915,6 @@ class FdfParser:
         return MacroDict\r
 \r
     def __EvaluateConditional(self, Expression, Line, Op = None, Value = None):\r
-        FileLineTuple = GetRealFileLine(self.FileName, Line)\r
         MacroPcdDict = self.__CollectMacroPcd()\r
         if Op == 'eval':\r
             try:\r
@@ -922,7 +922,7 @@ class FdfParser:
                     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
@@ -931,7 +931,7 @@ class FdfParser:
                                 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
@@ -939,12 +939,12 @@ class FdfParser:
                                       " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"\r
                                       " of the DSC file (%s), and it is currently defined in this section:"\r
                                       " %s, line #: %d." % (Excpt.Pcd, GlobalData.gPlatformOtherPcds['DSCFILE'], Info[0], Info[1]),\r
-                                      *FileLineTuple)\r
+                                      self.FileName, Line)\r
                     else:\r
                         raise Warning("PCD (%s) is not defined in DSC file (%s)" % (Excpt.Pcd, GlobalData.gPlatformOtherPcds['DSCFILE']),\r
-                                      *FileLineTuple)\r
+                                      self.FileName, Line)\r
                 else:\r
-                    raise Warning(str(Excpt), *FileLineTuple)\r
+                    raise Warning(str(Excpt), self.FileName, Line)\r
         else:\r
             if Expression.startswith('$(') and Expression[-1] == ')':\r
                 Expression = Expression[2:-1]            \r
@@ -1362,13 +1362,14 @@ class FdfParser:
 \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
@@ -1442,6 +1443,17 @@ class FdfParser:
 \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
@@ -1808,7 +1820,7 @@ class FdfParser:
             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
@@ -2329,7 +2341,7 @@ class FdfParser:
         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
@@ -2337,7 +2349,7 @@ class FdfParser:
         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
@@ -2371,7 +2383,7 @@ class FdfParser:
                 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
@@ -2381,7 +2393,7 @@ class FdfParser:
             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
@@ -2718,7 +2730,7 @@ class FdfParser:
         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
@@ -2777,7 +2789,7 @@ class FdfParser:
             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
@@ -2849,7 +2861,7 @@ class FdfParser:
 \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
@@ -3139,7 +3151,7 @@ class FdfParser:
 \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
@@ -3532,7 +3544,7 @@ class FdfParser:
         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
@@ -3729,7 +3741,7 @@ class FdfParser:
 \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
@@ -3779,7 +3791,7 @@ class FdfParser:
 \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
@@ -3859,7 +3871,7 @@ class FdfParser:
                 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
@@ -3927,7 +3939,7 @@ class FdfParser:
                 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
@@ -4667,7 +4679,7 @@ class FdfParser:
                     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
@@ -4723,7 +4735,7 @@ class FdfParser:
                         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
@@ -4734,7 +4746,7 @@ class FdfParser:
                         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
@@ -4765,16 +4777,16 @@ if __name__ == "__main__":
     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