]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaFileParser.py
BaseTools: Fix old python2 idioms
[mirror_edk2.git] / BaseTools / Source / Python / Ecc / MetaFileWorkspace / MetaFileParser.py
index 237cf5acfea13ad0210cf3edda189e1b8d2fbe9f..a41223f285fffcd39d0f1d4e9125a787ca24abcf 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file is used to parse meta files\r
 #\r
-# Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
@@ -26,7 +26,7 @@ import EccToolError
 \r
 from CommonDataClass.DataClass import *\r
 from Common.DataType import *\r
-from Common.String import *\r
+from Common.StringUtils import *\r
 from Common.Misc import GuidStructureStringToGuidString, CheckPcdDatum, PathClass, AnalyzePcdData\r
 from Common.Expression import *\r
 from CommonDataClass.Exceptions import *\r
@@ -68,7 +68,7 @@ def ParseMacro(Parser):
         self._ItemType = MODEL_META_DATA_DEFINE\r
         # DEFINE defined macros\r
         if Type == TAB_DSC_DEFINES_DEFINE:\r
-            if type(self) == DecParser:\r
+            if isinstance(self, DecParser):\r
                 if MODEL_META_DATA_HEADER in self._SectionType:\r
                     self._FileLocalMacros[Name] = Value\r
                 else:\r
@@ -83,7 +83,7 @@ def ParseMacro(Parser):
                 SectionLocalMacros = self._SectionsMacroDict[SectionDictKey]\r
                 SectionLocalMacros[Name] = Value\r
         # EDK_GLOBAL defined macros\r
-        elif type(self) != DscParser:\r
+        elif not isinstance(self, DscParser):\r
             EdkLogger.error('Parser', FORMAT_INVALID, "EDK_GLOBAL can only be used in .dsc file",\r
                             ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)\r
         elif self._SectionType != MODEL_META_DATA_HEADER:\r
@@ -215,7 +215,7 @@ class MetaFileParser(object):
     #   DataInfo = [data_type, scope1(arch), scope2(platform/moduletype)]\r
     #\r
     def __getitem__(self, DataInfo):\r
-        if type(DataInfo) != type(()):\r
+        if not isinstance(DataInfo, type(())):\r
             DataInfo = (DataInfo,)\r
 \r
         # Parse the file first, if necessary\r
@@ -257,7 +257,7 @@ class MetaFileParser(object):
         TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT)\r
         self._ValueList[0:len(TokenList)] = TokenList\r
         # Don't do macro replacement for dsc file at this point\r
-        if type(self) != DscParser:\r
+        if not isinstance(self, DscParser):\r
             Macros = self._Macros\r
             self._ValueList = [ReplaceMacro(Value, Macros) for Value in self._ValueList]\r
 \r
@@ -355,7 +355,7 @@ class MetaFileParser(object):
             if os.path.exists(UniFile):\r
                 self._UniObj = UniParser(UniFile, IsExtraUni=False, IsModuleUni=False)\r
         \r
-        if type(self) == InfParser and self._Version < 0x00010005:\r
+        if isinstance(self, InfParser) and self._Version < 0x00010005:\r
             # EDK module allows using defines as macros\r
             self._FileLocalMacros[Name] = Value\r
         self._Defines[Name] = Value\r
@@ -370,7 +370,7 @@ class MetaFileParser(object):
             self._ValueList[1] = TokenList2[1]              # keys\r
         else:\r
             self._ValueList[1] = TokenList[0]\r
-        if len(TokenList) == 2 and type(self) != DscParser: # value\r
+        if len(TokenList) == 2 and not isinstance(self, DscParser): # value\r
             self._ValueList[2] = ReplaceMacro(TokenList[1], self._Macros)\r
 \r
         if self._ValueList[1].count('_') != 4:\r
@@ -561,7 +561,7 @@ class InfParser(MetaFileParser):
                     NmakeLine = ''\r
 \r
             # section content\r
