]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Ecc/Check.py
BaseTools/ECC: Fix an identification issue of typedef function.
[mirror_edk2.git] / BaseTools / Source / Python / Ecc / Check.py
index 6803afdfddb6f694d18e7948b2e0a97a7c0399be..268e02126c1b1d433fb0fc730c3969ef607765d0 100644 (file)
@@ -15,10 +15,10 @@ import Common.LongFilePathOs as os
 import re\r
 from CommonDataClass.DataClass import *\r
 import Common.DataType as DT\r
-from .EccToolError import *\r
-from .MetaDataParser import ParseHeaderCommentSection\r
-from . import EccGlobalData\r
-from . import c\r
+from Ecc.EccToolError import *\r
+from Ecc.MetaDataParser import ParseHeaderCommentSection\r
+from Ecc import EccGlobalData\r
+from Ecc import c\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
 from Common.MultipleWorkspace import MultipleWorkspace as mws\r
 \r
@@ -270,6 +270,66 @@ class Check(object):
         self.FunctionLayoutCheckPrototype()\r
         self.FunctionLayoutCheckBody()\r
         self.FunctionLayoutCheckLocalVariable()\r
+        self.FunctionLayoutCheckDeprecated()\r
+    \r
+    # To check if the deprecated functions are used\r
+    def FunctionLayoutCheckDeprecated(self):\r
+        if EccGlobalData.gConfig.CFunctionLayoutCheckNoDeprecated == '1' or EccGlobalData.gConfig.CFunctionLayoutCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+            EdkLogger.quiet("Checking function no deprecated one being used ...")\r
+\r
+            DeprecatedFunctionSet = ('UnicodeValueToString',\r
+                                     'AsciiValueToString',\r
+                                     'StrCpy',\r
+                                     'StrnCpy',\r
+                                     'StrCat',\r
+                                     'StrnCat',\r
+                                     'UnicodeStrToAsciiStr',\r
+                                     'AsciiStrCpy',\r
+                                     'AsciiStrnCpy',\r
+                                     'AsciiStrCat',\r
+                                     'AsciiStrnCat',\r
+                                     'AsciiStrToUnicodeStr',\r
+                                     'PcdSet8',\r
+                                     'PcdSet16',\r
+                                     'PcdSet32',\r
+                                     'PcdSet64',\r
+                                     'PcdSetPtr',\r
+                                     'PcdSetBool',\r
+                                     'PcdSetEx8',\r
+                                     'PcdSetEx16',\r
+                                     'PcdSetEx32',\r
+                                     'PcdSetEx64',\r
+                                     'PcdSetExPtr',\r
+                                     'PcdSetExBool',\r
+                                     'LibPcdSet8',\r
+                                     'LibPcdSet16',\r
+                                     'LibPcdSet32',\r
+                                     'LibPcdSet64',\r
+                                     'LibPcdSetPtr',\r
+                                     'LibPcdSetBool',\r
+                                     'LibPcdSetEx8',\r
+                                     'LibPcdSetEx16',\r
+                                     'LibPcdSetEx32',\r
+                                     'LibPcdSetEx64',\r
+                                     'LibPcdSetExPtr',\r
+                                     'LibPcdSetExBool',\r
+                                     'GetVariable',\r
+                                     'GetEfiGlobalVariable',\r
+                                     )\r
+\r
+            for IdentifierTable in EccGlobalData.gIdentifierTableList:\r
+                SqlCommand = """select ID, Name, BelongsToFile from %s\r
+                                where Model = %s """ % (IdentifierTable, MODEL_IDENTIFIER_FUNCTION_CALLING)\r
+                RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+                for Record in RecordSet:\r
+                    for Key in DeprecatedFunctionSet:\r
+                        if Key == Record[1]:\r
+                            if not EccGlobalData.gException.IsException(ERROR_C_FUNCTION_LAYOUT_CHECK_NO_DEPRECATE, Key):\r
+                                OtherMsg = 'The function [%s] is deprecated which should NOT be used' % Key\r
+                                EccGlobalData.gDb.TblReport.Insert(ERROR_C_FUNCTION_LAYOUT_CHECK_NO_DEPRECATE,\r
+                                                                   OtherMsg=OtherMsg,\r
+                                                                   BelongsToTable=IdentifierTable,\r
+                                                                   BelongsToItem=Record[0])\r
 \r
     def WalkTree(self):\r
         IgnoredPattern = c.GetIgnoredDirListPattern()\r
@@ -586,13 +646,23 @@ class Check(object):
         if EccGlobalData.gConfig.IncludeFileCheckData == '1' or EccGlobalData.gConfig.IncludeFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
             EdkLogger.quiet("Checking header file data ...")\r
 \r
+            # Get all typedef functions\r
+            gAllTypedefFun = []\r
+            for IdentifierTable in EccGlobalData.gIdentifierTableList:\r
+                SqlCommand = """select Name from %s\r
+                                where Model = %s """ % (IdentifierTable, MODEL_IDENTIFIER_TYPEDEF)\r
+                RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+                for Record in RecordSet:\r
+                    if Record[0].startswith('('):\r
+                        gAllTypedefFun.append(Record[0])\r
+\r
 #            for Dirpath, Dirnames, Filenames in self.WalkTree():\r
 #                for F in Filenames:\r
 #                    if os.path.splitext(F)[1] in ('.h'):\r
 #                        FullName = os.path.join(Dirpath, F)\r
 #                        MsgList = c.CheckHeaderFileData(FullName)\r
             for FullName in EccGlobalData.gHFileList:\r
-                MsgList = c.CheckHeaderFileData(FullName)\r
+                MsgList = c.CheckHeaderFileData(FullName, gAllTypedefFun)\r
 \r
     # Doxygen document checking\r
     def DoxygenCheck(self):\r