1. Add Database supporting for INF/DEC/DSC in building which can be used by ECC tool.
authorhche10x <hche10x@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 27 Feb 2008 07:56:24 +0000 (07:56 +0000)
committerhche10x <hche10x@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 27 Feb 2008 07:56:24 +0000 (07:56 +0000)
2. Add conditional statement supporting of DSC as the latest specification
3. Improve the performance of database operations of ECC tool
4. Adjust the structure of INF/DEC/DSC class objects to support multiple ARCH of defines

git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1022 7335b38e-4728-0410-8992-fb3ffe349368

22 files changed:
Source/Python/Common/DataType.py
Source/Python/Common/Database.py
Source/Python/Common/DecClassObject.py
Source/Python/Common/DscClassObject.py
Source/Python/Common/EdkIIWorkspaceBuild.py
Source/Python/Common/InfClassObject.py
Source/Python/Common/Parsing.py [new file with mode: 0644]
Source/Python/Common/String.py
Source/Python/CommonDataClass/DataClass.py
Source/Python/CommonDataClass/ModuleClass.py
Source/Python/CommonDataClass/PackageClass.py
Source/Python/CommonDataClass/PlatformClass.py
Source/Python/Ecc/Database.py
Source/Python/Table/Table.py
Source/Python/Table/TableDataModel.py
Source/Python/Table/TableDec.py [new file with mode: 0644]
Source/Python/Table/TableDsc.py
Source/Python/Table/TableFile.py
Source/Python/Table/TableFunction.py
Source/Python/Table/TableIdentifier.py
Source/Python/Table/TableInf.py [new file with mode: 0644]
Source/Python/Table/TablePcd.py

index 001cdcf..e73b5cb 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file is used to define common static strings used by INF/DEC/DSC files\r
 #\r
-# Copyright (c) 2007, Intel Corporation\r
+# Copyright (c) 2007 ~ 2008, Intel Corporation\r
 # All rights reserved. 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
@@ -31,7 +31,7 @@ TAB_EFI_SOURCE = '$(EFI_SOURCE)'
 TAB_WORKSPACE = '$(WORKSPACE)'\r
 \r
 TAB_ARCH_NULL = ''\r
-TAB_ARCH_COMMON = 'Common'\r
+TAB_ARCH_COMMON = 'COMMON'\r
 TAB_ARCH_IA32 = 'IA32'\r
 TAB_ARCH_X64 = 'X64'\r
 TAB_ARCH_IPF = 'IPF'\r
@@ -56,7 +56,7 @@ SUP_MODULE_USER_DEFINED = 'USER_DEFINED'
 SUP_MODULE_LIST = [SUP_MODULE_BASE, SUP_MODULE_SEC, SUP_MODULE_PEI_CORE, SUP_MODULE_PEIM, SUP_MODULE_DXE_CORE, SUP_MODULE_DXE_DRIVER, \\r
                    SUP_MODULE_DXE_RUNTIME_DRIVER, SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_UEFI_DRIVER, \\r
                    SUP_MODULE_UEFI_APPLICATION, SUP_MODULE_USER_DEFINED]\r
-SUP_MODULE_LIST_STRING = TAB_SPACE_SPLIT.join(l for l in SUP_MODULE_LIST)\r
+SUP_MODULE_LIST_STRING = TAB_VALUE_SPLIT.join(l for l in SUP_MODULE_LIST)\r
 \r
 EDK_COMPONENT_TYPE_LIBRARY = 'LIBRARY'\r
 EDK_COMPONENT_TYPE_SECUARITY_CORE = 'SECUARITY_CORE'\r
@@ -208,6 +208,9 @@ TAB_PCDS_DYNAMIC_X64 = TAB_PCDS + TAB_PCDS_DYNAMIC + TAB_SPLIT + TAB_ARCH_X64
 TAB_PCDS_DYNAMIC_IPF = TAB_PCDS + TAB_PCDS_DYNAMIC + TAB_SPLIT + TAB_ARCH_IPF\r
 TAB_PCDS_DYNAMIC_EBC = TAB_PCDS + TAB_PCDS_DYNAMIC + TAB_SPLIT + TAB_ARCH_EBC\r
 \r
+TAB_PCD_DYNAMIC_TYPE_LIST = [TAB_PCDS_DYNAMIC_DEFAULT_NULL, TAB_PCDS_DYNAMIC_VPD_NULL, TAB_PCDS_DYNAMIC_HII_NULL]\r
+TAB_PCD_DYNAMIC_EX_TYPE_LIST = [TAB_PCDS_DYNAMIC_EX_DEFAULT_NULL, TAB_PCDS_DYNAMIC_EX_VPD_NULL, TAB_PCDS_DYNAMIC_EX_HII_NULL]\r
+\r
 TAB_DEPEX = 'Depex'\r
 TAB_DEPEX_COMMON = TAB_DEPEX + TAB_SPLIT + TAB_ARCH_COMMON\r
 TAB_DEPEX_IA32 = TAB_DEPEX + TAB_SPLIT + TAB_ARCH_IA32\r
index d2aded8..d26896b 100644 (file)
@@ -41,10 +41,13 @@ from Table.TableFile import TableFile
 #\r
 class Database(object):\r
     def __init__(self, DbPath):\r
-        self.Conn = sqlite3.connect(DbPath)\r
+        if os.path.exists(DbPath):\r
+            os.remove(DbPath)\r
+        self.Conn = sqlite3.connect(DbPath, isolation_level = 'DEFERRED')\r
+        self.Conn.execute("PRAGMA page_size=8192")\r
+        self.Conn.execute("PRAGMA synchronous=OFF")\r
         self.Cur = self.Conn.cursor()\r
         self.TblDataModel = TableDataModel(self.Cur)\r
-        self.TblDsc = TableDsc(self.Cur)\r
         self.TblFile = TableFile(self.Cur)\r
     \r
     ## Initialize build database\r
@@ -58,15 +61,14 @@ class Database(object):
         #\r
         # Drop all old existing tables\r
         #\r
-        self.TblDataModel.Drop()\r
-        self.TblDsc.Drop()\r
-        self.TblFile.Drop()\r
+#        self.TblDataModel.Drop()\r
+#        self.TblDsc.Drop()\r
+#        self.TblFile.Drop()\r
         \r
         #\r
         # Create new tables\r
         #\r
         self.TblDataModel.Create()\r
-        self.TblDsc.Create()\r
         self.TblFile.Create()\r
         \r
         #\r
index ddbc58a..76bedba 100644 (file)
@@ -20,7 +20,32 @@ from DataType import *
 from Identification import *\r
 from Dictionary import *\r
 from CommonDataClass.PackageClass import *\r
+from CommonDataClass.CommonClass import PcdClass\r
 from BuildToolError import *\r
+from Table.TableDec import TableDec\r
+import Database as Database\r
+from Parsing import *\r
+import GlobalData\r
+\r
+#\r
+# Global variable\r
+#\r
+Section = {TAB_UNKNOWN.upper() : MODEL_UNKNOWN,\r
+           TAB_DEC_DEFINES.upper() : MODEL_META_DATA_HEADER,\r
+           TAB_INCLUDES.upper() : MODEL_EFI_INCLUDE,\r
+           TAB_LIBRARY_CLASSES.upper() : MODEL_EFI_LIBRARY_CLASS,\r
+           TAB_COMPONENTS.upper() : MODEL_META_DATA_COMPONENT,\r
+           TAB_GUIDS.upper() : MODEL_EFI_GUID,\r
+           TAB_PROTOCOLS.upper() : MODEL_EFI_PROTOCOL,\r
+           TAB_PPIS.upper() : MODEL_EFI_PPI,\r
+           TAB_PCDS_FIXED_AT_BUILD_NULL.upper() : MODEL_PCD_FIXED_AT_BUILD,\r
+           TAB_PCDS_PATCHABLE_IN_MODULE_NULL.upper() : MODEL_PCD_PATCHABLE_IN_MODULE,\r
+           TAB_PCDS_FEATURE_FLAG_NULL.upper() : MODEL_PCD_FEATURE_FLAG,\r
+           TAB_PCDS_DYNAMIC_EX_NULL.upper() : MODEL_PCD_DYNAMIC_EX,\r
+           TAB_PCDS_DYNAMIC_NULL.upper() : MODEL_PCD_DYNAMIC,\r
+           TAB_USER_EXTENSIONS.upper() : MODEL_META_DATA_USER_EXTENSION\r
+           }\r
+\r
 \r
 ## DecObject\r
 #\r
@@ -107,23 +132,39 @@ class DecContents(DecObject):
 # @var KeyList:             To store value for KeyList, a list for all Keys used in Dec\r
 #\r
 class Dec(DecObject):\r
-    def __init__(self, Filename = None, IsMergeAllArches = False, IsToPackage = False, WorkspaceDir = None):\r
+    def __init__(self, Filename = None, IsMergeAllArches = False, IsToPackage = False, WorkspaceDir = None, Database = None, SupArchList = DataType.ARCH_LIST):\r
         self.Identification = Identification()\r
         self.Defines = DecDefines()\r
         self.UserExtensions = ''\r
         self.Package = PackageClass()\r
         self.WorkspaceDir = WorkspaceDir\r
+        self.Cur = Database.Cur\r
+        self.TblFile = Database.TblFile\r
+        self.TblDec = TableDec(Database.Cur)\r
+        self.SupArchList = SupArchList\r
         \r
         self.Contents = {}\r
-        for Arch in DataType.ARCH_LIST_FULL:\r
-            self.Contents[Arch] = DecContents()\r
+#        for Arch in DataType.ARCH_LIST_FULL:\r
+#            self.Contents[Arch] = DecContents()\r
         \r
         self.KeyList = [\r
             TAB_INCLUDES, TAB_GUIDS, TAB_PROTOCOLS, TAB_PPIS, TAB_LIBRARY_CLASSES, \\r
             TAB_PCDS_FIXED_AT_BUILD_NULL, TAB_PCDS_PATCHABLE_IN_MODULE_NULL, TAB_PCDS_FEATURE_FLAG_NULL, \\r
-            TAB_PCDS_DYNAMIC_NULL, TAB_PCDS_DYNAMIC_EX_NULL\r
+            TAB_PCDS_DYNAMIC_NULL, TAB_PCDS_DYNAMIC_EX_NULL, TAB_DEC_DEFINES\r
         ]\r
     \r
+        #\r
+        # Upper all KEYs to ignore case sensitive when parsing\r
+        #\r
+        self.KeyList = map(lambda c: c.upper(), self.KeyList)\r
+        \r
+        #\r
+        # Init RecordSet\r
+        #\r
+        self.RecordSet = {}        \r
+        for Key in self.KeyList:\r
+            self.RecordSet[Section[Key]] = []\r
+        \r
         #\r
         # Load Dec file if filename is not None\r
         #\r
@@ -175,36 +216,166 @@ class Dec(DecObject):
     # @param Filename:  Input value for filename of Dec file\r
     #\r
     def LoadDecFile(self, Filename):\r
-        (Filepath, Name) = os.path.split(Filename)\r
-        self.Identification.FileName = Name\r
+        #\r
+        # Insert a record for file\r
+        #\r
+        Filename = NormPath(Filename)\r
         self.Identification.FileFullPath = Filename\r
-        self.Identification.FileRelativePath = Filepath\r
+        (self.Identification.FileRelativePath, self.Identification.FileName) = os.path.split(Filename)\r
+        FileID = self.TblFile.InsertFile(Filename, MODEL_FILE_DSC)\r
+        \r
+        #\r
+        # Init DecTable\r
+        #\r
+        self.TblDec.Table = "Dec%s" % FileID\r
+        self.TblDec.Create()\r
+        \r
+        #\r
+        # Init common datas\r
+        #\r
+        IfDefList, SectionItemList, CurrentSection, ArchList, ThirdList, IncludeFiles = \\r
+        [], [], TAB_UNKNOWN, [], [], []\r
+        LineNo = 0\r
+        \r
+        #\r
+        # Parse file content\r
+        #\r
+        FileContent = open(Filename, 'r').read()\r
+        for Line in FileContent.splitlines():\r
+            LineNo = LineNo + 1\r
+            #\r
+            # Reomve spaces in head and tail\r
+            #\r
+            Line = Line.strip()\r
+            \r
+            #\r
+            # Ignore comments\r
+            #\r
+            if Line.startswith(TAB_COMMENT_SPLIT):\r
+                continue\r
+            \r
+            #\r
+            # Remove comments at tail and remove spaces again\r
+            #\r
+            Line = CleanString(Line)\r
+            if Line == '':\r
+                continue\r
+            \r
+            #\r
+            # Find a new section tab\r
+            # First insert previous section items\r
+            # And then parse the content of the new section\r
+            #\r
+            if Line.startswith(TAB_SECTION_START) and Line.endswith(TAB_SECTION_END):\r
+                #\r
+                # Insert items data of previous section\r
+                #\r
+                self.InsertSectionItemsIntoDatabase(FileID, Filename, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList)\r
+                #\r
+                # Parse the new section\r
+                #\r
+                SectionItemList = []\r
+                ArchList = []\r
+                ThirdList = []\r
+                \r
+                LineList = GetSplitValueList(Line[len(TAB_SECTION_START):len(Line) - len(TAB_SECTION_END)], TAB_COMMA_SPLIT)\r
+                for Item in LineList:\r
+                    ItemList = GetSplitValueList(Item, TAB_SPLIT)\r
+                    CurrentSection = ItemList[0]\r
+                    if CurrentSection.upper() not in self.KeyList:\r
+                        RaiseParserError(Line, CurrentSection, Filename, '', LineNo)\r
+                    ItemList.append('')\r
+                    ItemList.append('')\r
+                    if len(ItemList) > 5:\r
+                        RaiseParserError(Line, CurrentSection, Filename, '', LineNo)\r
+                    else:\r
+                        if ItemList[1] != '' and ItemList[1].upper() not in ARCH_LIST_FULL:\r
+                            EdkLogger.error("Parser", PARSER_ERROR, "Invalid Arch definition '%s' found" % ItemList[1], File=Filename, Line=LineNo)\r
+                        ArchList.append(ItemList[1].upper())\r
+                        ThirdList.append(ItemList[2])\r
+\r
+                continue\r
+            \r
+            #\r
+            # Not in any defined section\r
+            #\r
+            if CurrentSection == TAB_UNKNOWN:\r
+                ErrorMsg = "%s is not in any defined section" % Line\r
+                EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, File=Filename, Line=LineNo)\r
+\r
+            #\r
+            # Add a section item\r
+            #\r
+            SectionItemList.append([Line, LineNo])\r
+            # End of parse\r
+        #End of For\r
+        \r
+        #\r
+        # Insert items data of last section\r
+        #\r
+        self.InsertSectionItemsIntoDatabase(FileID, Filename, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList)\r
         \r
-        F = open(Filename, 'r').read()\r
-        F = PreCheck(Filename, F, self.KeyList)\r
-        Sects = F.split(DataType.TAB_SECTION_START)\r
-        for Sect in Sects:\r
-            TabList = GetSplitValueList(Sect.split(TAB_SECTION_END, 1)[0], DataType.TAB_COMMA_SPLIT)\r
-            for Tab in TabList:\r
-                if Tab.upper() == TAB_INF_DEFINES.upper():\r
-                    GetSingleValueOfKeyFromLines(Sect, self.Defines.DefinesDictionary, TAB_COMMENT_SPLIT, TAB_EQUAL_SPLIT, True, TAB_VALUE_SPLIT)\r
+        #\r
+        # Replace all DEFINE macros with its actual values\r
+        #\r
+        ParseDefineMacro2(self.TblDec, self.RecordSet, GlobalData.gGlobalDefines)\r
+\r
+    ## Parse DEFINE statement\r
+    #\r
+    # Get DEFINE macros\r
+    #\r
+    # 1. Insert a record into TblDec\r
+    # Value1: Macro Name\r
+    # Value2: Macro Value\r
+    #\r
+    def ParseDefine(self, LineValue, StartLine, Table, FileID, Filename, SectionName, Model, Arch):\r
+        EdkLogger.debug(EdkLogger.DEBUG_2, "DEFINE statement '%s' found in section %s" % (LineValue, SectionName))\r
+        SectionModel = Section[SectionName.upper()]\r
+        Define = GetSplitValueList(CleanString(LineValue[LineValue.upper().find(DataType.TAB_DEFINE.upper() + ' ') + len(DataType.TAB_DEFINE + ' ') : ]), TAB_EQUAL_SPLIT, 1)\r
+        Table.Insert(Model, Define[0], Define[1], '', Arch, SectionModel, FileID, StartLine, -1, StartLine, -1, 0)\r
+    \r
+    ## First time to insert records to database\r
+    # \r
+    # Insert item data of a section to database\r
+    # @param FileID:           The ID of belonging file\r
+    # @param Filename:         The name of belonging file\r
+    # @param CurrentSection:   The name of currect section\r
+    # @param SectionItemList:  A list of items of the section\r
+    # @param ArchList:         A list of arches\r
+    # @param ThirdList:        A list of third parameters, ModuleType for LibraryClass and SkuId for Dynamic Pcds\r
+    # @param IfDefList:        A list of all conditional statements\r
+    #\r
+    def InsertSectionItemsIntoDatabase(self, FileID, Filename, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList):\r
+        #\r
+        # Insert each item data of a section\r
+        #\r
+        for Index in range(0, len(ArchList)):\r
+            Arch = ArchList[Index]\r
+            Third = ThirdList[Index]\r
+            if Arch == '':\r
+                Arch = TAB_ARCH_COMMON\r
+\r
+            Model = Section[CurrentSection.upper()]\r
+            Records = self.RecordSet[Model]\r
+            for SectionItem in SectionItemList:\r
+                BelongsToItem, EndLine, EndColumn = -1, -1, -1\r
+                LineValue, StartLine, EndLine = SectionItem[0], SectionItem[1], SectionItem[1]\r
+\r
+                EdkLogger.debug(4, "Parsing %s ..." %LineValue)\r
+                #\r
+                # And then parse DEFINE statement\r
+                #\r
+                if LineValue.upper().find(DataType.TAB_DEFINE.upper() + ' ') > -1:\r
+                    self.ParseDefine(LineValue, StartLine, self.TblDec, FileID, Filename, CurrentSection, MODEL_META_DATA_DEFINE, Arch)\r
                     continue\r
-                for Arch in DataType.ARCH_LIST_FULL + [DataType.TAB_ARCH_NULL]:\r
-                    for Key in self.KeyList:\r
-                        if Arch != DataType.TAB_ARCH_NULL:\r
-                            Target = (Key + DataType.TAB_SPLIT + Arch).upper()\r
-                        else:\r
-                            Target = Key.upper()\r
-                        if Tab.upper() == Target:\r
-                            if Arch != DataType.TAB_ARCH_NULL:\r
-                                Command = 'self.ParseDec(Sect, Tab, self.Contents[Arch].' + Key + ')'\r
-                                eval(Command)\r
-                                continue\r
-                            else:\r
-                                Command = "self.ParseDec(Sect, Tab, self.Contents['" + DataType.TAB_ARCH_COMMON + "']." + Key + ')'\r
-                                eval(Command)\r
-                                continue\r
-        #EndFor\r
+                \r
+                #\r
+                # At last parse other sections\r
+                #\r
+                ID = self.TblDec.Insert(Model, LineValue, '', '', Arch, -1, FileID, StartLine, -1, StartLine, -1, 0)\r
+                Records.append([LineValue, Arch, StartLine, ID, Third])\r
+            \r
+            self.RecordSet[Model] = Records\r
 \r
     ## Transfer to Package Object\r
     # \r
@@ -212,42 +383,137 @@ class Dec(DecObject):
     #\r
     def DecToPackage(self):\r
         #\r
-        # Get value for Header\r
+        # Init global information for the file\r
         #\r
-        self.Package.Header.Name = self.Defines.DefinesDictionary[TAB_DEC_DEFINES_PACKAGE_NAME][0]\r
-        self.Package.Header.Guid = self.Defines.DefinesDictionary[TAB_DEC_DEFINES_PACKAGE_GUID][0]\r
-        self.Package.Header.Version = self.Defines.DefinesDictionary[TAB_DEC_DEFINES_PACKAGE_VERSION][0]\r
-        self.Package.Header.FileName = self.Identification.FileName\r
-        self.Package.Header.FullPath = self.Identification.FileFullPath\r
-        self.Package.Header.DecSpecification = self.Defines.DefinesDictionary[TAB_DEC_DEFINES_DEC_SPECIFICATION][0]\r
-        File = self.Package.Header.FullPath\r
+        ContainerFile = self.Identification.FileFullPath\r
         \r
         #\r
-        # Includes\r
-        # <IncludeDirectory>\r
+        # Generate Package Header\r
         #\r
+        self.GenPackageHeader(ContainerFile)\r
+        \r
+        #\r
+        # Generate Includes\r
+        #\r
+        self.GenIncludes(ContainerFile)\r
+\r
+        #\r
+        # Generate Guids\r
+        #\r
+        self.GenGuids(ContainerFile)\r
+\r
+        #\r
+        # Generate Protocols\r
+        #\r
+        self.GenProtocols(ContainerFile)\r
+\r
+        #\r
+        # Generate Ppis\r
+        #\r
+        self.GenPpis(ContainerFile)\r
+        \r
+        #\r
+        # Generate LibraryClasses\r
+        #\r
+        self.GenLibraryClasses(ContainerFile)\r
+        \r
+        #\r
+        # Generate Pcds\r
+        #\r
+        self.GenPcds(ContainerFile)\r
+    \r
+    ## Get Package Header\r
+    #\r
+    # Gen Package Header of Dec as <Key> = <Value>\r
+    #\r
+    # @param ContainerFile: The Dec file full path \r
+    #\r
+    def GenPackageHeader(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate PackageHeader ...")\r
+        #\r
+        # Update all defines item in database\r
+        #\r
+        RecordSet = self.RecordSet[MODEL_META_DATA_HEADER]\r
+        for Record in RecordSet:\r
+            ValueList = GetSplitValueList(Record[0], TAB_EQUAL_SPLIT)\r
+            if len(ValueList) != 2:\r
+                RaiseParserError(Record[0], 'Defines', ContainerFile, '<Key> = <Value>', Record[2])\r
+            ID, Value1, Value2, Arch, LineNo = Record[3], ValueList[0], ValueList[1], Record[1], Record[2]\r
+            SqlCommand = """update %s set Value1 = '%s', Value2 = '%s'\r
+                            where ID = %s""" % (self.TblDec.Table, ConvertToSqlString2(Value1), ConvertToSqlString2(Value2), ID)\r
+            self.TblDec.Exec(SqlCommand)\r
+        \r
+        #\r
+        # Get detailed information\r
+        #\r
+        for Arch in self.SupArchList:\r
+            PackageHeader = PackageHeaderClass()\r
+            \r
+            PackageHeader.Name = QueryDefinesItem(self.TblDec, TAB_DEC_DEFINES_PACKAGE_NAME, Arch)[0]\r
+            PackageHeader.Guid = QueryDefinesItem(self.TblDec, TAB_DEC_DEFINES_PACKAGE_GUID, Arch)[0]\r
+            PackageHeader.Version = QueryDefinesItem(self.TblDec, TAB_DEC_DEFINES_PACKAGE_VERSION, Arch)[0]\r
+            PackageHeader.FileName = self.Identification.FileName\r
+            PackageHeader.FullPath = self.Identification.FileFullPath\r
+            PackageHeader.DecSpecification = QueryDefinesItem(self.TblDec, TAB_DEC_DEFINES_DEC_SPECIFICATION, Arch)[0]\r
+            \r
+            self.Package.Header[Arch] = PackageHeader\r
+    \r
+    ## GenIncludes\r
+    #\r
+    # Gen Includes of Dec\r
+    # \r
+    #\r
+    # @param ContainerFile: The Dec file full path \r
+    #\r
+    def GenIncludes(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_INCLUDES)\r
         Includes = {}\r
-        for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].Includes:\r
-                MergeArches(Includes, Item, Arch)\r
+        #\r
+        # Get all Includes\r
+        #\r
+        RecordSet = self.RecordSet[MODEL_EFI_INCLUDE]\r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in self.SupArchList:\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    MergeArches(Includes, Record[0], Arch)\r
+\r
         for Key in Includes.keys():\r
             Include = IncludeClass()\r
             Include.FilePath = NormPath(Key)\r
             Include.SupArchList = Includes[Key]\r
             self.Package.Includes.append(Include)\r
-            \r
+    \r
+    ## GenGuids\r
+    #\r
+    # Gen Guids of Dec\r
+    # <CName>=<GuidValue>\r
+    #\r
+    # @param ContainerFile: The Dec file full path \r
+    #\r
+    def GenGuids(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_GUIDS)\r
+        Guids = {}\r
         #\r
-        # Guids\r
-        # <CName>=<GuidValue>\r
+        # Get all Guids\r
         #\r
-        Guids = {}\r
-        for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].Guids:\r
-                List = GetSplitValueList(Item, DataType.TAB_EQUAL_SPLIT)\r
-                if len(List) != 2:\r
-                    RaiseParserError(Item, 'Guids', File, '<CName>=<GuidValue>')\r
-                else:\r
-                    MergeArches(Guids, (List[0], List[1]), Arch)\r
+        RecordSet = self.RecordSet[MODEL_EFI_GUID]\r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in self.SupArchList:\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    List = GetSplitValueList(Record[0], DataType.TAB_EQUAL_SPLIT)\r
+                    if len(List) != 2:\r
+                        RaiseParserError(Record[0], 'Guids', ContainerFile, '<CName>=<GuidValue>', Record[2])\r
+                    else:\r
+                        MergeArches(Guids, (List[0], List[1]), Arch)\r
+                \r
         for Key in Guids.keys():\r
             Guid = GuidClass()\r
             Guid.CName = Key[0]\r
@@ -255,87 +521,148 @@ class Dec(DecObject):
             Guid.SupArchList = Guids[Key]\r
             self.Package.GuidDeclarations.append(Guid)\r
 \r
-        # \r
-        # Protocols\r
-        # <CName>=<GuidValue>\r
-        #\r
+    ## GenProtocols\r
+    #\r
+    # Gen Protocols of Dec\r
+    # <CName>=<GuidValue>\r
+    #\r
+    # @param ContainerFile: The Dec file full path \r
+    #\r
+    def GenProtocols(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_PROTOCOLS)\r
         Protocols = {}\r
-        for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].Protocols:\r
-                List = GetSplitValueList(Item, DataType.TAB_EQUAL_SPLIT)\r
-                if len(List) != 2:\r
-                    RaiseParserError(Item, 'Protocols', File, '<CName>=<GuidValue>')\r
-                else:\r
-                    MergeArches(Protocols, (List[0], List[1]), Arch)\r
+        #\r
+        # Get all Guids\r
+        #\r
+        RecordSet = self.RecordSet[MODEL_EFI_PROTOCOL]\r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in self.SupArchList:\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    List = GetSplitValueList(Record[0], DataType.TAB_EQUAL_SPLIT)\r
+                    if len(List) != 2:\r
+                        RaiseParserError(Record[0], 'Protocols', ContainerFile, '<CName>=<GuidValue>', Record[2])\r
+                    else:\r
+                        MergeArches(Protocols, (List[0], List[1]), Arch)\r
+                \r
         for Key in Protocols.keys():\r
             Protocol = ProtocolClass()\r
             Protocol.CName = Key[0]\r
             Protocol.Guid = Key[1]\r
             Protocol.SupArchList = Protocols[Key]\r
             self.Package.ProtocolDeclarations.append(Protocol)\r
+    \r
+    ## GenPpis\r
+    #\r
+    # Gen Ppis of Dec\r
+    # <CName>=<GuidValue>\r
+    #\r
+    # @param ContainerFile: The Dec file full path \r
+    #\r
+    def GenPpis(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_PPIS)\r
+        Ppis = {}\r
+        #\r
+        # Get all Guids\r
+        #\r
+        RecordSet = self.RecordSet[MODEL_EFI_PPI]\r
         \r
         #\r
-        # Ppis\r
-        # <CName>=<GuidValue>\r
+        # Go through each arch\r
         #\r
-        Ppis = {}\r
-        for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].Ppis:\r
-                List = GetSplitValueList(Item, DataType.TAB_EQUAL_SPLIT)\r
-                if len(List) != 2:\r
-                    RaiseParserError(Item, 'Ppis', File, '<CName>=<GuidValue>')\r
-                else:\r
-                    MergeArches(Ppis, (List[0], List[1]), Arch)\r
+        for Arch in self.SupArchList:\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    List = GetSplitValueList(Record[0], DataType.TAB_EQUAL_SPLIT)\r
+                    if len(List) != 2:\r
+                        RaiseParserError(Record[0], 'Ppis', ContainerFile, '<CName>=<GuidValue>', Record[2])\r
+                    else:\r
+                        MergeArches(Ppis, (List[0], List[1]), Arch)\r
+        \r
         for Key in Ppis.keys():\r
             Ppi = PpiClass()\r
             Ppi.CName = Key[0]\r
             Ppi.Guid = Key[1]\r
             Ppi.SupArchList = Ppis[Key]\r
             self.Package.PpiDeclarations.append(Ppi)\r
-            \r
+    \r
+    ## GenLibraryClasses\r
+    #\r
+    # Gen LibraryClasses of Dec\r
+    # <CName>=<GuidValue>\r
+    #\r
+    # @param ContainerFile: The Dec file full path \r
+    #\r
+    def GenLibraryClasses(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES)\r
+        LibraryClasses = {}\r
         #\r
-        # LibraryClasses\r
-        # <LibraryClassName>|<LibraryClassInstance>\r
+        # Get all Guids\r
         #\r
-        LibraryClasses = {}\r
-        for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].LibraryClasses:\r
-                List = GetSplitValueList(Item[0], DataType.TAB_VALUE_SPLIT)\r
-                if len(List) != 2:\r
-                    RaiseParserError(Item[0], 'LibraryClasses', File, '<LibraryClassName>|<LibraryClassInstanceFilename>')\r
-                else:\r
-                    CheckFileExist(self.WorkspaceDir, os.path.join(self.Identification.FileRelativePath, List[1]), File, 'LibraryClasses', Item[0])\r
-                    if Item[1] == ['']:\r
-                            Item[1] = DataType.SUP_MODULE_LIST\r
-                    MergeArches(LibraryClasses, (List[0], List[1]) + tuple(Item[1]), Arch)\r
+        RecordSet = self.RecordSet[MODEL_EFI_LIBRARY_CLASS]\r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in self.SupArchList:\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    List = GetSplitValueList(Record[0], DataType.TAB_VALUE_SPLIT)\r
+                    if len(List) != 2:\r
+                        RaiseParserError(Record[0], 'LibraryClasses', ContainerFile, '<LibraryClassName>|<LibraryClassInstanceFilename>', Record[2])\r
+                    else:\r
+                        CheckFileExist(self.Identification.FileRelativePath, List[1], ContainerFile, 'LibraryClasses', Record[0])\r
+                    MergeArches(LibraryClasses, (List[0], List[1]), Arch)\r
+        \r
         for Key in LibraryClasses.keys():\r
             LibraryClass = LibraryClassClass()\r
             LibraryClass.LibraryClass = Key[0]\r
             LibraryClass.RecommendedInstance = NormPath(Key[1])\r
-            LibraryClass.SupModuleList = list(Key[2:])\r
+            LibraryClass.SupModuleList = SUP_MODULE_LIST\r
             LibraryClass.SupArchList = LibraryClasses[Key]\r
             self.Package.LibraryClassDeclarations.append(LibraryClass)\r
+    \r
+    ## GenPcds\r
+    #\r
+    # Gen Pcds of Dec\r
+    # <TokenSpcCName>.<TokenCName>|<Value>|<DatumType>|<Token>\r
+    #\r
+    # @param ContainerFile: The Dec file full path \r
+    #\r
+    def GenPcds(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_PCDS)\r
+        Pcds = {}\r
+        #\r
+        # Get all Guids\r
+        #\r
+        RecordSet1 = self.RecordSet[MODEL_PCD_FIXED_AT_BUILD]\r
+        RecordSet2 = self.RecordSet[MODEL_PCD_PATCHABLE_IN_MODULE]\r
+        RecordSet3 = self.RecordSet[MODEL_PCD_FEATURE_FLAG]\r
+        RecordSet4 = self.RecordSet[MODEL_PCD_DYNAMIC_EX]\r
+        RecordSet5 = self.RecordSet[MODEL_PCD_DYNAMIC]\r
         \r
         #\r
-        # Pcds\r
-        # <TokenSpcCName>.<TokenCName>|<Value>|<DatumType>|<Token>\r
+        # Go through each arch\r
         #\r
-        Pcds = {}\r
-        for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].PcdsFixedAtBuild:\r
-                MergeArches(Pcds, self.GetPcdOfDec(Item, TAB_PCDS_FIXED_AT_BUILD, File), Arch)\r
-            \r
-            for Item in self.Contents[Arch].PcdsPatchableInModule:\r
-                MergeArches(Pcds, self.GetPcdOfDec(Item, TAB_PCDS_PATCHABLE_IN_MODULE, File), Arch)\r
-            \r
-            for Item in self.Contents[Arch].PcdsFeatureFlag:\r
-                MergeArches(Pcds, self.GetPcdOfDec(Item, TAB_PCDS_FEATURE_FLAG, File), Arch)\r
-            \r
-            for Item in self.Contents[Arch].PcdsDynamicEx:\r
-                MergeArches(Pcds, self.GetPcdOfDec(Item, TAB_PCDS_DYNAMIC_EX, File), Arch)\r
-            \r
-            for Item in self.Contents[Arch].PcdsDynamic:\r
-                MergeArches(Pcds, self.GetPcdOfDec(Item, TAB_PCDS_DYNAMIC, File), Arch)\r
+        for Arch in self.SupArchList:\r
+            for Record in RecordSet1:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    MergeArches(Pcds, self.GetPcdOfDec(Record[0], TAB_PCDS_FIXED_AT_BUILD, ContainerFile, Record[2]), Arch)\r
+            for Record in RecordSet2:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    MergeArches(Pcds, self.GetPcdOfDec(Record[0], TAB_PCDS_PATCHABLE_IN_MODULE, ContainerFile, Record[2]), Arch)\r
+            for Record in RecordSet3:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    MergeArches(Pcds, self.GetPcdOfDec(Record[0], TAB_PCDS_FEATURE_FLAG, ContainerFile, Record[2]), Arch)\r
+            for Record in RecordSet4:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    MergeArches(Pcds, self.GetPcdOfDec(Record[0], TAB_PCDS_DYNAMIC_EX, ContainerFile, Record[2]), Arch)\r
+            for Record in RecordSet5:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    MergeArches(Pcds, self.GetPcdOfDec(Record[0], TAB_PCDS_DYNAMIC, ContainerFile, Record[2]), Arch)                    \r
 \r
         for Key in Pcds.keys():\r
             Pcd = PcdClass()\r