-            self._ValueList = ['','','']\r
+            self._ValueList = ['', '', '']\r
             # parse current line, result will be put in self._ValueList\r
             self._SectionParser[self._SectionType](self)\r
             if self._ValueList is None or self._ItemType == MODEL_META_DATA_DEFINE:\r
@@ -920,7 +920,7 @@ class DscParser(MetaFileParser):
 \r
     ## Directive statement parser\r
     def _DirectiveParser(self):\r
-        self._ValueList = ['','','']\r
+        self._ValueList = ['', '', '']\r
         TokenList = GetSplitValueList(self._CurrentLine, ' ', 1)\r
         self._ValueList[0:len(TokenList)] = TokenList\r
 \r
@@ -1110,7 +1110,7 @@ class DscParser(MetaFileParser):
 \r
     ## Override parent's method since we'll do all macro replacements in parser\r
     def _GetMacros(self):\r
-        Macros = dict( [('ARCH','IA32'), ('FAMILY','MSFT'),('TOOL_CHAIN_TAG','VS2008x86'),('TARGET','DEBUG')])\r
+        Macros = dict( [('ARCH', 'IA32'), ('FAMILY', 'MSFT'), ('TOOL_CHAIN_TAG', 'VS2008x86'), ('TARGET', 'DEBUG')])\r
         Macros.update(self._FileLocalMacros)\r
         Macros.update(self._GetApplicableSectionMacro())\r
         Macros.update(GlobalData.gEdkGlobal)\r
@@ -1183,7 +1183,7 @@ class DscParser(MetaFileParser):
 \r
             try:\r
                 Processer[self._ItemType]()\r
-            except EvaluationException, Excpt:\r
+            except EvaluationException as Excpt:\r
                 # \r
                 # Only catch expression evaluation error here. We need to report\r
                 # the precise number of line on which the error occurred\r
@@ -1192,7 +1192,7 @@ class DscParser(MetaFileParser):
 #                 EdkLogger.error('Parser', FORMAT_INVALID, "Invalid expression: %s" % str(Excpt),\r
 #                                 File=self._FileWithError, ExtraData=' '.join(self._ValueList),\r
 #                                 Line=self._LineIndex+1)\r
-            except MacroException, Excpt:\r
+            except MacroException as Excpt:\r
                 EdkLogger.error('Parser', FORMAT_INVALID, str(Excpt),\r
                                 File=self._FileWithError, ExtraData=' '.join(self._ValueList), \r
                                 Line=self._LineIndex+1)\r
@@ -1225,7 +1225,7 @@ class DscParser(MetaFileParser):
         self._RawTable.Drop()\r
         self._Table.Drop()\r
         for Record in RecordList:\r
-            EccGlobalData.gDb.TblDsc.Insert(Record[1],Record[2],Record[3],Record[4],Record[5],Record[6],Record[7],Record[8],Record[9],Record[10],Record[11],Record[12],Record[13],Record[14])\r
+            EccGlobalData.gDb.TblDsc.Insert(Record[1], Record[2], Record[3], Record[4], Record[5], Record[6], Record[7], Record[8], Record[9], Record[10], Record[11], Record[12], Record[13], Record[14])\r
         GlobalData.gPlatformDefines.update(self._FileLocalMacros)\r
         self._PostProcessed = True\r
         self._Content = None\r
@@ -1246,7 +1246,7 @@ class DscParser(MetaFileParser):
 \r
     def __RetrievePcdValue(self):\r
         Records = self._RawTable.Query(MODEL_PCD_FEATURE_FLAG, BelongsToItem=-1.0)\r
-        for TokenSpaceGuid,PcdName,Value,Dummy2,Dummy3,ID,Line in Records:\r
+        for TokenSpaceGuid, PcdName, Value, Dummy2, Dummy3, ID, Line in Records:\r
             Value, DatumType, MaxDatumSize = AnalyzePcdData(Value)\r
             # Only use PCD whose value is straitforward (no macro and PCD)\r
             if self.SymbolPattern.findall(Value):\r
