]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Ecc/c.py
BaseTools/Ecc: Fix grammar in Ecc error message
[mirror_edk2.git] / BaseTools / Source / Python / Ecc / c.py
index 953f1630b69394d0ea1eee3848d2da3313a79a7b..61ad084fcc5b85b5a2194afd8bb1a4b4b65fdaee 100644 (file)
@@ -1,14 +1,9 @@
 ## @file\r
 # This file is used to be the c coding style checking of ECC tool\r
 #\r
-# Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
-# This program and the accompanying materials\r
-# are licensed and made available under the terms and conditions of the BSD License\r
-# which accompanies this distribution.  The full text of the license may be found at\r
-# 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
+# Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2020, Arm Limited. All rights reserved.<BR>\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 \r
 from __future__ import print_function\r
@@ -35,7 +30,7 @@ IgnoredKeywordList = ['EFI_ERROR']
 \r
 def GetIgnoredDirListPattern():\r
     skipList = list(EccGlobalData.gConfig.SkipDirList) + ['.svn']\r
-    DirString = string.join(skipList, '|')\r
+    DirString = '|'.join(skipList)\r
     p = re.compile(r'.*[\\/](?:%s)[\\/]?.*' % DirString)\r
     return p\r
 \r
@@ -70,7 +65,9 @@ def GetIdType(Str):
     Type = DataClass.MODEL_UNKNOWN\r
     Str = Str.replace('#', '# ')\r
     List = Str.split()\r
-    if List[1] == 'include':\r
+    if len(List) < 2:\r
+        pass\r
+    elif List[1] == 'include':\r
         Type = DataClass.MODEL_IDENTIFIER_INCLUDE\r
     elif List[1] == 'define':\r
         Type = DataClass.MODEL_IDENTIFIER_MACRO_DEFINE\r
@@ -501,6 +498,8 @@ def CollectSourceCodeDataIntoDB(RootDir):
     tuple = os.walk(RootDir)\r
     IgnoredPattern = GetIgnoredDirListPattern()\r
     ParseErrorFileList = []\r
+    TokenReleaceList = EccGlobalData.gConfig.TokenReleaceList\r
+    TokenReleaceList.extend(['L",\\\""'])\r
 \r
     for dirpath, dirnames, filenames in tuple:\r
         if IgnoredPattern.match(dirpath.upper()):\r
@@ -525,6 +524,7 @@ def CollectSourceCodeDataIntoDB(RootDir):
                 EdkLogger.info("Parsing " + FullName)\r
                 model = f.endswith('c') and DataClass.MODEL_FILE_C or DataClass.MODEL_FILE_H\r
                 collector = CodeFragmentCollector.CodeFragmentCollector(FullName)\r
+                collector.TokenReleaceList = TokenReleaceList\r
                 try:\r
                     collector.ParseFile()\r
                 except UnicodeError:\r
@@ -733,7 +733,7 @@ def SplitPredicateByOp(Str, Op, IsFuncCalling=False):
 \r
             while not LBFound and (Str[Index].isalnum() or Str[Index] == '_'):\r
                 Index += 1\r
-            # maybe type-cast at the begining, skip it.\r
+            # maybe type-cast at the beginning, skip it.\r
             RemainingStr = Str[Index:].lstrip()\r
             if RemainingStr.startswith(')') and not LBFound:\r
                 Index += 1\r
@@ -834,7 +834,7 @@ def GetDataTypeFromModifier(ModifierStr):
     for M in MList:\r
         if M in EccGlobalData.gConfig.ModifierSet:\r
             continue\r
-        # remove array sufix\r
+        # remove array suffix\r
         if M.startswith('[') or M.endswith(']'):\r
             continue\r
         ReturnType += M + ' '\r
@@ -963,7 +963,7 @@ def StripComments(Str):
             ListFromStr[Index] = ' '\r
             Index += 1\r
         # check for // comment\r