@@ -353,14 +680,14 @@ class Dec(DecObject):
     # Get Pcd of Dec as <TokenSpcCName>.<TokenCName>|<Value>|<DatumType>|<Token>\r
     # @retval (TokenSpcCName, TokenCName, Value, DatumType, Token, ItemType) Formatted Pcd Item\r
     #\r
-    def GetPcdOfDec(self, Item, Type, File):\r
+    def GetPcdOfDec(self, Item, Type, File, LineNo = -1):\r
         Format = '<TokenSpaceGuidCName>.<PcdCName>|<Value>|<DatumType>|<Token>'\r
         List = GetSplitValueList(Item)\r
         if len(List) != 4:\r
-            RaiseParserError(Item, 'Pcds' + Type, File, Format)\r
+            RaiseParserError(Item, 'Pcds' + Type, File, Format, LineNo)\r
         TokenInfo = GetSplitValueList(List[0], DataType.TAB_SPLIT)\r
         if len(TokenInfo) != 2:\r
-            RaiseParserError(Item, 'Pcds' + Type, File, Format)\r
+            RaiseParserError(Item, 'Pcds' + Type, File, Format, LineNo)\r
         \r
         return (TokenInfo[0], TokenInfo[1], List[1], List[2], List[3], Type)\r
     \r
@@ -385,12 +712,14 @@ class Dec(DecObject):
     #\r
     def ShowPackage(self):\r
         M = self.Package\r
-        print 'Filename =', M.Header.FileName\r
-        print 'FullPath =', M.Header.FullPath\r
-        print 'BaseName =', M.Header.Name\r
-        print 'Guid =', M.Header.Guid\r
-        print 'Version =', M.Header.Version\r
-        print 'DecSpecification =', M.Header.DecSpecification\r
+        for Arch in M.Header.keys():\r
+            print '\nArch =', Arch\r
+            print 'Filename =', M.Header[Arch].FileName\r
+            print 'FullPath =', M.Header[Arch].FullPath\r
+            print 'BaseName =', M.Header[Arch].Name\r
+            print 'Guid =', M.Header[Arch].Guid\r
+            print 'Version =', M.Header[Arch].Version\r
+            print 'DecSpecification =', M.Header[Arch].DecSpecification\r
         print '\nIncludes =', M.Includes\r
         for Item in M.Includes:\r
             print Item.FilePath, Item.SupArchList\r
@@ -416,7 +745,16 @@ class Dec(DecObject):
 # script.\r
 #\r
 if __name__ == '__main__':\r
+    EdkLogger.Initialize()\r
+    EdkLogger.SetLevel(EdkLogger.DEBUG_0)\r
+    \r
     W = os.getenv('WORKSPACE')\r
-    F = os.path.join(W, 'Nt32Pkg/Nt32Pkg.dec')\r
-    P = Dec(os.path.normpath(F), True, True, W)\r
+    #F = os.path.join(W, 'Nt32Pkg/Nt32Pkg.dec')\r
+    F = os.path.join(W, 'MdeModulePkg\MdeModulePkg.dec')\r
+    Db = Database.Database(DATABASE_PATH)\r
+    Db.InitDatabase()\r
+    \r
+    P = Dec(os.path.normpath(F), False, True, W, Db)\r
     P.ShowPackage()\r
+    \r
+    Db.Close()\r
index a50732f..63dac2d 100755 (executable)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file is used to define each component of DSC file\r
 #\r
-# Copyright (c) 2007, Intel Corporation\r
+# Copyright (c) 2007 ~ 2008, Intel Corporation\r
 # All rights reserved. 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
 # Import Modules\r
 #\r
 import os\r
-import EdkLogger\r
+import EdkLogger as EdkLogger\r
+import Database as Database\r
 from String import *\r
+from Parsing import *\r
 from DataType import *\r
 from Identification import *\r
 from Dictionary import *\r
@@ -25,6 +27,31 @@ from CommonDataClass.CommonClass import SkuInfoClass
 from BuildToolError import *\r
 from Misc import sdict\r
 import GlobalData\r
+from Table.TableDsc import TableDsc\r
+\r
+#\r
+# Global variable\r
+#\r
+Section = {TAB_UNKNOWN.upper() : MODEL_UNKNOWN,\r
+           TAB_DSC_DEFINES.upper() : MODEL_META_DATA_HEADER,\r
+           TAB_BUILD_OPTIONS.upper() : MODEL_META_DATA_BUILD_OPTION,\r
+           TAB_SKUIDS.upper() : MODEL_EFI_SKU_ID,\r
+           TAB_LIBRARIES.upper() : MODEL_EFI_LIBRARY_INSTANCE,\r
+           TAB_LIBRARY_CLASSES.upper() : MODEL_EFI_LIBRARY_CLASS,\r
+           TAB_PCDS_FIXED_AT_BUILD_NULL.upper() : MODEL_PCD_FIXED_AT_BUILD,\r
+           TAB_PCDS_PATCHABLE_IN_MODULE_NULL.upper() : MODEL_PCD_PATCHABLE_IN_MODULE,\r
+           TAB_PCDS_FEATURE_FLAG_NULL.upper() : MODEL_PCD_FEATURE_FLAG,\r
+           TAB_PCDS_DYNAMIC_EX_NULL.upper() : MODEL_PCD_DYNAMIC_EX,\r
+           TAB_PCDS_DYNAMIC_EX_DEFAULT_NULL.upper() :  MODEL_PCD_DYNAMIC_EX_DEFAULT,\r
+           TAB_PCDS_DYNAMIC_EX_VPD_NULL.upper() : MODEL_PCD_DYNAMIC_EX_VPD,\r
+           TAB_PCDS_DYNAMIC_EX_HII_NULL.upper() : MODEL_PCD_DYNAMIC_EX_HII,\r
+           TAB_PCDS_DYNAMIC_NULL.upper() : MODEL_PCD_DYNAMIC,\r
+           TAB_PCDS_DYNAMIC_DEFAULT_NULL.upper() : MODEL_PCD_DYNAMIC_DEFAULT,\r
+           TAB_PCDS_DYNAMIC_VPD_NULL.upper() : MODEL_PCD_DYNAMIC_VPD,\r
+           TAB_PCDS_DYNAMIC_HII_NULL.upper() : MODEL_PCD_DYNAMIC_HII,\r
+           TAB_COMPONENTS.upper() : MODEL_META_DATA_COMPONENT,\r
+           TAB_USER_EXTENSIONS.upper() : MODEL_META_DATA_USER_EXTENSION\r
+           }\r
 \r
 ## DscObject\r
 #\r
@@ -146,25 +173,40 @@ class DscContents(DscObject):
 class Dsc(DscObject):\r
     _NullClassIndex = 0\r
 \r
-    def __init__(self, Filename = None, IsMergeAllArches = False, IsToPlatform = False, WorkspaceDir = None):\r
+    def __init__(self, Filename = None, IsMergeAllArches = False, IsToPlatform = False, WorkspaceDir = None, Database = None):\r
         self.Identification = Identification()\r
         self.Defines = DscDefines()\r
         self.Contents = {}\r
         self.UserExtensions = ''\r
         self.Platform = PlatformClass()\r
         self.WorkspaceDir = WorkspaceDir\r
+        self.Cur = Database.Cur\r
+        self.TblFile = Database.TblFile\r
+        self.TblDsc = TableDsc(Database.Cur)\r
         self._Macro = {}    # for inf file local replacement\r
 \r
-        for Arch in DataType.ARCH_LIST_FULL:\r
-            self.Contents[Arch] = DscContents()\r
+#        for Arch in DataType.ARCH_LIST_FULL:\r
+#            self.Contents[Arch] = DscContents()\r
 \r
         self.KeyList = [\r
             TAB_SKUIDS, TAB_LIBRARIES, TAB_LIBRARY_CLASSES, TAB_BUILD_OPTIONS, TAB_PCDS_FIXED_AT_BUILD_NULL, \\r
             TAB_PCDS_PATCHABLE_IN_MODULE_NULL, TAB_PCDS_FEATURE_FLAG_NULL, \\r
             TAB_PCDS_DYNAMIC_DEFAULT_NULL, TAB_PCDS_DYNAMIC_HII_NULL, TAB_PCDS_DYNAMIC_VPD_NULL, \\r
             TAB_PCDS_DYNAMIC_EX_DEFAULT_NULL, TAB_PCDS_DYNAMIC_EX_HII_NULL, TAB_PCDS_DYNAMIC_EX_VPD_NULL, \\r
-            TAB_COMPONENTS\r
+            TAB_COMPONENTS, TAB_DSC_DEFINES\r
         ]\r
+        \r
+        #\r
+        # Upper all KEYs to ignore case sensitive when parsing\r
+        #\r
+        self.KeyList = map(lambda c: c.upper(), self.KeyList)\r
+        \r
+        #\r
+        # Init RecordSet\r
+        #\r
+#        self.RecordSet = {}        \r
+#        for Key in self.KeyList:\r
+#            self.RecordSet[Section[Key]] = []\r
 \r
         #\r
         # Load Dsc file if filename is not None\r
@@ -214,289 +256,645 @@ class Dsc(DscObject):
                 Command = "self.Contents[Arch]." + Key + ".extend(" + "self.Contents['" + DataType.TAB_ARCH_COMMON + "']." + Key + ")"\r
                 eval(Command)\r
 \r
-    ## Load Dsc file\r
-    #\r
-    # Load the file if it exists\r
-    #\r
-    # @param Filename:  Input value for filename of Dsc file\r
-    #\r
-    def LoadDscFile(self, Filename):\r
-        (Filepath, Name) = os.path.split(Filename)\r
-        self.Identification.FileName = Name\r
-        self.Identification.FileFullPath = Filename\r
-        self.Identification.FileRelativePath = Filepath\r
-\r
-        F = open(Filename, 'r').read()\r
-        F = PreCheck(Filename, F, self.KeyList)\r
-        Sects = F.split(DataType.TAB_SECTION_START)\r
-        for Sect in Sects:\r
-            TabList = GetSplitValueList(Sect.split(TAB_SECTION_END, 1)[0], DataType.TAB_COMMA_SPLIT)\r
-            for Tab in TabList:\r
-                if Tab.upper() == TAB_INF_DEFINES.upper():\r
-                    GetSingleValueOfKeyFromLines(Sect, self.Defines.DefinesDictionary, TAB_COMMENT_SPLIT, TAB_EQUAL_SPLIT, True, TAB_VALUE_SPLIT)\r
-                    continue\r
-                for Arch in DataType.ARCH_LIST_FULL + [DataType.TAB_ARCH_NULL]:\r
-                    for Key in self.KeyList:\r
-                        if Arch != DataType.TAB_ARCH_NULL:\r
-                            Target = (Key + DataType.TAB_SPLIT + Arch).upper()\r
-                        else:\r
-                            Target = Key.upper()\r
-                        if SplitModuleType(Tab)[0].upper() == Target:\r
-                            if Arch != DataType.TAB_ARCH_NULL:\r
-                                Command = 'self.ParseDsc(Sect, Tab, self.Contents[Arch].' + Key + ')'\r
-                                eval(Command)\r
-                                continue\r
-                            else:\r
-                                Command = "self.ParseDsc(Sect, Tab, self.Contents['" + DataType.TAB_ARCH_COMMON + "']." + Key + ')'\r
-                                eval(Command)\r
-                                continue\r
-\r
-        self._Macro = self.Defines.DefinesDictionary[TAB_INF_DEFINES_MACRO]\r
-        self._Macro.update(GlobalData.gGlobalDefines)\r
-\r
     ## Transfer to Platform Object\r
     # \r
     # Transfer all contents of an Inf file to a standard Module Object\r
     #\r
     def DscToPlatform(self):\r
         #\r
-        # Get value for Header\r
+        # Get Macro defined in GlobalDefines\r
         #\r
-        self.Platform.Header.Name = self.Defines.DefinesDictionary[TAB_DSC_DEFINES_PLATFORM_NAME][0]\r
-        self.Platform.Header.Guid = self.Defines.DefinesDictionary[TAB_DSC_DEFINES_PLATFORM_GUID][0]\r
-        self.Platform.Header.Version = self.Defines.DefinesDictionary[TAB_DSC_DEFINES_PLATFORM_VERSION][0]\r
-        self.Platform.Header.FileName = self.Identification.FileName\r
-        self.Platform.Header.FullPath = self.Identification.FileFullPath\r
-        self.Platform.Header.DscSpecification = self.Defines.DefinesDictionary[TAB_DSC_DEFINES_DSC_SPECIFICATION][0]\r
-        File = self.Platform.Header.FullPath\r
-\r
-        self.Platform.Header.SkuIdName = self.Defines.DefinesDictionary[TAB_DSC_DEFINES_SKUID_IDENTIFIER]\r
-        self.Platform.Header.SupArchList = self.Defines.DefinesDictionary[TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES]\r
-        self.Platform.Header.BuildTargets = self.Defines.DefinesDictionary[TAB_DSC_DEFINES_BUILD_TARGETS]\r
-        self.Platform.Header.OutputDirectory = NormPath(self.Defines.DefinesDictionary[TAB_DSC_DEFINES_OUTPUT_DIRECTORY][0], self._Macro)\r
-        self.Platform.Header.BuildNumber = self.Defines.DefinesDictionary[TAB_DSC_DEFINES_BUILD_NUMBER][0]\r
-        self.Platform.Header.MakefileName = self.Defines.DefinesDictionary[TAB_DSC_DEFINES_MAKEFILE_NAME][0]\r
-\r
-        self.Platform.Header.BsBaseAddress = self.Defines.DefinesDictionary[TAB_DSC_DEFINES_BS_BASE_ADDRESS][0]\r
-        self.Platform.Header.RtBaseAddress = self.Defines.DefinesDictionary[TAB_DSC_DEFINES_RT_BASE_ADDRESS][0]\r
+        self._Macro = self.Defines.DefinesDictionary[TAB_INF_DEFINES_MACRO]\r
+        self._Macro.update(GlobalData.gGlobalDefines)\r
+        \r
+        #\r
+        # Init global information for the file\r
+        #\r
+        ContainerFile = self.Identification.FileFullPath\r
+        \r
+        #\r
+        # Generate Platform Header\r
+        #\r
+        self.GenPlatformHeader(ContainerFile)\r
+        \r
+        #\r
+        # Generate BuildOptions\r
+        #\r
+        self.GenBuildOptions(ContainerFile)\r
+        \r
+        #\r
+        # Generate SkuInfos\r
+        #\r
+        self.GenSkuInfos(ContainerFile)\r
+        \r
+        #\r
+        # Generate Libraries\r
+        #\r
+        self.GenLibraries(ContainerFile)\r
+        \r
+        #\r
+        # Generate LibraryClasses\r
+        #\r
+        self.GenLibraryClasses(ContainerFile)\r
+        \r
+        #\r
+        # Generate Pcds\r
+        #\r
+        self.GenPcds(DataType.TAB_PCDS_FIXED_AT_BUILD, ContainerFile)\r
+        self.GenPcds(DataType.TAB_PCDS_PATCHABLE_IN_MODULE, ContainerFile)\r
+        self.GenFeatureFlagPcds(DataType.TAB_PCDS_FEATURE_FLAG, ContainerFile)\r
+        self.GenDynamicDefaultPcds(DataType.TAB_PCDS_DYNAMIC_DEFAULT, ContainerFile)\r
+        self.GenDynamicDefaultPcds(DataType.TAB_PCDS_DYNAMIC_EX_DEFAULT, ContainerFile)\r
+        self.GenDynamicHiiPcds(DataType.TAB_PCDS_DYNAMIC_HII, ContainerFile)\r
+        self.GenDynamicHiiPcds(DataType.TAB_PCDS_DYNAMIC_EX_HII, ContainerFile)\r
+        self.GenDynamicVpdPcds(DataType.TAB_PCDS_DYNAMIC_VPD, ContainerFile)\r
+        self.GenDynamicVpdPcds(DataType.TAB_PCDS_DYNAMIC_EX_VPD, ContainerFile)\r
+        \r
+        #\r
+        # Generate Components\r
+        #\r
+        self.GenComponents(ContainerFile)\r
+    #End of DscToPlatform\r
 \r
+    ## Get Platform Header\r
+    #\r
+    # Gen Platform Header of Dsc as <Key> = <Value>\r
+    #\r
+    # @param ContainerFile: The Dsc file full path \r
+    #\r
+    def GenPlatformHeader(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate PlatformHeader ...")\r
         #\r
-        # Define of Defines\r
+        # Update all defines item in database\r
         #\r
-        if self.Defines.DefinesDictionary[TAB_DSC_DEFINES_DEFINE][0] != '':\r
-            for Item in self.Defines.DefinesDictionary[TAB_DSC_DEFINES_DEFINE]:\r
-                List = Item.split(DataType.TAB_EQUAL_SPLIT)\r
-                if len(List) != 2:\r
-                    RaiseParserError(Item, 'DEFINE of Defines', File, 'DEFINE <MACRO> = <PATH>')\r
-                else:\r
-                    self.Platform.Header.Define[CleanString(List[0])] = CleanString(List[1])\r
+        SqlCommand = """select ID, Value1, Arch, StartLine from %s\r
+                        where Model = %s\r
+                        and Enabled > -1""" % (self.TblDsc.Table, MODEL_META_DATA_HEADER)\r
+        RecordSet = self.TblDsc.Exec(SqlCommand)\r
+        for Record in RecordSet:\r
+            ValueList = GetSplitValueList(Record[1], TAB_EQUAL_SPLIT)\r
+            if len(ValueList) != 2:\r
+                RaiseParserError(Record[1], 'Defines', ContainerFile, '<Key> = <Value>', Record[3])\r
+            ID, Value1, Value2, Arch = Record[0], ValueList[0], ValueList[1], Record[2]\r
+            SqlCommand = """update %s set Value1 = '%s', Value2 = '%s'\r
+                            where ID = %s""" % (self.TblDsc.Table, ConvertToSqlString2(Value1), ConvertToSqlString2(Value2), ID)\r
+            self.TblDsc.Exec(SqlCommand)\r
+        \r
+        #\r
+        # Get detailed information\r
+        #\r
+        for Arch in DataType.ARCH_LIST:\r
+            PlatformHeader = PlatformHeaderClass()\r
+            \r
+            PlatformHeader.Name = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_PLATFORM_NAME, Arch)[0]\r
+            PlatformHeader.Guid = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_PLATFORM_GUID, Arch)[0]\r
+            PlatformHeader.Version = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_PLATFORM_VERSION, Arch)[0]\r
+            PlatformHeader.FileName = self.Identification.FileName\r
+            PlatformHeader.FullPath = self.Identification.FileFullPath\r
+            PlatformHeader.DscSpecification = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_DSC_SPECIFICATION, Arch)[0]\r
+    \r
+            PlatformHeader.SkuIdName = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_SKUID_IDENTIFIER, Arch)\r
+            PlatformHeader.SupArchList = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES, Arch)\r
+            PlatformHeader.BuildTargets = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_BUILD_TARGETS, Arch)\r
+            PlatformHeader.OutputDirectory = NormPath(QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_OUTPUT_DIRECTORY, Arch)[0])\r
+            PlatformHeader.BuildNumber = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_BUILD_NUMBER, Arch)[0]\r
+            PlatformHeader.MakefileName = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_MAKEFILE_NAME, Arch)[0]\r
+    \r
+            PlatformHeader.BsBaseAddress = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_BS_BASE_ADDRESS, Arch)[0]\r
+            PlatformHeader.RtBaseAddress = QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_RT_BASE_ADDRESS, Arch)[0]\r
 \r
-        Fdf = PlatformFlashDefinitionFileClass()\r
-        Fdf.FilePath = NormPath(self.Defines.DefinesDictionary[TAB_DSC_DEFINES_FLASH_DEFINITION][0], self._Macro)\r
-        self.Platform.FlashDefinitionFile = Fdf\r
+            self.Platform.Header[Arch] = PlatformHeader\r
+            Fdf = PlatformFlashDefinitionFileClass()\r
+            Fdf.FilePath = NormPath(QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_FLASH_DEFINITION, Arch)[0])\r
+            self.Platform.FlashDefinitionFile = Fdf\r
 \r
+    ## GenBuildOptions\r
+    #\r
+    # Gen BuildOptions of Dsc\r
+    # [<Family>:]<ToolFlag>=Flag\r
+    #\r
+    # @param ContainerFile: The Dsc file full path \r
+    #\r
+    def GenBuildOptions(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_BUILD_OPTIONS)\r
+        BuildOptions = {}\r
         #\r
-        # BuildOptions\r
-        # [<Family>:]<ToolFlag>=Flag\r
+        # Get all include files\r
+        #\r
+        IncludeFiles = QueryDscItem(self.TblDsc, MODEL_META_DATA_INCLUDE, MODEL_META_DATA_BUILD_OPTION)\r
+        \r
+        #\r
+        # Get all BuildOptions\r
+        #\r
+        RecordSet = QueryDscItem(self.TblDsc, MODEL_META_DATA_BUILD_OPTION, -1)\r
+        \r
+        #\r
+        # Go through each arch\r
         #\r
-        BuildOptions = {}\r
-        IncludeFiles = {}\r
         for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].BuildOptions:\r
-                if GenInclude(Item, IncludeFiles, Arch):\r
-                    IncludeFile = CleanString(Item[Item.upper().find(DataType.TAB_INCLUDE.upper() + ' ') + len(DataType.TAB_INCLUDE + ' ') : ])\r
-                    CheckFileExist(self.WorkspaceDir, IncludeFile, self.Platform.Header.FullPath, 'BuildOptions', Item)\r
-                    for NewItem in open(WorkspaceFile(self.WorkspaceDir, IncludeFile), 'r').readlines():\r
-                        MergeArches(BuildOptions, GetBuildOption(NewItem, File), Arch)\r
-                    continue\r
-                MergeArches(BuildOptions, GetBuildOption(Item, File), Arch)\r
+            for IncludeFile in IncludeFiles:\r
+                if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper():\r
+                    Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, TAB_BUILD_OPTIONS, '', IncludeFile[2])\r
+                    for NewItem in open(Filename, 'r').readlines():\r
+                        if CleanString(NewItem) == '':\r
+                            continue\r
+                        (Family, ToolChain, Flag) = GetBuildOption(NewItem, Filename, -1)\r
+                        MergeArches(BuildOptions, (Family, ToolChain, Flag), Arch)\r
+            \r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper():\r
+                    (Family, ToolChain, Flag) = GetBuildOption(Record[0], ContainerFile, Record[2])\r
+                    MergeArches(BuildOptions, (Family, ToolChain, Flag), Arch)\r
+                    #\r
+                    # Update to Database\r
+                    #\r
+                    #SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'\r
+                    #                where ID = %s""" % (self.TblDsc.Table, ConvertToSqlString2(Family), ConvertToSqlString2(ToolChain), ConvertToSqlString2(Flag), Record[3])\r
+                    #self.TblDsc.Exec(SqlCommand)\r
 \r
-        self.Platform.BuildOptions.IncludeFiles = IncludeFiles\r
         for Key in BuildOptions.keys():\r
             BuildOption = BuildOptionClass(Key[0], Key[1], Key[2])\r
             BuildOption.SupArchList = BuildOptions[Key]\r
             self.Platform.BuildOptions.BuildOptionList.append(BuildOption)\r
-\r
+            \r
+    ## GenSkuInfos\r
+    #\r
+    # Gen SkuInfos of Dsc\r
+    # <Integer>|<UiName>\r
+    #\r
+    # @param ContainerFile: The Dsc file full path \r
+    #\r
+    def GenSkuInfos(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_SKUIDS)\r
         #\r
         # SkuIds\r
         # <Integer>|<UiName>\r
         #\r
-        IncludeFiles = {}\r
         self.Platform.SkuInfos.SkuInfoList['DEFAULT'] = '0'\r
+        \r
+        #\r
+        # Get all include files\r
+        #\r
+        IncludeFiles = QueryDscItem(self.TblDsc, MODEL_META_DATA_INCLUDE, MODEL_EFI_SKU_ID)\r
+        \r
+        #\r
+        # Get all SkuInfos\r
+        #\r
+        RecordSet = QueryDscItem(self.TblDsc, MODEL_EFI_SKU_ID, -1)\r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
         for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].SkuIds:\r
-                if GenInclude(Item, IncludeFiles, Arch):\r
-                    IncludeFile = CleanString(Item[Item.upper().find(DataType.TAB_INCLUDE.upper() + ' ') + len(DataType.TAB_INCLUDE + ' ') : ])\r
-                    CheckFileExist(self.WorkspaceDir, IncludeFile, self.Platform.Header.FullPath, 'SkuIds', Item)\r
-                    for NewItem in open(WorkspaceFile(self.WorkspaceDir, IncludeFile), 'r').readlines():\r
+            for IncludeFile in IncludeFiles:\r
+                if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper():\r
+                    Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, TAB_SKUIDS, '', IncludeFile[2])\r
+                    for NewItem in open(Filename, 'r').readlines():\r
+                        if CleanString(NewItem) == '':\r
+                            continue\r
                         List = GetSplitValueList(NewItem)\r
                         if len(List) != 2:\r
-                            RaiseParserError(NewItem, 'SkuIds', WorkspaceFile(self.WorkspaceDir, IncludeFile), '<Integer>|<UiName>')\r
+                            RaiseParserError(NewItem, TAB_SKUIDS, Filename, '<Integer>|<UiName>')\r
                         else:\r
                             self.Platform.SkuInfos.SkuInfoList[List[1]] = List[0]\r
-                    continue\r
-                List = GetSplitValueList(Item)\r
-                if len(List) != 2:\r
-                    RaiseParserError(Item, 'SkuIds', File, '<Integer>|<UiName>')\r
-                else:\r
-                    self.Platform.SkuInfos.SkuInfoList[List[1]] = List[0]\r
-        self.Platform.SkuInfos.IncludeFiles = IncludeFiles\r
-\r
+            \r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper():\r
+                    List = GetSplitValueList(Record[0])\r
+                    if len(List) != 2:\r
+                        RaiseParserError(Record[0], TAB_SKUIDS, ContainerFile, '<Integer>|<UiName>')\r
+                    else:\r
+                        self.Platform.SkuInfos.SkuInfoList[List[1]] = List[0]\r
+                        #\r
+                        # Update to Database\r
+                        #\r
+                        #SqlCommand = """update %s set Value1 = '%s', Value2 = '%s'\r
+                        #                where ID = %s""" % (self.TblDsc.Table, ConvertToSqlString2(List[0]), ConvertToSqlString2(List[1]), Record[3])\r
+                        #self.TblDsc.Exec(SqlCommand)\r
+    \r
+    ## GenLibraries\r
+    #\r
+    # Gen Libraries of Dsc\r
+    # <PathAndFilename>\r
+    #\r
+    # @param ContainerFile: The Dsc file full path \r
+    #\r
+    def GenLibraries(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_LIBRARIES)\r
+        Libraries = {}\r
         #\r
-        # Libraries\r
-        # <PathAndFilename>\r
+        # Get all include files\r
+        #\r
+        IncludeFiles = QueryDscItem(self.TblDsc, MODEL_META_DATA_INCLUDE, MODEL_EFI_LIBRARY_INSTANCE)\r
+        \r
+        #\r
+        # Get all Libraries\r
+        #\r
+        RecordSet = QueryDscItem(self.TblDsc, MODEL_EFI_LIBRARY_INSTANCE, -1)\r
+        \r
+        #\r
+        # Go through each arch\r
         #\r
-        Libraries = {}\r
-        IncludeFiles = {}\r
-        Defines = {}\r
         for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].Libraries:\r
-                if GenInclude(Item, IncludeFiles, Arch):\r
-                    IncludeFile = CleanString(Item[Item.upper().find(DataType.TAB_INCLUDE.upper() + ' ') + len(DataType.TAB_INCLUDE + ' ') : ])\r
-                    CheckFileExist(self.WorkspaceDir, IncludeFile, self.Platform.Header.FullPath, 'Libraries', Item)\r
-                    for NewItem in open(WorkspaceFile(self.WorkspaceDir, IncludeFile), 'r').readlines():\r
-                        MergeArches(Libraries, Item, Arch)\r
-                    continue\r
-                Status = GenDefines(Item, Arch, Defines)\r
-                #\r
-                # Find DEFINE statement\r
-                #\r
-                if Status == 0:\r
-                    pass\r
-                #\r
-                # Find DEFINE statement but in wrong format\r
-                #\r
-                elif Status == -1:\r
-                    RaiseParserError(Item, 'Libraries', File, 'DEFINE <VarName> = <PATH>')\r
-                #\r
-                # Not find DEFINE statement\r
-                #\r
-                elif Status == 1:\r
-                    MergeArches(Libraries, Item, Arch)\r
-        self.Platform.Libraries.IncludeFiles = IncludeFiles\r
+            for IncludeFile in IncludeFiles:\r
+                if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper():\r
+                    Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, TAB_LIBRARIES, '', IncludeFile[2])\r
+                    for NewItem in open(Filename, 'r').readlines():\r
+                        if CleanString(NewItem) == '':\r
+                            continue\r
+                        MergeArches(Libraries, NewItem, Arch)\r
+            \r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper():\r
+                    MergeArches(Libraries, Record[0], Arch)\r
+        \r
         for Key in Libraries.keys():\r
             Library = PlatformLibraryClass()\r
-            Library.FilePath = NormPath(Key, self._Macro)\r
-            Library.Define = Defines\r
+            Library.FilePath = NormPath(Key)\r
             Library.SupArchList = Libraries[Key]\r
             self.Platform.Libraries.LibraryList.append(Library)\r
 \r
+    ## GenLibraryClasses\r
+    #\r
+    # Get LibraryClasses of Dsc\r
+    # <LibraryClassKeyWord>|<LibraryInstance>\r
+    #\r
+    # @param ContainerFile: The Dsc file full path \r
+    #\r
+    def GenLibraryClasses(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES)\r
+        LibraryClasses = {}\r
         #\r
-        # LibraryClasses\r
-        # <LibraryClassKeyWord>|<LibraryInstance>\r
+        # Get all include files\r
+        #\r
+        IncludeFiles = QueryDscItem(self.TblDsc, MODEL_META_DATA_INCLUDE, MODEL_EFI_LIBRARY_CLASS)\r
+        \r
+        #\r
+        # Get all LibraryClasses\r
+        #\r
+        RecordSet = QueryDscItem(self.TblDsc, MODEL_EFI_LIBRARY_CLASS, -1)\r
+        \r
+        #\r
+        # Go through each arch\r
         #\r
-        LibraryClasses = {}\r
-        IncludeFiles = {}\r
-        Defines = {}\r
         for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].LibraryClasses:\r
-                if GenInclude(Item[0], IncludeFiles, Arch):\r
-                    IncludeFile = CleanString(Item[0][Item[0].upper().find(DataType.TAB_INCLUDE.upper() + ' ') + len(DataType.TAB_INCLUDE + ' ') : ])\r
-                    IncludeFilePath = WorkspaceFile(self.WorkspaceDir, IncludeFile)\r
-                    CheckFileExist(self.WorkspaceDir, IncludeFile, self.Platform.Header.FullPath, 'LibraryClasses', Item[0])\r
-                    for NewItem in open(IncludeFilePath, 'r').readlines():\r
-                        MergeArches(LibraryClasses, self.GenLibraryClass([NewItem, Item[1]], IncludeFilePath), Arch)\r
-                    continue\r
-                Status = GenDefines(Item[0], Arch, Defines)\r
-                #\r
-                # Find DEFINE statement\r
-                #\r
-                if Status == 0:\r
-                    pass\r
-                #\r
-                # Find DEFINE statement but in wrong format\r
-                #\r
-                elif Status == -1:\r
-                    RaiseParserError(Item[0], 'LibraryClasses', File, 'DEFINE <VarName> = <PATH>')\r
-                #\r
-                # Not find DEFINE statement\r
-                #\r
-                elif Status == 1:\r
-                    MergeArches(LibraryClasses, self.GenLibraryClass(Item, self.Platform.Header.FullPath), Arch)\r
-        self.Platform.LibraryClasses.IncludeFiles = IncludeFiles\r
+            for IncludeFile in IncludeFiles:\r
+                if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper():\r
+                    Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, TAB_LIBRARY_CLASSES, '', IncludeFile[2])\r
+                    for NewItem in open(Filename, 'r').readlines():\r
+                        if CleanString(NewItem) == '':\r
+                            continue\r
+                        MergeArches(LibraryClasses, GetLibraryClass([NewItem, IncludeFile[4]], Filename, self.WorkspaceDir, -1), Arch)\r
+            \r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper():\r
+                    (LibClassName, LibClassIns, SupModelList) = GetLibraryClass([Record[0], Record[4]], ContainerFile, self.WorkspaceDir, Record[2])\r
+                    MergeArches(LibraryClasses, (LibClassName, LibClassIns, SupModelList), Arch)\r
+                    #\r
+                    # Update to Database\r
+                    #\r
+                    #SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'\r
+                    #                where ID = %s""" % (self.TblDsc.Table, ConvertToSqlString2(LibClassName), ConvertToSqlString2(LibClassIns), ConvertToSqlString2(SupModelList), Record[3])\r
+                    #self.TblDsc.Exec(SqlCommand)\r
+\r
         for Key in LibraryClasses.keys():\r
             Library = PlatformLibraryClass()\r
             Library.Name = Key[0]\r
             Library.FilePath = NormPath(Key[1], self._Macro)\r
-            Library.SupModuleList = list(Key[2:])\r
-            Library.Define = Defines\r
+            Library.SupModuleList = GetSplitValueList(Key[2])\r
             Library.SupArchList = LibraryClasses[Key]\r
             self.Platform.LibraryClasses.LibraryList.append(Library)\r
+    \r
+    ## Gen Pcds\r
+    #\r
+    # Gen Pcd of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<Type>|<MaximumDatumSize>]\r
+    #\r
+    # @param Type:           The type of Pcd\r
+    # @param ContainerFile:  The file which describes the pcd, used for error report\r
+    #\r
+    def GenPcds(self, Type = '', ContainerFile = ''):\r
+        Pcds = {}\r
+        if Type == DataType.TAB_PCDS_PATCHABLE_IN_MODULE:\r
+            Model = MODEL_PCD_PATCHABLE_IN_MODULE\r
+        elif Type == DataType.TAB_PCDS_FIXED_AT_BUILD:\r
+            Model = MODEL_PCD_FIXED_AT_BUILD\r
+        else:\r
+            pass\r
+        EdkLogger.debug(2, "Generate %s ..." % Type)\r
+        \r
+        #\r
+        # Get all include files\r
+        #\r
+        IncludeFiles = QueryDscItem(self.TblDsc, MODEL_META_DATA_INCLUDE, Model)\r
+        \r
+        #\r
+        # Get all Pcds\r
+        #\r
+        RecordSet = QueryDscItem(self.TblDsc, Model, -1)       \r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in DataType.ARCH_LIST:\r
+            for IncludeFile in IncludeFiles:\r
+                if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper():\r
+                    Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, Type, '', IncludeFile[2])\r
+                    for NewItem in open(Filename, 'r').readlines():\r
+                        if CleanString(NewItem) == '':\r
+                            continue\r
+                        MergeArches(Pcds, GetPcd(NewItem, Type, Filename, -1), Arch)\r
 \r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper():\r
