]> 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 9f31d4d4de07a7386c2e35c5445467562c621241..a41223f285fffcd39d0f1d4e9125a787ca24abcf 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file is used to parse meta files\r
 #\r
-# Copyright (c) 2008 - 2014, 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
@@ -22,10 +22,11 @@ import copy
 import Common.EdkLogger as EdkLogger\r
 import Common.GlobalData as GlobalData\r
 import EccGlobalData\r
+import EccToolError\r
 \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
@@ -33,6 +34,7 @@ from CommonDataClass.Exceptions import *
 from MetaFileTable import MetaFileStorage\r
 from GenFds.FdfParser import FdfParser\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
+from Common.LongFilePathSupport import CodecOpenLongFilePath\r
 \r
 ## A decorator used to parse macro definition\r
 def ParseMacro(Parser):\r
@@ -66,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
@@ -81,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
@@ -174,6 +176,9 @@ class MetaFileParser(object):
         self._PostProcessed = False\r
         # Different version of meta-file has different way to parse.\r
         self._Version = 0\r
+        # UNI object and extra UNI object\r
+        self._UniObj = None\r
+        self._UniExtraObj = None\r
 \r
     ## Store the parsed data in table\r
     def _Store(self, *Args):\r
@@ -210,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
@@ -223,7 +228,7 @@ class MetaFileParser(object):
                 self.Start()\r
 \r
         # No specific ARCH or Platform given, use raw data\r
-        if self._RawTable and (len(DataInfo) == 1 or DataInfo[1] == None):\r
+        if self._RawTable and (len(DataInfo) == 1 or DataInfo[1] is None):\r
             return self._RawTable.Query(*DataInfo)\r
 \r
         # Do post-process if necessary\r
@@ -252,14 +257,22 @@ 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
     ## Skip unsupported data\r
     def _Skip(self):\r
-        EdkLogger.warn("Parser", "Unrecognized content", File=self.MetaFile,\r
-                        Line=self._LineIndex+1, ExtraData=self._CurrentLine);\r
+        if self._SectionName == TAB_USER_EXTENSIONS.upper() and self._CurrentLine.upper().endswith('.UNI'):\r
+            if EccGlobalData.gConfig.UniCheckHelpInfo == '1' or EccGlobalData.gConfig.UniCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+                ExtraUni = self._CurrentLine.strip()\r
+                ExtraUniFile = os.path.join(os.path.dirname(self.MetaFile), ExtraUni)\r
+                IsModuleUni = self.MetaFile.upper().endswith('.INF')\r
+                self._UniExtraObj = UniParser(ExtraUniFile, IsExtraUni=True, IsModuleUni=IsModuleUni)\r
+                self._UniExtraObj.Start()\r
+        else:\r
+            EdkLogger.warn("Parser", "Unrecognized content", File=self.MetaFile,\r
+                            Line=self._LineIndex + 1, ExtraData=self._CurrentLine);\r
         self._ValueList[0:1] = [self._CurrentLine]\r
 \r
     ## Section header parser\r
@@ -328,8 +341,21 @@ class MetaFileParser(object):
             except:\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
+        elif Name == 'MODULE_UNI_FILE':\r
+            UniFile = os.path.join(os.path.dirname(self.MetaFile), Value)\r
+            if os.path.exists(UniFile):\r
+                self._UniObj = UniParser(UniFile, IsExtraUni=False, IsModuleUni=True)\r
+                self._UniObj.Start()\r
+            else:\r
+                EdkLogger.error('Parser', FILE_NOT_FOUND, "Module UNI file %s is missing." % Value,\r
+                                ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1,\r
+                                RaiseError=False)\r
+        elif Name == 'PACKAGE_UNI_FILE':\r
+            UniFile = os.path.join(os.path.dirname(self.MetaFile), Value)\r
+            if os.path.exists(UniFile):\r
+                self._UniObj = UniParser(UniFile, IsExtraUni=False, IsModuleUni=False)\r
+        \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
@@ -344,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
@@ -535,10 +561,10 @@ 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 == None or self._ItemType == MODEL_META_DATA_DEFINE:\r
+            if self._ValueList is None or self._ItemType == MODEL_META_DATA_DEFINE:\r
                 self._ItemType = -1\r
                 continue\r
             #\r
@@ -757,6 +783,10 @@ class DscParser(MetaFileParser):
         "FIX_LOAD_TOP_MEMORY_ADDRESS"\r
     ]\r
 \r
+    SubSectionDefineKeywords = [\r
+        "FILE_GUID"\r
+    ]\r
+\r
     SymbolPattern = ValueExpression.SymbolPattern\r
 \r
     ## Constructor of DscParser\r
@@ -847,7 +877,7 @@ class DscParser(MetaFileParser):
 \r
             self._ValueList = ['', '', '']\r
             self._SectionParser[SectionType](self)\r