-        elif ListFromStr[Index] == '/' and ListFromStr[Index + 1] == '/' and ListFromStr[Index + 2] != '\n':\r
+        elif ListFromStr[Index] == '/' and ListFromStr[Index + 1] == '/':\r
             InComment = True\r
             DoubleSlashComment = True\r
 \r
@@ -1019,7 +1019,7 @@ def GetFinalTypeValue(Type, FieldName, TypedefDict, SUDict):
                 Type = GetDataTypeFromModifier(Field[0:Index])\r
                 return Type.strip()\r
             else:\r
-            # For the condition that the field in struct is an array with [] sufixes...\r
+            # For the condition that the field in struct is an array with [] suffixes...\r
                 if not Field[Index + len(FieldName)].isalnum():\r
                     Type = GetDataTypeFromModifier(Field[0:Index])\r
                     return Type.strip()\r
@@ -1297,7 +1297,7 @@ def CheckFuncLayoutReturnType(FullFileName):
         Result0 = Result[0]\r
         if Result0.upper().startswith('STATIC'):\r
             Result0 = Result0[6:].strip()\r
-        Index = Result0.find(ReturnType)\r
+        Index = Result0.find(TypeStart)\r
         if Index != 0 or Result[3] != 0:\r
             PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_RETURN_TYPE, '[%s] Return Type should appear at the start of line' % FuncName, 'Function', Result[1])\r
 \r
@@ -1511,7 +1511,7 @@ def CheckFuncLayoutBody(FullFileName):
 \r
     FileTable = 'Identifier' + str(FileID)\r
     Db = GetDB()\r
-    SqlStatement = """ select BodyStartColumn, EndColumn, ID\r
+    SqlStatement = """ select BodyStartColumn, EndColumn, ID, Name\r
                        from Function\r
                        where BelongsToFile = %d\r
                    """ % (FileID)\r
@@ -1520,9 +1520,15 @@ def CheckFuncLayoutBody(FullFileName):
         return ErrorMsgList\r
     for Result in ResultSet:\r
         if Result[0] != 0:\r
-            PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_BODY, 'open brace should be at the very beginning of a line.', 'Function', Result[2])\r
+            if not EccGlobalData.gException.IsException(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_BODY, Result[3]):\r
+                PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_BODY,\r
+                              'The open brace should be at the very beginning of a line for the function [%s].' % Result[3],\r
+                              'Function', Result[2])\r
         if Result[1] != 0:\r
-            PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_BODY, 'close brace should be at the very beginning of a line.', 'Function', Result[2])\r
+            if not EccGlobalData.gException.IsException(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_BODY, Result[3]):\r
+                PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_BODY,\r
+                              'The close brace should be at the very beginning of a line for the function [%s].' % Result[3],\r
+                              'Function', Result[2])\r
 \r
 def CheckFuncLayoutLocalVariable(FullFileName):\r
     ErrorMsgList = []\r
@@ -1554,7 +1560,7 @@ def CheckFuncLayoutLocalVariable(FullFileName):
             continue\r
 \r
         for Result in ResultSet:\r
-            if len(Result[1]) > 0 and 'CONST' not in Result[3]:\r
+            if len(Result[1]) > 0 and 'CONST' not in Result[3] and 'STATIC' not in Result[3]:\r
                 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_NO_INIT_OF_VARIABLE, 'Variable Name: %s' % Result[0], FileTable, Result[2])\r
 \r
 def CheckMemberVariableFormat(Name, Value, FileTable, TdId, ModelId):\r
@@ -1623,7 +1629,7 @@ def CheckMemberVariableFormat(Name, Value, FileTable, TdId, ModelId):
         Field = Field.strip()\r
         if Field == '':\r
             continue\r
-        # For the condition that the field in struct is an array with [] sufixes...\r
+        # For the condition that the field in struct is an array with [] suffixes...\r
         if Field[-1] == ']':\r
             LBPos = Field.find('[')\r
             Field = Field[0:LBPos]\r
@@ -1856,7 +1862,7 @@ def CheckDeclNoUseCType(FullFileName):
                        where Model = %d\r
                    """ % (FileTable, DataClass.MODEL_IDENTIFIER_VARIABLE)\r
     ResultSet = Db.TblFile.Exec(SqlStatement)\r