+                    MergeArches(Pcds, GetPcd(Record[0], Type, ContainerFile, Record[2]), Arch)\r
+                \r
+        for Key in Pcds:\r
+            Pcd = PcdClass(Key[0], '', Key[1], Key[3], Key[4], Key[2], Key[5], [], {}, [])\r
+            Pcd.SupArchList = Pcds[Key]\r
+            self.Platform.DynamicPcdBuildDefinitions.append(Pcd)\r
+    \r
+    ## Gen FeatureFlagPcds\r
+    #\r
+    # Gen FeatureFlagPcds of Dsc file as <PcdTokenSpaceGuidCName>.<TokenCName>|TRUE/FALSE\r
+    #\r
+    # @param Type:           The type of Pcd\r
+    # @param ContainerFile:  The file which describes the pcd, used for error report\r
+    #\r
+    def GenFeatureFlagPcds(self, Type = '', ContainerFile = ''):\r
+        Pcds = {}\r
+        if Type == DataType.TAB_PCDS_FEATURE_FLAG:\r
+            Model = MODEL_PCD_FEATURE_FLAG\r
+        else:\r
+            pass\r
+        EdkLogger.debug(2, "Generate %s ..." % Type)\r
+        \r
+        #\r
+        # Get all include files\r
+        #\r
+        IncludeFiles = QueryDscItem(self.TblDsc, MODEL_META_DATA_INCLUDE, Model)\r
+        \r
+        #\r
+        # Get all FeatureFlagPcds\r
         #\r
-        # Pcds\r
+        RecordSet = QueryDscItem(self.TblDsc, Model, -1)       \r
+        \r
         #\r
-        self.GenPcds(DataType.TAB_PCDS_FIXED_AT_BUILD, File)\r
-        self.GenPcds(DataType.TAB_PCDS_PATCHABLE_IN_MODULE, File)\r
-        self.GenFeatureFlagPcds(DataType.TAB_PCDS_FEATURE_FLAG, File)\r
-        self.GenDynamicDefaultPcds(DataType.TAB_PCDS_DYNAMIC_DEFAULT, File)\r
-        self.GenDynamicDefaultPcds(DataType.TAB_PCDS_DYNAMIC_EX_DEFAULT, File)\r
-        self.GenDynamicHiiPcds(DataType.TAB_PCDS_DYNAMIC_HII, File)\r
-        self.GenDynamicHiiPcds(DataType.TAB_PCDS_DYNAMIC_EX_HII, File)\r
-        self.GenDynamicVpdPcds(DataType.TAB_PCDS_DYNAMIC_VPD, File)\r
-        self.GenDynamicVpdPcds(DataType.TAB_PCDS_DYNAMIC_EX_VPD, File)\r
+        # Go through each arch\r
+        #\r
+        for Arch in DataType.ARCH_LIST:\r
+            for IncludeFile in IncludeFiles:\r
+                if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper():\r
+                    Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, Type, '', IncludeFile[2])\r
+                    for NewItem in open(Filename, 'r').readlines():\r
+                        if CleanString(NewItem) == '':\r
+                            continue\r
+                        MergeArches(Pcds, GetFeatureFlagPcd(NewItem, Type, Filename, -1), Arch)\r
+\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper():\r
+                    MergeArches(Pcds, GetFeatureFlagPcd(Record[0], Type, ContainerFile, Record[2]), Arch)\r
 \r
+        for Key in Pcds:\r
+            Pcd = PcdClass(Key[0], '', Key[1], '', '', Key[2], Key[3], [], {}, [])\r
+            Pcd.SupArchList = Pcds[Key]\r
+            self.Platform.DynamicPcdBuildDefinitions.append(Pcd)\r
+    \r
+    ## Gen DynamicDefaultPcds\r
+    #\r
+    # Gen DynamicDefaultPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<DatumTyp>[|<MaxDatumSize>]]\r
+    #\r
+    # @param Type:           The type of Pcd\r
+    # @param ContainerFile:  The file which describes the pcd, used for error report\r
+    #\r
+    def GenDynamicDefaultPcds(self, Type = '', ContainerFile = ''):\r
+        Pcds = {}\r
+        SkuInfoList = {}\r
+        if Type == DataType.TAB_PCDS_DYNAMIC_DEFAULT:\r
+            Model = MODEL_PCD_DYNAMIC_DEFAULT\r
+        elif Type == DataType.TAB_PCDS_DYNAMIC_EX_DEFAULT:\r
+            Model = MODEL_PCD_DYNAMIC_EX_DEFAULT\r
+        else:\r
+            pass\r
+        EdkLogger.debug(2, "Generate %s ..." % Type)\r
+        \r
         #\r
-        # Components\r
+        # Get all include files\r
+        #\r
+        IncludeFiles = QueryDscItem(self.TblDsc, MODEL_META_DATA_INCLUDE, Model)\r
+        \r
+        #\r
+        # Get all DynamicDefaultPcds\r
+        #\r
+        RecordSet = QueryDscItem(self.TblDsc, Model, -1)       \r
+        \r
+        #\r
+        # Go through each arch\r
         #\r
-        Components = sdict()\r
-        IncludeFiles = {}\r
-        Defines = {}\r
         for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].Components:\r
-                if GenInclude(Item[0], IncludeFiles, Arch):\r
-                    IncludeFile = CleanString(Item[0][Item[0].upper().find(DataType.TAB_INCLUDE.upper() + ' ') + len(DataType.TAB_INCLUDE + ' ') : ])\r
-                    IncludeFilePath = WorkspaceFile(self.WorkspaceDir, IncludeFile)\r
-                    CheckFileExist(self.WorkspaceDir, IncludeFile, self.Platform.Header.FullPath, 'Components', Item[0])\r
-                    NewItems = []\r
-                    GetComponents(open(IncludeFilePath, 'r').read(), TAB_COMPONENTS, NewItems, TAB_COMMENT_SPLIT)\r
-                    for NewItem in NewItems:\r
-                        MergeArches(Components, self.GenComponent(NewItem, IncludeFilePath), Arch)\r
-                    continue\r
-                Status = GenDefines(Item[0], Arch, Defines)\r
-                #\r
-                # Find DEFINE statement\r
-                #\r
-                if Status == 0:\r
-                    pass\r
-                #\r
-                # Find DEFINE statement but in wrong format\r
-                #\r
-                elif Status == -1:\r
-                    RaiseParserError(Item[0], 'Components', File, 'DEFINE <VarName> = <PATH>')\r
-                #\r
-                # Not find DEFINE statement\r
-                #\r
-                elif Status == 1:\r
-                    MergeArches(Components, self.GenComponent(Item, self.Platform.Header.FullPath), Arch)\r
-        self.Platform.Modules.IncludeFiles = IncludeFiles\r
-        for Key in Components.keys():\r
-            Key.Define = Defines\r
-            Key.SupArchList = Components[Key]\r
-            self.Platform.Modules.ModuleList.append(Key)\r
+            for IncludeFile in IncludeFiles:\r
+                if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper():\r
+                    Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, Type, '', IncludeFile[2])\r
+                    for NewItem in open(Filename, 'r').readlines():\r
+                        if CleanString(NewItem) == '':\r
+                            continue\r
+                        (K1, K2, K3, K4, K5, K6) = GetDynamicDefaultPcd(NewItem, Type, Filename, -1)\r
+                        MergeArches(Pcds,  (K1, K2, K3, K4, K5, K6, IncludeFile[4]), Arch)\r
 \r
-    #End of DscToPlatform\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper():\r
+                    (K1, K2, K3, K4, K5, K6) = GetDynamicDefaultPcd(Record[0], Type, ContainerFile, Record[2])\r
+                    MergeArches(Pcds,  (K1, K2, K3, K4, K5, K6, Record[4]), Arch)\r
 \r
-    ## Get Library Class\r
+        for Key in Pcds:\r
+            (Status, SkuInfoList) = self.GenSkuInfoList(Key[6], self.Platform.SkuInfos.SkuInfoList, '', '', '', '', '', Key[2])\r
+            if Status == False:\r
+                ErrorMsg = "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList, Type)\r
+                EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, ContainerFile)\r
+            Pcd = PcdClass(Key[0], '', Key[1], Key[3], Key[4], Key[2], Key[5], [], SkuInfoList, [])\r
+            Pcd.SupArchList = Pcds[Key]\r
+            self.Platform.DynamicPcdBuildDefinitions.append(Pcd)\r
+    \r
+    ## Gen DynamicHiiPcds\r
     #\r
-    # Get Library of Dsc as <LibraryClassKeyWord>|<LibraryInstance>\r
-    # \r
-    # @param Item:           String as <LibraryClassKeyWord>|<LibraryInstance>\r
-    # @param ContainerFile:  The file which describes the library class, used for error report\r
+    # Gen DynamicHiiPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<String>|<VariableGuidCName>|<VariableOffset>[|<DefaultValue>[|<MaximumDatumSize>]]\r
     #\r
-    # @retval (LibraryClassKeyWord, LibraryInstance, [SUP_MODULE_LIST]) Formatted Library Item\r
+    # @param Type:           The type of Pcd\r
+    # @param ContainerFile:  The file which describes the pcd, used for error report\r
     #\r
-    def GenLibraryClass(self, Item, ContainerFile):\r
-        List = GetSplitValueList(Item[0])\r
-        if len(List) != 2:\r
-            RaiseParserError(Item[0], 'LibraryClasses', ContainerFile, '<LibraryClassKeyWord>|<LibraryInstance>')\r
+    def GenDynamicHiiPcds(self, Type = '', ContainerFile = ''):\r
+        Pcds = {}\r
+        SkuInfoList = {}\r
+        if Type == DataType.TAB_PCDS_DYNAMIC_HII:\r
+            Model = MODEL_PCD_DYNAMIC_HII\r
+        elif Type == DataType.TAB_PCDS_DYNAMIC_EX_HII:\r
+            Model = MODEL_PCD_DYNAMIC_EX_HII\r
         else:\r
-            CheckFileType(List[1], '.Inf', ContainerFile, 'library class instance', Item[0])\r
-            CheckFileExist(self.WorkspaceDir, List[1], ContainerFile, 'LibraryClasses', Item[0])\r
-            if Item[1] == ['']:\r
-                Item[1] = DataType.SUP_MODULE_LIST\r
-        return (List[0], List[1]) + tuple(Item[1])\r
+            pass\r
+        EdkLogger.debug(2, "Generate %s ..." % Type)\r
+        \r
+        #\r
+        # Get all include files\r
+        #\r
+        IncludeFiles = QueryDscItem(self.TblDsc, MODEL_META_DATA_INCLUDE, Model)\r
+        \r
+        #\r
+        # Get all DynamicHiiPcds\r
+        #\r
+        RecordSet = QueryDscItem(self.TblDsc, Model, -1)       \r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in DataType.ARCH_LIST:\r
+            for IncludeFile in IncludeFiles:\r
+                if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper():\r
+                    Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, Type, '', IncludeFile[2])\r
+                    for NewItem in open(Filename, 'r').readlines():\r
+                        if CleanString(NewItem) == '':\r
+                            continue\r
+                        (K1, K2, K3, K4, K5, K6, K7, K8) = GetDynamicHiiPcd(NewItem, Type, Filename, -1)\r
+                        MergeArches(Pcds,  (K1, K2, K3, K4, K5, K6, K7, K8, IncludeFile[4]), Arch)\r
+\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper():\r
+                    (K1, K2, K3, K4, K5, K6, K7, K8) = GetDynamicHiiPcd(Record[0], Type, ContainerFile, Record[2])\r
+                    MergeArches(Pcds,  (K1, K2, K3, K4, K5, K6, K7, K8, Record[4]), Arch)\r
+        \r
+        for Key in Pcds:\r
+            (Status, SkuInfoList) = self.GenSkuInfoList(Key[8], self.Platform.SkuInfos.SkuInfoList, Key[2], Key[3], Key[4], Key[5], '', '')\r
+            if Status == False:\r
+                ErrorMsg = "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList, Type)\r
+                EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, ContainerFile)\r
+            Pcd = PcdClass(Key[0], '', Key[1], '', Key[6], Key[5], Key[7], [], SkuInfoList, [])\r
+            Pcd.SupArchList = Pcds[Key]\r
+            self.Platform.DynamicPcdBuildDefinitions.append(Pcd)\r
 \r
+    ## Gen DynamicVpdPcds\r
+    #\r
+    # Gen DynamicVpdPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<VpdOffset>[|<MaximumDatumSize>]\r
+    #\r
+    # @param Type:           The type of Pcd\r
+    # @param ContainerFile:  The file which describes the pcd, used for error report\r
+    #\r
+    def GenDynamicVpdPcds(self, Type = '', ContainerFile = ''):\r
+        Pcds = {}\r
+        SkuInfoList = {}\r
+        if Type == DataType.TAB_PCDS_DYNAMIC_VPD:\r
+            Model = MODEL_PCD_DYNAMIC_VPD\r
+        elif Type == DataType.TAB_PCDS_DYNAMIC_EX_VPD:\r
+            Model = MODEL_PCD_DYNAMIC_EX_VPD\r
+        else:\r
+            pass\r
+        EdkLogger.debug(2, "Generate %s ..." % Type)\r
+        \r
+        #\r
+        # Get all include files\r
+        #\r
+        IncludeFiles = QueryDscItem(self.TblDsc, MODEL_META_DATA_INCLUDE, Model)\r
+        \r
+        #\r
+        # Get all DynamicVpdPcds\r
+        #\r
+        RecordSet = QueryDscItem(self.TblDsc, Model, -1)       \r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in DataType.ARCH_LIST:\r
+            for IncludeFile in IncludeFiles:\r
+                if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper():\r
+                    Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, Type, '', IncludeFile[2])\r
+                    for NewItem in open(Filename, 'r').readlines():\r
+                        if CleanString(NewItem) == '':\r
+                            continue\r
+                        (K1, K2, K3, K4, K5) = GetDynamicVpdPcd(NewItem, Type, Filename, -1)\r
+                        MergeArches(Pcds,  (K1, K2, K3, K4, K5, IncludeFile[4]), Arch)\r
+\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper():\r
+                    (K1, K2, K3, K4, K5) = GetDynamicVpdPcd(Record[0], Type, ContainerFile, Record[2])\r
+                    MergeArches(Pcds,  (K1, K2, K3, K4, K5, Record[4]), Arch)\r
+\r
+        for Key in Pcds:\r
+            (Status, SkuInfoList) = self.GenSkuInfoList(Key[5], self.Platform.SkuInfos.SkuInfoList, '', '', '', '', Key[2], '')\r
+            if Status == False:\r
+                ErrorMsg = "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList, Type)\r
+                EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, ContainerFile)\r
+            Pcd = PcdClass(Key[0], '', Key[1], '', Key[3], '', Key[4], [], SkuInfoList, [])\r
+            Pcd.SupArchList = Pcds[Key]\r
+            self.Platform.DynamicPcdBuildDefinitions.append(Pcd)\r
+            \r
+    \r
+    ## Get Component \r
+    #\r
+    # Get Component section defined in Dsc file\r
+    #\r
+    # @param ContainerFile:  The file which describes the Components, used for error report\r
+    #\r
+    # @retval PlatformModuleClass() A instance for PlatformModuleClass\r
+    #\r
+    def GenComponents(self, ContainerFile):        \r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_COMPONENTS)\r
+        Components = sdict()\r
+        #\r
+        # Get all include files\r
+        #\r
+        IncludeFiles = QueryDscItem(self.TblDsc, MODEL_META_DATA_INCLUDE, MODEL_META_DATA_COMPONENT)\r
+        \r
+        #\r
+        # Get all Components\r
+        #\r
+        RecordSet = QueryDscItem(self.TblDsc, MODEL_META_DATA_COMPONENT, -1)  \r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in DataType.ARCH_LIST:\r
+            for IncludeFile in IncludeFiles:\r
+                if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper():\r
+                    Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, TAB_COMPONENTS, '', IncludeFile[2])\r
+                    for NewItem in open(Filename, 'r').readlines():\r
+                        if CleanString(NewItem) == '':\r
+                            continue\r
+                        NewItems = []\r
+                        GetComponents(open(Filename, 'r').read(), TAB_COMPONENTS, NewItems, TAB_COMMENT_SPLIT)\r
+                        for NewComponent in NewItems:\r
+                            MergeArches(Components, self.GenComponent(NewComponent, Filename), Arch)\r
+\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper():\r
+                    Lib, Bo, Pcd = [], [], []\r
+                    \r
+                    SubLibSet = QueryDscItem(self.TblDsc, MODEL_EFI_LIBRARY_CLASS, Record[3])\r
+                    for SubLib in SubLibSet:\r
+                        Lib.append(SubLib[0])\r
+                    \r
+                    SubBoSet = QueryDscItem(self.TblDsc, MODEL_META_DATA_BUILD_OPTION, Record[3])\r
+                    for SubBo in SubBoSet:\r
+                        Bo.append(SubBo[0])\r
+                    \r
+                    SubPcdSet1 = QueryDscItem(self.TblDsc, MODEL_PCD_FIXED_AT_BUILD, Record[3])\r
+                    SubPcdSet2 = QueryDscItem(self.TblDsc, MODEL_PCD_PATCHABLE_IN_MODULE, Record[3])\r
+                    SubPcdSet3 = QueryDscItem(self.TblDsc, MODEL_PCD_FEATURE_FLAG, Record[3])\r
+                    SubPcdSet4 = QueryDscItem(self.TblDsc, MODEL_PCD_DYNAMIC_EX_DEFAULT, Record[3])\r
+                    SubPcdSet5 = QueryDscItem(self.TblDsc, MODEL_PCD_DYNAMIC_DEFAULT, Record[3])\r
+                    for SubPcd in SubPcdSet1:\r
+                        Pcd.append([DataType.TAB_PCDS_FIXED_AT_BUILD, SubPcd[0]])\r
+                    for SubPcd in SubPcdSet2:\r
+                        Pcd.append([DataType.TAB_PCDS_PATCHABLE_IN_MODULE, SubPcd[0]])\r
+                    for SubPcd in SubPcdSet3:\r
+                        Pcd.append([DataType.TAB_PCDS_FEATURE_FLAG, SubPcd[0]])\r
+                    for SubPcd in SubPcdSet4:\r
+                        Pcd.append([DataType.TAB_PCDS_DYNAMIC_EX, SubPcd[0]])\r
+                    for SubPcd in SubPcdSet5:\r
+                        Pcd.append([DataType.TAB_PCDS_DYNAMIC, SubPcd[0]])\r
+                    Item = [Record[0], Lib, Bo, Pcd]\r
+                    MergeArches(Components, self.GenComponent(Item, ContainerFile), Arch)\r
+\r
+        for Key in Components.keys():\r
+            Key.SupArchList = Components[Key]\r
+            self.Platform.Modules.ModuleList.append(Key)\r
+    \r
     ## Get Component \r
     #\r
     # Get Component section defined in Dsc file\r
@@ -506,7 +904,7 @@ class Dsc(DscObject):
     #\r
     # @retval PlatformModuleClass() A instance for PlatformModuleClass\r
     #\r
-    def GenComponent(self, Item, ContainerFile):\r
+    def GenComponent(self, Item, ContainerFile, LineNo = -1):\r
         (InfFilename, ExecFilename) = GetExec(Item[0])\r
         LibraryClasses = Item[1]\r
         BuildOptions = Item[2]\r
@@ -514,8 +912,8 @@ class Dsc(DscObject):
         Component = PlatformModuleClass()\r
         Component.FilePath = NormPath(InfFilename, self._Macro)\r
         Component.ExecFilePath = NormPath(ExecFilename, self._Macro)\r
-        CheckFileType(Component.FilePath, '.Inf', ContainerFile, 'component name', Item[0])\r
-        CheckFileExist(self.WorkspaceDir, Component.FilePath, ContainerFile, 'component', Item[0])\r
+        CheckFileType(Component.FilePath, '.Inf', ContainerFile, 'component name', Item[0], LineNo)\r
+        CheckFileExist(self.WorkspaceDir, Component.FilePath, ContainerFile, 'component', Item[0], LineNo)\r
         for Lib in LibraryClasses:\r
             List = GetSplitValueList(Lib)\r
             if len(List) != 2:\r
@@ -525,8 +923,8 @@ class Dsc(DscObject):
             if LibName == "" or LibName == "NULL":\r
                 LibName = "NULL%d" % self._NullClassIndex\r
                 self._NullClassIndex += 1\r
-            CheckFileType(List[1], '.Inf', ContainerFile, 'library instance of component ', Lib)\r
-            CheckFileExist(self.WorkspaceDir, LibFile, ContainerFile, 'library instance of component', Lib)\r
+            CheckFileType(List[1], '.Inf', ContainerFile, 'library instance of component ', Lib, LineNo)\r
+            CheckFileExist(self.WorkspaceDir, LibFile, ContainerFile, 'library instance of component', Lib, LineNo)\r
             Component.LibraryClasses.LibraryList.append(PlatformLibraryClass(LibName, LibFile))\r
         for BuildOption in BuildOptions:\r
             Key = GetBuildOption(BuildOption, ContainerFile)\r
@@ -571,66 +969,6 @@ class Dsc(DscObject):
         return Component\r
     #End of GenComponent\r
 \r
-    ## Gen FeatureFlagPcds\r
-    #\r
-    # Gen FeatureFlagPcds of Dsc file as <PcdTokenSpaceGuidCName>.<TokenCName>|TRUE/FALSE\r
-    #\r
-    # @param Type:           The type of Pcd\r
-    # @param ContainerFile:  The file which describes the pcd, used for error report\r
-    #\r
-    def GenFeatureFlagPcds(self, Type = '', ContainerFile = ''):\r
-        Pcds = {}\r
-        Items = []\r
-        for Arch in DataType.ARCH_LIST:\r
-            if Type == DataType.TAB_PCDS_FEATURE_FLAG:\r
-                Items = self.Contents[Arch].PcdsFeatureFlag\r
-            else:\r
-                pass\r
-\r
-            for Item in Items:\r
-                List = GetSplitValueList(Item)\r
-                if len(List) != 2:\r
-                    RaiseParserError(Item, 'Pcds' + Type, ContainerFile, '<PcdTokenSpaceGuidCName>.<TokenCName>|TRUE/FALSE')\r
-\r
-                CheckPcdTokenInfo(List[0], 'Pcds' + Type, ContainerFile)\r
-                TokenInfo = GetSplitValueList(List[0], DataType.TAB_SPLIT)\r
-                MergeArches(Pcds, (TokenInfo[1], TokenInfo[0], List[1], Type), Arch)\r
-        for Key in Pcds:\r
-            Pcd = PcdClass(Key[0], '', Key[1], '', '', Key[2], Key[3], [], {}, [])\r
-            Pcd.SupArchList = Pcds[Key]\r
-            self.Platform.DynamicPcdBuildDefinitions.append(Pcd)\r
-\r
-    ## Gen Pcds\r
-    #\r
-    # Gen Pcd of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<Type>|<MaximumDatumSize>]\r
-    #\r
-    # @param Type:           The type of Pcd\r
-    # @param ContainerFile:  The file which describes the pcd, used for error report\r
-    #\r
-    def GenPcds(self, Type = '', ContainerFile = ''):\r
-        Pcds = {}\r
-        Items = []\r
-        for Arch in DataType.ARCH_LIST:\r
-            if Type == DataType.TAB_PCDS_PATCHABLE_IN_MODULE:\r
-                Items = self.Contents[Arch].PcdsPatchableInModule\r
-            elif Type == DataType.TAB_PCDS_FIXED_AT_BUILD:\r
-                Items = self.Contents[Arch].PcdsFixedAtBuild\r
-            else:\r
-                pass\r
-\r
-            for Item in Items:\r
-                List = GetSplitValueList(Item + DataType.TAB_VALUE_SPLIT * 2)\r
-                if len(List) < 4:\r
-                    RaiseParserError(Item, 'Pcds' + Type, ContainerFile, '<PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<Type>|<MaximumDatumSize>]')\r
-\r
-                CheckPcdTokenInfo(List[0], 'Pcds' + Type, ContainerFile)\r
-                TokenInfo = GetSplitValueList(List[0], DataType.TAB_SPLIT)\r
-                MergeArches(Pcds, (TokenInfo[1], TokenInfo[0], List[1], List[2], List[3], Type), Arch)\r
-        for Key in Pcds:\r
-            Pcd = PcdClass(Key[0], '', Key[1], Key[3], Key[4], Key[2], Key[5], [], {}, [])\r
-            Pcd.SupArchList = Pcds[Key]\r
-            self.Platform.DynamicPcdBuildDefinitions.append(Pcd)\r
-\r
     ## Gen SkuInfoList\r
     #\r
     # Gen SkuInfoList section defined in Dsc file\r
@@ -648,6 +986,7 @@ class Dsc(DscObject):
     # @retval (True, SkuInfoList)  Found in section SkuId of Dsc file\r
     #\r
     def GenSkuInfoList(self, SkuNameList, SkuInfo, VariableName = '', VariableGuid = '', VariableOffset = '', HiiDefaultValue = '', VpdOffset = '', DefaultValue = ''):\r
+        SkuNameList = GetSplitValueList(SkuNameList)\r
         if SkuNameList == None or SkuNameList == [] or SkuNameList == ['']:\r
             SkuNameList = ['DEFAULT']\r
         SkuInfoList = {}\r
@@ -659,114 +998,427 @@ class Dsc(DscObject):
 \r
         return True, SkuInfoList\r
 \r
-    ## Gen DynamicDefaultPcds\r
+    ## Parse Include statement\r
     #\r
-    # Gen DynamicDefaultPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<DatumTyp>[|<MaxDatumSize>]]\r
+    # Get include file path\r
     #\r
-    # @param Type:           The type of Pcd\r
-    # @param ContainerFile:  The file which describes the pcd, used for error report\r
+    # 1. Insert a record into TblFile ???\r
+    # 2. Insert a record into TblDsc\r
+    # Value1: IncludeFilePath\r
     #\r
-    def GenDynamicDefaultPcds(self, Type = '', ContainerFile = ''):\r
-        Pcds = {}\r
-        Items = []\r
-        SkuInfoList = {}\r
-        for Arch in DataType.ARCH_LIST:\r
-            if Type == DataType.TAB_PCDS_DYNAMIC_DEFAULT:\r
-                Items = self.Contents[Arch].PcdsDynamicDefault\r
-            elif Type == DataType.TAB_PCDS_DYNAMIC_EX_DEFAULT:\r
-                Items = self.Contents[Arch].PcdsDynamicExDefault\r
-            else:\r
-                pass\r
-\r
-            for Item in Items:\r
-                List = GetSplitValueList(Item[0] + DataType.TAB_VALUE_SPLIT * 2)\r
-                if len(List) < 4 or len(List) > 8:\r
-                    RaiseParserError(Item[0], 'Pcds' + Type, ContainerFile, '<PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<DatumTyp>[|<MaxDatumSize>]]')\r
-\r
-                CheckPcdTokenInfo(List[0], 'Pcds' + Type, ContainerFile)\r
-                TokenInfo = GetSplitValueList(List[0], DataType.TAB_SPLIT)\r
-                MergeArches(Pcds, (TokenInfo[1], TokenInfo[0], List[1], List[2], List[3], Type), Arch)\r
-        for Key in Pcds:\r
-            (Status, SkuInfoList) = self.GenSkuInfoList(Item[1], self.Platform.SkuInfos.SkuInfoList, '', '', '', '', '', Key[2])\r
-            if Status == False:\r
-                ErrorMsg = "SKUID '%s' of '%s' is not defined" % (SkuInfoList, Type)\r
-                EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, File=self.Platform.Header.FullPath)\r
-            Pcd = PcdClass(Key[0], '', Key[1], Key[3], Key[4], Key[2], Key[5], [], SkuInfoList, [])\r
-            Pcd.SupArchList = Pcds[Key]\r
-            self.Platform.DynamicPcdBuildDefinitions.append(Pcd)\r
+    # @param LineValue:  The line of incude statement \r
+    def ParseInclude(self, LineValue, StartLine, Table, FileID, Filename, SectionName, Model, Arch):\r
+        EdkLogger.debug(EdkLogger.DEBUG_2, "!include statement '%s' found in section %s" % (LineValue, SectionName))\r
+        SectionModel = Section[SectionName.upper()]\r
+        IncludeFile = CleanString(LineValue[LineValue.upper().find(DataType.TAB_INCLUDE.upper() + ' ') + len(DataType.TAB_INCLUDE + ' ') : ])\r
+        Table.Insert(Model, IncludeFile, '', '', Arch, SectionModel, FileID, StartLine, -1, StartLine, -1, 0)\r
+    \r
+    ## Parse DEFINE statement\r
+    #\r
+    # Get DEFINE macros\r
+    #\r
+    # 1. Insert a record into TblDsc\r
+    # Value1: Macro Name\r
+    # Value2: Macro Value\r
+    #\r
+    def ParseDefine(self, LineValue, StartLine, Table, FileID, Filename, SectionName, Model, Arch):\r
+        EdkLogger.debug(EdkLogger.DEBUG_2, "DEFINE statement '%s' found in section %s" % (LineValue, SectionName))\r
+        SectionModel = Section[SectionName.upper()]\r
+        Define = GetSplitValueList(CleanString(LineValue[LineValue.upper().find(DataType.TAB_DEFINE.upper() + ' ') + len(DataType.TAB_DEFINE + ' ') : ]), TAB_EQUAL_SPLIT, 1)\r
+        Table.Insert(Model, Define[0], Define[1], '', Arch, SectionModel, FileID, StartLine, -1, StartLine, -1, 0)\r
+    \r
+    ## Parse Defines section\r
+    #\r
+    # Get one item in defines section\r
+    #\r
+    # Value1: Item Name\r
+    # Value2: Item Value\r
+    #\r
+    def ParseDefinesSection(self, LineValue, StartLine, Table, FileID, Filename, SectionName, Model, Arch):\r
+        EdkLogger.debug(EdkLogger.DEBUG_2, "Parse '%s' found in section %s" % (LineValue, SectionName))\r
+        Defines = GetSplitValueList(LineValue, TAB_EQUAL_SPLIT, 1)\r
+        if len(Defines) != 2:\r
+            RaiseParserError(LineValue, SectionName, Filename, '', StartLine)\r
+        self.TblDsc.Insert(Model, Defines[0], Defines[1], '', Arch, -1, FileID, StartLine, -1, StartLine, -1, 0)\r
 \r
-    ## Gen DynamicHiiPcds\r
+    ## Insert conditional statements\r
     #\r
-    # Gen DynamicHiiPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<String>|<VariableGuidCName>|<VariableOffset>[|<DefaultValue>[|<MaximumDatumSize>]]\r
+    # Pop an item from IfDefList\r
+    # Insert conditional statements to database\r
     #\r
-    # @param Type:           The type of Pcd\r
-    # @param ContainerFile:  The file which describes the pcd, used for error report\r
+    # @param Filename:   Path of parsing file\r
+    # @param IfDefList:  A list stored current conditional statements\r
+    # @param EndLine:    The end line no\r
+    # @param ArchList:   Support arch list\r
     #\r
-    def GenDynamicHiiPcds(self, Type = '', ContainerFile = ''):\r
-        Pcds = {}\r
-        Items = []\r
-        SkuInfoList = {}\r
-        for Arch in DataType.ARCH_LIST:\r
-            if Type == DataType.TAB_PCDS_DYNAMIC_HII:\r
-                Items = self.Contents[Arch].PcdsDynamicHii\r
-            elif Type == DataType.TAB_PCDS_DYNAMIC_EX_HII:\r
-                Items = self.Contents[Arch].PcdsDynamicExHii\r
-            else:\r
-                pass\r
-\r
-            for Item in Items:\r
-                List = GetSplitValueList(Item[0] + DataType.TAB_VALUE_SPLIT * 2)\r
-                if len(List) < 6:\r
-                    RaiseParserError(Item[0], 'Pcds' + Type, ContainerFile, '<PcdTokenSpaceGuidCName>.<TokenCName>|<String>|<VariableGuidCName>|<VariableOffset>[|<DefaultValue>[|<MaximumDatumSize>]]')\r
-\r
-                CheckPcdTokenInfo(List[0], 'Pcds' + Type, ContainerFile)\r
-                TokenInfo = GetSplitValueList(List[0], DataType.TAB_SPLIT)\r
-                MergeArches(Pcds, (TokenInfo[1], TokenInfo[0], List[1], List[2], List[3], List[4], List[5], Type), Arch)\r
-        for Key in Pcds:\r
-            (Status, SkuInfoList) = self.GenSkuInfoList(Item[1], self.Platform.SkuInfos.SkuInfoList, Key[2], Key[3], Key[4], Key[5], '', '')\r
-            if Status == False:\r
-                ErrorMsg = "SKUID '%s' of '%s' is not defined" % (SkuInfoList, Type)\r
-                EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, File=self.Platform.Header.FullPath)\r
-            Pcd = PcdClass(Key[0], '', Key[1], '', Key[6], Key[5], Key[7], [], SkuInfoList, [])\r
-            Pcd.SupArchList = Pcds[Key]\r
-            self.Platform.DynamicPcdBuildDefinitions.append(Pcd)\r
+    def InsertConditionalStatement(self, Filename, FileID, BelongsToItem, IfDefList, EndLine, ArchList):\r
+        (Value1, Value2, Value3, Model, StartColumn, EndColumn, Enabled) = ('', '', '', -1, -1, -1, 0)\r
+        if IfDefList == []:\r
+            ErrorMsg = 'Not suited conditional statement in file %s' % Filename\r
+            EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, Filename)\r
+        else:\r
+            #\r
+            # Get New Dsc item ID\r
+            #\r
+            DscID = self.TblDsc.GetCount() + 1\r
+            \r
+            #\r
+            # Pop the conditional statements which is closed\r
+            #\r
+            PreviousIf = IfDefList.pop()\r
+            EdkLogger.debug(EdkLogger.DEBUG_5, 'Previous IfDef: ' + str(PreviousIf))\r
+            \r
+            #\r
+            # !ifdef and !ifndef\r
+            #\r
+            if PreviousIf[2] in (MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF):\r
+                Value1 = PreviousIf[0]\r
+                Model = PreviousIf[2]\r
+                self.TblDsc.Insert(Model, Value1, Value2, Value3, ArchList, BelongsToItem, FileID, PreviousIf[1], StartColumn, EndLine, EndColumn, Enabled)\r
+            #\r
+            # !if and !elseif\r
+            #\r
+            elif PreviousIf[2] in (MODEL_META_DATA_CONDITIONAL_STATEMENT_IF, Model):\r
+                List = PreviousIf[0].split(' ')\r
+                Value1 = List[0]\r
+                Value2 = List[1]\r
+                Value3 = List[2]\r
+                Value3 = SplitString(Value3)\r
+                Model = PreviousIf[2]\r
+                self.TblDsc.Insert(Model, Value1, Value2, Value3, ArchList, BelongsToItem, FileID, PreviousIf[1], StartColumn, EndLine, EndColumn, Enabled)\r
+            #\r
+            # !else\r
+            #\r
+            elif PreviousIf[2] in (MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE, Model):\r
+                Value1 = PreviousIf[0].strip()\r
+                Model = PreviousIf[2]\r
+                self.TblDsc.Insert(Model, Value1, Value2, Value3, ArchList, BelongsToItem, FileID, PreviousIf[1], StartColumn, EndLine, EndColumn, Enabled)\r
 \r