-            if self._ValueList == None:\r
+            if self._ValueList is None:\r
                 continue\r
             #\r
             # Model, Value1, Value2, Value3, Arch, ModuleType, BelongsToItem=-1, BelongsToFile=-1,\r
@@ -890,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
@@ -967,7 +997,8 @@ class DscParser(MetaFileParser):
         if not self._ValueList[2]:\r
             EdkLogger.error('Parser', FORMAT_INVALID, "No value specified",\r
                             ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)\r
-        if not self._ValueList[1] in self.DefineKeywords:\r
+        if (not self._ValueList[1] in self.DefineKeywords and\r
+            (self._InSubsection and self._ValueList[1] not in self.SubSectionDefineKeywords)):\r
             EdkLogger.error('Parser', FORMAT_INVALID,\r
                             "Unknown keyword found: %s. "\r
                             "If this is a macro you must "\r
@@ -1079,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
@@ -1152,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
@@ -1161,12 +1192,12 @@ 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
 \r
-            if self._ValueList == None:\r
+            if self._ValueList is None:\r
                 continue \r
 \r
             NewOwner = self._IdMapping.get(Owner, -1)\r
@@ -1194,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
@@ -1215,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
@@ -1228,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
@@ -1274,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
@@ -1286,6 +1317,9 @@ class DscParser(MetaFileParser):
                                 File=self._FileWithError, ExtraData=' '.join(self._ValueList), \r
                                 Line=self._LineIndex+1)\r
                 Result = Excpt.result\r
