## @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
\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
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
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
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
\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
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
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
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
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
\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
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
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
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
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
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
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
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
\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