-    ## Gen DynamicVpdPcds\r
+    ## Load Dsc file\r
     #\r
-    # Gen DynamicVpdPcds of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<VpdOffset>[|<MaximumDatumSize>]\r
+    # Load the file if it exists\r
     #\r
-    # @param Type:           The type of Pcd\r
-    # @param ContainerFile:  The file which describes the pcd, used for error report\r
+    # @param Filename:  Input value for filename of Dsc file\r
     #\r
-    def GenDynamicVpdPcds(self, Type = '', ContainerFile = ''):\r
-        Pcds = {}\r
-        Items = []\r
-        SkuInfoList = {}\r
-        for Arch in DataType.ARCH_LIST:\r
-            if Type == DataType.TAB_PCDS_DYNAMIC_VPD:\r
-                Items = self.Contents[Arch].PcdsDynamicVpd\r
-            elif Type == DataType.TAB_PCDS_DYNAMIC_EX_VPD:\r
-                Items = self.Contents[Arch].PcdsDynamicExVpd\r
-            else:\r
-                pass\r
-\r
-            for Item in Items:\r
-                List = GetSplitValueList(Item[0] + DataType.TAB_VALUE_SPLIT)\r
-                if len(List) < 3:\r
-                    RaiseParserError(Item[0], 'Pcds' + Type, ContainerFile, '<PcdTokenSpaceGuidCName>.<TokenCName>|<VpdOffset>[|<MaximumDatumSize>]')\r
-\r
-                CheckPcdTokenInfo(List[0], 'Pcds' + Type, ContainerFile)\r
-                TokenInfo = GetSplitValueList(List[0], DataType.TAB_SPLIT)\r
-                MergeArches(Pcds, (TokenInfo[1], TokenInfo[0], List[1], List[2], Type), Arch)\r
-        for Key in Pcds:\r
-            (Status, SkuInfoList) = self.GenSkuInfoList(Item[1], self.Platform.SkuInfos.SkuInfoList, '', '', '', '', Key[2], '')\r
-            if Status == False:\r
-                ErrorMsg = "SKUID '%s' of '%s' is not defined." % (SkuInfoList, Type)\r
-                EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, File=self.Platform.Header.FullPath)\r
-            Pcd = PcdClass(Key[0], '', Key[1], '', Key[3], '', Key[4], [], SkuInfoList, [])\r
-            Pcd.SupArchList = Pcds[Key]\r
-            self.Platform.DynamicPcdBuildDefinitions.append(Pcd)\r
+    def LoadDscFile(self, Filename):\r
+        #\r
+        # Insert a record for file\r
+        #\r
+        Filename = NormPath(Filename)\r
+        self.Identification.FileFullPath = Filename\r
+        (self.Identification.FileRelativePath, self.Identification.FileName) = os.path.split(Filename)\r
+        FileID = self.TblFile.InsertFile(Filename, MODEL_FILE_DSC)\r
+        \r
+        #\r
+        # Init DscTable\r
+        #\r
+        self.TblDsc.Table = "Dsc%s" % FileID\r
+        self.TblDsc.Create()\r
+        \r
+        #\r
+        # Init common datas\r
+        #\r
+        IfDefList, SectionItemList, CurrentSection, ArchList, ThirdList, IncludeFiles = \\r
+        [], [], TAB_UNKNOWN, [], [], []\r
+        LineNo = 0\r
+        \r
+        #\r
+        # Parse file content\r
+        #\r
+        FileContent = open(Filename, 'r').read()\r
+        for Line in FileContent.splitlines():\r
+            LineNo = LineNo + 1\r
+            #\r
+            # Reomve spaces in head and tail\r
+            #\r
+            Line = Line.strip()\r
+            \r
+            #\r
+            # Ignore comments\r
+            #\r
+            if Line.startswith(TAB_COMMENT_SPLIT):\r
+                continue\r
+            \r
+            #\r
+            # Remove comments at tail and remove spaces again\r
+            #\r
+            Line = CleanString(Line)\r
+            if Line == '':\r
+                continue\r
+            \r
+            #\r
+            # Find a new section tab\r
+            # First insert previous section items\r
+            # And then parse the content of the new section\r
+            #\r
+            if Line.startswith(TAB_SECTION_START) and Line.endswith(TAB_SECTION_END):\r
+                #\r
+                # Insert items data of previous section\r
+                #\r
+                self.InsertSectionItemsIntoDatabase(FileID, Filename, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList)\r
+                #\r
+                # Parse the new section\r
+                #\r
+                SectionItemList = []\r
+                ArchList = []\r
+                ThirdList = []\r
+                \r
+                LineList = GetSplitValueList(Line[len(TAB_SECTION_START):len(Line) - len(TAB_SECTION_END)], TAB_COMMA_SPLIT)\r
+                for Item in LineList:\r
+                    ItemList = GetSplitValueList(Item, TAB_SPLIT)\r
+                    CurrentSection = ItemList[0]\r
+                    if CurrentSection.upper() not in self.KeyList:\r
+                        RaiseParserError(Line, CurrentSection, Filename, '', LineNo)\r
+                    ItemList.append('')\r
+                    ItemList.append('')\r
+                    if len(ItemList) > 5:\r
+                        RaiseParserError(Line, CurrentSection, Filename, '', LineNo)\r
+                    else:\r
+                        if ItemList[1] != '' and ItemList[1].upper() not in ARCH_LIST_FULL:\r
+                            EdkLogger.error("Parser", PARSER_ERROR, "Invalid Arch definition '%s' found" % ItemList[1], File=Filename, Line=LineNo)\r
+                        ArchList.append(ItemList[1].upper())\r
+                        ThirdList.append(ItemList[2])\r
+\r
+                continue\r
+            \r
+            #\r
+            # Not in any defined section\r
+            #\r
+            if CurrentSection == TAB_UNKNOWN:\r
+                ErrorMsg = "%s is not in any defined section" % Line\r
+                EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, File=Filename, Line=LineNo)\r
+\r
+            #\r
+            # Add a section item\r
+            #\r
+            SectionItemList.append([Line, LineNo])\r
+            # End of parse\r
+        #End of For\r
+        \r
+        #\r
+        # Insert items data of last section\r
+        #\r
+        self.InsertSectionItemsIntoDatabase(FileID, Filename, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList)\r
+        \r
+        #\r
+        # Parse conditional statements\r
+        #\r
+        self.ParseConditionalStatement()\r
+        \r
+        #\r
+        # Replace all DEFINE macros with its actual values\r
+        #\r
+        #ParseDefineMacro2(self.TblDsc, self.RecordSet, GlobalData.gGlobalDefines)\r
+        ParseDefineMacro(self.TblDsc, GlobalData.gGlobalDefines)\r
+        \r
+    \r
+    ## ParseConditionalStatement\r
+    #\r
+    # Search all conditional statement and disable no match records\r
+    #\r
+    def ParseConditionalStatement(self):\r
+        #\r
+        # Disabled all !if/!elif/!ifdef statements without DEFINE\r
+        #\r
+        SqlCommand = """select A.StartLine, A.EndLine from %s as A \r
+                        where A.Model in (%s, %s, %s)\r
+                        and A.Enabled = 0\r
+                        and A.Value1 not in (select B.Value1 from %s as B \r
+                                             where B.Model = %s\r
+                                             and B.Enabled = 0\r
+                                             and A.StartLine > B.StartLine\r
+                                             and A.Arch = B.Arch\r
+                                             and A.BelongsToItem = B.BelongsToItem\r
+                                             and A.BelongsToFile = B.BelongsToFile) """ % \\r
+                        (self.TblDsc.Table, \\r
+                         MODEL_META_DATA_CONDITIONAL_STATEMENT_IF, MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF, \\r
+                         self.TblDsc.Table, \\r
+                         MODEL_META_DATA_DEFINE)\r
+        RecordSet = self.TblDsc.Exec(SqlCommand)\r
+        for Record in RecordSet:\r
+            SqlCommand = """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" %(self.TblDsc.Table, Record[0], Record[1])\r
+            self.TblDsc.Exec(SqlCommand)\r
 \r
+        #\r
+        # Disabled !ifndef with DEFINE\r
+        #\r
+        SqlCommand = """select A.StartLine, A.EndLine from %s as A \r
+                        where A.Model = %s\r
+                        and A.Enabled = 0\r
+                        and A.Value1 in (select B.Value1 from %s as B \r
+                                         where B.Model = %s\r
+                                         and B.Enabled = 0\r
+                                         and A.StartLine > B.StartLine\r
+                                         and A.Arch = B.Arch\r
+                                         and A.BelongsToItem = B.BelongsToItem\r
+                                         and A.BelongsToFile = B.BelongsToFile)""" % \\r
+                        (self.TblDsc.Table, \\r
+                         MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF, \\r
+                         self.TblDsc.Table, \\r
+                         MODEL_META_DATA_DEFINE)\r
+        RecordSet = self.TblDsc.Exec(SqlCommand)\r
+        for Record in RecordSet:\r
+            SqlCommand = """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" %(self.TblDsc.Table, Record[0], Record[1])\r
+            EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)\r
+            self.Cur.execute(SqlCommand)\r
+        \r
+        #\r
+        # Disabled !if, !elif and !else with un-match value\r
+        #\r
+        SqlCommand = """select A.Model, A.Value1, A.Value2, A.Value3, A.StartLine, A.EndLine, B.Value2 from %s as A join %s as B\r
+                        where A.Model in (%s, %s)\r
+                        and A.Enabled = 0\r
+                        and B.Enabled = 0\r
+                        and B.Model = %s\r
+                        and A.Value1 = B.Value1\r
+                        and A.StartLine > B.StartLine\r
+                        and A.BelongsToItem = B.BelongsToItem\r
+                        and A.BelongsToFile = B.BelongsToFile""" % \\r
+                        (self.TblDsc.Table, self.TblDsc.Table, \\r
+                         MODEL_META_DATA_CONDITIONAL_STATEMENT_IF, MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE, \\r
+                         MODEL_META_DATA_DEFINE)\r
+        RecordSet = self.TblDsc.Exec(SqlCommand)\r
+        DisabledList = []\r
+        for Record in RecordSet:\r
+            if Record[0] == MODEL_META_DATA_CONDITIONAL_STATEMENT_IF:\r
+                if not self.Compare(Record[6], Record[2], Record[3]):\r
+                    SqlCommand = """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" %(self.TblDsc.Table, Record[4], Record[5])\r
+                    self.TblDsc.Exec(SqlCommand)\r
+                else:\r
+                    DisabledList.append(Record[1])\r
+                continue\r
+            if Record[0] == MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE and Record[1] in DisabledList:\r
+                SqlCommand = """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" %(self.TblDsc.Table, Record[4], Record[5])\r
+                self.TblDsc.Exec(SqlCommand)         \r
+    \r
+    ## Compare\r
+    #\r
+    # Compare two values\r
+    # @param Value1:\r
+    # @param CompareType:\r
+    # @param Value2:   \r
+    #\r
+    def Compare(self, Value1, CompareType, Value2):\r
+        Command = """Value1 %s Value2""" %CompareType\r
+        return eval(Command)\r
+    \r
+    ## First time to insert records to database\r
+    # \r
+    # Insert item data of a section to database\r
+    # @param FileID:           The ID of belonging file\r
+    # @param Filename:         The name of belonging file\r
+    # @param CurrentSection:   The name of currect section\r
+    # @param SectionItemList:  A list of items of the section\r
+    # @param ArchList:         A list of arches\r
+    # @param ThirdList:        A list of third parameters, ModuleType for LibraryClass and SkuId for Dynamic Pcds\r
+    # @param IfDefList:        A list of all conditional statements\r
+    #\r
+    def InsertSectionItemsIntoDatabase(self, FileID, Filename, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList):\r
+        #\r
+        # Insert each item data of a section\r
+        #\r
+        for Index in range(0, len(ArchList)):\r
+            Arch = ArchList[Index]\r
+            Third = ThirdList[Index]\r
+            if Arch == '':\r
+                Arch = TAB_ARCH_COMMON.upper()\r
+            \r
+            Model = Section[CurrentSection.upper()]\r
+            #Records = self.RecordSet[Model]\r
+\r
+            for SectionItem in SectionItemList:\r
+                BelongsToItem, EndLine, EndColumn = -1, -1, -1\r
+                LineValue, StartLine, EndLine = SectionItem[0], SectionItem[1], SectionItem[1]\r
+                \r
+                \r
+                EdkLogger.debug(4, "Parsing %s ..." %LineValue)\r
+                #\r
+                # Parse '!ifdef'\r
+                #\r
+                if LineValue.upper().find(TAB_IF_DEF.upper()) > -1:\r
+                    IfDefList.append((LineValue[len(TAB_IF_N_DEF):].strip(), StartLine, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF))\r
+                    continue\r
+                \r
+                #\r
+                # Parse '!ifndef'\r
+                #\r
+                if LineValue.upper().find(TAB_IF_N_DEF.upper()) > -1:\r
+                    IfDefList.append((LineValue[len(TAB_IF_N_DEF):].strip(), StartLine, MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF))\r
+                    continue\r
+                \r
+                #\r
+                # Parse '!endif'\r
+                #\r
+                if LineValue.upper().find(TAB_END_IF.upper()) > -1:\r
+                    self.InsertConditionalStatement(Filename, FileID, Model, IfDefList, StartLine, Arch)\r
+                    continue\r
+                #\r
+                # Parse '!if'\r
+                #\r
+                if LineValue.upper().find(TAB_IF.upper()) > -1:\r
+                    IfDefList.append((LineValue[len(TAB_IF):].strip(), StartLine, MODEL_META_DATA_CONDITIONAL_STATEMENT_IF))\r
+                    continue\r
+                \r
+                #\r
+                # Parse '!elseif'\r
+                #\r
+                if LineValue.upper().find(TAB_ELSE_IF.upper()) > -1:\r
+                    self.InsertConditionalStatement(Filename, FileID, Model, IfDefList, StartLine - 1, Arch)\r
+                    IfDefList.append((LineValue[len(TAB_ELSE_IF):].strip(), StartLine, MODEL_META_DATA_CONDITIONAL_STATEMENT_IF))\r
+                    continue\r
+                \r
+                #\r
+                # Parse '!else'\r
+                #\r
+                if LineValue.upper().find(TAB_ELSE.upper()) > -1:\r
+                    Key = IfDefList[-1][0].split(' ' , 1)[0].strip()\r
+                    self.InsertConditionalStatement(Filename, FileID, Model, IfDefList, StartLine, Arch)\r
+                    IfDefList.append((Key, StartLine, MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE))\r
+                    continue\r
+            \r
+                #\r
+                # Parse !include statement first\r
+                #\r
+                if LineValue.upper().find(DataType.TAB_INCLUDE.upper() + ' ') > -1:\r
+                    self.ParseInclude(LineValue, StartLine, self.TblDsc, FileID, Filename, CurrentSection, MODEL_META_DATA_INCLUDE, Arch)\r
+                    continue\r
+                \r
+                #\r
+                # And then parse DEFINE statement\r
+                #\r
+                if LineValue.upper().find(DataType.TAB_DEFINE.upper() + ' ') > -1:\r
+                    self.ParseDefine(LineValue, StartLine, self.TblDsc, FileID, Filename, CurrentSection, MODEL_META_DATA_DEFINE, Arch)\r
+                    continue\r
+                \r
+                #\r
+                # At last parse other sections\r
+                #\r
+                if CurrentSection == TAB_LIBRARY_CLASSES or CurrentSection in TAB_PCD_DYNAMIC_TYPE_LIST or CurrentSection in TAB_PCD_DYNAMIC_EX_TYPE_LIST:\r
+                    ID = self.TblDsc.Insert(Model, LineValue, Third, '', Arch, -1, FileID, StartLine, -1, StartLine, -1, 0)\r
+                    #Records.append([LineValue, Arch, StartLine, ID, Third])\r
+                    continue\r
+                elif CurrentSection != TAB_COMPONENTS:\r
+                    ID = self.TblDsc.Insert(Model, LineValue, '', '', Arch, -1, FileID, StartLine, -1, StartLine, -1, 0)\r
+                    #Records.append([LineValue, Arch, StartLine, ID, Third])\r
+                    continue\r
+            \r
+            #\r
+            # Parse COMPONENT section\r
+            #\r
+            if CurrentSection == TAB_COMPONENTS:\r
+                Components = []\r
+                GetComponent(SectionItemList, Components)\r
+                for Component in Components:\r
+                    EdkLogger.debug(4, "Parsing component %s ..." %Component)\r
+                    DscItmeID = self.TblDsc.Insert(MODEL_META_DATA_COMPONENT, Component[0], '', '', Arch, -1, FileID, StartLine, -1, StartLine, -1, 0)\r
+                    for Item in Component[1]:\r
+                        self.TblDsc.Insert(MODEL_EFI_LIBRARY_CLASS, Item, '', '', Arch, DscItmeID, FileID, StartLine, -1, StartLine, -1, 0)\r
+                    for Item in Component[2]:\r
+                        self.TblDsc.Insert(MODEL_META_DATA_BUILD_OPTION, Item, '', '', Arch, DscItmeID, FileID, StartLine, -1, StartLine, -1, 0)\r
+                    for Item in Component[3]:\r
+                        Model = Section[Item[0].upper()]\r
+                        self.TblDsc.Insert(Model, Item[1], '', '', Arch, DscItmeID, FileID, StartLine, -1, StartLine, -1, 0)\r
+                \r
     ## Show detailed information of Dsc\r
     #\r
     # Print all members and their values of Dsc class\r
@@ -788,25 +1440,27 @@ class Dsc(DscObject):
     #\r
     def ShowPlatform(self):\r
         M = self.Platform\r
-        print 'Filename =', M.Header.FileName\r
-        print 'FullPath =', M.Header.FullPath\r
-        print 'BaseName =', M.Header.Name\r
-        print 'Guid =', M.Header.Guid\r
-        print 'Version =', M.Header.Version\r
-        print 'DscSpecification =', M.Header.DscSpecification\r
-        print 'SkuId =', M.Header.SkuIdName\r
-        print 'SupArchList =', M.Header.SupArchList\r
-        print 'BuildTargets =', M.Header.BuildTargets\r
-        print 'OutputDirectory =', M.Header.OutputDirectory\r
-        print 'BuildNumber =', M.Header.BuildNumber\r
-        print 'MakefileName =', M.Header.MakefileName\r
+        for Arch in M.Header.keys():\r
+            print '\nArch =', Arch\r
+            print 'Filename =', M.Header[Arch].FileName\r
+            print 'FullPath =', M.Header[Arch].FullPath\r
+            print 'BaseName =', M.Header[Arch].Name\r
+            print 'Guid =', M.Header[Arch].Guid\r
+            print 'Version =', M.Header[Arch].Version\r
+            print 'DscSpecification =', M.Header[Arch].DscSpecification\r
+            print 'SkuId =', M.Header[Arch].SkuIdName\r
+            print 'SupArchList =', M.Header[Arch].SupArchList\r
+            print 'BuildTargets =', M.Header[Arch].BuildTargets\r
+            print 'OutputDirectory =', M.Header[Arch].OutputDirectory\r
+            print 'BuildNumber =', M.Header[Arch].BuildNumber\r
+            print 'MakefileName =', M.Header[Arch].MakefileName\r
+            print 'BsBaseAddress =', M.Header[Arch].BsBaseAddress\r
+            print 'RtBaseAddress =', M.Header[Arch].RtBaseAddress\r
+            print 'Define =', M.Header[Arch].Define\r
         print 'Fdf =', M.FlashDefinitionFile.FilePath\r
-        print 'BsBaseAddress =', M.Header.BsBaseAddress\r
-        print 'RtBaseAddress =', M.Header.RtBaseAddress\r
-        print 'Define =', M.Header.Define\r
         print '\nBuildOptions =', M.BuildOptions, M.BuildOptions.IncludeFiles\r
         for Item in M.BuildOptions.BuildOptionList:\r
-            print '\t', Item.ToolChainFamily, Item.ToolChain, Item.Option, Item.SupArchList\r
+            print '\t', 'ToolChainFamily =', Item.ToolChainFamily, 'ToolChain =', Item.ToolChain, 'Option =', Item.Option, 'Arch =', Item.SupArchList\r
         print '\nSkuIds =', M.SkuInfos.SkuInfoList, M.SkuInfos.IncludeFiles\r
         print '\nLibraries =', M.Libraries, M.Libraries.IncludeFiles\r
         for Item in M.Libraries.LibraryList:\r
@@ -835,7 +1489,16 @@ class Dsc(DscObject):
 # script.\r
 #\r
 if __name__ == '__main__':\r
+    EdkLogger.Initialize()\r
+    EdkLogger.SetLevel(EdkLogger.DEBUG_0)\r
+    \r
     W = os.getenv('WORKSPACE')\r
     F = os.path.join(W, 'Nt32Pkg/Nt32Pkg.dsc')\r
-    P = Dsc(os.path.normpath(F), True, True, W)\r
+    \r
+    Db = Database.Database(DATABASE_PATH)\r
+    Db.InitDatabase()\r
+    \r
+    P = Dsc(os.path.normpath(F), False, True, W, Db)\r
     P.ShowPlatform()\r
+    \r
+    Db.Close()\r
index b5c72ed..0e9c105 100755 (executable)
@@ -23,7 +23,9 @@ from DscClassObject import *
 from String import *\r
 from BuildToolError import *\r
 from Misc import sdict\r
-from CommonDataClass.CommonClass import *\r
+#from CommonDataClass.CommonClass import *\r
+import Database as Database\r
+import time as time\r
 \r
 ## PcdClassObject\r
 #\r
@@ -452,13 +454,19 @@ class WorkspaceBuild(object):
         for Arch in DataType.ARCH_LIST:\r
             self.Build[Arch] = ItemBuild(Arch)\r
 \r
+        #\r
+        # Init build database\r
+        #\r
+        self.Db = Database.Database(DATABASE_PATH)\r
+        self.Db.InitDatabase()\r
+        \r
         #\r
         # Get active platform\r
         #\r
         self.DscFileName = NormPath(ActivePlatform)\r
         File = self.WorkspaceFile(self.DscFileName)\r
         if os.path.exists(File) and os.path.isfile(File):\r
-            self.DscDatabase[self.DscFileName] = Dsc(File, True, True, self.WorkspaceDir)\r
+            self.DscDatabase[self.DscFileName] = Dsc(File, False, True, self.WorkspaceDir, self.Db)\r
         else:\r
             EdkLogger.error("AutoGen", FILE_NOT_FOUND, ExtraData = File)\r
 \r
@@ -471,9 +479,18 @@ class WorkspaceBuild(object):
             #\r
             # Get global information\r
             #\r
-            self.SupArchList = Platform.Header.SupArchList\r
-            self.BuildTarget = Platform.Header.BuildTargets\r
-            self.SkuId = Platform.Header.SkuIdName\r
+            Tmp = set()\r
+            for Arch in DataType.ARCH_LIST:\r
+                for Item in Platform.Header[Arch].SupArchList:\r
+                    Tmp.add(Item)\r
+            self.SupArchList = list(Tmp)\r
+            Tmp = set()\r
+            for Arch in DataType.ARCH_LIST:\r
+                for Item in Platform.Header[Arch].BuildTargets:\r
+                    Tmp.add(Item)\r
+            self.BuildTarget = list(Tmp)\r
+            for Arch in self.SupArchList:\r
+                self.SkuId = Platform.Header[Arch].SkuIdName\r
             self.Fdf = Platform.FlashDefinitionFile.FilePath\r
 \r
             #\r
@@ -528,13 +545,13 @@ class WorkspaceBuild(object):
                 # Defines\r
                 #\r
                 Pb.DescFilePath = Dsc\r
-                Pb.PlatformName = Platform.Header.Name\r
-                Pb.Guid = Platform.Header.Guid\r
-                Pb.Version = Platform.Header.Version\r
-                Pb.DscSpecification = Platform.Header.DscSpecification\r
-                Pb.OutputDirectory = Platform.Header.OutputDirectory\r
+                Pb.PlatformName = Platform.Header[Arch].Name\r
+                Pb.Guid = Platform.Header[Arch].Guid\r
+                Pb.Version = Platform.Header[Arch].Version\r
+                Pb.DscSpecification = Platform.Header[Arch].DscSpecification\r
+                Pb.OutputDirectory = Platform.Header[Arch].OutputDirectory\r
                 Pb.FlashDefinition = Platform.FlashDefinitionFile.FilePath\r
-                Pb.BuildNumber = Platform.Header.BuildNumber\r
+                Pb.BuildNumber = Platform.Header[Arch].BuildNumber\r
 \r
                 #\r
                 # SkuId\r
@@ -632,9 +649,9 @@ class WorkspaceBuild(object):
                 # Defines\r
                 #\r
                 Pb.DescFilePath = Dec\r
-                Pb.PackageName = Package.Header.Name\r
-                Pb.Guid = Package.Header.Guid\r
-                Pb.Version = Package.Header.Version\r
+                Pb.PackageName = Package.Header[Arch].Name\r
+                Pb.Guid = Package.Header[Arch].Guid\r
+                Pb.Version = Package.Header[Arch].Version\r
 \r
                 #\r
                 # Protocols\r
@@ -1124,6 +1141,8 @@ class WorkspaceBuild(object):
         self.GenPlatformDatabase(PcdsSet)\r
         self.GenModuleDatabase(InfList)\r
         \r
+        self.Db.Close()\r
+        \r
         #\r
         # Update Libraries Of Platform\r
         #\r
@@ -1227,7 +1246,7 @@ class WorkspaceBuild(object):
         File = self.WorkspaceFile(InfFileName)\r
         if os.path.exists(File) and os.path.isfile(File):\r
             if InfFileName not in self.InfDatabase:\r
-                self.InfDatabase[InfFileName] = Inf(File, True, True, self.WorkspaceDir)\r
+                self.InfDatabase[InfFileName] = Inf(File, False, True, self.WorkspaceDir, self.Db, self.SupArchList)\r
         else:\r
             EdkLogger.error("AutoGen", FILE_NOT_FOUND, ExtraData=File)\r
 \r
@@ -1241,7 +1260,7 @@ class WorkspaceBuild(object):
         File = self.WorkspaceFile(DecFileName)\r
         if os.path.exists(File) and os.path.isfile(File):\r
             if DecFileName not in self.DecDatabase:\r
-                self.DecDatabase[DecFileName] = Dec(File, True, True, self.WorkspaceDir)\r
+                self.DecDatabase[DecFileName] = Dec(File, False, True, self.WorkspaceDir, self.Db, self.SupArchList)\r
         else:\r
             EdkLogger.error("AutoGen", FILE_NOT_FOUND, ExtraData=File)\r
 \r
@@ -1646,7 +1665,12 @@ class WorkspaceBuild(object):
 # script.\r
 #\r
 if __name__ == '__main__':\r
+    print 'Start!', time.strftime('%H:%M:%S', time.localtime())\r
+    EdkLogger.Initialize()\r
+    EdkLogger.SetLevel(EdkLogger.QUIET)\r
+    \r
     W = os.getenv('WORKSPACE')\r
     Ewb = WorkspaceBuild('Nt32Pkg/Nt32Pkg.dsc', W)\r
-    Ewb.GenBuildDatabase({('PcdDevicePathSupportDevicePathFromText, gEfiMdeModulePkgTokenSpaceGuid') : 'KKKKKKKKKKKKKKKKKKKKK'}, ['Test.Inf'])\r
+    Ewb.GenBuildDatabase({('PcdDevicePathSupportDevicePathFromText', 'gEfiMdeModulePkgTokenSpaceGuid') : 'KKKKKKKKKKKKKKKKKKKKK'}, ['Test.Inf'])\r
+    print 'Done!', time.strftime('%H:%M:%S', time.localtime())\r
     Ewb.ShowWorkspaceBuild()\r
index 396d67a..fef1f44 100755 (executable)
@@ -26,6 +26,34 @@ from Dictionary import *
 from BuildToolError import *\r
 from Misc import sdict\r
 import GlobalData\r
