]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/FdfParser.py
BaseTools: Refactor python print statements
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FdfParser.py
index 8a9296c49d1d1faeeaf09a4e61284e0206f72415..6b4f724f6d9ca6aec7828a606855874be9a1b004 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
@@ -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
@@ -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