-    CTypeTuple = ('int', 'unsigned', 'char', 'void', 'static', 'long')\r
+    CTypeTuple = ('int', 'unsigned', 'char', 'void', 'long')\r
     for Result in ResultSet:\r
         for Type in CTypeTuple:\r
             if PatternInModifier(Result[0], Type):\r
@@ -2144,7 +2150,7 @@ def CheckBooleanValueComparison(FullFileName):
                     PrintErrorMsg(ERROR_PREDICATE_EXPRESSION_CHECK_BOOLEAN_VALUE, 'Predicate Expression: %s' % Exp, FileTable, Str[2])\r
 \r
 \r
-def CheckHeaderFileData(FullFileName):\r
+def CheckHeaderFileData(FullFileName, AllTypedefFun=[]):\r
     ErrorMsgList = []\r
 \r
     FileID = GetTableID(FullFileName, ErrorMsgList)\r
@@ -2160,7 +2166,11 @@ def CheckHeaderFileData(FullFileName):
     ResultSet = Db.TblFile.Exec(SqlStatement)\r
     for Result in ResultSet:\r
         if not Result[1].startswith('extern'):\r
-            PrintErrorMsg(ERROR_INCLUDE_FILE_CHECK_DATA, 'Variable definition appears in header file', FileTable, Result[0])\r
+            for Item in AllTypedefFun:\r
+                if '(%s)' % Result[1] in Item:\r
+                    break\r
+            else:\r
+                PrintErrorMsg(ERROR_INCLUDE_FILE_CHECK_DATA, 'Variable definition appears in header file', FileTable, Result[0])\r
 \r
     SqlStatement = """ select ID\r
                        from Function\r
@@ -2381,7 +2391,7 @@ def CheckFileHeaderDoxygenComments(FullFileName):
                     PrintErrorMsg(ERROR_HEADER_CHECK_FILE, 'File header comment content should start with two spaces at each line', FileTable, ID)\r
 \r
             CommentLine = CommentLine.strip()\r
-            if CommentLine.startswith('Copyright'):\r
+            if CommentLine.startswith('Copyright') or ('Copyright' in CommentLine and CommentLine.lower().startswith('(c)')):\r
                 NoCopyrightFlag = False\r
                 if CommentLine.find('All rights reserved') == -1:\r
                     for Copyright in EccGlobalData.gConfig.Copyright:\r
@@ -2602,8 +2612,8 @@ def CheckFunctionHeaderConsistentWithDoxygenComment(FuncModifier, FuncHeader, Fu
 \r
 \r
             if Tag.find(ParamName) == -1 and ParamName != 'VOID' and ParamName != 'void':\r
-                ErrorMsgList.append('Line %d : in Comment, <%s> does NOT consistent with parameter name %s ' % (CommentStartLine, (TagPartList[0] + ' ' + TagPartList[1]).replace('\n', '').replace('\r', ''), ParamName))\r
-                PrintErrorMsg(ERROR_DOXYGEN_CHECK_FUNCTION_HEADER, 'in Comment, <%s> does NOT consistent with parameter name %s ' % ((TagPartList[0] + ' ' + TagPartList[1]).replace('\n', '').replace('\r', ''), ParamName), TableName, CommentId)\r
+                ErrorMsgList.append('Line %d : in Comment, <%s> is NOT consistent with parameter name %s ' % (CommentStartLine, (TagPartList[0] + ' ' + TagPartList[1]).replace('\n', '').replace('\r', ''), ParamName))\r
+                PrintErrorMsg(ERROR_DOXYGEN_CHECK_FUNCTION_HEADER, 'in Comment, <%s> is NOT consistent with parameter name %s ' % ((TagPartList[0] + ' ' + TagPartList[1]).replace('\n', '').replace('\r', ''), ParamName), TableName, CommentId)\r
             Index += 1\r
 \r
         if Index < ParamNumber:\r