+from Table.TableInf import TableInf\r
+import Database as Database\r
+from Parsing import *\r
+\r
+#\r
+# Global variable\r
+#\r
+Section = {TAB_UNKNOWN.upper() : MODEL_UNKNOWN,\r
+           TAB_INF_DEFINES.upper() : MODEL_META_DATA_HEADER,\r
+           TAB_BUILD_OPTIONS.upper() : MODEL_META_DATA_BUILD_OPTION,\r
+           TAB_INCLUDES.upper() : MODEL_EFI_INCLUDE,\r
+           TAB_LIBRARIES.upper() : MODEL_EFI_LIBRARY_INSTANCE,\r
+           TAB_LIBRARY_CLASSES.upper() : MODEL_EFI_LIBRARY_CLASS,\r
+           TAB_PACKAGES.upper() : MODEL_META_DATA_PACKAGE,\r
+           TAB_NMAKE.upper() : MODEL_META_DATA_NMAKE,\r
+           TAB_INF_FIXED_PCD.upper() : MODEL_PCD_FIXED_AT_BUILD,\r
+           TAB_INF_PATCH_PCD.upper() : MODEL_PCD_PATCHABLE_IN_MODULE,\r
+           TAB_INF_FEATURE_PCD.upper() : MODEL_PCD_FEATURE_FLAG,\r
+           TAB_INF_PCD_EX.upper() : MODEL_PCD_DYNAMIC_EX,\r
+           TAB_INF_PCD.upper() : MODEL_PCD_DYNAMIC,\r
+           TAB_SOURCES.upper() : MODEL_EFI_SOURCE_FILE,\r
+           TAB_GUIDS.upper() : MODEL_EFI_GUID,\r
+           TAB_PROTOCOLS.upper() : MODEL_EFI_PROTOCOL,\r
+           TAB_PPIS.upper() : MODEL_EFI_PPI,\r
+           TAB_DEPEX.upper() : MODEL_EFI_DEPEX,\r
+           TAB_BINARIES.upper() : MODEL_EFI_BINARY_FILE,\r
+           TAB_USER_EXTENSIONS.upper() : MODEL_META_DATA_USER_EXTENSION\r
+           }\r
 \r
 gComponentType2ModuleType = {\r
     "LIBRARY"               :   "BASE",\r
@@ -184,10 +212,10 @@ class InfContents(InfObject):
 # @var Module:              To store value for Module, it is a structure as ModuleClass\r
 # @var WorkspaceDir:        To store value for WorkspaceDir\r
 # @var Contents:            To store value for Contents, it is a structure as InfContents\r
-# @var KeyList:             To store value for KeyList, a list for all Keys used in Dec\r
+# @var KeyList:             To store value for KeyList, a list for all Keys used in Inf\r
 #\r
 class Inf(InfObject):\r
-    def __init__(self, Filename = None, IsMergeAllArches = False, IsToModule = False, WorkspaceDir = None):\r
+    def __init__(self, Filename = None, IsMergeAllArches = False, IsToModule = False, WorkspaceDir = None, Database = None, SupArchList = DataType.ARCH_LIST):\r
         self.Identification = Identification()\r
         self.Defines = {} # InfDefines()\r
         self.Contents = {}\r
@@ -195,17 +223,33 @@ class Inf(InfObject):
         self.Module = ModuleClass()\r
         self.WorkspaceDir = WorkspaceDir\r
         self._Macro = {}    # for inf file local replacement\r
-\r
-        for Arch in DataType.ARCH_LIST_FULL:\r
-            self.Contents[Arch] = InfContents()\r
+        self.Cur = Database.Cur\r
+        self.TblFile = Database.TblFile\r
+        self.TblInf = TableInf(Database.Cur)\r
+        self.SupArchList = SupArchList\r
+        \r
+        \r
+#        for Arch in DataType.ARCH_LIST_FULL:\r
+#            self.Contents[Arch] = InfContents()\r
 \r
         self.KeyList = [\r
             TAB_SOURCES, TAB_BUILD_OPTIONS, TAB_BINARIES, TAB_INCLUDES, TAB_GUIDS, \r
             TAB_PROTOCOLS, TAB_PPIS, TAB_LIBRARY_CLASSES, TAB_PACKAGES, TAB_LIBRARIES, \r
             TAB_INF_FIXED_PCD, TAB_INF_PATCH_PCD, TAB_INF_FEATURE_PCD, TAB_INF_PCD, \r
-            TAB_INF_PCD_EX, TAB_DEPEX, TAB_NMAKE\r
+            TAB_INF_PCD_EX, TAB_DEPEX, TAB_NMAKE, TAB_INF_DEFINES\r
         ]\r
-\r
+        #\r
+        # Upper all KEYs to ignore case sensitive when parsing\r
+        #\r
+        self.KeyList = map(lambda c: c.upper(), self.KeyList)\r
+        \r
+        #\r
+        # Init RecordSet\r
+        #\r
+        self.RecordSet = {}        \r
+        for Key in self.KeyList:\r
+            self.RecordSet[Section[Key]] = []\r
+        \r
         #\r
         # Load Inf file if filename is not None\r
         #\r
@@ -229,11 +273,11 @@ class Inf(InfObject):
     # Find the contents defined in all arches and merge them to all\r
     #\r
     def MergeAllArches(self):\r
-        if DataType.TAB_ARCH_COMMON.upper() in self.Defines:\r
+        if DataType.TAB_ARCH_COMMON in self.Defines:\r
             for Arch in DataType.ARCH_LIST:\r
                 if Arch not in self.Defines:\r
                     self.Defines[Arch] = InfDefines()\r
-                self.Defines[Arch].extend(self.Defines[DataType.TAB_ARCH_COMMON.upper()])\r
+                self.Defines[Arch].extend(self.Defines[DataType.TAB_ARCH_COMMON])\r
                 self._Macro.update(self.Defines[Arch].DefinesDictionary[TAB_INF_DEFINES_MACRO])\r
         self._Macro.update(GlobalData.gGlobalDefines)\r
 \r
@@ -259,486 +303,90 @@ class Inf(InfObject):
         else:\r
             GetMultipleValuesOfKeyFromLines(Lines, Key, KeyField, TAB_COMMENT_SPLIT)\r
 \r
-    ## Convert [Defines] section content to ModuleHeaderClass\r
-    #\r
-    # Convert [Defines] section content to ModuleHeaderClass\r
-    #\r
-    # @param Defines        The content under [Defines] section\r
-    # @param ModuleHeader   An object of ModuleHeaderClass\r
-    # @param Arch           The supported ARCH\r
+    ## Transfer to Module Object\r
+    # \r
+    # Transfer all contents of an Inf file to a standard Module Object\r
     #\r
-    def DefinesToModuleHeader(self, Defines, ModuleHeader, Arch):\r
-        ModuleHeader.SupArchList.append(Arch)\r
-        # macro definitions\r
-        ModuleHeader.MacroDefines.update(Defines.DefinesDictionary[TAB_INF_DEFINES_MACRO])\r
-        ModuleHeader.MacroDefines.update(GlobalData.gGlobalDefines)\r
-        #\r
-        # Get value for Header\r
-        #\r
-        ModuleHeader.InfVersion = Defines.DefinesDictionary[TAB_INF_DEFINES_INF_VERSION][0]\r
-        # R8 modules may use macro in base name\r
-        # ModuleHeader.Name = ReplaceMacro(Defines.DefinesDictionary[TAB_INF_DEFINES_BASE_NAME][0], ModuleHeader.MacroDefines)\r
-        ModuleHeader.Name = Defines.DefinesDictionary[TAB_INF_DEFINES_BASE_NAME][0]\r
-        ModuleHeader.Guid = Defines.DefinesDictionary[TAB_INF_DEFINES_FILE_GUID][0]\r
-        \r
-        ModuleHeader.FileName = self.Identification.FileName\r
-        ModuleHeader.FullPath = self.Identification.FileFullPath\r
-        File = ModuleHeader.FullPath\r
-        \r
-        ModuleHeader.EfiSpecificationVersion = Defines.DefinesDictionary[TAB_INF_DEFINES_EFI_SPECIFICATION_VERSION][0]\r
-        ModuleHeader.EdkReleaseVersion = Defines.DefinesDictionary[TAB_INF_DEFINES_EDK_RELEASE_VERSION][0]\r
-           \r
-        ModuleHeader.ModuleType = Defines.DefinesDictionary[TAB_INF_DEFINES_MODULE_TYPE][0]\r
-        ModuleHeader.BinaryModule = Defines.DefinesDictionary[TAB_INF_DEFINES_BINARY_MODULE][0]\r
-        ModuleHeader.ComponentType = Defines.DefinesDictionary[TAB_INF_DEFINES_COMPONENT_TYPE][0]\r
-        ModuleHeader.MakefileName = Defines.DefinesDictionary[TAB_INF_DEFINES_MAKEFILE_NAME][0]\r
-        ModuleHeader.BuildNumber = Defines.DefinesDictionary[TAB_INF_DEFINES_BUILD_NUMBER][0]\r
-        ModuleHeader.BuildType = Defines.DefinesDictionary[TAB_INF_DEFINES_BUILD_TYPE][0]\r
-        ModuleHeader.FfsExt = Defines.DefinesDictionary[TAB_INF_DEFINES_FFS_EXT][0]\r
-        ModuleHeader.FvExt = Defines.DefinesDictionary[TAB_INF_DEFINES_FV_EXT][0]\r
-        ModuleHeader.SourceFv = Defines.DefinesDictionary[TAB_INF_DEFINES_SOURCE_FV][0]\r
-        ModuleHeader.PcdIsDriver = Defines.DefinesDictionary[TAB_INF_DEFINES_PCD_IS_DRIVER][0]\r
-        ModuleHeader.TianoR8FlashMap_h = Defines.DefinesDictionary[TAB_INF_DEFINES_TIANO_R8_FLASHMAP_H][0]\r
-        ModuleHeader.Shadow = Defines.DefinesDictionary[TAB_INF_DEFINES_SHADOW][0]\r
-        \r
-        #\r
-        # Get version of INF\r
-        #\r
-        if ModuleHeader.InfVersion != "":\r
-            # R9 inf\r
-            VersionNumber = Defines.DefinesDictionary[TAB_INF_DEFINES_VERSION_NUMBER][0]\r
-            VersionString = Defines.DefinesDictionary[TAB_INF_DEFINES_VERSION_STRING][0]\r
-            if len(VersionNumber) > 0 and len(VersionString) == 0:\r
-                EdkLogger.warn(2000, 'VERSION_NUMBER depricated; INF file %s should be modified to use VERSION_STRING instead.' % self.Identification.FileFullPath)\r
-                ModuleHeader.Version = VersionNumber\r
-            if len(VersionString) > 0:\r
-                if len(VersionNumber) > 0:\r
-                    EdkLogger.warn(2001, 'INF file %s defines both VERSION_NUMBER and VERSION_STRING, using VERSION_STRING' % self.Identification.FileFullPath)\r
-                ModuleHeader.Version = VersionString\r
-        else:\r
-            # R8 inf\r
-            ModuleHeader.InfVersion = "0x00010000"\r
-            VersionNumber = Defines.DefinesDictionary[TAB_INF_DEFINES_VERSION][0]\r
-            VersionString = Defines.DefinesDictionary[TAB_INF_DEFINES_VERSION_STRING][0]\r
-            if VersionString == '' and VersionNumber != '':\r
-                VersionString = VersionNumber\r
-            if ModuleHeader.ComponentType in gComponentType2ModuleType:\r
-                ModuleHeader.ModuleType = gComponentType2ModuleType[ModuleHeader.ComponentType]\r
-            elif ModuleHeader.ComponentType != '':\r
-                EdkLogger.error("Parser", PARSER_ERROR, "Unsupported R8 component type [%s]" % ModuleHeader.ComponentType,\r
-                                ExtraData=File)\r
-        #\r
-        # LibraryClass of Defines\r
-        #\r
-        if Defines.DefinesDictionary[TAB_INF_DEFINES_LIBRARY_CLASS][0] != '':\r
-            for Item in Defines.DefinesDictionary[TAB_INF_DEFINES_LIBRARY_CLASS]:\r
-                List = GetSplitValueList(Item, DataType.TAB_VALUE_SPLIT, 1)\r
-                Lib = LibraryClassClass()\r
-                Lib.LibraryClass = CleanString(List[0])\r
-                if len(List) == 1:\r
-                    Lib.SupModuleList = DataType.SUP_MODULE_LIST\r
-                elif len(List) == 2:\r
-                    Lib.SupModuleList = GetSplitValueList(CleanString(List[1]), ' ')\r
-                ModuleHeader.LibraryClass.append(Lib)\r
-        elif ModuleHeader.ComponentType == "LIBRARY":\r
-            Lib = LibraryClassClass()\r
-            Lib.LibraryClass = ModuleHeader.Name\r
-            Lib.SupModuleList = DataType.SUP_MODULE_LIST\r
-            ModuleHeader.LibraryClass.append(Lib)\r
-        \r
+    def InfToModule(self):\r
         #\r
-        # Custom makefile of Defines\r
+        # Init global information for the file\r
         #\r
-        if Defines.DefinesDictionary[TAB_INF_DEFINES_CUSTOM_MAKEFILE][0] != '':\r
-            for Item in Defines.DefinesDictionary[TAB_INF_DEFINES_CUSTOM_MAKEFILE]:\r
-                List = Item.split(DataType.TAB_VALUE_SPLIT)\r
-                if len(List) == 2:\r
-                    ModuleHeader.CustomMakefile[CleanString(List[0])] = CleanString(List[1])\r
-                else:\r
-                    RaiseParserError(Item, 'CUSTOM_MAKEFILE of Defines', File, 'CUSTOM_MAKEFILE=<Family>|<Filename>')\r
+        ContainerFile = self.Identification.FileFullPath\r
         \r
         #\r
-        # EntryPoint and UnloadImage of Defines\r
+        # Generate Package Header\r
         #\r
-        if Defines.DefinesDictionary[TAB_INF_DEFINES_ENTRY_POINT][0] != '':\r
-            for Item in Defines.DefinesDictionary[TAB_INF_DEFINES_ENTRY_POINT]:\r
-                Image = ModuleExternImageClass()\r
-                Image.ModuleEntryPoint = CleanString(Item)\r
-                self.Module.ExternImages.append(Image)\r
-        if Defines.DefinesDictionary[TAB_INF_DEFINES_UNLOAD_IMAGE][0] != '':\r
-            for Item in Defines.DefinesDictionary[TAB_INF_DEFINES_UNLOAD_IMAGE]:\r
-                Image = ModuleExternImageClass()\r
-                Image.ModuleUnloadImage = CleanString(Item)\r
-                self.Module.ExternImages.append(Image)\r
+        self.GenModuleHeader(ContainerFile)\r
         \r
         #\r
-        # Constructor and Destructor of Defines\r
+        # Generate BuildOptions\r
         #\r
-        if Defines.DefinesDictionary[TAB_INF_DEFINES_CONSTRUCTOR][0] != '':\r
-            for Item in Defines.DefinesDictionary[TAB_INF_DEFINES_CONSTRUCTOR]:\r
-                LibraryClass = ModuleExternLibraryClass()\r
-                LibraryClass.Constructor = CleanString(Item)\r
-                self.Module.ExternLibraries.append(LibraryClass)\r
-        if Defines.DefinesDictionary[TAB_INF_DEFINES_DESTRUCTOR][0] != '':\r
-            for Item in Defines.DefinesDictionary[TAB_INF_DEFINES_DESTRUCTOR]:\r
-                LibraryClass = ModuleExternLibraryClass()\r
-                LibraryClass.Destructor = CleanString(Item)\r
-                self.Module.ExternLibraries.append(LibraryClass)\r
+        self.GenBuildOptions(ContainerFile)\r
         \r
         #\r
-        # Define of Defines\r
+        # Generate Includes\r
         #\r
-        if Defines.DefinesDictionary[TAB_INF_DEFINES_DEFINE][0] != '':\r
-            for Item in Defines.DefinesDictionary[TAB_INF_DEFINES_DEFINE]:\r
-                List = Item.split(DataType.TAB_EQUAL_SPLIT)\r
-                if len(List) != 2:\r
-                    RaiseParserError(Item, 'DEFINE of Defines', File, 'DEFINE <Word> = <Word>')\r
-                else:\r
-                    ModuleHeader.Define[CleanString(List[0])] = CleanString(List[1])\r
+        self.GenIncludes(ContainerFile)\r
         \r
         #\r
-        # Spec\r
-        #\r
-        if Defines.DefinesDictionary[TAB_INF_DEFINES_SPEC][0] != '':\r
-            for Item in Defines.DefinesDictionary[TAB_INF_DEFINES_SPEC]:\r
-                List = Item.split(DataType.TAB_EQUAL_SPLIT)\r
-                if len(List) != 2:\r
-                    RaiseParserError(Item, 'SPEC of Defines', File, 'SPEC <Word> = <Version>')\r
-                else:\r
-                    ModuleHeader.Specification[CleanString(List[0])] = CleanString(List[1])\r
-                \r
-\r
-    ## Transfer to Module Object\r
-    # \r
-    # Transfer all contents of an Inf file to a standard Module Object\r
-    #\r
-    def InfToModule(self):\r
-        File = self.Identification.FileFullPath\r
-        for Arch in DataType.ARCH_LIST:\r
-            if Arch not in self.Defines:\r
-                continue\r
-            ModuleHeader = ModuleHeaderClass()\r
-            self.DefinesToModuleHeader(self.Defines[Arch], ModuleHeader, Arch)\r
-            self.Module.Header[Arch] = ModuleHeader\r
-        #\r
-        # BuildOptions\r
-        # [<Family>:]<ToolFlag>=Flag\r
+        # Generate Libraries\r
         #\r
-        BuildOptions = {}\r
-        for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].BuildOptions:\r
-                MergeArches(BuildOptions, GetBuildOption(Item, File), Arch)\r
-        for Key in BuildOptions.keys():\r
-            BuildOption = BuildOptionClass(Key[0], Key[1], Key[2])\r
-            BuildOption.SupArchList = BuildOptions[Key]\r
-            self.Module.BuildOptions.append(BuildOption)    \r
+        self.GenLibraries(ContainerFile)\r
         \r
         #\r
-        # Includes\r
+        # Generate LibraryClasses\r
         #\r
-        Includes = sdict()\r
-        for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].Includes:\r
-                MergeArches(Includes, Item, Arch)\r
-        for Key in Includes.keys():\r
-            Include = IncludeClass()\r
-            Include.FilePath = NormPath(Key, self._Macro)\r
-            Include.SupArchList = Includes[Key]\r
-            self.Module.Includes.append(Include)\r
+        self.GenLibraryClasses(ContainerFile)\r
         \r
         #\r
-        # Libraries\r
+        # Generate Packages\r
         #\r
-        Libraries = sdict()\r
-        for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].Libraries:\r
-                MergeArches(Libraries, Item, Arch)\r
-        for Key in Libraries.keys():\r
-            Library = ModuleLibraryClass()\r
-            # replace macro and remove file extension\r
-            Library.Library = ReplaceMacro(Key, self._Macro).rsplit('.', 1)[0]\r
-            Library.SupArchList = Libraries[Key]\r
-            self.Module.Libraries.append(Library)\r
+        self.GenPackages(ContainerFile)\r
         \r
         #\r
-        # LibraryClasses\r
-        # LibraryClass[|<LibraryClassInstanceFilename>[|<TokenSpaceGuidCName>.<PcdCName>]]\r
+        # Generate Nmakes\r
         #\r
-        LibraryClasses = {}\r
-        Defines = {}\r
-        for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].LibraryClasses:\r
-                Status = GenDefines(Item[0], Arch, Defines)\r
-                #\r
-                # Find DEFINE statement\r
-                #\r
-                if Status == 0:\r
-                    pass\r
-                #\r
-                # Find DEFINE statement but in wrong format\r
-                #\r
-                elif Status == -1:\r
-                    RaiseParserError(Item[0], 'LibraryClasses', File, 'DEFINE <VarName> = <PATH>')\r
-                #\r
-                # Not find DEFINE statement\r
-                #\r
-                elif Status == 1:\r
-                    #\r
-                    # { (LibraryClass, Instance, PcdFeatureFlag, ModuleType1|ModuleType2|ModuleType3) : [Arch1, Arch2, ...] }\r
-                    #\r
-                    ItemList = GetSplitValueList((Item[0] + DataType.TAB_VALUE_SPLIT * 2))\r
-                    CheckFileType(ItemList[1], '.Inf', File, 'LibraryClasses', Item[0])\r
-                    CheckFileExist(self.WorkspaceDir, ItemList[1], File, 'LibraryClasses', Item[0])\r
-                    CheckPcdTokenInfo(ItemList[2], 'LibraryClasses', File)\r
-                    MergeArches(LibraryClasses, (ItemList[0], ItemList[1], ItemList[2], DataType.TAB_VALUE_SPLIT.join(Item[1])), Arch)\r
-        for Key in LibraryClasses.keys():\r
-            KeyList = Key[0].split(DataType.TAB_VALUE_SPLIT)\r
-            LibraryClass = LibraryClassClass()\r
-            LibraryClass.Define = Defines\r
-            LibraryClass.LibraryClass = Key[0]\r
-            LibraryClass.RecommendedInstance = NormPath(Key[1], self._Macro)\r
-            LibraryClass.FeatureFlag = Key[2]\r
-            LibraryClass.SupArchList = LibraryClasses[Key]\r
-            if Key[3] != '':\r
-                LibraryClass.SupModuleList = GetSplitValueList(Key[3])\r
-            else:\r
-                LibraryClass.SupModuleList = DataType.SUP_MODULE_LIST\r
-            self.Module.LibraryClasses.append(LibraryClass)\r
+        self.GenNmakes(ContainerFile)\r
         \r
         #\r
-        # Packages\r
-        #\r
-        Packages = {}\r
-        Defines = {}\r
-        for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].Packages:\r
-                Status = GenDefines(Item, Arch, Defines)\r
-                #\r
-                # Find DEFINE statement\r
-                #\r
-                if Status == 0:\r
-                    pass\r
-                #\r
-                # Find DEFINE statement but in wrong format\r
-                #\r
-                elif Status == -1:\r
-                    RaiseParserError(Item[0], 'Packages', File, 'DEFINE <VarName> = <PATH>')\r
-                #\r
-                # Not find DEFINE statement\r
-                #\r
-                elif Status == 1:\r
-                    CheckFileType(Item, '.Dec', File, 'package', Item)\r
-                    CheckFileExist(self.WorkspaceDir, Item, File, 'Packages', Item)\r
-                    MergeArches(Packages, Item, Arch)\r
-        for Key in Packages.keys():\r
-            Package = ModulePackageDependencyClass()\r
-            Package.Define = Defines\r
-            Package.FilePath = NormPath(Key, self._Macro)\r
-            Package.SupArchList = Packages[Key]\r
-            self.Module.PackageDependencies.append(Package)\r
-            \r
-        #\r
-        # Nmake\r
+        # Generate Pcds\r
         #\r
-        Nmakes = sdict()\r
-        for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].Nmake:\r
-                MergeArches(Nmakes, Item, Arch)\r
-        for Key in Nmakes.keys():\r
-            List = GetSplitValueList(Key, DataType.TAB_EQUAL_SPLIT, MaxSplit=1)\r
-            if len(List) != 2:\r
-                RaiseParserError(Item[0], 'Nmake', File, '<MacroName> = <Value>')\r
-            Nmake = ModuleNmakeClass()\r
-            Nmake.Name = List[0]\r
-            Nmake.Value = List[1]\r
-            Nmake.SupArchList = Nmakes[Key]\r
-            self.Module.Nmake.append(Nmake)\r
-\r
-            # convert R8 format to R9 format\r
-            if Nmake.Name == "IMAGE_ENTRY_POINT":\r
-                Image = ModuleExternImageClass()\r
-                Image.ModuleEntryPoint = Nmake.Value\r
-                self.Module.ExternImages.append(Image)\r
-            elif Nmake.Name == "DPX_SOURCE":\r
-                Source = ModuleSourceFileClass(NormPath(Nmake.Value, self._Macro), "", "", "", "", Nmake.SupArchList)\r
-                self.Module.Sources.append(Source)\r
-            else:\r
-                ToolList = gNmakeFlagPattern.findall(Nmake.Name)\r
-                if len(ToolList) == 0 or len(ToolList) != 1:\r
-                    EdkLogger.warn("\nParser", "Don't know how to do with MACRO: %s" % Nmake.Name, \r
-                                   ExtraData=File)\r
-                else:\r
-                    if ToolList[0] in gNmakeFlagName2ToolCode:\r
-                        Tool = gNmakeFlagName2ToolCode[ToolList[0]]\r
-                    else:\r
-                        Tool = ToolList[0]\r
-                    BuildOption = BuildOptionClass("MSFT", "*_*_*_%s_FLAGS" % Tool, Nmake.Value)\r
-                    BuildOption.SupArchList = Nmake.SupArchList\r
-                    self.Module.BuildOptions.append(BuildOption)\r
+        self.GenPcds(ContainerFile)\r
         \r
         #\r
-        # Pcds\r
-        # <TokenSpaceGuidCName>.<PcdCName>[|<Value>]\r
+        # Generate Sources\r
         #\r
-        Pcds = {}\r
-        for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].FixedPcd:\r
-                #\r
-                # Library should not have FixedPcd\r
-                #\r
-                if self.Module.Header[Arch].LibraryClass != {}:\r
-                    pass\r
-                MergeArches(Pcds, self.GetPcdOfInf(Item, TAB_PCDS_FIXED_AT_BUILD, File), Arch)\r
-            \r
-            for Item in self.Contents[Arch].PatchPcd:\r
-                MergeArches(Pcds, self.GetPcdOfInf(Item, TAB_PCDS_PATCHABLE_IN_MODULE, File), Arch)\r
-            \r
-            for Item in self.Contents[Arch].FeaturePcd:\r
-                MergeArches(Pcds, self.GetPcdOfInf(Item, TAB_PCDS_FEATURE_FLAG, File), Arch)\r
-            \r
-            for Item in self.Contents[Arch].PcdEx:\r
-                MergeArches(Pcds, self.GetPcdOfInf(Item, TAB_PCDS_DYNAMIC_EX, File), Arch)\r
-            \r
-            for Item in self.Contents[Arch].Pcd:\r
-                MergeArches(Pcds, self.GetPcdOfInf(Item, "", File), Arch)\r
-                #MergeArches(Pcds, self.GetPcdOfInf(Item, TAB_PCDS_DYNAMIC_EX, File), Arch)\r
-                #MergeArches(Pcds, self.GetPcdOfInf(Item, TAB_PCDS_FEATURE_FLAG, File), Arch)\r
-                #MergeArches(Pcds, self.GetPcdOfInf(Item, TAB_PCDS_FIXED_AT_BUILD, File), Arch)\r
-                #MergeArches(Pcds, self.GetPcdOfInf(Item, TAB_PCDS_PATCHABLE_IN_MODULE, File), Arch)\r
-                \r
-        for Key in Pcds.keys():\r
-            Pcd = PcdClass()\r
-            Pcd.CName = Key[1]\r
-            Pcd.TokenSpaceGuidCName = Key[0]\r
-            Pcd.DefaultValue = Key[2]\r
-            Pcd.ItemType = Key[3]\r
-            Pcd.SupArchList = Pcds[Key]\r
-            self.Module.PcdCodes.append(Pcd)\r
+        self.GenSources(ContainerFile)\r
         \r
         #\r
-        # Sources\r
-        # <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]\r
-        #\r
-        Sources = {}\r
-        for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].Sources:\r
-                ItemNew = Item + DataType.TAB_VALUE_SPLIT * 4\r
-                List = GetSplitValueList(ItemNew)\r
-                if len(List) < 5 or len(List) > 9:\r
-                    RaiseParserError(Item, 'Sources', File, '<Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]')\r
-                List[0] = List[0].replace('\\', '/')\r
-                List[0] = NormPath(List[0], self._Macro)\r
-                CheckFileExist(self.Identification.FileRelativePath, List[0], File, 'Sources', Item)\r
-                CheckPcdTokenInfo(List[4], 'Sources', File)\r
-                MergeArches(Sources, (List[0], List[1], List[2], List[3], List[4]), Arch)\r
-        for Key in Sources.keys():\r
-            Source = ModuleSourceFileClass(Key[0], Key[2], Key[3], Key[1], Key[4], Sources[Key])\r
-            self.Module.Sources.append(Source)\r
-\r
-        #\r
-        # UserExtensions\r
+        # Generate UserExtensions\r
         #\r
-        if self.UserExtensions != '':\r
-            UserExtension = UserExtensionsClass()\r
-            Lines = self.UserExtensions.splitlines()\r
-            List = GetSplitValueList(Lines[0], DataType.TAB_SPLIT, 2)\r
-            if len(List) != 3:\r
-                RaiseParserError(Lines[0], 'UserExtensions', File, "UserExtensions.UserId.'Identifier'")\r
-            else:\r
-                UserExtension.UserID = List[1]\r
-                UserExtension.Identifier = List[2][0:-1].replace("'", '').replace('\"', '')\r
-                for Line in Lines[1:]:\r
-                    UserExtension.Content = UserExtension.Content + CleanString(Line) + '\n'\r
-            self.Module.UserExtensions.append(UserExtension)\r
+        self.GenUserExtensions(ContainerFile)\r
         \r
         #\r
-        # Guids\r
+        # Generate Guids\r
         #\r
-        Guids = {}\r
-        for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].Guids:\r
-                MergeArches(Guids, Item, Arch)\r
-        for Key in Guids.keys():\r
-            Guid = GuidClass()\r
-            Guid.CName = Key\r
-            Guid.SupArchList = Guids[Key]\r
-            self.Module.Guids.append(Guid)\r
+        self.GenGuids(ContainerFile)\r
 \r
         #\r
-        # Protocols\r
+        # Generate Protocols\r
         #\r
-        Protocols = {}\r
-        for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].Protocols:\r
-                MergeArches(Protocols, Item, Arch)\r
-        for Key in Protocols.keys():\r
-            Protocol = ProtocolClass()\r
-            Protocol.CName = Key\r
-            Protocol.SupArchList = Protocols[Key]\r
-            self.Module.Protocols.append(Protocol)\r
-        \r
+        self.GenProtocols(ContainerFile)\r
+\r
         #\r
-        # Ppis\r
+        # Generate Ppis\r
         #\r
-        Ppis = {}\r
-        for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].Ppis:\r
-                MergeArches(Ppis, Item, Arch)\r
-        for Key in Ppis.keys():\r
-            Ppi = PpiClass()\r
-            Ppi.CName = Key\r
-            Ppi.SupArchList = Ppis[Key]\r
-            self.Module.Ppis.append(Ppi)\r
+        self.GenPpis(ContainerFile)\r
         \r
         #\r
-        # Depex\r
+        # Generate Depexes\r
         #\r
-        Depex = {}\r
-        Defines = {}\r
-        for Arch in DataType.ARCH_LIST:\r
-            Line = ''\r
-            for Item in self.Contents[Arch].Depex:\r
-                Status = GenDefines(Item, Arch, Defines)\r
-                #\r
-                # Find DEFINE statement\r
-                #\r
-                if Status == 0:\r
-                    pass\r
-                #\r
-                # Find DEFINE statement but in wrong format\r
-                #\r
-                elif Status == -1:\r
-                    RaiseParserError(Item, 'Depex', File, 'DEFINE <VarName> = <PATH>')\r
-                #\r
-                # Not find DEFINE statement\r
-                #\r
-                elif Status == 1:\r
-                    Line = Line + Item + ' '\r
-            MergeArches(Depex, Line, Arch)\r
-        for Key in Depex.keys():\r
-            Dep = ModuleDepexClass()\r
-            Dep.Depex = Key\r
-            Dep.SupArchList = Depex[Key]\r
-            Dep.Define = Defines\r
-            self.Module.Depex.append(Dep)\r
+        self.GenDepexes(ContainerFile)\r
         \r
         #\r
-        # Binaries\r
-        # <FileType>|<Filename>|<Target>[|<TokenSpaceGuidCName>.<PcdCName>]\r
+        # Generate Binaries\r
         #\r
-        Binaries = {}\r
-        for Arch in DataType.ARCH_LIST:\r
-            for Item in self.Contents[Arch].Binaries:\r
-                ItemNew = Item + DataType.TAB_VALUE_SPLIT\r
-                List = GetSplitValueList(ItemNew)\r
-                if len(List) != 4 and len(List) != 5:\r
-                    RaiseParserError(Item, 'Binaries', File, "<FileType>|<Filename>|<Target>[|<TokenSpaceGuidCName>.<PcdCName>]")\r
-                else:\r
-                    CheckPcdTokenInfo(List[3], 'Binaries', File)\r
-                    MergeArches(Binaries, (List[0], List[1], List[2], List[3]), Arch)\r
-        for Key in Binaries.keys():\r
-            Binary = ModuleBinaryFileClass(NormPath(Key[1], self._Macro), Key[0], Key[2], Key[3], Binaries[Key])\r
-            self.Module.Binaries.append(Binary)\r
+        self.GenBinaries(ContainerFile)\r
         \r
     ## Get Pcd Values of Inf\r
     #\r
@@ -750,7 +398,7 @@ class Inf(InfObject):
     #\r
     # @retval (TokenSpcCName, TokenCName, Value, ItemType) Formatted Pcd Item\r
     #\r
-    def GetPcdOfInf(self, Item, Type, File):\r
+    def GetPcdOfInf(self, Item, Type, File, LineNo):\r
         Format = '<TokenSpaceGuidCName>.<PcdCName>[|<Value>]'\r
         InfType = ''\r
         if Type == TAB_PCDS_FIXED_AT_BUILD:\r
@@ -765,15 +413,10 @@ class Inf(InfObject):
             InfType = TAB_INF_PCD\r
         List = GetSplitValueList(Item + DataType.TAB_VALUE_SPLIT)\r
         if len(List) < 2 or len(List) > 3:\r
-            RaiseParserError(Item, InfType, File, Format)\r
+            RaiseParserError(Item, InfType, File, Format, LineNo)\r
         TokenInfo = GetSplitValueList(List[0], DataType.TAB_SPLIT)\r
         if len(TokenInfo) != 2:\r
-            RaiseParserError(Item, InfType, File, Format)\r
-        if len(List) == 3 and List[1] == '':\r
-            #\r
-            # Value is empty\r
-            #\r
-            RaiseParserError(Item, 'Pcds' + Type, File, Format)\r
+            RaiseParserError(Item, InfType, File, Format, LineNo)\r
 \r
         return (TokenInfo[0], TokenInfo[1], List[1], Type)\r
 \r
@@ -792,13 +435,61 @@ class Inf(InfObject):
         if len(TokenList) == 2:\r
             Arch = TokenList[1].upper()\r
         else:\r
-            Arch = TAB_ARCH_COMMON.upper()\r
+            Arch = TAB_ARCH_COMMON\r
 \r
         if Arch not in self.Defines:\r
             self.Defines[Arch] = InfDefines()\r
         GetSingleValueOfKeyFromLines(Lines, self.Defines[Arch].DefinesDictionary, \r
                                      TAB_COMMENT_SPLIT, TAB_EQUAL_SPLIT, False, None)\r
 \r
+    ## First time to insert records to database\r
+    # \r
+    # Insert item data of a section to database\r
+    # @param FileID:           The ID of belonging file\r
+    # @param Filename:         The name of belonging file\r
+    # @param CurrentSection:   The name of currect section\r
+    # @param SectionItemList:  A list of items of the section\r
+    # @param ArchList:         A list of arches\r
+    # @param ThirdList:        A list of third parameters, ModuleType for LibraryClass and SkuId for Dynamic Pcds\r
+    # @param IfDefList:        A list of all conditional statements\r
+    #\r
+    def InsertSectionItemsIntoDatabase(self, FileID, Filename, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList):\r
+        #\r
+        # Insert each item data of a section\r
+        #\r
+        for Index in range(0, len(ArchList)):\r
+            Arch = ArchList[Index]\r
+            Third = ThirdList[Index]\r
+            if Arch == '':\r
+                Arch = TAB_ARCH_COMMON\r
+\r
+            Model = Section[CurrentSection.upper()]\r
+            Records = self.RecordSet[Model]\r
+            for SectionItem in SectionItemList:\r
+                BelongsToItem, EndLine, EndColumn = -1, -1, -1\r
+                LineValue, StartLine, EndLine = SectionItem[0], SectionItem[1], SectionItem[1]\r
+                \r
+                EdkLogger.debug(4, "Parsing %s ..." %LineValue)\r
+                #\r
+                # And then parse DEFINE statement\r
+                #\r
+                if LineValue.upper().find(DataType.TAB_DEFINE.upper() + ' ') > -1:\r
+                    self.ParseDefine(LineValue, StartLine, self.TblInf, FileID, Filename, CurrentSection, MODEL_META_DATA_DEFINE, Arch)\r
+                    continue\r
+                \r
+                #\r
+                # At last parse other sections\r
+                #\r
+                if CurrentSection == TAB_LIBRARY_CLASSES or CurrentSection == TAB_INF_DEFINES:\r
+                    ID = self.TblInf.Insert(Model, LineValue, Third, Third, '', '', Arch, -1, FileID, StartLine, -1, StartLine, -1, 0)\r
+                    Records.append([LineValue, Arch, StartLine, ID, Third])\r
+                    continue\r
+                else:\r
+                    ID = self.TblInf.Insert(Model, LineValue, '', '', '', '', Arch, -1, FileID, StartLine, -1, StartLine, -1, 0)\r
+                    Records.append([LineValue, Arch, StartLine, ID, Third])\r
+                    continue\r
+            self.RecordSet[Model] = Records\r
+    \r
     ## Load Inf file\r
     #\r
     # Load the file if it exists\r
@@ -806,47 +497,117 @@ class Inf(InfObject):
     # @param Filename:  Input value for filename of Inf file\r
     #\r
     def LoadInfFile(self, Filename):     \r
-        (Filepath, Name) = os.path.split(Filename)\r
-        self.Identification.FileName = Name\r
+        #\r
+        # Insert a record for file\r
+        #\r
+        Filename = NormPath(Filename)\r
         self.Identification.FileFullPath = Filename\r
-        self.Identification.FileRelativePath = Filepath\r
-        \r
-        F = open(Filename, 'r').read()\r
-        F = PreCheck(Filename, F, self.KeyList)\r
-        Sects = F.split(DataType.TAB_SECTION_START)\r
-        for Sect in Sects:\r
-            TabList = GetSplitValueList(Sect.split(TAB_SECTION_END, 1)[0], DataType.TAB_COMMA_SPLIT)\r
-            for Tab in TabList:\r
-                if Tab.upper().find(TAB_INF_DEFINES.upper()) > -1:\r
-                    self.ParseDefines(Filename, Tab, Sect)\r
-                    continue\r
-                if Tab.upper().find(DataType.TAB_USER_EXTENSIONS.upper()) > -1:\r
-                    self.UserExtensions = Sect\r
-                    continue\r
-                for Arch in DataType.ARCH_LIST_FULL + [DataType.TAB_ARCH_NULL, "PLATFORM"]:\r
-                    for Key in self.KeyList:\r
-                        if Arch != DataType.TAB_ARCH_NULL:\r
-                            Target = (Key + DataType.TAB_SPLIT + Arch).upper()\r
-                        else:\r
-                            Target = Key.upper()\r
-                        if SplitModuleType(Tab)[0].upper() == Target:\r
-                            if Arch != DataType.TAB_ARCH_NULL and Arch != "PLATFORM":\r
-                                Command = 'self.ParseInf(Sect, Tab, self.Contents[Arch].' + Key + ')'\r
-                                eval(Command)\r
-                                continue\r
-                            else:\r
-                                Command = "self.ParseInf(Sect, Tab, self.Contents['" + DataType.TAB_ARCH_COMMON + "']." + Key + ')'\r
-                                eval(Command)\r
-                                continue\r
-            #EndFor\r
-\r
-    ## Show detailed information of Inf\r
-    #\r
-    # Print all members and their values of Inf class\r
-    #\r
-    def ShowInf(self):\r
-        print TAB_SECTION_START + TAB_INF_DEFINES + TAB_SECTION_END\r
-        printDict(self.Defines.DefinesDictionary)\r
+        (self.Identification.FileRelativePath, self.Identification.FileName) = os.path.split(Filename)\r
+        FileID = self.TblFile.InsertFile(Filename, MODEL_FILE_DSC)\r
+        \r
+        #\r
+        # Init InfTable\r
+        #\r
+        self.TblInf.Table = "Inf%s" % FileID\r
+        self.TblInf.Create()\r
+        \r
+        #\r
+        # Init common datas\r
+        #\r
+        IfDefList, SectionItemList, CurrentSection, ArchList, ThirdList, IncludeFiles = \\r
+        [], [], TAB_UNKNOWN, [], [], []\r
+        LineNo = 0\r
+        \r
+        #\r
+        # Parse file content\r
+        #\r
+        FileContent = open(Filename, 'r').read()\r
+        for Line in FileContent.splitlines():\r
+            LineNo = LineNo + 1\r
+            #\r
+            # Reomve spaces in head and tail\r
+            #\r
+            Line = Line.strip()\r
+            \r
+            #\r
+            # Ignore comments\r
+            #\r
+            if Line.startswith(TAB_COMMENT_SPLIT):\r
+                continue\r
+            \r
+            #\r
+            # Remove comments at tail and remove spaces again\r
+            #\r
+            Line = CleanString(Line)\r
+            if Line == '':\r
+                continue\r
+            \r
+            #\r
+            # Find a new section tab\r
+            # First insert previous section items\r
+            # And then parse the content of the new section\r
+            #\r
+            if Line.startswith(TAB_SECTION_START) and Line.endswith(TAB_SECTION_END):\r
+                #\r
+                # Insert items data of previous section\r
+                #\r
+                self.InsertSectionItemsIntoDatabase(FileID, Filename, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList)\r
+                #\r
+                # Parse the new section\r
+                #\r
+                SectionItemList = []\r
+                ArchList = []\r
+                ThirdList = []\r
+                \r
+                LineList = GetSplitValueList(Line[len(TAB_SECTION_START):len(Line) - len(TAB_SECTION_END)], TAB_COMMA_SPLIT)\r
+                for Item in LineList:\r
+                    ItemList = GetSplitValueList(Item, TAB_SPLIT)\r
+                    CurrentSection = ItemList[0]\r
+                    if CurrentSection.upper() not in self.KeyList:\r
+                        RaiseParserError(Line, CurrentSection, Filename, '', LineNo)\r
+                    ItemList.append('')\r
+                    ItemList.append('')\r
+                    if len(ItemList) > 5:\r
+                        RaiseParserError(Line, CurrentSection, Filename, '', LineNo)\r
+                    else:\r
+                        if ItemList[1] != '' and ItemList[1].upper() not in ARCH_LIST_FULL:\r
+                            EdkLogger.error("Parser", PARSER_ERROR, "Invalid Arch definition '%s' found" % ItemList[1], File=Filename, Line=LineNo)\r
+                        ArchList.append(ItemList[1].upper())\r
+                        ThirdList.append(ItemList[2])\r
+\r
+                continue\r
+            \r
+            #\r
+            # Not in any defined section\r
+            #\r
+            if CurrentSection == TAB_UNKNOWN:\r
+                ErrorMsg = "%s is not in any defined section" % Line\r
+                EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, File=Filename, Line=LineNo)\r
+\r
+            #\r
+            # Add a section item\r
+            #\r
+            SectionItemList.append([Line, LineNo])\r
+            # End of parse\r
+        #End of For\r
+        \r
+        #\r
+        # Insert items data of last section\r
+        #\r
+        self.InsertSectionItemsIntoDatabase(FileID, Filename, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList)\r
+        \r
+        #\r
+        # Replace all DEFINE macros with its actual values\r
+        #\r
+        ParseDefineMacro2(self.TblInf, self.RecordSet, GlobalData.gGlobalDefines)\r
+\r
+    ## Show detailed information of Inf\r
+    #\r
+    # Print all members and their values of Inf class\r
+    #\r
+    def ShowInf(self):\r
+        print TAB_SECTION_START + TAB_INF_DEFINES + TAB_SECTION_END\r
+        printDict(self.Defines.DefinesDictionary)\r
 \r
         for key in self.KeyList:\r
             for arch in DataType.ARCH_LIST_FULL:\r