+            except BadExpression as Exc:\r
+                EdkLogger.debug(EdkLogger.DEBUG_5, str(Exc), self._ValueList[1])\r
+                Result = False\r
 \r
         if self._ItemType in [MODEL_META_DATA_CONDITIONAL_STATEMENT_IF,\r
                               MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF,\r
@@ -1399,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
@@ -1537,9 +1571,9 @@ 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 == None or self._ItemType == MODEL_META_DATA_DEFINE:\r
+            if self._ValueList is None or self._ItemType == MODEL_META_DATA_DEFINE:\r
                 self._ItemType = -1\r
                 self._Comments = []\r
                 continue\r
@@ -1680,9 +1714,10 @@ class DecParser(MetaFileParser):
                     continue\r
                 else:\r
                     if GuidValue.startswith('{'):\r
-                        HexList.append('0x' + str(GuidValue[3:]))\r
+                        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
@@ -1757,6 +1792,89 @@ class DecParser(MetaFileParser):
         if not IsValid:\r
             EdkLogger.error('Parser', FORMAT_INVALID, Cause, ExtraData=self._CurrentLine,\r
                             File=self.MetaFile, Line=self._LineIndex+1)\r
+        \r
+        if EccGlobalData.gConfig.UniCheckPCDInfo == '1' or EccGlobalData.gConfig.UniCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+            # check Description, Prompt information\r
+            PatternDesc = re.compile('##\s*([\x21-\x7E\s]*)', re.S)\r
+            PatternPrompt = re.compile('#\s+@Prompt\s+([\x21-\x7E\s]*)', re.S)\r
+            Description = None\r
+            Prompt = None\r
+            # check @ValidRange, @ValidList and @Expression format valid\r
+            ErrorCodeValid = '0x0 <= %s <= 0xFFFFFFFF'\r
+            PatternValidRangeIn = '(NOT)?\s*(\d+\s*-\s*\d+|0[xX][a-fA-F0-9]+\s*-\s*0[xX][a-fA-F0-9]+|LT\s*\d+|LT\s*0[xX][a-fA-F0-9]+|GT\s*\d+|GT\s*0[xX][a-fA-F0-9]+|LE\s*\d+|LE\s*0[xX][a-fA-F0-9]+|GE\s*\d+|GE\s*0[xX][a-fA-F0-9]+|XOR\s*\d+|XOR\s*0[xX][a-fA-F0-9]+|EQ\s*\d+|EQ\s*0[xX][a-fA-F0-9]+)'\r
+            PatternValidRng = re.compile('^' + '(NOT)?\s*' + PatternValidRangeIn + '$')\r
+            for Comment in self._Comments:\r
+                Comm = Comment[0].strip()\r
+                if not Comm:\r
+                    continue\r
+                if not Description:\r
+                    Description = PatternDesc.findall(Comm)\r
+                if not Prompt:\r
+                    Prompt = PatternPrompt.findall(Comm)\r
+                if Comm[0] == '#':\r
+                    ValidFormt = Comm.lstrip('#')\r
+                    ValidFormt = ValidFormt.lstrip()\r
+                    if ValidFormt[0:11] == '@ValidRange':\r
+                        ValidFormt = ValidFormt[11:]\r
+                        ValidFormt = ValidFormt.lstrip()\r
+                        try:\r
+                            ErrorCode, Expression = ValidFormt.split('|', 1)\r
+                        except ValueError:\r
+                            ErrorCode = '0x0'\r
+                            Expression = ValidFormt\r
+                        ErrorCode, Expression = ErrorCode.strip(), Expression.strip()\r
+                        try:\r
+                            if not eval(ErrorCodeValid % ErrorCode):\r
+                                EdkLogger.warn('Parser', '@ValidRange ErrorCode(%s) of PCD %s is not valid UINT32 value.' % (ErrorCode, TokenList[0]))\r
+                        except:\r
+                            EdkLogger.warn('Parser', '@ValidRange ErrorCode(%s) of PCD %s is not valid UINT32 value.' % (ErrorCode, TokenList[0]))\r
+                        if not PatternValidRng.search(Expression):\r
+                            EdkLogger.warn('Parser', '@ValidRange Expression(%s) of PCD %s is incorrect format.' % (Expression, TokenList[0]))\r
+                    if ValidFormt[0:10] == '@ValidList':\r
+                        ValidFormt = ValidFormt[10:]\r
+                        ValidFormt = ValidFormt.lstrip()\r
+                        try:\r
+                            ErrorCode, Expression = ValidFormt.split('|', 1)\r
+                        except ValueError:\r
+                            ErrorCode = '0x0'\r
+                            Expression = ValidFormt\r
+                        ErrorCode, Expression = ErrorCode.strip(), Expression.strip()\r
+                        try:\r
+                            if not eval(ErrorCodeValid % ErrorCode):\r
+                                EdkLogger.warn('Parser', '@ValidList ErrorCode(%s) of PCD %s is not valid UINT32 value.' % (ErrorCode, TokenList[0]))\r
+                        except:\r
+                            EdkLogger.warn('Parser', '@ValidList ErrorCode(%s) of PCD %s is not valid UINT32 value.' % (ErrorCode, TokenList[0]))\r
+                        Values = Expression.split(',')\r
+                        for Value in Values:\r
+                            Value = Value.strip()\r
+                            try:\r
+                                eval(Value)\r
+                            except:\r
+                                EdkLogger.warn('Parser', '@ValidList Expression of PCD %s include a invalid value(%s).' % (TokenList[0], Value))\r
+                                break\r
+                    if ValidFormt[0:11] == '@Expression':\r
+                        ValidFormt = ValidFormt[11:]\r
+                        ValidFormt = ValidFormt.lstrip()\r
+                        try:\r
+                            ErrorCode, Expression = ValidFormt.split('|', 1)\r
+                        except ValueError:\r
+                            ErrorCode = '0x0'\r
+                            Expression = ValidFormt\r
+                        ErrorCode, Expression = ErrorCode.strip(), Expression.strip()\r
+                        try:\r
+                            if not eval(ErrorCodeValid % ErrorCode):\r
+                                EdkLogger.warn('Parser', '@Expression ErrorCode(%s) of PCD %s is not valid UINT32 value.' % (ErrorCode, TokenList[0]))\r
+                        except:\r
+                            EdkLogger.warn('Parser', '@Expression ErrorCode(%s) of PCD %s is not valid UINT32 value.' % (ErrorCode, TokenList[0]))\r
+                        if not Expression:\r
+                            EdkLogger.warn('Parser', '@Expression Expression of PCD %s is incorrect format.' % TokenList[0])\r
+            if not Description:\r
+                EdkLogger.warn('Parser', 'PCD %s Description information is not provided.' % TokenList[0])\r
+            if not Prompt:\r
+                EdkLogger.warn('Parser', 'PCD %s Prompt information is not provided.' % TokenList[0])\r
+            # check Description, Prompt localization information\r
+            if self._UniObj:\r
+                self._UniObj.CheckPcdInfo(TokenList[0])\r
 \r
         if ValueList[0] in ['True', 'true', 'TRUE']:\r
             ValueList[0] = '1'\r
@@ -1782,25 +1900,14 @@ class DecParser(MetaFileParser):
     }\r
 \r
 \r
-## FdfObject\r
-#\r
-# This class defined basic Fdf object which is used by inheriting\r
-# \r
-# @param object:       Inherited from object class\r
-#\r
-class FdfObject(object):\r
-    def __init__(self):\r
-        object.__init__()\r
-\r
 ## Fdf\r
 #\r
 # This class defined the structure used in Fdf object\r
 # \r
-# @param FdfObject:     Inherited from FdfObject class\r
 # @param Filename:      Input value for Ffilename of Fdf file, default is None\r
 # @param WorkspaceDir:  Input value for current workspace directory, default is None\r
 #\r
-class Fdf(FdfObject):\r
+class Fdf(object):\r
     def __init__(self, Filename = None, IsToDatabase = False, WorkspaceDir = None, Database = None):\r
         self.WorkspaceDir = WorkspaceDir\r
         self.IsToDatabase = IsToDatabase\r
