##\r
# Import Modules\r
#\r
+from __future__ import print_function\r
import Common.LongFilePathOs as os\r
import re\r
import time\r
#\r
# First judge whether this DEFINE is in conditional directive statements or not.\r
#\r
- if type(self) == DscParser and self._InDirective > -1:\r
+ if isinstance(self, DscParser) and self._InDirective > -1:\r
pass\r
else:\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
self._ConstructSectionMacroDict(Name, Value)\r
\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
# 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
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
for Item in GetSplitValueList(self._CurrentLine[1:-1], TAB_COMMA_SPLIT):\r
if Item == '':\r
continue\r
- ItemList = GetSplitValueList(Item, TAB_SPLIT,3)\r
+ ItemList = GetSplitValueList(Item, TAB_SPLIT, 3)\r
# different section should not mix in one section\r
if self._SectionName != '' and self._SectionName != ItemList[0].upper():\r
EdkLogger.error('Parser', FORMAT_INVALID, "Different section names in the same section",\r
EdkLogger.error('Parser', FORMAT_INVALID, "Invalid version number",\r
ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\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
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
\r
## Construct section Macro dict \r
def _ConstructSectionMacroDict(self, Name, Value):\r
- ScopeKey = [(Scope[0], Scope[1],Scope[2]) for Scope in self._Scope]\r
+ ScopeKey = [(Scope[0], Scope[1], Scope[2]) for Scope in self._Scope]\r
ScopeKey = tuple(ScopeKey)\r
#\r
# DecParser SectionType is a list, will contain more than one item only in Pcd Section\r
# As Pcd section macro usage is not alllowed, so here it is safe\r
#\r
- if type(self) == DecParser:\r
+ if isinstance(self, DecParser):\r
SectionDictKey = self._SectionType[0], ScopeKey\r
else:\r
SectionDictKey = self._SectionType, ScopeKey\r
SpeSpeMacroDict = {}\r
\r
ActiveSectionType = self._SectionType\r
- if type(self) == DecParser:\r
+ if isinstance(self, DecParser):\r
ActiveSectionType = self._SectionType[0]\r
\r
for (SectionType, Scope) in self._SectionsMacroDict:\r
continue\r
\r
for ActiveScope in self._Scope:\r
- Scope0, Scope1 ,Scope2= ActiveScope[0], ActiveScope[1],ActiveScope[2]\r
- if(Scope0, Scope1,Scope2) not in Scope:\r
+ Scope0, Scope1, Scope2= ActiveScope[0], ActiveScope[1], ActiveScope[2]\r
+ if(Scope0, Scope1, Scope2) not in Scope:\r
break\r
else:\r
SpeSpeMacroDict.update(self._SectionsMacroDict[(SectionType, Scope)])\r
\r
for ActiveScope in self._Scope:\r
- Scope0, Scope1,Scope2 = ActiveScope[0], ActiveScope[1],ActiveScope[2]\r
- if(Scope0, Scope1,Scope2) not in Scope and (Scope0, TAB_COMMON, TAB_COMMON) not in Scope and (TAB_COMMON, Scope1, TAB_COMMON) not in Scope:\r
+ Scope0, Scope1, Scope2 = ActiveScope[0], ActiveScope[1], ActiveScope[2]\r
+ if(Scope0, Scope1, Scope2) not in Scope and (Scope0, TAB_COMMON, TAB_COMMON) not in Scope and (TAB_COMMON, Scope1, TAB_COMMON) not in Scope:\r
break\r
else:\r
ComSpeMacroDict.update(self._SectionsMacroDict[(SectionType, Scope)])\r
# Model, Value1, Value2, Value3, Arch, Platform, BelongsToItem=-1,\r
# LineBegin=-1, ColumnBegin=-1, LineEnd=-1, ColumnEnd=-1, Enabled=-1\r
#\r
- for Arch, Platform,_ in self._Scope:\r
+ for Arch, Platform, _ in self._Scope:\r
LastItem = self._Store(self._SectionType,\r
self._ValueList[0],\r
self._ValueList[1],\r
self._DirectiveParser()\r
continue\r
if Line[0] == TAB_OPTION_START and not self._InSubsection:\r
- EdkLogger.error("Parser", FILE_READ_FAILURE, "Missing the '{' before %s in Line %s" % (Line, Index+1),ExtraData=self.MetaFile)\r
+ EdkLogger.error("Parser", FILE_READ_FAILURE, "Missing the '{' before %s in Line %s" % (Line, Index+1), ExtraData=self.MetaFile)\r
\r
if self._InSubsection:\r
SectionType = self._SubsectionType\r
@ParseMacro\r
def _SkuIdParser(self):\r
TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT)\r
- if len(TokenList) not in (2,3):\r
+ if len(TokenList) not in (2, 3):\r
EdkLogger.error('Parser', FORMAT_INVALID, "Correct format is '<Number>|<UiName>[|<UiName>]'",\r
ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r
self._ValueList[0:len(TokenList)] = TokenList\r
\r
# Validate the datum type of Dynamic Defaul PCD and DynamicEx Default PCD\r
ValueList = GetSplitValueList(self._ValueList[2])\r
- if len(ValueList) > 1 and ValueList[1] in [TAB_UINT8 , TAB_UINT16, TAB_UINT32 , TAB_UINT64] \\r
+ if len(ValueList) > 1 and ValueList[1] in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64] \\r
and self._ItemType in [MODEL_PCD_DYNAMIC_DEFAULT, MODEL_PCD_DYNAMIC_EX_DEFAULT]:\r
EdkLogger.error('Parser', FORMAT_INVALID, "The datum type '%s' of PCD is wrong" % ValueList[1],\r
ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r
# Validate the VariableName of DynamicHii and DynamicExHii for PCD Entry must not be an empty string\r
if self._ItemType in [MODEL_PCD_DYNAMIC_HII, MODEL_PCD_DYNAMIC_EX_HII]:\r
DscPcdValueList = GetSplitValueList(TokenList[1], TAB_VALUE_SPLIT, 1)\r
- if len(DscPcdValueList[0].replace('L','').replace('"','').strip()) == 0:\r
+ if len(DscPcdValueList[0].replace('L', '').replace('"', '').strip()) == 0:\r
EdkLogger.error('Parser', FORMAT_INVALID, "The VariableName field in the HII format PCD entry must not be an empty string",\r
ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r
\r
Macros.update(self._Symbols)\r
if GlobalData.BuildOptionPcd:\r
for Item in GlobalData.BuildOptionPcd:\r
- if type(Item) is tuple:\r
+ if isinstance(Item, tuple):\r
continue\r
PcdName, TmpValue = Item.split("=")\r
TmpValue = BuildOptionValue(TmpValue, self._GuidDict)\r
self._ContentIndex = 0\r
self._InSubsection = False\r
while self._ContentIndex < len(self._Content) :\r
- Id, self._ItemType, V1, V2, V3, S1, S2, S3,Owner, self._From, \\r
+ Id, self._ItemType, V1, V2, V3, S1, S2, S3, Owner, self._From, \\r
LineStart, ColStart, LineEnd, ColEnd, Enabled = self._Content[self._ContentIndex]\r
\r
if self._From < 0:\r
break\r
Record = self._Content[self._ContentIndex]\r
if LineStart == Record[10] and LineEnd == Record[12]:\r
- if [Record[5], Record[6],Record[7]] not in self._Scope:\r
- self._Scope.append([Record[5], Record[6],Record[7]])\r
+ if [Record[5], Record[6], Record[7]] not in self._Scope:\r
+ self._Scope.append([Record[5], Record[6], Record[7]])\r
self._ContentIndex += 1\r
else:\r
break\r
self._InSubsection = False\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
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
MODEL_PCD_DYNAMIC_VPD, MODEL_PCD_DYNAMIC_EX_DEFAULT, MODEL_PCD_DYNAMIC_EX_HII,\r
MODEL_PCD_DYNAMIC_EX_VPD):\r
Records = self._RawTable.Query(PcdType, BelongsToItem= -1.0)\r
- for TokenSpaceGuid, PcdName, Value, Dummy2, Dummy3, Dummy4,ID, Line in Records:\r
+ for TokenSpaceGuid, PcdName, Value, Dummy2, Dummy3, Dummy4, ID, Line in Records:\r
Name = TokenSpaceGuid + '.' + PcdName\r
if Name not in GlobalData.gPlatformOtherPcds:\r
PcdLine = Line\r
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
if PcdValue and "." not in self._ValueList[0]:\r
try:\r
ValList[Index] = ValueExpression(PcdValue, self._Macros)(True)\r
- except WrnExpression, Value:\r
+ except WrnExpression as Value:\r
ValList[Index] = Value.result\r
except:\r
pass\r
try:\r
self._ValueList[2] = '|'.join(ValList)\r
except Exception:\r
- print ValList\r
+ print(ValList)\r
\r
def __ProcessComponent(self):\r
self._ValueList[0] = ReplaceMacro(self._ValueList[0], self._Macros)\r
if self._DefinesCount > 1:\r
EdkLogger.error('Parser', FORMAT_INVALID, 'Multiple [Defines] section is exist.', self.MetaFile )\r
if self._DefinesCount == 0:\r
- EdkLogger.error('Parser', FORMAT_INVALID, 'No [Defines] section exist.',self.MetaFile)\r
+ EdkLogger.error('Parser', FORMAT_INVALID, 'No [Defines] section exist.', self.MetaFile)\r
self._Done()\r
\r
\r
self._CurrentStructurePcdName = ""\r
else:\r
if self._CurrentStructurePcdName != TAB_SPLIT.join(PcdNames[:2]):\r
- EdkLogger.error('Parser', FORMAT_INVALID, "Pcd Name does not match: %s and %s " % (self._CurrentStructurePcdName , TAB_SPLIT.join(PcdNames[:2])),\r
+ EdkLogger.error('Parser', FORMAT_INVALID, "Pcd Name does not match: %s and %s " % (self._CurrentStructurePcdName, TAB_SPLIT.join(PcdNames[:2])),\r
File=self.MetaFile, Line=self._LineIndex + 1)\r
self._ValueList[1] = TAB_SPLIT.join(PcdNames[2:])\r
self._ValueList[2] = PcdTockens[1]\r
try:\r
self._GuidDict.update(self._AllPcdDict)\r
ValueList[0] = ValueExpressionEx(ValueList[0], ValueList[1], self._GuidDict)(True)\r
- except BadExpression, Value:\r
+ except BadExpression as Value:\r
EdkLogger.error('Parser', FORMAT_INVALID, Value, ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r
# check format of default value against the datum type\r
IsValid, Cause = CheckPcdDatum(ValueList[1], ValueList[0])\r