@@ -862,36 +623,38 @@ class Inf(InfObject):
     #\r
     def ShowModule(self):\r
         M = self.Module\r
-        print 'Filename =', M.Header.FileName\r
-        print 'FullPath =', M.Header.FullPath\r
-        print 'BaseName =', M.Header.Name\r
-        print 'Guid =', M.Header.Guid\r
-        print 'Version =', M.Header.Version\r
-        print 'InfVersion =', M.Header.InfVersion\r
-        print 'EfiSpecificationVersion =', M.Header.EfiSpecificationVersion\r
-        print 'EdkReleaseVersion =', M.Header.EdkReleaseVersion                \r
-        print 'ModuleType =', M.Header.ModuleType\r
-        print 'BinaryModule =', M.Header.BinaryModule\r
-        print 'ComponentType =', M.Header.ComponentType\r
-        print 'MakefileName =', M.Header.MakefileName\r
-        print 'BuildNumber =', M.Header.BuildNumber\r
-        print 'BuildType =', M.Header.BuildType\r
-        print 'FfsExt =', M.Header.FfsExt\r
-        print 'FvExt =', M.Header.FvExt\r
-        print 'SourceFv =', M.Header.SourceFv\r
-        print 'PcdIsDriver =', M.Header.PcdIsDriver\r
-        print 'TianoR8FlashMap_h =', M.Header.TianoR8FlashMap_h\r
-        print 'Shadow =', M.Header.Shadow\r
-        print 'LibraryClass =', M.Header.LibraryClass\r
-        for Item in M.Header.LibraryClass:\r
-            print Item.LibraryClass, DataType.TAB_VALUE_SPLIT.join(Item.SupModuleList)\r
-        print 'CustomMakefile =', M.Header.CustomMakefile\r
+        for Arch in M.Header.keys():\r
+            print '\nArch =', Arch\r
+            print 'Filename =', M.Header[Arch].FileName\r
+            print 'FullPath =', M.Header[Arch].FullPath\r
+            print 'BaseName =', M.Header[Arch].Name\r
+            print 'Guid =', M.Header[Arch].Guid\r
+            print 'Version =', M.Header[Arch].Version\r
+            print 'InfVersion =', M.Header[Arch].InfVersion\r
+            print 'EfiSpecificationVersion =', M.Header[Arch].EfiSpecificationVersion\r
+            print 'EdkReleaseVersion =', M.Header[Arch].EdkReleaseVersion                \r
+            print 'ModuleType =', M.Header[Arch].ModuleType\r
+            print 'BinaryModule =', M.Header[Arch].BinaryModule\r
+            print 'ComponentType =', M.Header[Arch].ComponentType\r
+            print 'MakefileName =', M.Header[Arch].MakefileName\r
+            print 'BuildNumber =', M.Header[Arch].BuildNumber\r
+            print 'BuildType =', M.Header[Arch].BuildType\r
+            print 'FfsExt =', M.Header[Arch].FfsExt\r
+            print 'FvExt =', M.Header[Arch].FvExt\r
+            print 'SourceFv =', M.Header[Arch].SourceFv\r
+            print 'PcdIsDriver =', M.Header[Arch].PcdIsDriver\r
+            print 'TianoR8FlashMap_h =', M.Header[Arch].TianoR8FlashMap_h\r
+            print 'Shadow =', M.Header[Arch].Shadow\r
+            print 'LibraryClass =', M.Header[Arch].LibraryClass\r
+            for Item in M.Header[Arch].LibraryClass:\r
+                print Item.LibraryClass, DataType.TAB_VALUE_SPLIT.join(Item.SupModuleList)\r
+            print 'CustomMakefile =', M.Header[Arch].CustomMakefile\r
+            print 'Define =', M.Header[Arch].Define\r
+            print 'Specification =', M.Header[Arch].Specification\r
         for Item in self.Module.ExternImages:\r
-            print 'Entry_Point = %s, UnloadImage = %s' % (Item.ModuleEntryPoint, Item.ModuleUnloadImage)\r
+            print '\nEntry_Point = %s, UnloadImage = %s' % (Item.ModuleEntryPoint, Item.ModuleUnloadImage)\r
         for Item in self.Module.ExternLibraries:\r
             print 'Constructor = %s, Destructor = %s' % (Item.Constructor, Item.Destructor)\r
-        print 'Define =', M.Header.Define\r
-        print 'Specification =', M.Header.Specification\r
         print '\nBuildOptions =', M.BuildOptions\r
         for Item in M.BuildOptions:\r
             print Item.ToolChainFamily, Item.ToolChain, Item.Option, Item.SupArchList\r
@@ -935,13 +698,667 @@ class Inf(InfObject):
         for Binary in M.Binaries:\r
             print 'Type=', Binary.FileType, 'Target=', Binary.Target, 'Name=', Binary.BinaryFile, 'FeatureFlag=', Binary.FeatureFlag, 'SupArchList=', Binary.SupArchList\r
 \r
