]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Ecc/Database.py
Sync EDKII BaseTools to BaseTools project r2042.
[mirror_edk2.git] / BaseTools / Source / Python / Ecc / Database.py
index 9520be4345f9af735ee34404bfc76ffd66a76bb4..4b79cb708fab74265139c26e99943eae7a8f8d1d 100644 (file)
@@ -41,7 +41,7 @@ DATABASE_PATH = "Ecc.db"
 # This class defined the ECC databse\r
 # During the phase of initialization, the database will create all tables and\r
 # insert all records of table DataModel\r
-# \r
+#\r
 # @param object:    Inherited from object class\r
 # @param DbPath:    A string for the path of the ECC database\r
 #\r
@@ -64,7 +64,7 @@ class Database(object):
         self.TblDec = None\r
         self.TblDsc = None\r
         self.TblFdf = None\r
-    \r
+\r
     ## Initialize ECC database\r
     #\r
     # 1. Delete all old existing tables\r
@@ -85,7 +85,7 @@ class Database(object):
         # to avoid non-ascii charater conversion error\r
         self.Conn.text_factory = str\r
         self.Cur = self.Conn.cursor()\r
-        \r
+\r
         self.TblDataModel = TableDataModel(self.Cur)\r
         self.TblFile = TableFile(self.Cur)\r
         self.TblFunction = TableFunction(self.Cur)\r
@@ -96,7 +96,7 @@ class Database(object):
         self.TblDec = TableDec(self.Cur)\r
         self.TblDsc = TableDsc(self.Cur)\r
         self.TblFdf = TableFdf(self.Cur)\r
-        \r
+\r
         #\r
         # Create new tables\r
         #\r
@@ -110,7 +110,7 @@ class Database(object):
             self.TblDec.Create()\r
             self.TblDsc.Create()\r
             self.TblFdf.Create()\r
-        \r
+\r
         #\r
         # Init each table's ID\r
         #\r
@@ -123,13 +123,13 @@ class Database(object):
         self.TblDec.InitID()\r
         self.TblDsc.InitID()\r
         self.TblFdf.InitID()\r
-        \r
+\r
         #\r
         # Initialize table DataModel\r
         #\r
         if NewDatabase:\r
             self.TblDataModel.InitTable()\r
-        \r
+\r
         EdkLogger.verbose("Initialize ECC database ... DONE!")\r
 \r
     ## Query a table\r
@@ -138,7 +138,7 @@ class Database(object):
     #\r
     def QueryTable(self, Table):\r
         Table.Query()\r
-    \r
+\r
     ## Close entire database\r
     #\r
     # Commit all first\r
@@ -147,15 +147,15 @@ class Database(object):
     def Close(self):\r
         #\r
         # Commit to file\r
-        #        \r
+        #\r
         self.Conn.commit()\r
-        \r
+\r
         #\r
         # Close connection and cursor\r
         #\r
         self.Cur.close()\r
         self.Conn.close()\r
-    \r
+\r
     ## Insert one file information\r
     #\r
     # Insert one file's information to the database\r
@@ -171,43 +171,44 @@ 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 = "Identifier%s" % FileID\r
-        IdTable.Create()\r
 \r