@@ -1259,7 +1259,7 @@ class DscParser(MetaFileParser):
             self._Symbols[Name] = Value\r
 \r
         Records = self._RawTable.Query(MODEL_PCD_FIXED_AT_BUILD, BelongsToItem=-1.0)\r
-        for TokenSpaceGuid,PcdName,Value,Dummy2,Dummy3,ID,Line in Records:\r
+        for TokenSpaceGuid, PcdName, Value, Dummy2, Dummy3, ID, Line in Records:\r
             Value, DatumType, MaxDatumSize = AnalyzePcdData(Value)\r
             # Only use PCD whose value is straitforward (no macro and PCD)\r
             if self.SymbolPattern.findall(Value):\r
@@ -1305,10 +1305,10 @@ class DscParser(MetaFileParser):
             Macros.update(GlobalData.gGlobalDefines)\r
             try:\r
                 Result = ValueExpression(self._ValueList[1], Macros)()\r
-            except SymbolNotFound, Exc:\r
+            except SymbolNotFound as Exc:\r
                 EdkLogger.debug(EdkLogger.DEBUG_5, str(Exc), self._ValueList[1])\r
                 Result = False\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
@@ -1317,7 +1317,7 @@ class DscParser(MetaFileParser):
                                 File=self._FileWithError, ExtraData=' '.join(self._ValueList), \r
                                 Line=self._LineIndex+1)\r
                 Result = Excpt.result\r
-            except BadExpression, Exc:\r
+            except BadExpression as Exc:\r
                 EdkLogger.debug(EdkLogger.DEBUG_5, str(Exc), self._ValueList[1])\r
                 Result = False\r
 \r
@@ -1433,17 +1433,17 @@ class DscParser(MetaFileParser):
         #\r
         # PCD value can be an expression\r
         #\r
-        if len(ValueList) > 1 and ValueList[1] == 'VOID*':\r
+        if len(ValueList) > 1 and ValueList[1] == TAB_VOID:\r
             PcdValue = ValueList[0]      \r
             try:\r
                 ValueList[0] = ValueExpression(PcdValue, self._Macros)(True)\r
-            except WrnExpression, Value:\r
+            except WrnExpression as Value:\r
                 ValueList[0] = Value.result          \r
         else:\r
             PcdValue = ValueList[-1]\r
             try:\r
                 ValueList[-1] = ValueExpression(PcdValue, self._Macros)(True)\r
-            except WrnExpression, Value:\r
+            except WrnExpression as Value:\r
                 ValueList[-1] = Value.result\r
             \r
             if ValueList[-1] == 'True':\r
@@ -1571,7 +1571,7 @@ class DecParser(MetaFileParser):
                 continue\r
 \r
             # section content\r
-            self._ValueList = ['','','']\r
+            self._ValueList = ['', '', '']\r
             self._SectionParser[self._SectionType[0]](self)\r
             if self._ValueList is None or self._ItemType == MODEL_META_DATA_DEFINE:\r
                 self._ItemType = -1\r
@@ -1717,7 +1717,7 @@ class DecParser(MetaFileParser):
                         GuidValue = GuidValue.lstrip(' {')\r
                         HexList.append('0x' + str(GuidValue[2:]))\r
                         Index += 1\r
-            self._ValueList[1] = "{ %s, %s, %s, { %s, %s, %s, %s, %s, %s, %s, %s }}" % (HexList[0], HexList[1], HexList[2],HexList[3],HexList[4],HexList[5],HexList[6],HexList[7],HexList[8],HexList[9],HexList[10])\r
+            self._ValueList[1] = "{ %s, %s, %s, { %s, %s, %s, %s, %s, %s, %s, %s }}" % (HexList[0], HexList[1], HexList[2], HexList[3], HexList[4], HexList[5], HexList[6], HexList[7], HexList[8], HexList[9], HexList[10])\r
         else:\r
             EdkLogger.error('Parser', FORMAT_INVALID, "Invalid GUID value format",\r
                             ExtraData=self._CurrentLine + \\r