+    ## Convert [Defines] section content to ModuleHeaderClass\r
+    #\r
+    # Convert [Defines] section content to ModuleHeaderClass\r
+    #\r
+    # @param Defines        The content under [Defines] section\r
+    # @param ModuleHeader   An object of ModuleHeaderClass\r
+    # @param Arch           The supported ARCH\r
+    #\r
+    def GenModuleHeader(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate ModuleHeader ...")\r
+        #\r
+        # Update all defines item in database\r
+        #\r
+        RecordSet = self.RecordSet[MODEL_META_DATA_HEADER]\r
+        for Record in RecordSet:\r
+            ValueList = GetSplitValueList(Record[0], TAB_EQUAL_SPLIT)\r
+            if len(ValueList) != 2:\r
+                RaiseParserError(Record[0], 'Defines', ContainerFile, '<Key> = <Value>', Record[2])\r
+            ID, Value1, Value2, Arch, LineNo = Record[3], ValueList[0], ValueList[1], Record[1], Record[2]\r
+            SqlCommand = """update %s set Value1 = '%s', Value2 = '%s'\r
+                            where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(Value1), ConvertToSqlString2(Value2), ID)\r
+            self.TblInf.Exec(SqlCommand)\r
+        \r
+        for Arch in DataType.ARCH_LIST:\r
+            ModuleHeader = ModuleHeaderClass()\r
+            ModuleHeader.Name = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_BASE_NAME, Arch)[0]\r
+            ModuleHeader.Guid = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_FILE_GUID, Arch)[0]\r
+            ModuleHeader.Version = QueryDefinesItem(self.TblInf, TAB_DEC_DEFINES_PACKAGE_VERSION, Arch)[0]\r
+            ModuleHeader.FileName = self.Identification.FileName\r
+            ModuleHeader.FullPath = self.Identification.FileFullPath\r
+            ModuleHeader.InfVersion = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_INF_VERSION, Arch)[0]\r
+            \r
+            ModuleHeader.EfiSpecificationVersion = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_EFI_SPECIFICATION_VERSION, Arch)[0]\r
+            ModuleHeader.EdkReleaseVersion = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_EDK_RELEASE_VERSION, Arch)[0]\r
+            \r
+            ModuleHeader.ModuleType = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_MODULE_TYPE, Arch)[0]\r
+            ModuleHeader.BinaryModule = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_BINARY_MODULE, Arch)[0]\r
+            ModuleHeader.ComponentType = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_COMPONENT_TYPE, Arch)[0]\r
+            ModuleHeader.MakefileName = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_MAKEFILE_NAME, Arch)[0]\r
+            ModuleHeader.BuildNumber = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_BUILD_NUMBER, Arch)[0]\r
+            ModuleHeader.BuildType = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_BUILD_TYPE, Arch)[0]\r
+            ModuleHeader.FfsExt = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_FFS_EXT, Arch)[0]\r
+            ModuleHeader.SourceFv = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_SOURCE_FV, Arch)[0]\r
+            ModuleHeader.PcdIsDriver = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_PCD_IS_DRIVER, Arch)[0]\r
+            ModuleHeader.TianoR8FlashMap_h = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_TIANO_R8_FLASHMAP_H, Arch)[0]\r
+            ModuleHeader.Shadow = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_SHADOW, Arch)[0]\r
+        \r
+            #\r
+            # Get version of INF\r
+            #\r
+            if ModuleHeader.InfVersion != "":\r
+                # R9 inf\r
+                VersionNumber = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_VERSION_NUMBER, Arch)[0]\r
+                VersionString = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_VERSION_STRING, Arch)[0]\r
+                if len(VersionNumber) > 0 and len(VersionString) == 0:\r
+                    EdkLogger.warn(2000, 'VERSION_NUMBER depricated; INF file %s should be modified to use VERSION_STRING instead.' % self.Identification.FileFullPath)\r
+                    ModuleHeader.Version = VersionNumber\r
+                if len(VersionString) > 0:\r
+                    if len(VersionNumber) > 0:\r
+                        EdkLogger.warn(2001, 'INF file %s defines both VERSION_NUMBER and VERSION_STRING, using VERSION_STRING' % self.Identification.FileFullPath)\r
+                    ModuleHeader.Version = VersionString\r
+            else:\r
+                # R8 inf\r
+                ModuleHeader.InfVersion = "0x00010000"\r
+                VersionNumber = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_VERSION, Arch)[0]\r
+                VersionString = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_VERSION_STRING, Arch)[0]\r
+                if VersionString == '' and VersionNumber != '':\r
+                    VersionString = VersionNumber\r
+                if ModuleHeader.ComponentType in gComponentType2ModuleType:\r
+                    ModuleHeader.ModuleType = gComponentType2ModuleType[ModuleHeader[Arch].ComponentType]\r
+                elif ModuleHeader.ComponentType != '':\r
+                    EdkLogger.error("Parser", PARSER_ERROR, "Unsupported R8 component type [%s]" % ModuleHeader[Arch].ComponentType,\r
+                                    ExtraData=ContainerFile)\r
+            #\r
+            # LibraryClass of Defines\r
+            #\r
+            RecordSet = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_LIBRARY_CLASS, Arch)\r
+            if RecordSet[0] != '':\r
+                for Item in RecordSet:\r
+                    List = GetSplitValueList(Item, DataType.TAB_VALUE_SPLIT, 1)\r
+                    Lib = LibraryClassClass()\r
+                    Lib.LibraryClass = CleanString(List[0])\r
+                    if len(List) == 1:\r
+                        Lib.SupModuleList = DataType.SUP_MODULE_LIST\r
+                    elif len(List) == 2:\r
+                        Lib.SupModuleList = GetSplitValueList(CleanString(List[1]), ' ')\r
+                    ModuleHeader.LibraryClass.append(Lib)\r
+            elif ModuleHeader.ComponentType == "LIBRARY":\r
+                Lib = LibraryClassClass()\r
+                Lib.LibraryClass = ModuleHeader.Name\r
+                Lib.SupModuleList = DataType.SUP_MODULE_LIST\r
+                ModuleHeader.LibraryClass.append(Lib)\r
+            \r
+            #\r
+            # Custom makefile of Defines\r
+            #\r
+            RecordSet = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_CUSTOM_MAKEFILE, Arch)\r
+            if RecordSet[0] != '':\r
+                for Item in RecordSet:\r
+                    List = Item.split(DataType.TAB_VALUE_SPLIT)\r
+                    if len(List) == 2:\r
+                        ModuleHeader.CustomMakefile[CleanString(List[0])] = CleanString(List[1])\r
+                    else:\r
+                        RaiseParserError(Item, 'CUSTOM_MAKEFILE of Defines', File, 'CUSTOM_MAKEFILE=<Family>|<Filename>')\r
+            \r
+            #\r
+            # EntryPoint and UnloadImage of Defines\r
+            #\r
+            RecordSet = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_ENTRY_POINT, Arch)\r
+            if RecordSet[0] != '':\r
+                for Item in RecordSet:\r
+                    Image = ModuleExternImageClass()\r
+                    Image.ModuleEntryPoint = CleanString(Item)\r
+                    self.Module.ExternImages.append(Image)\r
+            RecordSet = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_UNLOAD_IMAGE, Arch)\r
+            if RecordSet[0] != '':\r
+                for Item in RecordSet:\r
+                    Image = ModuleExternImageClass()\r
+                    Image.ModuleUnloadImage = CleanString(Item)\r
+                    self.Module.ExternImages.append(Image)\r
+            \r
+            #\r
+            # Constructor and Destructor of Defines\r
+            #\r
+            RecordSet = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_CONSTRUCTOR, Arch)\r
+            if RecordSet[0] != '':\r
+                for Item in RecordSet:\r
+                    LibraryClass = ModuleExternLibraryClass()\r
+                    LibraryClass.Constructor = CleanString(Item)\r
+                    self.Module.ExternLibraries.append(LibraryClass)\r
+            RecordSet = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_DESTRUCTOR, Arch)\r
+            if RecordSet[0] != '':\r
+                for Item in RecordSet:\r
+                    LibraryClass = ModuleExternLibraryClass()\r
+                    LibraryClass.Destructor = CleanString(Item)\r
+                    self.Module.ExternLibraries.append(LibraryClass)\r
+            \r
+            #\r
+            # Define of Defines\r
+            #\r
+            RecordSet = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_DEFINE, Arch)\r
+            if RecordSet[0] != '':\r
+                for Item in RecordSet:\r
+                    List = Item.split(DataType.TAB_EQUAL_SPLIT)\r
+                    if len(List) != 2:\r
+                        RaiseParserError(Item, 'DEFINE of Defines', File, 'DEFINE <Word> = <Word>')\r
+                    else:\r
+                        ModuleHeader.Define[CleanString(List[0])] = CleanString(List[1])\r
+            \r
+            #\r
+            # Spec\r
+            #\r
+            RecordSet = QueryDefinesItem(self.TblInf, TAB_INF_DEFINES_SPEC, Arch)\r
+            if RecordSet[0] != '':\r
+                for Item in RecordSet:\r
+                    List = Item.split(DataType.TAB_EQUAL_SPLIT)\r
+                    if len(List) != 2:\r
+                        RaiseParserError(Item, 'SPEC of Defines', File, 'SPEC <Word> = <Version>')\r
+                    else:\r
+                        ModuleHeader.Specification[CleanString(List[0])] = CleanString(List[1])\r
+            \r
+            self.Module.Header[Arch] = ModuleHeader\r
+    \r
+    \r
+    ## GenBuildOptions\r
+    #\r
+    # Gen BuildOptions of Inf\r
+    # [<Family>:]<ToolFlag>=Flag\r
+    #\r
+    # @param ContainerFile: The Inf file full path \r
+    #\r
+    def GenBuildOptions(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_BUILD_OPTIONS)\r
+        BuildOptions = {}\r
+        #\r
+        # Get all BuildOptions\r
+        #\r
+        RecordSet = self.RecordSet[MODEL_META_DATA_BUILD_OPTION]\r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in self.SupArchList:\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    (Family, ToolChain, Flag) = GetBuildOption(Record[0], ContainerFile, Record[2])\r
+                    MergeArches(BuildOptions, (Family, ToolChain, Flag), Arch)\r
+                    #\r
+                    # Update to Database\r
+                    #\r
+                    #SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'\r
+                    #                where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(Family), ConvertToSqlString2(ToolChain), ConvertToSqlString2(Flag), Record[3])\r
+                    #self.TblInf.Exec(SqlCommand)\r
+\r
+        for Key in BuildOptions.keys():\r
+            BuildOption = BuildOptionClass(Key[0], Key[1], Key[2])\r
+            BuildOption.SupArchList = BuildOptions[Key]\r
+            self.Module.BuildOptions.append(BuildOption)  \r
+\r
+    ## GenIncludes\r
+    #\r
+    # Gen Includes of Inf\r
+    # \r
+    #\r
+    # @param ContainerFile: The Inf file full path \r
+    #\r
+    def GenIncludes(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_INCLUDES)\r
+        Includes = sdict()\r
+        #\r
+        # Get all Includes\r
+        #\r
+        RecordSet = self.RecordSet[MODEL_EFI_INCLUDE]\r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in self.SupArchList:\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    MergeArches(Includes, Record[0], Arch)\r
+\r
+        for Key in Includes.keys():\r
+            Include = IncludeClass()\r
+            Include.FilePath = NormPath(Key)\r
+            Include.SupArchList = Includes[Key]\r
+            self.Module.Includes.append(Include)\r
+        \r
+    ## GenLibraries\r
+    #\r
+    # Gen Libraries of Inf\r
+    # \r
+    #\r
+    # @param ContainerFile: The Inf file full path \r
+    #\r
+    def GenLibraries(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_LIBRARIES)\r
+        Libraries = sdict()\r
+        #\r
+        # Get all Includes\r
+        #\r
+        RecordSet = self.RecordSet[MODEL_EFI_LIBRARY_INSTANCE]\r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in self.SupArchList:\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    MergeArches(Libraries, Record[0], Arch)\r
+\r
+        for Key in Libraries.keys():\r
+            Library = ModuleLibraryClass()\r
+            # replace macro and remove file extension\r
+            Library.Library = Key.rsplit('.', 1)[0]\r
+            Library.SupArchList = Libraries[Key]\r
+            self.Module.Libraries.append(Library)\r
+    \r
+    ## GenLibraryClasses\r
+    #\r
+    # Get LibraryClass of Inf\r
+    # <LibraryClassKeyWord>|<LibraryInstance>\r
+    #\r
+    # @param ContainerFile: The Inf file full path \r
+    #\r
+    def GenLibraryClasses(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES)\r
+        LibraryClasses = {}\r
+        #\r
+        # Get all LibraryClasses\r
+        #\r
+        RecordSet = self.RecordSet[MODEL_EFI_LIBRARY_CLASS]\r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in self.SupArchList:\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    (LibClassName, LibClassIns, Pcd, SupModelList) = GetLibraryClassOfInf([Record[0], Record[4]], ContainerFile, self.WorkspaceDir, Record[2])\r
+                    MergeArches(LibraryClasses, (LibClassName, LibClassIns, Pcd, SupModelList), Arch)\r
+                    #\r
+                    # Update to Database\r
+                    #\r
+                    #SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'\r
+                    #                where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(LibClassName), ConvertToSqlString2(LibClassIns), ConvertToSqlString2(SupModelList), Record[3])\r
+                    #self.TblInf.Exec(SqlCommand)\r
+        \r
+        for Key in LibraryClasses.keys():\r
+            KeyList = Key[0].split(DataType.TAB_VALUE_SPLIT)\r
+            LibraryClass = LibraryClassClass()\r
+            LibraryClass.LibraryClass = Key[0]\r
+            LibraryClass.RecommendedInstance = NormPath(Key[1])\r
+            LibraryClass.FeatureFlag = Key[2]\r
+            LibraryClass.SupArchList = LibraryClasses[Key]\r
+            LibraryClass.SupModuleList = GetSplitValueList(Key[3])\r
+            self.Module.LibraryClasses.append(LibraryClass)\r
+\r
+    ## GenPackages\r
+    #\r
+    # Gen Packages of Inf\r
+    # \r
+    #\r
+    # @param ContainerFile: The Inf file full path \r
+    #\r
+    def GenPackages(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_PACKAGES)\r
+        Packages = {}\r
+        #\r
+        # Get all Packages\r
+        #\r
+        RecordSet = self.RecordSet[MODEL_META_DATA_PACKAGE]\r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in self.SupArchList:\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    CheckFileType(Record[0], '.Dec', ContainerFile, 'package', Record[0], Record[2])\r
+                    CheckFileExist(self.WorkspaceDir, Record[0], ContainerFile, 'Packages', Record[0], Record[2])\r
+                    MergeArches(Packages, Record[0], Arch)\r
+                    \r
+        for Key in Packages.keys():\r
+            Package = ModulePackageDependencyClass()\r
+            Package.FilePath = NormPath(Key)\r
+            Package.SupArchList = Packages[Key]\r
+            self.Module.PackageDependencies.append(Package)\r
+\r
+    ## GenNmakes\r
+    #\r
+    # Gen Nmakes of Inf\r
+    # \r
+    #\r
+    # @param ContainerFile: The Inf file full path \r
+    #\r
+    def GenNmakes(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_NMAKE)\r
+        Nmakes = sdict()\r
+        #\r
+        # Get all Nmakes\r
+        #\r
+        RecordSet = self.RecordSet[MODEL_META_DATA_NMAKE]\r
+\r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in self.SupArchList:\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    MergeArches(Nmakes, Record[0], Arch)\r
+                \r
+        for Key in Nmakes.keys():\r
+            List = GetSplitValueList(Key, DataType.TAB_EQUAL_SPLIT, MaxSplit=1)\r
+            if len(List) != 2:\r
+                RaiseParserError(Key, 'Nmake', ContainerFile, '<MacroName> = <Value>')\r
+            Nmake = ModuleNmakeClass()\r
+            Nmake.Name = List[0]\r
+            Nmake.Value = List[1]\r
+            Nmake.SupArchList = Nmakes[Key]\r
+            self.Module.Nmake.append(Nmake)\r
+\r
+            # convert R8 format to R9 format\r
+            if Nmake.Name == "IMAGE_ENTRY_POINT":\r
+                Image = ModuleExternImageClass()\r
+                Image.ModuleEntryPoint = Nmake.Value\r
+                self.Module.ExternImages.append(Image)\r
+            elif Nmake.Name == "DPX_SOURCE":\r
+                Source = ModuleSourceFileClass(NormPath(Nmake.Value), "", "", "", "", Nmake.SupArchList)\r
+                self.Module.Sources.append(Source)\r
+            else:\r
+                ToolList = gNmakeFlagPattern.findall(Nmake.Name)\r
+                if len(ToolList) == 0 or len(ToolList) != 1:\r
+                    EdkLogger.warn("\nParser", "Don't know how to do with MACRO: %s" % Nmake.Name, \r
+                                   ExtraData=ContainerFile)\r
+                else:\r
+                    if ToolList[0] in gNmakeFlagName2ToolCode:\r
+                        Tool = gNmakeFlagName2ToolCode[ToolList[0]]\r
+                    else:\r
+                        Tool = ToolList[0]\r
+                    BuildOption = BuildOptionClass("MSFT", "*_*_*_%s_FLAGS" % Tool, Nmake.Value)\r
+                    BuildOption.SupArchList = Nmake.SupArchList\r
+                    self.Module.BuildOptions.append(BuildOption)\r
+    \r
+    ## GenPcds\r
+    #\r
+    # Gen Pcds of Inf\r
+    # <TokenSpaceGuidCName>.<PcdCName>[|<Value>]\r
+    #\r
+    # @param ContainerFile: The Dec file full path \r
+    #\r
+    def GenPcds(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_PCDS)\r
+        Pcds = {}\r
+        \r
+        #\r
+        # Get all Guids\r
+        #\r
+        RecordSet1 = self.RecordSet[MODEL_PCD_FIXED_AT_BUILD]\r
+        RecordSet2 = self.RecordSet[MODEL_PCD_PATCHABLE_IN_MODULE]\r
+        RecordSet3 = self.RecordSet[MODEL_PCD_FEATURE_FLAG]\r
+        RecordSet4 = self.RecordSet[MODEL_PCD_DYNAMIC_EX]\r
+        RecordSet5 = self.RecordSet[MODEL_PCD_DYNAMIC]\r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in self.SupArchList:\r
+            for Record in RecordSet1:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    if self.Module.Header[Arch].LibraryClass != {}:\r
+                        pass\r
+                    MergeArches(Pcds, self.GetPcdOfInf(Record[0], TAB_PCDS_FIXED_AT_BUILD, ContainerFile, Record[2]), Arch)\r
+            for Record in RecordSet2:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    MergeArches(Pcds, self.GetPcdOfInf(Record[0], TAB_PCDS_PATCHABLE_IN_MODULE, ContainerFile, Record[2]), Arch)\r
+            for Record in RecordSet3:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    MergeArches(Pcds, self.GetPcdOfInf(Record[0], TAB_PCDS_FEATURE_FLAG, ContainerFile, Record[2]), Arch)\r
+            for Record in RecordSet4:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    MergeArches(Pcds, self.GetPcdOfInf(Record[0], TAB_PCDS_DYNAMIC_EX, ContainerFile, Record[2]), Arch)\r
+            for Record in RecordSet5:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    MergeArches(Pcds, self.GetPcdOfInf(Record[0], "", ContainerFile, Record[2]), Arch)\r
+\r
+        for Key in Pcds.keys():\r
+            Pcd = PcdClass()\r
+            Pcd.CName = Key[1]\r
+            Pcd.TokenSpaceGuidCName = Key[0]\r
+            Pcd.DefaultValue = Key[2]\r
+            Pcd.ItemType = Key[3]\r
+            Pcd.SupArchList = Pcds[Key]\r
+            self.Module.PcdCodes.append(Pcd)\r
+    \r
+    ## GenSources\r
+    #\r
+    # Gen Sources of Inf\r
+    # <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]\r
+    #\r
+    # @param ContainerFile: The Dec file full path \r
+    #\r
+    def GenSources(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_SOURCES)\r
+        Sources = {}\r
+\r
+        #\r
+        # Get all Nmakes\r
+        #\r
+        RecordSet = self.RecordSet[MODEL_EFI_SOURCE_FILE]\r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in self.SupArchList:\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    MergeArches(Sources, GetSource(Record[0], ContainerFile, self.Identification.FileRelativePath, Record[2]), Arch)\r
+\r
+        for Key in Sources.keys():\r
+            Source = ModuleSourceFileClass(Key[0], Key[2], Key[3], Key[1], Key[4], Sources[Key])\r
+            self.Module.Sources.append(Source)\r
+    \r
+    ## GenUserExtensions\r
+    #\r
+    # Gen UserExtensions of Inf\r
+    #\r
+    def GenUserExtensions(self, ContainerFile):\r
+#        #\r
+#        # UserExtensions\r
+#        #\r
+#        if self.UserExtensions != '':\r
+#            UserExtension = UserExtensionsClass()\r
+#            Lines = self.UserExtensions.splitlines()\r
+#            List = GetSplitValueList(Lines[0], DataType.TAB_SPLIT, 2)\r
+#            if len(List) != 3:\r
+#                RaiseParserError(Lines[0], 'UserExtensions', File, "UserExtensions.UserId.'Identifier'")\r
+#            else:\r
+#                UserExtension.UserID = List[1]\r
+#                UserExtension.Identifier = List[2][0:-1].replace("'", '').replace('\"', '')\r
+#                for Line in Lines[1:]:\r
+#                    UserExtension.Content = UserExtension.Content + CleanString(Line) + '\n'\r
+#            self.Module.UserExtensions.append(UserExtension)\r
+        pass\r
+\r
+    ## GenGuids\r
+    #\r
+    # Gen Guids of Inf\r
+    # <CName>=<GuidValue>\r
+    #\r
+    # @param ContainerFile: The Inf file full path \r
+    #\r
+    def GenGuids(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_GUIDS)\r
+        Guids = {}\r
+        #\r
+        # Get all Guids\r
+        #\r
+        RecordSet = self.RecordSet[MODEL_EFI_GUID]\r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in self.SupArchList:\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    MergeArches(Guids, Record[0], Arch)\r
+        \r
+        for Key in Guids.keys():\r
+            Guid = GuidClass()\r
+            Guid.CName = Key\r
+            Guid.SupArchList = Guids[Key]\r
+            self.Module.Guids.append(Guid)\r
+\r
+    ## GenProtocols\r
+    #\r
+    # Gen Protocols of Inf\r
+    # <CName>\r
+    #\r
+    # @param ContainerFile: The Inf file full path \r
+    #\r
+    def GenProtocols(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_PROTOCOLS)\r
+        Protocols = {}\r
+        #\r
+        # Get all Guids\r
+        #\r
+        RecordSet = self.RecordSet[MODEL_EFI_PROTOCOL]\r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in self.SupArchList:\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    MergeArches(Protocols, Record[0], Arch)\r
+                \r
+        for Key in Protocols.keys():\r
+            Protocol = ProtocolClass()\r
+            Protocol.CName = Key\r
+            Protocol.SupArchList = Protocols[Key]\r
+            self.Module.Protocols.append(Protocol)\r
+    \r
+    ## GenPpis\r
+    #\r
+    # Gen Ppis of Inf\r
+    # <CName>\r
+    #\r
+    # @param ContainerFile: The Inf file full path \r
+    #\r
+    def GenPpis(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_PPIS)\r
+        Ppis = {}\r
+        #\r
+        # Get all Guids\r
+        #\r
+        RecordSet = self.RecordSet[MODEL_EFI_PPI]\r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in self.SupArchList:\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    MergeArches(Ppis, Record[0], Arch)\r
+\r
+        for Key in Ppis.keys():\r
+            Ppi = PpiClass()\r
+            Ppi.CName = Key\r
+            Ppi.SupArchList = Ppis[Key]\r
+            self.Module.Ppis.append(Ppi)\r
+\r
+    ## GenDepexes\r
+    #\r
+    # Gen Depex of Inf\r
+    #\r
+    # @param ContainerFile: The Inf file full path \r
+    #\r
+    def GenDepexes(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_DEPEX)\r
+        Depex = {}\r
+        #\r
+        # Get all Depexes\r
+        #\r
+        RecordSet = self.RecordSet[MODEL_EFI_DEPEX]\r
+        \r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in self.SupArchList:\r
+            Line = ''\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    Line = Line + Record[0] + ' '\r
+            MergeArches(Depex, Line, Arch)\r
+\r
+        for Key in Depex.keys():\r
+            Dep = ModuleDepexClass()\r
+            Dep.Depex = Key\r
+            Dep.SupArchList = Depex[Key]\r
+            self.Module.Depex.append(Dep)\r
+\r
+    ## GenBinaries\r
+    #\r
+    # Gen Binary of Inf\r
+    # <FileType>|<Filename>|<Target>[|<TokenSpaceGuidCName>.<PcdCName>]\r
+    #\r
+    # @param ContainerFile: The Dec file full path \r
+    #\r
+    def GenBinaries(self, ContainerFile):\r
+        EdkLogger.debug(2, "Generate %s ..." % TAB_BINARIES)\r
+        Binaries = {}\r
+        \r
+        #\r
+        # Get all Guids\r
+        #\r
+        RecordSet = self.RecordSet[MODEL_EFI_BINARY_FILE]\r
+\r
+        #\r
+        # Go through each arch\r
+        #\r
+        for Arch in self.SupArchList:\r
+            for Record in RecordSet:\r
+                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
+                    MergeArches(Binaries, GetBinary(Record[0], ContainerFile, self.Identification.FileRelativePath, Record[2]), Arch)\r
+\r
+        for Key in Binaries.keys():\r
+            Binary = ModuleBinaryFileClass(NormPath(Key[1]), Key[0], Key[2], Key[3], Binaries[Key])\r
+            self.Module.Binaries.append(Binary)\r
+\r
+    ## Parse DEFINE statement\r
+    #\r
+    # Get DEFINE macros\r
+    #\r
+    # 1. Insert a record into TblDec\r
+    # Value1: Macro Name\r
+    # Value2: Macro Value\r
+    #\r
+    def ParseDefine(self, LineValue, StartLine, Table, FileID, Filename, SectionName, Model, Arch):\r
+        EdkLogger.debug(EdkLogger.DEBUG_2, "DEFINE statement '%s' found in section %s" % (LineValue, SectionName))\r
+        SectionModel = Section[SectionName.upper()]\r
+        Define = GetSplitValueList(CleanString(LineValue[LineValue.upper().find(DataType.TAB_DEFINE.upper() + ' ') + len(DataType.TAB_DEFINE + ' ') : ]), TAB_EQUAL_SPLIT, 1)\r
+        Table.Insert(Model, Define[0], Define[1], '', '', '', Arch, SectionModel, FileID, StartLine, -1, StartLine, -1, 0)\r
+\r
 ##\r
 #\r
 # This acts like the main() function for the script, unless it is 'import'ed into another\r
 # script.\r
 #\r
 if __name__ == '__main__':\r
-    import sys\r
-    print os.path.abspath(sys.argv[1])\r
-    P = Inf(os.path.abspath(sys.argv[1]), True, True, os.getenv('WORKSPACE'))\r
+    EdkLogger.Initialize()\r
+    EdkLogger.SetLevel(EdkLogger.DEBUG_0)\r
+        \r
+    W = os.getenv('WORKSPACE')\r
+    F = os.path.join(W, 'MdeModulePkg/Application/HelloWorld/HelloWorld.inf')\r
+    \r
+    Db = Database.Database(DATABASE_PATH)\r
+    Db.InitDatabase()\r
+    \r
+    P = Inf(os.path.normpath(F), False, True, W, Db)\r
     P.ShowModule()\r
+    \r
+    Db.Close()\r
diff --git a/Source/Python/Common/Parsing.py b/Source/Python/Common/Parsing.py
new file mode 100644 (file)
index 0000000..c883046
--- /dev/null
@@ -0,0 +1,611 @@
+## @file\r
+# This file is used to define common parsing related functions used in parsing INF/DEC/DSC process \r
+#\r
+# Copyright (c) 2008, Intel Corporation\r
+# All rights reserved. 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
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+\r
+##\r
+# Import Modules\r
+#\r
+from String import *\r
+from CommonDataClass.DataClass import *\r
+from DataType import *\r
+\r
+## ParseDefineMacro\r
+#\r
+# Search whole table to find all defined Macro and replaced them with the real values\r
+#\r
+def ParseDefineMacro2(Table, RecordSets, GlobalMacro):\r
+    Macros = {}\r
+    #\r
+    # Find all DEFINE macros in section [Header] and its section\r
+    #\r
+    SqlCommand = """select Value1, Value2, BelongsToItem, StartLine, Arch from %s\r
+                    where Model = %s\r
+                    and Enabled > -1""" % (Table.Table, MODEL_META_DATA_DEFINE)\r
+    RecordSet = Table.Exec(SqlCommand)\r
+    for Record in RecordSet:\r
+        Macros[Record[0]] = Record[1]\r
+    \r
+    #\r
+    # Overrided by Global Macros\r
+    #\r
+    for Key in GlobalMacro.keys():\r
+        Macros[Key] = GlobalMacro[Key]\r
+    \r
+    #\r
+    # Replace the Macros\r
+    #\r
+    for Key in RecordSets.keys():\r
+        if RecordSets[Key] != []:\r
+            for Item in RecordSets[Key]:\r
+                Item[0] = ReplaceMacro(Item[0], Macros)\r
+    \r
+## ParseDefineMacro\r
+#\r
+# Search whole table to find all defined Macro and replaced them with the real values\r
+#\r
+def ParseDefineMacro(Table, GlobalMacro):\r
+    Macros = {}\r
+    #\r
+    # Find all DEFINE macros\r
+    #\r
+    SqlCommand = """select Value1, Value2, BelongsToItem, StartLine, Arch from %s\r
+                    where Model = %s\r
+                    and Enabled > -1""" % (Table.Table, MODEL_META_DATA_DEFINE)\r
+    RecordSet = Table.Exec(SqlCommand)\r
+    for Record in RecordSet:\r
+#***************************************************************************************************************************************************\r
+#            The follow SqlCommand (expr replace) is not supported in Sqlite 3.3.4 which is used in Python 2.5                                     *\r
+#            Reserved Only                                                                                                                         *\r
+#            SqlCommand = """update %s set Value1 = replace(Value1, '%s', '%s')                                                                    *\r
+#                            where ID in (select ID from %s                                                                                        * \r
+#                                         where Model = %s                                                                                         *\r
+#                                         and Value1 like '%%%s%%'                                                                                 *\r
+#                                         and StartLine > %s                                                                                       *\r
+#                                         and Enabled > -1                                                                                         *\r
+#                                         and Arch = '%s')""" % \                                                                                  *  \r
+#                                         (self.TblDsc.Table, Record[0], Record[1], self.TblDsc.Table, Record[2], Record[1], Record[3], Record[4]) *\r
+#***************************************************************************************************************************************************\r
+        Macros[Record[0]] = Record[1]\r
+    \r
+    #\r
+    # Overrided by Global Macros\r
+    #\r
+    for Key in GlobalMacro.keys():\r
+        Macros[Key] = GlobalMacro[Key]\r
+    \r
+    #\r
+    # Found all defined macro and replaced\r
+    #\r
+    SqlCommand = """select ID, Value1 from %s\r
+                    where Model != %s\r
+                    and Value1 like '%%$(%%' and Value1 like '%%)%%'\r
+                    and Enabled > -1"""  % (Table.Table, MODEL_META_DATA_DEFINE)\r
+    FoundRecords = Table.Exec(SqlCommand)\r
+    for FoundRecord in FoundRecords:\r
+        NewValue = ReplaceMacro(FoundRecord[1], Macros)\r
+        SqlCommand = """update %s set Value1 = '%s'\r
+                        where ID = %s""" % (Table.Table, ConvertToSqlString2(NewValue), FoundRecord[0])\r
+        Table.Exec(SqlCommand)\r
+\r
+##QueryDefinesItem\r
+#\r
+# Search item of section [Defines] by name, return its values\r
+#\r
+# @param Table: The Table to be executed\r
+# @param Name:  The Name of item of section [Defines]\r
+# @param Arch:  The Arch of item of section [Defines]\r
+#\r
+# @retval RecordSet: A list of all matched records\r
+#\r
+def QueryDefinesItem(Table, Name, Arch):\r
+    SqlCommand = """select Value2 from %s\r
+                    where Model = %s\r
+                    and Value1 = '%s'\r
+                    and Arch = '%s'\r
+                    and Enabled > -1""" % (Table.Table, MODEL_META_DATA_HEADER, ConvertToSqlString2(Name), ConvertToSqlString2(Arch))\r
+    RecordSet = Table.Exec(SqlCommand)\r
+    if len(RecordSet) < 1:\r
+        SqlCommand = """select Value2 from %s\r
+                    where Model = %s\r
+                    and Value1 = '%s'\r
+                    and Arch = '%s'\r
+                    and Enabled > -1""" % (Table.Table, MODEL_META_DATA_HEADER, ConvertToSqlString2(Name), ConvertToSqlString2(TAB_ARCH_COMMON.upper()))\r
+        RecordSet = Table.Exec(SqlCommand)\r
+    if len(RecordSet) == 1:\r
+        if Name == TAB_INF_DEFINES_LIBRARY_CLASS:\r
+            return [RecordSet[0][0]]\r
+        else:\r
+            return GetSplitValueList(RecordSet[0][0])\r
+    elif len(RecordSet) < 1:\r
+        return ['']\r
+    elif len(RecordSet) > 1:\r
+        RetVal = []\r
+        for Record in RecordSet:\r
+            if Name == TAB_INF_DEFINES_LIBRARY_CLASS:\r
+                RetVal.append(Record[0])\r
+            else:\r
+                Items = GetSplitValueList(Record[0])\r
+                for Item in Items:\r
+                    RetVal.append(Item)\r
+        return RetVal\r
+\r
+##QueryDscItem\r
+#\r
+# Search all dsc item for a specific section\r
+#\r
+# @param Table: The Table to be executed\r
+# @param Model:  The type of section\r
+#\r
+# @retval RecordSet: A list of all matched records\r
+#\r
+def QueryDscItem(Table, Model, BelongsToItem):\r
+    SqlCommand = """select Value1, Arch, StartLine, ID, Value2 from %s\r
+                    where Model = %s\r
+                    and BelongsToItem = %s\r
+                    and Enabled > -1""" % (Table.Table, Model, BelongsToItem)\r
+    return Table.Exec(SqlCommand)\r
+\r
+##QueryDecItem\r
+#\r
+# Search all dec item for a specific section\r
+#\r
+# @param Table: The Table to be executed\r
+# @param Model:  The type of section\r
+#\r
+# @retval RecordSet: A list of all matched records\r
+#\r
+def QueryDecItem(Table, Model, BelongsToItem):\r
+    SqlCommand = """select Value1, Arch, StartLine, ID, Value2 from %s\r
+                    where Model = %s\r
+                    and BelongsToItem = %s\r
+                    and Enabled > -1""" % (Table.Table, Model, BelongsToItem)\r
+    return Table.Exec(SqlCommand)\r
+\r
+##QueryInfItem\r
+#\r
+# Search all dec item for a specific section\r
+#\r
+# @param Table: The Table to be executed\r
+# @param Model: The type of section\r
+#\r
+# @retval RecordSet: A list of all matched records\r
+#\r
+def QueryInfItem(Table, Model, BelongsToItem):\r
+    SqlCommand = """select Value1, Arch, StartLine, ID, Value2 from %s\r
+                    where Model = %s\r
+                    and BelongsToItem = %s\r
+                    and Enabled > -1""" % (Table.Table, Model, BelongsToItem)\r
+    return Table.Exec(SqlCommand)\r
+\r
+## GetBuildOption\r
+#\r
+# Parse a string with format "[<Family>:]<ToolFlag>=Flag"\r
+# Return (Family, ToolFlag, Flag)\r
+#\r
+# @param String:  String with BuildOption statement\r
+# @param File:    The file which defines build option, used in error report\r
+#\r
+# @retval truple() A truple structure as (Family, ToolChain, Flag)\r
+#\r
+def GetBuildOption(String, File, LineNo = -1):\r
+    if String.find(TAB_EQUAL_SPLIT) < 0:\r
+        RaiseParserError(String, 'BuildOptions', File, '[<Family>:]<ToolFlag>=Flag', LineNo)\r
+    (Family, ToolChain, Flag) = ('', '', '')\r
+    List = GetSplitValueList(String, TAB_EQUAL_SPLIT, MaxSplit = 1)\r
+    if List[0].find(':') > -1:\r
+        Family = List[0][ : List[0].find(':')].strip()\r
+        ToolChain = List[0][List[0].find(':') + 1 : ].strip()\r
+    else:\r
+        ToolChain = List[0].strip()\r
+    Flag = List[1].strip()\r
+\r
+    return (Family, ToolChain, Flag)\r
+\r
+## Get Library Class\r
+#\r
+# Get Library of Dsc as <LibraryClassKeyWord>|<LibraryInstance>\r
+# \r
+# @param Item:           String as <LibraryClassKeyWord>|<LibraryInstance>\r
+# @param ContainerFile:  The file which describes the library class, used for error report\r
+#\r
+# @retval (LibraryClassKeyWord, LibraryInstance, [SUP_MODULE_LIST]) Formatted Library Item\r
+#\r
+def GetLibraryClass(Item, ContainerFile, WorkspaceDir, LineNo = -1):\r
+    List = GetSplitValueList(Item[0])\r
+    SupMod = SUP_MODULE_LIST_STRING\r
+    if len(List) != 2:\r
+        RaiseParserError(Item[0], 'LibraryClasses', ContainerFile, '<LibraryClassKeyWord>|<LibraryInstance>')\r
+    else:\r
+        CheckFileType(List[1], '.Inf', ContainerFile, 'library class instance', Item[0], LineNo)\r
+        CheckFileExist(WorkspaceDir, List[1], ContainerFile, 'LibraryClasses', Item[0], LineNo)\r
+        if Item[1] != '':\r
+            SupMod = Item[1]\r
+\r
+    return (List[0], List[1], SupMod)\r
+\r
+## Get Library Class\r
+#\r
+# Get Library of Dsc as <LibraryClassKeyWord>[|<LibraryInstance>][|<TokenSpaceGuidCName>.<PcdCName>]\r
+# \r
+# @param Item:           String as <LibraryClassKeyWord>|<LibraryInstance>\r
+# @param ContainerFile:  The file which describes the library class, used for error report\r
+#\r
+# @retval (LibraryClassKeyWord, LibraryInstance, [SUP_MODULE_LIST]) Formatted Library Item\r
+#\r
+def GetLibraryClassOfInf(Item, ContainerFile, WorkspaceDir, LineNo = -1):\r
+    ItemList = GetSplitValueList((Item[0] + DataType.TAB_VALUE_SPLIT * 2))\r
+    SupMod = SUP_MODULE_LIST_STRING\r
+\r
+    if len(ItemList) > 5:\r
+        RaiseParserError(Item[0], 'LibraryClasses', ContainerFile, '<LibraryClassKeyWord>[|<LibraryInstance>][|<TokenSpaceGuidCName>.<PcdCName>]')\r
+    else:\r
+        CheckFileType(ItemList[1], '.Inf', ContainerFile, 'LibraryClasses', Item[0], LineNo)\r
+        CheckFileExist(WorkspaceDir, ItemList[1], ContainerFile, 'LibraryClasses', Item[0], LineNo)\r
+        if ItemList[2] != '':\r
+            CheckPcdTokenInfo(ItemList[2], 'LibraryClasses', ContainerFile, LineNo)\r
+        if Item[1] != '':\r
+            SupMod = Item[1]\r
+\r
+    return (ItemList[0], ItemList[1], ItemList[2], SupMod)    \r
+\r
+## CheckPcdTokenInfo\r
+#\r
+# Check if PcdTokenInfo is following <TokenSpaceGuidCName>.<PcdCName>\r
+#\r
+# @param TokenInfoString:  String to be checked\r
+# @param Section:          Used for error report\r
+# @param File:             Used for error report\r
+#\r
+# @retval True PcdTokenInfo is in correct format\r
+#\r
+def CheckPcdTokenInfo(TokenInfoString, Section, File, LineNo = -1):\r
+    Format = '<TokenSpaceGuidCName>.<PcdCName>'\r
+    if TokenInfoString != '' and TokenInfoString != None:\r
+        TokenInfoList = GetSplitValueList(TokenInfoString, TAB_SPLIT)\r
+        if len(TokenInfoList) == 2:\r
+            return True\r
+\r
+    RaiseParserError(TokenInfoString, Section, File, Format, LineNo)\r
+\r
+## Get Pcd\r
+#\r
+# Get Pcd of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<Type>|<MaximumDatumSize>]\r
+# \r
+# @param Item:           String as <PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<Type>|<MaximumDatumSize>]\r
+# @param ContainerFile:  The file which describes the pcd, used for error report\r
+#\r
+# @retval (TokenInfo[1], TokenInfo[0], List[1], List[2], List[3], Type)\r
+#\r
+def GetPcd(Item, Type, ContainerFile, LineNo = -1):\r
+    List = GetSplitValueList(Item + TAB_VALUE_SPLIT * 2)\r
+    if len(List) < 4 or len(List) > 6:\r
+        RaiseParserError(Item, 'Pcds' + Type, ContainerFile, '<PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<Type>|<MaximumDatumSize>]', LineNo)\r
+    CheckPcdTokenInfo(List[0], 'Pcds' + Type, ContainerFile, LineNo)\r
+    TokenInfo = GetSplitValueList(List[0], TAB_SPLIT)\r
+    \r
+    return (TokenInfo[1], TokenInfo[0], List[1], List[2], List[3], Type)\r
+\r
+## Get FeatureFlagPcd\r
+#\r
+# Get FeatureFlagPcd of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|TRUE/FALSE\r
+# \r
+# @param Item:           String as <PcdTokenSpaceGuidCName>.<TokenCName>|TRUE/FALSE\r
+# @param ContainerFile:  The file which describes the pcd, used for error report\r
+#\r
+# @retval (TokenInfo[1], TokenInfo[0], List[1], Type)\r
+#\r
+def GetFeatureFlagPcd(Item, Type, ContainerFile, LineNo = -1):\r
+    List = GetSplitValueList(Item)\r
+    if len(List) != 2:\r
+        RaiseParserError(Item, 'Pcds' + Type, ContainerFile, '<PcdTokenSpaceGuidCName>.<TokenCName>|TRUE/FALSE', LineNo)\r
+\r
+    CheckPcdTokenInfo(List[0], 'Pcds' + Type, ContainerFile, LineNo)\r
+    TokenInfo = GetSplitValueList(List[0], DataType.TAB_SPLIT)\r
+    \r
+    return (TokenInfo[1], TokenInfo[0], List[1], Type)\r
+\r
+## Get DynamicDefaultPcd\r
+#\r
+# Get DynamicDefaultPcd of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<DatumTyp>[|<MaxDatumSize>]]\r
+# \r
+# @param Item:           String as <PcdTokenSpaceGuidCName>.<TokenCName>|TRUE/FALSE\r
+# @param ContainerFile:  The file which describes the pcd, used for error report\r
+#\r
+# @retval (TokenInfo[1], TokenInfo[0], List[1], List[2], List[3], Type)\r
+#\r
+def GetDynamicDefaultPcd(Item, Type, ContainerFile, LineNo = -1):\r
+    List = GetSplitValueList(Item + TAB_VALUE_SPLIT * 2)\r
+    if len(List) < 4 or len(List) > 8:\r
+        RaiseParserError(Item, 'Pcds' + Type, ContainerFile, '<PcdTokenSpaceGuidCName>.<TokenCName>|<Value>[|<DatumTyp>[|<MaxDatumSize>]]', LineNo)\r
+\r
+    CheckPcdTokenInfo(List[0], 'Pcds' + Type, ContainerFile, LineNo)\r
+    TokenInfo = GetSplitValueList(List[0], TAB_SPLIT)\r
+    \r
+    return (TokenInfo[1], TokenInfo[0], List[1], List[2], List[3], Type)\r
+\r
+## Get DynamicHiiPcd\r
+#\r
+# Get DynamicHiiPcd of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<String>|<VariableGuidCName>|<VariableOffset>[|<DefaultValue>[|<MaximumDatumSize>]]\r
+# \r
+# @param Item:           String as <PcdTokenSpaceGuidCName>.<TokenCName>|TRUE/FALSE\r
+# @param ContainerFile:  The file which describes the pcd, used for error report\r
+#\r
+# @retval (TokenInfo[1], TokenInfo[0], List[1], List[2], List[3], List[4], List[5], Type)\r
+#\r
+def GetDynamicHiiPcd(Item, Type, ContainerFile, LineNo = -1):\r
+    List = GetSplitValueList(Item + TAB_VALUE_SPLIT * 2)\r
+    if len(List) < 6 or len(List) > 8:\r
+        RaiseParserError(Item, 'Pcds' + Type, ContainerFile, '<PcdTokenSpaceGuidCName>.<TokenCName>|<String>|<VariableGuidCName>|<VariableOffset>[|<DefaultValue>[|<MaximumDatumSize>]]', LineNo)\r
+\r
+    CheckPcdTokenInfo(List[0], 'Pcds' + Type, ContainerFile, LineNo)\r
+    TokenInfo = GetSplitValueList(List[0], DataType.TAB_SPLIT)\r
+    \r
+    return (TokenInfo[1], TokenInfo[0], List[1], List[2], List[3], List[4], List[5], Type)\r
+\r
+## Get DynamicVpdPcd\r
+#\r
+# Get DynamicVpdPcd of Dsc as <PcdTokenSpaceGuidCName>.<TokenCName>|<VpdOffset>[|<MaximumDatumSize>]\r
+# \r
+# @param Item:           String as <PcdTokenSpaceGuidCName>.<TokenCName>|TRUE/FALSE\r
+# @param ContainerFile:  The file which describes the pcd, used for error report\r
+#\r
+# @retval (TokenInfo[1], TokenInfo[0], List[1], List[2], Type)\r
+#\r
+def GetDynamicVpdPcd(Item, Type, ContainerFile, LineNo = -1):\r
+    List = GetSplitValueList(Item + TAB_VALUE_SPLIT)\r
+    if len(List) < 3 or len(List) > 4:\r
+        RaiseParserError(Item, 'Pcds' + Type, ContainerFile, '<PcdTokenSpaceGuidCName>.<TokenCName>|<VpdOffset>[|<MaximumDatumSize>]', LineNo)\r
+\r
+    CheckPcdTokenInfo(List[0], 'Pcds' + Type, ContainerFile, LineNo)\r
+    TokenInfo = GetSplitValueList(List[0], DataType.TAB_SPLIT)\r
+    \r
+    return (TokenInfo[1], TokenInfo[0], List[1], List[2], Type)\r
+\r
+## GetComponent\r
+#\r
+# Parse block of the components defined in dsc file\r
+# Set KeyValues as [ ['component name', [lib1, lib2, lib3], [bo1, bo2, bo3], [pcd1, pcd2, pcd3]], ...]\r
+#\r
+# @param Lines:             The content to be parsed\r
+# @param KeyValues:         To store data after parsing\r
+#\r
+# @retval True Get component successfully\r
+#\r
+def GetComponent(Lines, KeyValues):\r
+    (findBlock, findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, False, False, False, False, False, False, False)\r
+    ListItem = None\r
+    LibraryClassItem = []\r
+    BuildOption = []\r
+    Pcd = []\r
+\r
+    for Line in Lines:\r
+        Line = Line[0]\r
+        \r
+        #\r
+        # Ignore !include statement\r
+        #\r
+        if Line.upper().find(TAB_INCLUDE.upper() + ' ') > -1 or Line.upper().find(TAB_DEFINE + ' ') > -1:\r
+            continue\r
+        \r
+        if findBlock == False:\r
+            ListItem = Line\r
+            #\r
+            # find '{' at line tail\r
+            #\r
+            if Line.endswith('{'):\r
+                findBlock = True\r
+                ListItem = CleanString(Line.rsplit('{', 1)[0], DataType.TAB_COMMENT_SPLIT)\r
+\r
+        #\r
+        # Parse a block content\r
+        #\r
+        if findBlock:\r
+            if Line.find('<LibraryClasses>') != -1:\r
+                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (True, False, False, False, False, False, False)\r
+                continue\r
+            if Line.find('<BuildOptions>') != -1:\r
+                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, True, False, False, False, False, False)\r
+                continue\r
+            if Line.find('<PcdsFeatureFlag>') != -1:\r
+                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, False, True, False, False, False, False)\r
+                continue\r
+            if Line.find('<PcdsPatchableInModule>') != -1:\r
+                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, False, False, True, False, False, False)\r
+                continue\r
+            if Line.find('<PcdsFixedAtBuild>') != -1:\r
+                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, False, False, False, True, False, False)\r
+                continue\r
+            if Line.find('<PcdsDynamic>') != -1:\r
+                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, False, False, False, False, True, False)\r
+                continue\r
+            if Line.find('<PcdsDynamicEx>') != -1:\r
+                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, False, False, False, False, False, True)\r
+                continue\r
+            if Line.endswith('}'):\r
+                #\r
+                # find '}' at line tail\r
+                #\r
+                KeyValues.append([ListItem, LibraryClassItem, BuildOption, Pcd])\r
+                (findBlock, findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, False, False, False, False, False, False, False)\r
+                LibraryClassItem, BuildOption, Pcd = [], [], []\r
+                continue\r
+\r
+        if findBlock:\r
+            if findLibraryClass:\r
+                LibraryClassItem.append(Line)\r
+            elif findBuildOption:\r
+                BuildOption.append(Line)\r
+            elif findPcdsFeatureFlag:\r
+                Pcd.append((DataType.TAB_PCDS_FEATURE_FLAG_NULL, Line))\r
+            elif findPcdsPatchableInModule:\r
+                Pcd.append((DataType.TAB_PCDS_PATCHABLE_IN_MODULE_NULL, Line))\r
+            elif findPcdsFixedAtBuild:\r
+                Pcd.append((DataType.TAB_PCDS_FIXED_AT_BUILD_NULL, Line))\r
+            elif findPcdsDynamic:\r
+                Pcd.append((DataType.TAB_PCDS_DYNAMIC_DEFAULT_NULL, Line))\r
+            elif findPcdsDynamicEx:\r
+                Pcd.append((DataType.TAB_PCDS_DYNAMIC_EX_DEFAULT_NULL, Line))\r
+        else:\r
+            KeyValues.append([ListItem, [], [], []])\r
+\r
+    return True\r
+\r
+## GetExec\r
+#\r
+# Parse a string with format "InfFilename [EXEC = ExecFilename]"\r
+# Return (InfFilename, ExecFilename)\r
+#\r
+# @param String:  String with EXEC statement\r
+#\r
+# @retval truple() A pair as (InfFilename, ExecFilename)\r
+#\r
+def GetExec(String):\r
+    InfFilename = ''\r
+    ExecFilename = ''\r
+    if String.find('EXEC') > -1:\r
+        InfFilename = String[ : String.find('EXEC')].strip()\r
+        ExecFilename = String[String.find('EXEC') + len('EXEC') : ].strip()\r
+    else:\r
+        InfFilename = String.strip()\r
+\r
+    return (InfFilename, ExecFilename)\r
+\r
+## GetComponents\r
+#\r
+# Parse block of the components defined in dsc file\r
+# Set KeyValues as [ ['component name', [lib1, lib2, lib3], [bo1, bo2, bo3], [pcd1, pcd2, pcd3]], ...]\r
+#\r
+# @param Lines:             The content to be parsed\r
+# @param Key:               Reserved \r
+# @param KeyValues:         To store data after parsing\r
+# @param CommentCharacter:  Comment char, used to ignore comment content\r
+#\r
+# @retval True Get component successfully\r
+#\r
+def GetComponents(Lines, Key, KeyValues, CommentCharacter):\r
+    if Lines.find(DataType.TAB_SECTION_END) > -1:\r
+        Lines = Lines.split(DataType.TAB_SECTION_END, 1)[1]\r
+    (findBlock, findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, False, False, False, False, False, False, False)\r
+    ListItem = None\r
+    LibraryClassItem = []\r
+    BuildOption = []\r
+    Pcd = []\r
+\r
+    LineList = Lines.split('\n')\r
+    for Line in LineList:\r
+        Line = CleanString(Line, CommentCharacter)\r
+        if Line == None or Line == '':\r
+            continue\r
+\r
+        if findBlock == False:\r
+            ListItem = Line\r
+            #\r
+            # find '{' at line tail\r
+            #\r
+            if Line.endswith('{'):\r
+                findBlock = True\r
+                ListItem = CleanString(Line.rsplit('{', 1)[0], CommentCharacter)\r
+\r
+        #\r
+        # Parse a block content\r
+        #\r
+        if findBlock:\r
+            if Line.find('<LibraryClasses>') != -1:\r
+                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (True, False, False, False, False, False, False)\r
+                continue\r
+            if Line.find('<BuildOptions>') != -1:\r
+                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, True, False, False, False, False, False)\r
+                continue\r
+            if Line.find('<PcdsFeatureFlag>') != -1:\r
+                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, False, True, False, False, False, False)\r
+                continue\r
+            if Line.find('<PcdsPatchableInModule>') != -1:\r
+                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, False, False, True, False, False, False)\r
+                continue\r
+            if Line.find('<PcdsFixedAtBuild>') != -1:\r
+                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, False, False, False, True, False, False)\r
+                continue\r
+            if Line.find('<PcdsDynamic>') != -1:\r
+                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, False, False, False, False, True, False)\r
+                continue\r
+            if Line.find('<PcdsDynamicEx>') != -1:\r
+                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, False, False, False, False, False, True)\r
+                continue\r
+            if Line.endswith('}'):\r
+                #\r
+                # find '}' at line tail\r
+                #\r
+                KeyValues.append([ListItem, LibraryClassItem, BuildOption, Pcd])\r
+                (findBlock, findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, False, False, False, False, False, False, False)\r
+                LibraryClassItem, BuildOption, Pcd = [], [], []\r
+                continue\r
+\r
+        if findBlock:\r
+            if findLibraryClass:\r
+                LibraryClassItem.append(Line)\r
+            elif findBuildOption:\r
+                BuildOption.append(Line)\r
+            elif findPcdsFeatureFlag:\r
+                Pcd.append((DataType.TAB_PCDS_FEATURE_FLAG, Line))\r
+            elif findPcdsPatchableInModule:\r
+                Pcd.append((DataType.TAB_PCDS_PATCHABLE_IN_MODULE, Line))\r
+            elif findPcdsFixedAtBuild:\r
+                Pcd.append((DataType.TAB_PCDS_FIXED_AT_BUILD, Line))\r
+            elif findPcdsDynamic:\r
+                Pcd.append((DataType.TAB_PCDS_DYNAMIC, Line))\r
+            elif findPcdsDynamicEx:\r
+                Pcd.append((DataType.TAB_PCDS_DYNAMIC_EX, Line))\r
+        else:\r
+            KeyValues.append([ListItem, [], [], []])\r
+\r
+    return True\r
+\r
+## Get Source\r
+#\r
+# Get Source of Inf as <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]\r
+# \r
+# @param Item:           String as <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]\r
+# @param ContainerFile:  The file which describes the library class, used for error report\r
+#\r
+# @retval (List[0], List[1], List[2], List[3], List[4])\r
+#\r
+def GetSource(Item, ContainerFile, FileRelativePath, LineNo = -1):\r
+    ItemNew = Item + DataType.TAB_VALUE_SPLIT * 4\r
+    List = GetSplitValueList(ItemNew)\r
+    if len(List) < 5 or len(List) > 9:\r
+        RaiseParserError(Item, 'Sources', ContainerFile, '<Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]', LineNo)\r
+    List[0] = NormPath(List[0])\r
+    CheckFileExist(FileRelativePath, List[0], ContainerFile, 'Sources', Item, LineNo)\r
+    if List[4] != '':\r
+        CheckPcdTokenInfo(List[4], 'Sources', ContainerFile, LineNo)\r
+\r
+    return (List[0], List[1], List[2], List[3], List[4])\r
+\r
+## Get Binary\r
+#\r
+# Get Binary of Inf as <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]\r
+# \r
+# @param Item:           String as <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]\r
+# @param ContainerFile:  The file which describes the library class, used for error report\r
+#\r
+# @retval (List[0], List[1], List[2], List[3])\r
+#\r
+def GetBinary(Item, ContainerFile, FileRelativePath, LineNo = -1):\r
+    ItemNew = Item + DataType.TAB_VALUE_SPLIT\r
+    List = GetSplitValueList(ItemNew)\r
+    if len(List) != 4 and len(List) != 5:\r
+        RaiseParserError(Item, 'Binaries', ContainerFile, "<FileType>|<Filename>|<Target>[|<TokenSpaceGuidCName>.<PcdCName>]", LineNo)\r
+    else:\r
+        if List[3] != '':\r
+            CheckPcdTokenInfo(List[3], 'Binaries', ContainerFile, LineNo)\r
+    \r
+    return (List[0], List[1], List[2], List[3])\r
index d021c96..08a7220 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file is used to define common string related functions used in parsing process \r
 #\r
-# Copyright (c) 2007, Intel Corporation\r
+# Copyright (c) 2007 ~ 2008, Intel Corporation\r
 # All rights reserved. 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
@@ -101,149 +101,6 @@ def GenInclude(String, IncludeFiles, Arch):
     else:\r
         return False\r
 \r
-## GetExec\r
-#\r
-# Parse a string with format "InfFilename [EXEC = ExecFilename]"\r
-# Return (InfFilename, ExecFilename)\r
-#\r
-# @param String:  String with EXEC statement\r
-#\r
-# @retval truple() A pair as (InfFilename, ExecFilename)\r
-#\r
-def GetExec(String):\r
-    InfFilename = ''\r
-    ExecFilename = ''\r
-    if String.find('EXEC') > -1:\r
-        InfFilename = String[ : String.find('EXEC')].strip()\r
-        ExecFilename = String[String.find('EXEC') + len('EXEC') : ].strip()\r
-    else:\r
-        InfFilename = String.strip()\r
-\r
-    return (InfFilename, ExecFilename)\r
-\r
-## GetBuildOption\r
-#\r
-# Parse a string with format "[<Family>:]<ToolFlag>=Flag"\r
-# Return (Family, ToolFlag, Flag)\r
-#\r
-# @param String:  String with BuildOption statement\r
-# @param File:    The file which defines build option, used in error report\r
-#\r
-# @retval truple() A truple structure as (Family, ToolChain, Flag)\r
-#\r
-def GetBuildOption(String, File):\r
-    if String.find(DataType.TAB_EQUAL_SPLIT) < 0:\r
-        RaiseParserError(String, 'BuildOptions', File, '[<Family>:]<ToolFlag>=Flag')\r
-    (Family, ToolChain, Flag) = ('', '', '')\r
-    List = GetSplitValueList(String, DataType.TAB_EQUAL_SPLIT, MaxSplit = 1)\r
-    if List[0].find(':') > -1:\r
-        Family = CleanString(List[0][ : List[0].find(':')])\r
-        ToolChain = CleanString(List[0][List[0].find(':') + 1 : ])\r
-    else:\r
-        ToolChain = CleanString(List[0])\r
-    Flag = CleanString(List[1])\r
-\r
-    return (Family, ToolChain, Flag)\r
-\r
-## GetComponents\r
-#\r
-# Parse block of the components defined in dsc file\r
-# Set KeyValues as [ ['component name', [lib1, lib2, lib3], [bo1, bo2, bo3], [pcd1, pcd2, pcd3]], ...]\r
-#\r
-# @param Lines:             The content to be parsed\r
-# @param Key:               Reserved \r
-# @param KeyValues:         To store data after parsing\r
-# @param CommentCharacter:  Comment char, used to ignore comment content\r
-#\r
-# @retval True Get component successfully\r
-#\r
-def GetComponents(Lines, Key, KeyValues, CommentCharacter):\r
-    if Lines.find(DataType.TAB_SECTION_END) > -1:\r
-        Lines = Lines.split(DataType.TAB_SECTION_END, 1)[1]\r
-    (findBlock, findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, False, False, False, False, False, False, False)\r
-    ListItem = None\r
-    LibraryClassItem = []\r
-    BuildOption = []\r
-    Pcd = []\r
-\r
-    LineList = Lines.split('\n')\r
-    for Line in LineList:\r
-        Line = CleanString(Line, CommentCharacter)\r
-        if Line == None or Line == '':\r
-            continue\r
-\r
-        if findBlock == False:\r
-            ListItem = Line\r
-            #\r
-            # find '{' at line tail\r
-            #\r
-            if Line.endswith('{'):\r
-                findBlock = True\r
-                ListItem = CleanString(Line.rsplit('{', 1)[0], CommentCharacter)\r
-\r
-        #\r
-        # Parse a block content\r
-        #\r
-        if findBlock:\r
-            if Line.find('<LibraryClasses>') != -1:\r
-                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (True, False, False, False, False, False, False)\r
-                continue\r
-            if Line.find('<BuildOptions>') != -1:\r
-                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, True, False, False, False, False, False)\r
-                continue\r
-            if Line.find('<PcdsFeatureFlag>') != -1:\r
-                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, False, True, False, False, False, False)\r
-                continue\r
-            if Line.find('<PcdsPatchableInModule>') != -1:\r
-                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, False, False, True, False, False, False)\r
-                continue\r
-            if Line.find('<PcdsFixedAtBuild>') != -1:\r
-                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, False, False, False, True, False, False)\r
-                continue\r
-            if Line.find('<PcdsDynamic>') != -1:\r
-                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, False, False, False, False, True, False)\r
-                continue\r
-            if Line.find('<PcdsDynamicEx>') != -1:\r
-                (findLibraryClass, findBuildOption, findPcdsFeatureFlag, findPcdsPatchableInModule, findPcdsFixedAtBuild, findPcdsDynamic, findPcdsDynamicEx) = (False, False, False, False, False, False, True)\r
-                continue\r
-            if Line.endswith('}'):\r
-                #\r
-                # find '}' at line tail\r
-                #\r
-                KeyValues.append([ListItem, LibraryClassItem, BuildOption, Pcd])\r
-                findBlock = False\r
-                findLibraryClass = False\r
-                findBuildOption = False\r
-                findPcdsFeatureFlag = False\r
-                findPcdsPatchableInModule = False\r
-                findPcdsFixedAtBuild = False\r
-                findPcdsDynamic = False\r
-                findPcdsDynamicEx = False\r
-                LibraryClassItem = []\r
-                BuildOption = []\r
-                Pcd = []\r
-                continue\r
-\r
-        if findBlock:\r
-            if findLibraryClass:\r
-                LibraryClassItem.append(Line)\r
-            elif findBuildOption:\r
-                BuildOption.append(Line)\r
-            elif findPcdsFeatureFlag:\r
-                Pcd.append((DataType.TAB_PCDS_FEATURE_FLAG, Line))\r
-            elif findPcdsPatchableInModule:\r
-                Pcd.append((DataType.TAB_PCDS_PATCHABLE_IN_MODULE, Line))\r
-            elif findPcdsFixedAtBuild:\r
-                Pcd.append((DataType.TAB_PCDS_FIXED_AT_BUILD, Line))\r
-            elif findPcdsDynamic:\r
-                Pcd.append((DataType.TAB_PCDS_DYNAMIC, Line))\r
-            elif findPcdsDynamicEx:\r
-                Pcd.append((DataType.TAB_PCDS_DYNAMIC_EX, Line))\r
-        else:\r
-            KeyValues.append([ListItem, [], [], []])\r
-\r
-    return True\r
-\r
 ## GetLibraryClassesWithModuleType\r
 #\r
 # Get Library Class definition when no module type defined\r