-        #\r
-        # Insert function of file\r
-        #\r
-        for Function in File.FunctionList:\r
-            FunctionID = self.TblFunction.Insert(Function.Header, Function.Modifier, Function.Name, Function.ReturnStatement, \\r
-                                    Function.StartLine, Function.StartColumn, Function.EndLine, Function.EndColumn, \\r
-                                    Function.BodyStartLine, Function.BodyStartColumn, FileID, \\r
-                                    Function.FunNameStartLine, Function.FunNameStartColumn)\r
+        if File.Model == DataClass.MODEL_FILE_C or File.Model == DataClass.MODEL_FILE_H:\r
+            IdTable = TableIdentifier(self.Cur)\r
+            IdTable.Table = "Identifier%s" % FileID\r
+            IdTable.Create()\r
+            #\r
+            # Insert function of file\r
+            #\r
+            for Function in File.FunctionList:\r
+                FunctionID = self.TblFunction.Insert(Function.Header, Function.Modifier, Function.Name, Function.ReturnStatement, \\r
+                                        Function.StartLine, Function.StartColumn, Function.EndLine, Function.EndColumn, \\r
+                                        Function.BodyStartLine, Function.BodyStartColumn, FileID, \\r
+                                        Function.FunNameStartLine, Function.FunNameStartColumn)\r
+                #\r
+                # Insert Identifier of function\r
+                #\r
+                for Identifier in Function.IdentifierList:\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
+                #\r
+                for Pcd in Function.PcdList:\r
+                    PcdID = self.TblPcd.Insert(Pcd.CName, Pcd.TokenSpaceGuidCName, Pcd.Token, Pcd.DatumType, Pcd.Model, \\r
+                                       FileID, FunctionID, Pcd.StartLine, Pcd.StartColumn, Pcd.EndLine, Pcd.EndColumn)\r
             #\r
-            # Insert Identifier of function\r
+            # Insert Identifier of file\r
             #\r
-            for Identifier in Function.IdentifierList:\r
+            for Identifier in File.IdentifierList:\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
+                                        FileID, -1, Identifier.StartLine, Identifier.StartColumn, Identifier.EndLine, Identifier.EndColumn)\r
             #\r
-            # Insert Pcd of function\r
+            # Insert Pcd of file\r
             #\r
-            for Pcd in Function.PcdList:\r
+            for Pcd in File.PcdList:\r
                 PcdID = self.TblPcd.Insert(Pcd.CName, Pcd.TokenSpaceGuidCName, Pcd.Token, Pcd.DatumType, Pcd.Model, \\r
-                                   FileID, FunctionID, Pcd.StartLine, Pcd.StartColumn, Pcd.EndLine, Pcd.EndColumn)\r
-        #\r
-        # Insert Identifier of file\r
-        #\r
-        for Identifier in File.IdentifierList:\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
-        #\r
-        for Pcd in File.PcdList:\r
-            PcdID = self.TblPcd.Insert(Pcd.CName, Pcd.TokenSpaceGuidCName, Pcd.Token, Pcd.DatumType, Pcd.Model, \\r
-                               FileID, -1, Pcd.StartLine, Pcd.StartColumn, Pcd.EndLine, Pcd.EndColumn)\r
-                \r
+                                   FileID, -1, Pcd.StartLine, Pcd.StartColumn, Pcd.EndLine, Pcd.EndColumn)\r
+\r
         EdkLogger.verbose("Insert information from file %s ... DONE!" % File.FullPath)\r
 \r
     ## UpdateIdentifierBelongsToFunction\r
@@ -217,7 +218,7 @@ class Database(object):
     #\r
     def UpdateIdentifierBelongsToFunction_disabled(self):\r
         EdkLogger.verbose("Update 'BelongsToFunction' for Identifiers started ...")\r
-        \r
+\r
         SqlCommand = """select ID, BelongsToFile, StartLine, EndLine, Model from Identifier"""\r
         EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)\r
         self.Cur.execute(SqlCommand)\r
@@ -233,7 +234,7 @@ class Database(object):
             # Check whether an identifier belongs to a function\r
             #\r
             EdkLogger.debug(4, "For common identifiers ... ")\r