@@ -1814,7 +1921,7 @@ class Fdf(FdfObject):
         #\r
         # Load Fdf file if filename is not None\r
         #\r
-        if Filename != None:\r
+        if Filename is not None:\r
             try:\r
                 self.LoadFdfFile(Filename)\r
             except Exception:\r
@@ -1873,6 +1980,71 @@ class Fdf(FdfObject):
                 BelongsToFile = self.InsertFile(FileName)\r
                 self.TblFdf.Insert(Model, Value1, Value2, Value3, Scope1, Scope2, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled)\r
 \r
+class UniParser(object):\r
+    # IsExtraUni defined the UNI file is Module UNI or extra Module UNI\r
+    # IsModuleUni defined the UNI file is Module UNI or Package UNI\r
+    def __init__(self, FilePath, IsExtraUni=False, IsModuleUni=True):\r
+        self.FilePath = FilePath\r
+        self.FileName = os.path.basename(FilePath)\r
+        self.IsExtraUni = IsExtraUni\r
+        self.IsModuleUni = IsModuleUni\r
+        self.FileIn = None\r
+        self.Missing = []\r
+        self.__read()\r
+    \r
+    def __read(self):\r
+        try:\r
+            self.FileIn = CodecOpenLongFilePath(self.FilePath, Mode='rb', Encoding='utf_8').read()\r
+        except UnicodeError:\r
+            self.FileIn = CodecOpenLongFilePath(self.FilePath, Mode='rb', Encoding='utf_16').read()\r
+        except UnicodeError:\r
+            self.FileIn = CodecOpenLongFilePath(self.FilePath, Mode='rb', Encoding='utf_16_le').read()\r
+        except IOError:\r
+            self.FileIn = ""\r
+    \r
+    def Start(self):\r
+        if self.IsModuleUni:\r
+            if self.IsExtraUni:\r
+                ModuleName = self.CheckKeyValid('STR_PROPERTIES_MODULE_NAME')\r
+                self.PrintLog('STR_PROPERTIES_MODULE_NAME', ModuleName)\r
+            else:\r
+                ModuleAbstract = self.CheckKeyValid('STR_MODULE_ABSTRACT')\r
+                self.PrintLog('STR_MODULE_ABSTRACT', ModuleAbstract)\r
+                ModuleDescription = self.CheckKeyValid('STR_MODULE_DESCRIPTION')\r
+                self.PrintLog('STR_MODULE_DESCRIPTION', ModuleDescription)\r
+        else:\r
+            if self.IsExtraUni:\r
+                PackageName = self.CheckKeyValid('STR_PROPERTIES_PACKAGE_NAME')\r
+                self.PrintLog('STR_PROPERTIES_PACKAGE_NAME', PackageName)\r
+            else:\r
+                PackageAbstract = self.CheckKeyValid('STR_PACKAGE_ABSTRACT')\r
+                self.PrintLog('STR_PACKAGE_ABSTRACT', PackageAbstract)\r
+                PackageDescription = self.CheckKeyValid('STR_PACKAGE_DESCRIPTION')\r
+                self.PrintLog('STR_PACKAGE_DESCRIPTION', PackageDescription)\r
+                \r
+    def CheckKeyValid(self, Key, Contents=None):\r
+        if not Contents:\r
+            Contents = self.FileIn\r
+        KeyPattern = re.compile('#string\s+%s\s+.*?#language.*?".*?"' % Key, re.S)\r
+        if KeyPattern.search(Contents):\r
+            return True\r
+        return False\r
+    \r
+    def CheckPcdInfo(self, PcdCName):\r
+        PromptKey = 'STR_%s_PROMPT' % PcdCName.replace('.', '_')\r
+        PcdPrompt = self.CheckKeyValid(PromptKey)\r
+        self.PrintLog(PromptKey, PcdPrompt)\r
+        HelpKey = 'STR_%s_HELP' % PcdCName.replace('.', '_')\r
+        PcdHelp = self.CheckKeyValid(HelpKey)\r
+        self.PrintLog(HelpKey, PcdHelp)\r
+    \r
+    def PrintLog(self, Key, Value):\r
+        if not Value and Key not in self.Missing:\r
+            Msg = '%s is missing in the %s file.' % (Key, self.FileName)\r
+            EdkLogger.warn('Parser', Msg)\r
+            EccGlobalData.gDb.TblReport.Insert(EccToolError.ERROR_GENERAL_CHECK_UNI_HELP_INFO, OtherMsg=Msg, BelongsToTable='File', BelongsToItem=-2)\r
+            self.Missing.append(Key)\r
+\r
 ##\r
 #\r
 # This acts like the main() function for the script, unless it is 'import'ed into another\r