@@ -560,20 +417,6 @@ def PreCheck(FileName, FileContent, SupSectionTag):
             #\r
             if not (Line.find('[') > -1 and Line.find(']') > -1):\r
                 EdkLogger.error("Parser", FORMAT_INVALID, Line=LineNo, File=FileName)\r
-\r
-            #\r
-            # Tag not in defined value\r
-            #\r
-            #TagList = GetSplitValueList(Line, DataType.TAB_COMMA_SPLIT)\r
-            #for Tag in TagList:\r
-            #    Tag = Tag.split(DataType.TAB_SPLIT, 1)[0].replace('[', '').replace(']', '').strip()\r
-            #    if Tag.upper() == DataType.TAB_COMMON_DEFINES.upper():\r
-            #        break\r
-            #    if Tag.upper() == DataType.TAB_USER_EXTENSIONS.upper():\r
-            #        break\r
-            #    if Tag.upper() not in map(lambda s: s.upper(), SupSectionTag):\r
-            #        ErrorMsg = "'%s' is not a supportted section name." % Tag\r
-            #        EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, File=FileName, Line=LineNo)\r
         \r
         #\r
         # Regenerate FileContent\r
@@ -599,12 +442,13 @@ def PreCheck(FileName, FileContent, SupSectionTag):
 #\r
 # @retval True The file type is correct\r
 #\r
-def CheckFileType(CheckFilename, ExtName, ContainerFilename, SectionName, Line):\r
+def CheckFileType(CheckFilename, ExtName, ContainerFilename, SectionName, Line, LineNo = -1):\r
     if CheckFilename != '' and CheckFilename != None:\r
         (Root, Ext) = os.path.splitext(CheckFilename)\r
         if Ext.upper() != ExtName.upper():\r
             ContainerFile = open(ContainerFilename, 'r').read()\r
-            LineNo = GetLineNo(ContainerFile, Line)\r
+            if LineNo == -1:\r
+                LineNo = GetLineNo(ContainerFile, Line)\r
             ErrorMsg = "Invalid %s. '%s' is found, but '%s' file is needed" % (SectionName, CheckFilename, ExtName)\r
             EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, Line=LineNo,\r
                             File=ContainerFilename)\r
@@ -623,38 +467,21 @@ def CheckFileType(CheckFilename, ExtName, ContainerFilename, SectionName, Line):
 # @param SectionName:        Used for error report\r
 # @param Line:               The line in container file which defines the file to be checked\r
 #\r
-# @retval True The file exists\r
+# @retval The file full path if the file exists\r
 #\r
-def CheckFileExist(WorkspaceDir, CheckFilename, ContainerFilename, SectionName, Line):\r
+def CheckFileExist(WorkspaceDir, CheckFilename, ContainerFilename, SectionName, Line, LineNo = -1):\r
+    CheckFile = ''\r
     if CheckFilename != '' and CheckFilename != None:\r
         CheckFile = WorkspaceFile(WorkspaceDir, CheckFilename)\r
         if not os.path.isfile(CheckFile):\r
             ContainerFile = open(ContainerFilename, 'r').read()\r
-            LineNo = GetLineNo(ContainerFile, Line)\r
+            if LineNo == -1:\r
+                LineNo = GetLineNo(ContainerFile, Line)\r
             ErrorMsg = "Can't find file '%s' defined in section '%s'" % (CheckFile, SectionName)\r
             EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg,\r
                             File=ContainerFilename, Line=LineNo)\r
 \r
-    return True\r
-\r
-## CheckPcdTokenInfo\r
-#\r
-# Check if PcdTokenInfo is following <TokenSpaceGuidCName>.<PcdCName>\r
-#\r
-# @param TokenInfoString:  String to be checked\r
-# @param Section:          Used for error report\r
-# @param File:             Used for error report\r
-#\r
-# @retval True PcdTokenInfo is in correct format\r
-#\r
-def CheckPcdTokenInfo(TokenInfoString, Section, File):\r
-    if TokenInfoString != '' and TokenInfoString != None:\r
-        Format = '<TokenSpaceGuidCName>.<PcdCName>'\r
-        TokenInfoList = GetSplitValueList(TokenInfoString, DataType.TAB_SPLIT)\r
-        if len(TokenInfoList) != 2:\r
-            RaiseParserError(TokenInfoString, Section, File, Format)\r
-\r
-    return True\r
+    return CheckFile\r
 \r
 ## GetLineNo\r
 #\r
@@ -733,6 +560,15 @@ def SplitString(String):
 def ConvertToSqlString(StringList):\r
     return map(lambda s: s.replace("'", "''") , StringList)\r
 \r
+## Convert To Sql String\r
+#\r
+# 1. Replace "'" with "''" in the String\r
+# \r
+# @param String:  A String to be converted\r
+#\r
+def ConvertToSqlString2(String):\r
+    return String.replace("'", "''")\r
+\r
 ##\r
 #\r
 # This acts like the main() function for the script, unless it is 'import'ed into another\r
index 40e30b0..d8917e0 100644 (file)
@@ -57,6 +57,8 @@ MODEL_EFI_PCD = 3006
 MODEL_EFI_SOURCE_FILE = 3007\r
 MODEL_EFI_BINARY_FILE = 3008\r
 MODEL_EFI_SKU_ID = 3009\r
+MODEL_EFI_INCLUDE = 3010\r
+MODEL_EFI_DEPEX = 3011\r
 \r
 MODEL_PCD = 4000\r
 MODEL_PCD_FIXED_AT_BUILD = 4001\r
@@ -81,6 +83,8 @@ MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF = 5007
 MODEL_META_DATA_BUILD_OPTION = 5008\r
 MODEL_META_DATA_COMPONENT = 5009\r
 MODEL_META_DATA_USER_EXTENSION = 5010\r
+MODEL_META_DATA_PACKAGE = 5011\r
+MODEL_META_DATA_NMAKE = 5012\r
 \r
 MODEL_LIST = [('MODEL_UNKNOWN', MODEL_UNKNOWN),\r
               ('MODEL_FILE_C', MODEL_FILE_C),\r
@@ -116,6 +120,8 @@ MODEL_LIST = [('MODEL_UNKNOWN', MODEL_UNKNOWN),
               ('MODEL_EFI_LIBRARY_INSTANCE', MODEL_EFI_LIBRARY_INSTANCE),\r
               ('MODEL_EFI_PCD', MODEL_EFI_PCD),\r
               ('MODEL_EFI_SKU_ID', MODEL_EFI_SKU_ID),\r
+              ('MODEL_EFI_INCLUDE', MODEL_EFI_INCLUDE),\r
+              ('MODEL_EFI_DEPEX', MODEL_EFI_DEPEX),\r
               ('MODEL_IDENTIFIER_UNION', MODEL_IDENTIFIER_UNION),\r
               ('MODEL_EFI_SOURCE_FILE', MODEL_EFI_SOURCE_FILE),\r
               ('MODEL_EFI_BINARY_FILE', MODEL_EFI_BINARY_FILE),\r
@@ -140,7 +146,9 @@ MODEL_LIST = [('MODEL_UNKNOWN', MODEL_UNKNOWN),
               ("MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF", MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF),\r
               ("MODEL_META_DATA_BUILD_OPTION", MODEL_META_DATA_BUILD_OPTION),\r
               ("MODEL_META_DATA_COMPONENT", MODEL_META_DATA_COMPONENT),\r
-              ('MODEL_META_DATA_USER_EXTENSION', MODEL_META_DATA_USER_EXTENSION)\r
+              ('MODEL_META_DATA_USER_EXTENSION', MODEL_META_DATA_USER_EXTENSION),\r
+              ('MODEL_META_DATA_PACKAGE', MODEL_META_DATA_PACKAGE),\r
+              ('MODEL_META_DATA_NMAKE', MODEL_META_DATA_NMAKE)\r
              ]\r
 \r
 ## FunctionClass\r
@@ -274,7 +282,7 @@ class IdentifierClass(object):
 # @var EndLine:                EndLine of a Pcd\r
 # @var EndColumn:              EndColumn of a Pcd\r
 #\r
-class PcdClass(object):\r
+class PcdDataClass(object):\r
     def __init__(self, ID = -1, CName = '', TokenSpaceGuidCName = '', Token = '', DatumType = '', Model = MODEL_UNKNOWN, \\r
                  BelongsToFile = -1, BelongsToFunction = -1, StartLine = -1, StartColumn = -1, EndLine = -1, EndColumn = -1):\r
         self.ID = ID\r
index 6ddf978..6464bd1 100755 (executable)
@@ -358,7 +358,7 @@ class ModuleNmakeClass(CommonClass):
 # @param object:    Inherited from object class\r
 #\r
 # @var Header:               To store value for Header, it is a structure as\r
-#                            ModuleHeaderClass\r
+#                            {Arch : ModuleHeaderClass}\r
 # @var LibraryClasses:       To store value for LibraryClasses, it is a list structure as\r
 #                            [ LibraryClassClass, ...]\r
 # @var Libraries:            To store value for Libraries, it is a list structure as\r
@@ -414,7 +414,7 @@ class ModuleNmakeClass(CommonClass):
 #\r
 class ModuleClass(object):\r
     def __init__(self):\r
-        self.Header = {}            # {ARCH: ModuleHeaderClass()}\r
+        self.Header = {}\r
         self.LibraryClasses = []\r
         self.Libraries = []\r
         self.Sources = []\r
index fd57af7..3fb43a7 100755 (executable)
@@ -74,7 +74,7 @@ class PackageIncludePkgHeaderClass(object):
 # @param object:                  Inherited from object class\r
 #\r
 # @var Header:                    To store value for Header, it is a structure as\r
-#                                 PackageHeaderClass\r
+#                                 {Arch : PackageHeaderClass}\r
 # @var Includes:                  To store value for Includes, it is a list structure as\r
 #                                 [ IncludeClass, ...]\r
 # @var LibraryClassDeclarations:  To store value for LibraryClassDeclarations, it is a list structure as\r
@@ -98,7 +98,7 @@ class PackageIncludePkgHeaderClass(object):
 #\r
 class PackageClass(object):\r
     def __init__(self):\r
-        self.Header = PackageHeaderClass()\r
+        self.Header = {}\r
         self.Includes = []\r
         self.LibraryClassDeclarations = []\r
         self.IndustryStdHeaders = []\r
index d39339a..1cc1061 100644 (file)
@@ -389,7 +389,7 @@ class PlatformModuleClasses(IncludeStatementClass):
 # @param object:                    Inherited from object class\r
 #\r
 # @var Header:                      To store value for Header, it is a structure as\r
-#                                   PlatformHeaderClass\r
+#                                   {Arch : PlatformHeaderClass()}\r
 # @var SkuInfos:                    To store value for SkuInfos, it is a structure as\r
 #                                   SkuInfoListClass\r
 # @var Libraries:                   To store value for Libraries, it is a structure as\r
@@ -411,7 +411,7 @@ class PlatformModuleClasses(IncludeStatementClass):
 #\r
 class PlatformClass(object):\r
     def __init__(self):\r
-        self.Header = PlatformHeaderClass()\r
+        self.Header = {}\r
         self.SkuInfos = SkuInfoListClass()\r
         self.Libraries = PlatformLibraryClasses()\r
         self.LibraryClasses = PlatformLibraryClasses()\r
index b0195eb..48032a8 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file is used to create a database used by ECC tool\r
 #\r
-# Copyright (c) 2007, Intel Corporation\r
+# Copyright (c) 2007 ~ 2008, Intel Corporation\r
 # All rights reserved. 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
@@ -47,6 +47,8 @@ DATABASE_PATH = "Database/Ecc.db"
 class Database(object):\r
     def __init__(self, DbPath):\r
         self.Conn = sqlite3.connect(DbPath, isolation_level = 'DEFERRED')\r
+        self.Conn.execute("PRAGMA page_size=4096")\r
+        self.Conn.execute("PRAGMA synchronous=OFF")\r
         self.Cur = self.Conn.cursor()\r
         self.TblDataModel = TableDataModel(self.Cur)\r
         self.TblFile = TableFile(self.Cur)\r
@@ -125,6 +127,9 @@ class Database(object):
         # Insert a record for file\r
         #\r
         FileID = self.TblFile.Insert(File.Name, File.ExtName, File.Path, File.FullPath, Model = File.Model, TimeStamp = File.TimeStamp)\r
+        IdTable = TableIdentifier(self.Cur)\r
+        IdTable.Table = "file%s" % FileID\r
+        IdTable.Create()\r
 \r
         #\r
         # Insert function of file\r
@@ -137,7 +142,7 @@ class Database(object):
             # Insert Identifier of function\r
             #\r
             for Identifier in Function.IdentifierList:\r
-                IdentifierID = self.TblIdentifier.Insert(Identifier.Modifier, Identifier.Type, Identifier.Name, Identifier.Value, Identifier.Model, \\r
+                IdentifierID = IdTable.Insert(Identifier.Modifier, Identifier.Type, Identifier.Name, Identifier.Value, Identifier.Model, \\r
                                         FileID, FunctionID, Identifier.StartLine, Identifier.StartColumn, Identifier.EndLine, Identifier.EndColumn)\r
             #\r
             # Insert Pcd of function\r
@@ -149,7 +154,7 @@ class Database(object):
         # Insert Identifier of file\r
         #\r
         for Identifier in File.IdentifierList:\r
-            IdentifierID = self.TblIdentifier.Insert(Identifier.Modifier, Identifier.Type, Identifier.Name, Identifier.Value, Identifier.Model, \\r
+            IdentifierID = IdTable.Insert(Identifier.Modifier, Identifier.Type, Identifier.Name, Identifier.Value, Identifier.Model, \\r
                                     FileID, -1, Identifier.StartLine, Identifier.StartColumn, Identifier.EndLine, Identifier.EndColumn)\r
         #\r
         # Insert Pcd of file\r
@@ -165,7 +170,7 @@ class Database(object):
     # Update the field "BelongsToFunction" for each Indentifier\r
     #\r
     #\r
-    def UpdateIdentifierBelongsToFunction(self):\r
+    def UpdateIdentifierBelongsToFunction_disabled(self):\r
         EdkLogger.verbose("Update 'BelongsToFunction' for Identifiers started ...")\r
         \r
         SqlCommand = """select ID, BelongsToFile, StartLine, EndLine, Model from Identifier"""\r
@@ -212,6 +217,56 @@ class Database(object):
         \r
         EdkLogger.verbose("Update 'BelongsToFunction' for Identifiers ... DONE")\r
 \r
+\r
+    ## UpdateIdentifierBelongsToFunction\r
+    #\r
+    # Update the field "BelongsToFunction" for each Indentifier\r
+    #\r
+    #\r
+    def UpdateIdentifierBelongsToFunction(self):\r
+        EdkLogger.verbose("Update 'BelongsToFunction' for Identifiers started ...")\r
+        \r
+        SqlCommand = """select ID, BelongsToFile, StartLine, EndLine from Function"""\r
+        EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)\r
+        self.Cur.execute(SqlCommand)\r
+        Records = self.Cur.fetchall()\r
+        Data1 = []\r
+        Data2 = []\r
+        for Record in Records:\r
+            FunctionID = Record[0]\r
+            BelongsToFile = Record[1]\r
+            StartLine = Record[2]\r
+            EndLine = Record[3]\r
+            #Data1.append(("'file%s'" % BelongsToFile, FunctionID, BelongsToFile, StartLine, EndLine))\r
+            #Data2.append(("'file%s'" % BelongsToFile, FunctionID, DataClass.MODEL_IDENTIFIER_FUNCTION_HEADER, BelongsToFile, DataClass.MODEL_IDENTIFIER_COMMENT, StartLine - 1))\r
+\r
+            SqlCommand = """Update file%s set BelongsToFunction = %s where BelongsToFile = %s and StartLine > %s and EndLine < %s""" % \\r
+                        (BelongsToFile, FunctionID, BelongsToFile, StartLine, EndLine)\r
+            self.Cur.execute(SqlCommand)\r
+\r
+            SqlCommand = """Update file%s set BelongsToFunction = %s, Model = %s where BelongsToFile = %s and Model = %s and EndLine = %s""" % \\r
+                         (BelongsToFile, FunctionID, DataClass.MODEL_IDENTIFIER_FUNCTION_HEADER, BelongsToFile, DataClass.MODEL_IDENTIFIER_COMMENT, StartLine - 1)\r
+            self.Cur.execute(SqlCommand)\r
+#       #\r
+#       # Check whether an identifier belongs to a function\r
+#       #\r
+#       print Data1\r
+#       SqlCommand = """Update ? set BelongsToFunction = ? where BelongsToFile = ? and StartLine > ? and EndLine < ?"""\r
+#       print SqlCommand\r
+#       EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)\r
+#       self.Cur.executemany(SqlCommand, Data1)\r
+#\r
+#       #\r
+#       # Check whether the identifier is a function header\r
+#       #\r
+#       EdkLogger.debug(4, "For function headers ... ")\r
+#       SqlCommand = """Update ? set BelongsToFunction = ?, Model = ? where BelongsToFile = ? and Model = ? and EndLine = ?"""\r
+#       EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)\r
+#       self.Cur.executemany(SqlCommand, Data2)\r
+#\r
+#       EdkLogger.verbose("Update 'BelongsToFunction' for Identifiers ... DONE")\r
+    \r
+\r
 ##\r
 #\r
 # This acts like the main() function for the script, unless it is 'import'ed into another\r
index ec5cbc4..8d8c925 100644 (file)
@@ -45,8 +45,7 @@ class Table(object):
     # Insert a record into a table\r
     #\r
     def Insert(self, SqlCommand):\r
-        EdkLogger.debug(4, SqlCommand)\r
-        self.Cur.execute(SqlCommand)\r
+        self.Exec(SqlCommand)\r
     \r
     ## Query table\r
     #\r
@@ -79,7 +78,7 @@ class Table(object):
     # @retval Count:  Total count of all records\r
     #\r
     def GetCount(self):\r
-        SqlCommand = """select count(*) as Count from %s""" % self.Table\r
+        SqlCommand = """select count(ID) from %s""" % self.Table\r
         self.Cur.execute(SqlCommand)\r
         for Item in self.Cur:\r
             return Item[0]\r
@@ -97,3 +96,17 @@ class Table(object):
             self.ID = self.ID + 1\r
 \r
         return self.ID\r
+    ## Exec\r
+    #\r
+    # Exec Sql Command, return result\r
+    #\r
+    # @param SqlCommand:  The SqlCommand to be executed\r
+    #\r
+    # @retval RecordSet:  The result after executed\r
+    #\r
+    def Exec(self, SqlCommand):\r
+        EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand)\r
+        self.Cur.execute(SqlCommand)\r
+        RecordSet = self.Cur.fetchall()\r
+        EdkLogger.debug(4, "RecordSet: %s" % RecordSet)\r
+        return RecordSet\r
index 6accc9d..1e5fe47 100644 (file)
@@ -41,7 +41,7 @@ class TableDataModel(Table):
     # @param Description:  Description of a ModelType\r
     #\r
     def Create(self):\r
-        SqlCommand = """create table IF NOT EXISTS %s (ID SINGLE PRIMARY KEY,\r
+        SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r
                                                        CrossIndex INTEGER NOT NULL,\r
                                                        Name VARCHAR NOT NULL,\r
                                                        Description VARCHAR\r
diff --git a/Source/Python/Table/TableDec.py b/Source/Python/Table/TableDec.py
new file mode 100644 (file)
index 0000000..c3f56fd
--- /dev/null
@@ -0,0 +1,108 @@
+## @file\r
+# This file is used to create/update/query/erase table for dec datas\r
+#\r
+# Copyright (c) 2008, Intel Corporation\r
+# All rights reserved. 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
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+\r
+##\r
+# Import Modules\r
+#\r
+import Common.EdkLogger as EdkLogger\r
+import CommonDataClass.DataClass as DataClass\r
+from Table import Table\r
+from Common.String import ConvertToSqlString\r
+\r
+## TableDec\r
+#\r
+# This class defined a table used for data model\r
+# \r
+# @param object:       Inherited from object class\r
+#\r
+#\r
+class TableDec(Table):\r
+    def __init__(self, Cursor):\r
+        Table.__init__(self, Cursor)\r
+        self.Table = 'Dec'\r
+    \r
+    ## Create table\r
+    #\r
+    # Create table Dec\r
+    #\r
+    # @param ID:             ID of a Dec item\r
+    # @param Model:          Model of a Dec item\r
+    # @param Value1:         Value1 of a Dec item\r
+    # @param Value2:         Value2 of a Dec item\r
+    # @param Value3:         Value3 of a Dec item\r
+    # @param Arch:           Arch of a Dec item\r
+    # @param BelongsToItem:  The item belongs to which another item\r
+    # @param BelongsToFile:  The item belongs to which dsc file\r
+    # @param StartLine:      StartLine of a Dec item\r
+    # @param StartColumn:    StartColumn of a Dec item\r
+    # @param EndLine:        EndLine of a Dec item\r
+    # @param EndColumn:      EndColumn of a Dec item\r
+    # @param Enabled:        If this item enabled\r
+    #\r
+    def Create(self):\r
+        SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r
+                                                       Model INTEGER NOT NULL,\r
+                                                       Value1 VARCHAR NOT NULL,\r
+                                                       Value2 VARCHAR,\r
+                                                       Value3 VARCHAR,\r
+                                                       Arch VarCHAR,\r
+                                                       BelongsToItem SINGLE NOT NULL,\r
+                                                       BelongsToFile SINGLE NOT NULL,\r
+                                                       StartLine INTEGER NOT NULL,\r
+                                                       StartColumn INTEGER NOT NULL,\r
+                                                       EndLine INTEGER NOT NULL,\r
+                                                       EndColumn INTEGER NOT NULL,\r
+                                                       Enabled INTEGER DEFAULT 0\r
+                                                      )""" % self.Table\r
+        Table.Create(self, SqlCommand)\r
+\r
+    ## Insert table\r
+    #\r
+    # Insert a record into table Dec\r
+    #\r
+    # @param ID:             ID of a Dec item\r
+    # @param Model:          Model of a Dec item\r
+    # @param Value1:         Value1 of a Dec item\r
+    # @param Value2:         Value2 of a Dec item\r
+    # @param Value3:         Value3 of a Dec item\r
+    # @param Arch:           Arch of a Dec item\r
+    # @param BelongsToItem:  The item belongs to which another item\r
+    # @param BelongsToFile:  The item belongs to which dsc file\r
+    # @param StartLine:      StartLine of a Dec item\r
+    # @param StartColumn:    StartColumn of a Dec item\r
+    # @param EndLine:        EndLine of a Dec item\r
+    # @param EndColumn:      EndColumn of a Dec item\r
+    # @param Enabled:        If this item enabled\r
+    #\r
+    def Insert(self, Model, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled):\r
+        self.ID = self.ID + 1\r
+        (Value1, Value2, Value3, Arch) = ConvertToSqlString((Value1, Value2, Value3, Arch))\r
+        SqlCommand = """insert into %s values(%s, %s, '%s', '%s', '%s', '%s', %s, %s, %s, %s, %s, %s, %s)""" \\r
+                     % (self.Table, self.ID, Model, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled)\r
+        Table.Insert(self, SqlCommand)\r
+        \r
+        return self.ID\r
+    \r
+    ## Query table\r
+    #\r
+    # @param Model:  The Model of Record \r
+    #\r
+    # @retval:       A recordSet of all found records \r
+    #\r
+    def Query(self, Model):\r
+        SqlCommand = """select ID, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine from %s\r
+                        where Model = %s\r
+                        and Enabled > -1""" % (self.Table, Model)\r
+        EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand)\r
+        self.Cur.execute(SqlCommand)\r
+        return self.Cur.fetchall()\r
index 5cb6ab7..62608a0 100644 (file)
@@ -50,7 +50,7 @@ class TableDsc(Table):
     # @param Enabled:        If this item enabled\r
     #\r
     def Create(self):\r
-        SqlCommand = """create table IF NOT EXISTS %s (ID SINGLE PRIMARY KEY,\r
+        SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r
                                                        Model INTEGER NOT NULL,\r
                                                        Value1 VARCHAR NOT NULL,\r
                                                        Value2 VARCHAR,\r
@@ -86,9 +86,23 @@ class TableDsc(Table):
     #\r
     def Insert(self, Model, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled):\r
         self.ID = self.ID + 1\r
-        #(Value1, Value2, Value3, Arch) = ConvertToSqlString((Value1, Value2, Value3, Arch))\r
+        (Value1, Value2, Value3, Arch) = ConvertToSqlString((Value1, Value2, Value3, Arch))\r
         SqlCommand = """insert into %s values(%s, %s, '%s', '%s', '%s', '%s', %s, %s, %s, %s, %s, %s, %s)""" \\r
                      % (self.Table, self.ID, Model, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled)\r
         Table.Insert(self, SqlCommand)\r
         \r
-        return self.ID
\ No newline at end of file
+        return self.ID\r
+    \r
+    ## Query table\r
+    #\r
+    # @param Model:  The Model of Record \r
+    #\r
+    # @retval:       A recordSet of all found records \r
+    #\r
+    def Query(self, Model):\r
+        SqlCommand = """select ID, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine from %s\r
+                        where Model = %s\r
+                        and Enabled > -1""" % (self.Table, Model)\r
+        EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand)\r
+        self.Cur.execute(SqlCommand)\r
+        return self.Cur.fetchall()\r
index 4287a64..9be6494 100644 (file)
@@ -17,6 +17,8 @@
 import Common.EdkLogger as EdkLogger\r
 from Table import Table\r
 from Common.String import ConvertToSqlString\r
+import os\r
+from CommonDataClass.DataClass import FileClass\r
 \r
 ## TableFile\r
 #\r
@@ -42,7 +44,7 @@ class TableFile(Table):
     # @param TimeStamp: TimeStamp of a File\r
     #\r
     def Create(self):\r
-        SqlCommand = """create table IF NOT EXISTS %s (ID SINGLE PRIMARY KEY,\r
+        SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r
                                                        Name VARCHAR NOT NULL,\r
                                                        ExtName VARCHAR,\r
                                                        Path VARCHAR,\r
@@ -72,3 +74,18 @@ class TableFile(Table):
         Table.Insert(self, SqlCommand)\r
         \r
         return self.ID\r
+    ## InsertFile\r
+    #\r
+    # Insert one file to table\r
+    #\r
+    # @param FileFullPath:  The full path of the file\r
+    # @param Model:         The model of the file \r
+    # \r
+    # @retval FileID:       The ID after record is inserted\r
+    #\r
+    def InsertFile(self, FileFullPath, Model):\r
+        (Filepath, Name) = os.path.split(FileFullPath)\r
+        (Root, Ext) = os.path.splitext(FileFullPath)\r
+        TimeStamp = os.stat(FileFullPath)[8]\r
+        File = FileClass(-1, Name, Ext, Filepath, FileFullPath, Model, '', [], [], [])\r
+        return self.Insert(File.Name, File.ExtName, File.Path, File.FullPath, File.Model, TimeStamp)\r
index 844aa65..0cb1b91 100644 (file)
@@ -47,7 +47,7 @@ class TableFunction(Table):
     # @param BelongsToFile:    The Function belongs to which file\r
     #\r
     def Create(self):\r
-        SqlCommand = """create table IF NOT EXISTS %s (ID SINGLE PRIMARY KEY,\r
+        SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r
                                                        Header TEXT,\r
                                                        Modifier VARCHAR,\r
                                                        Name VARCHAR NOT NULL,\r
index debb7c2..3cf33f2 100644 (file)
@@ -48,7 +48,7 @@ class TableIdentifier(Table):
     # @param EndColumn:          EndColumn of a Identifier\r
     #\r
     def Create(self):\r
-        SqlCommand = """create table IF NOT EXISTS %s(ID SINGLE PRIMARY KEY,\r
+        SqlCommand = """create table IF NOT EXISTS %s(ID INTEGER PRIMARY KEY,\r
                                                       Modifier VARCHAR,\r
                                                       Type VARCHAR,\r
                                                       Name VARCHAR NOT NULL,\r
diff --git a/Source/Python/Table/TableInf.py b/Source/Python/Table/TableInf.py
new file mode 100644 (file)
index 0000000..65ca1ce
--- /dev/null
@@ -0,0 +1,114 @@
+## @file\r
+# This file is used to create/update/query/erase table for inf datas\r
+#\r
+# Copyright (c) 2008, Intel Corporation\r
+# All rights reserved. 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
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+\r
+##\r
+# Import Modules\r
+#\r
+import Common.EdkLogger as EdkLogger\r
+import CommonDataClass.DataClass as DataClass\r
+from Table import Table\r
+from Common.String import ConvertToSqlString\r
+\r
+## TableInf\r
+#\r
+# This class defined a table used for data model\r
+# \r
+# @param object:       Inherited from object class\r
+#\r
+#\r
+class TableInf(Table):\r
+    def __init__(self, Cursor):\r
+        Table.__init__(self, Cursor)\r
+        self.Table = 'Inf'\r
+    \r
+    ## Create table\r
+    #\r
+    # Create table Inf\r
+    #\r
+    # @param ID:             ID of a Inf item\r
+    # @param Model:          Model of a Inf item\r
+    # @param Value1:         Value1 of a Inf item\r
+    # @param Value2:         Value2 of a Inf item\r
+    # @param Value3:         Value3 of a Inf item\r
+    # @param Value4:         Value4 of a Inf item\r
+    # @param Value5:         Value5 of a Inf item\r
+    # @param Arch:           Arch of a Inf item\r
+    # @param BelongsToItem:  The item belongs to which another item\r
+    # @param BelongsToFile:  The item belongs to which dsc file\r
+    # @param StartLine:      StartLine of a Inf item\r
+    # @param StartColumn:    StartColumn of a Inf item\r
+    # @param EndLine:        EndLine of a Inf item\r
+    # @param EndColumn:      EndColumn of a Inf item\r
+    # @param Enabled:        If this item enabled\r
+    #\r
+    def Create(self):\r
+        SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r
+                                                       Model INTEGER NOT NULL,\r
+                                                       Value1 VARCHAR NOT NULL,\r
+                                                       Value2 VARCHAR,\r
+                                                       Value3 VARCHAR,\r
+                                                       Value4 VARCHAR,\r
+                                                       Value5 VARCHAR,\r
+                                                       Arch VarCHAR,\r
+                                                       BelongsToItem SINGLE NOT NULL,\r
+                                                       BelongsToFile SINGLE NOT NULL,\r
+                                                       StartLine INTEGER NOT NULL,\r
+                                                       StartColumn INTEGER NOT NULL,\r
+                                                       EndLine INTEGER NOT NULL,\r
+                                                       EndColumn INTEGER NOT NULL,\r
+                                                       Enabled INTEGER DEFAULT 0\r
+                                                      )""" % self.Table\r
+        Table.Create(self, SqlCommand)\r
+\r
+    ## Insert table\r
+    #\r
+    # Insert a record into table Inf\r
+    #\r
+    # @param ID:             ID of a Inf item\r
+    # @param Model:          Model of a Inf item\r
+    # @param Value1:         Value1 of a Inf item\r
+    # @param Value2:         Value2 of a Inf item\r
+    # @param Value3:         Value3 of a Inf item\r
+    # @param Value4:         Value4 of a Inf item\r
+    # @param Value5:         Value5 of a Inf item\r
+    # @param Arch:           Arch of a Inf item\r
+    # @param BelongsToItem:  The item belongs to which another item\r
+    # @param BelongsToFile:  The item belongs to which dsc file\r
+    # @param StartLine:      StartLine of a Inf item\r
+    # @param StartColumn:    StartColumn of a Inf item\r
+    # @param EndLine:        EndLine of a Inf item\r
+    # @param EndColumn:      EndColumn of a Inf item\r
+    # @param Enabled:        If this item enabled\r
+    #\r
+    def Insert(self, Model, Value1, Value2, Value3, Value4, Value5, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled):\r
+        self.ID = self.ID + 1\r
+        (Value1, Value2, Value3, Value4, Value5, Arch) = ConvertToSqlString((Value1, Value2, Value3, Value4, Value5, Arch))\r
+        SqlCommand = """insert into %s values(%s, %s, '%s', '%s', '%s', '%s', '%s', '%s', %s, %s, %s, %s, %s, %s, %s)""" \\r
+                     % (self.Table, self.ID, Model, Value1, Value2, Value3, Value4, Value5, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled)\r
+        Table.Insert(self, SqlCommand)\r
+        \r
+        return self.ID\r
+    \r
+    ## Query table\r
+    #\r
+    # @param Model:  The Model of Record \r
+    #\r
+    # @retval:       A recordSet of all found records \r
+    #\r
+    def Query(self, Model):\r
+        SqlCommand = """select ID, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine from %s\r
+                        where Model = %s\r
+                        and Enabled > -1""" % (self.Table, Model)\r
+        EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand)\r
+        self.Cur.execute(SqlCommand)\r
+        return self.Cur.fetchall()\r
index ce34494..ba91d17 100644 (file)
@@ -48,7 +48,7 @@ class TablePcd(Table):
     # @param EndColumn:            EndColumn of a Pcd\r
     #\r
     def Create(self):\r
-        SqlCommand = """create table IF NOT EXISTS %s (ID SINGLE PRIMARY KEY,\r
+        SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r
                                                        CName VARCHAR NOT NULL,\r
                                                        TokenSpaceGuidCName VARCHAR NOT NULL,\r
                                                        Token INTEGER,\r