-            SqlCommand = """select ID from Function \r
+            SqlCommand = """select ID from Function\r
                         where StartLine < %s and EndLine > %s\r
                         and BelongsToFile = %s""" % (StartLine, EndLine, BelongsToFile)\r
             EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)\r
@@ -243,13 +244,13 @@ class Database(object):
                 SqlCommand = """Update Identifier set BelongsToFunction = %s where ID = %s""" % (ID[0], IdentifierID)\r
                 EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)\r
                 self.Cur.execute(SqlCommand)\r
-            \r
+\r
             #\r
             # Check whether the identifier is a function header\r
             #\r
-            EdkLogger.debug(4, "For function headers ... ") \r
+            EdkLogger.debug(4, "For function headers ... ")\r
             if Model == DataClass.MODEL_IDENTIFIER_COMMENT:\r
-                SqlCommand = """select ID from Function \r
+                SqlCommand = """select ID from Function\r
                         where StartLine = %s + 1\r
                         and BelongsToFile = %s""" % (EndLine, BelongsToFile)\r
                 EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)\r
@@ -259,7 +260,7 @@ class Database(object):
                     SqlCommand = """Update Identifier set BelongsToFunction = %s, Model = %s where ID = %s""" % (ID[0], DataClass.MODEL_IDENTIFIER_FUNCTION_HEADER, IdentifierID)\r
                     EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)\r
                     self.Cur.execute(SqlCommand)\r
-        \r
+\r
         EdkLogger.verbose("Update 'BelongsToFunction' for Identifiers ... DONE")\r
 \r
 \r
@@ -270,7 +271,7 @@ class Database(object):
     #\r
     def UpdateIdentifierBelongsToFunction(self):\r
         EdkLogger.verbose("Update 'BelongsToFunction' for Identifiers started ...")\r
-        \r
+\r
         SqlCommand = """select ID, BelongsToFile, StartLine, EndLine from Function"""\r
         Records = self.TblFunction.Exec(SqlCommand)\r
         Data1 = []\r
@@ -308,7 +309,7 @@ class Database(object):
 #       self.Cur.executemany(SqlCommand, Data2)\r
 #\r
 #       EdkLogger.verbose("Update 'BelongsToFunction' for Identifiers ... DONE")\r
-    \r
+\r
 \r
 ##\r
 #\r
@@ -320,11 +321,11 @@ if __name__ == '__main__':
     #EdkLogger.SetLevel(EdkLogger.VERBOSE)\r
     EdkLogger.SetLevel(EdkLogger.DEBUG_0)\r
     EdkLogger.verbose("Start at " + time.strftime('%H:%M:%S', time.localtime()))\r
-    \r
+\r
     Db = Database(DATABASE_PATH)\r
     Db.InitDatabase()\r
     Db.QueryTable(Db.TblDataModel)\r
-    \r
+\r
     identifier1 = DataClass.IdentifierClass(-1, '', '', "i''1", 'aaa', DataClass.MODEL_IDENTIFIER_COMMENT, 1, -1, 32,  43,  54,  43)\r
     identifier2 = DataClass.IdentifierClass(-1, '', '', 'i1', 'aaa', DataClass.MODEL_IDENTIFIER_COMMENT, 1, -1, 15,  43,  20,  43)\r
     identifier3 = DataClass.IdentifierClass(-1, '', '', 'i1', 'aaa', DataClass.MODEL_IDENTIFIER_COMMENT, 1, -1, 55,  43,  58,  43)\r
@@ -333,12 +334,12 @@ if __name__ == '__main__':
     file = DataClass.FileClass(-1, 'F1', 'c', 'C:\\', 'C:\\F1.exe', DataClass.MODEL_FILE_C, '2007-12-28', [fun1], [identifier1, identifier2, identifier3, identifier4], [])\r
     Db.InsertOneFile(file)\r
     Db.UpdateIdentifierBelongsToFunction()\r
-        \r
+\r
     Db.QueryTable(Db.TblFile)\r
     Db.QueryTable(Db.TblFunction)\r
     Db.QueryTable(Db.TblPcd)\r
     Db.QueryTable(Db.TblIdentifier)\r
-    \r
+\r
     Db.Close()\r
     EdkLogger.verbose("End at " + time.strftime('%H:%M:%S', time.localtime()))\r
-    \r
+\r