Skip to content

Commit

Permalink
1. Add two checkpoints to check “file name collisions in header files…
Browse files Browse the repository at this point in the history
…” and “structure name collisions”

git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1257 7335b38e-4728-0410-8992-fb3ffe349368
  • Loading branch information
hche10x committed Jun 17, 2008
1 parent 753afac commit 5aa3c38
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Source/Python/Ecc/Check.py
Expand Up @@ -154,6 +154,7 @@ def DeclAndDataTypeCheck(self):
self.DeclCheckEFIAPIModifier()
self.DeclCheckEnumeratedType()
self.DeclCheckStructureDeclaration()
self.DeclCheckSameStructure()
self.DeclCheckUnionType()


Expand Down Expand Up @@ -222,6 +223,27 @@ def DeclCheckStructureDeclaration(self):
FullName = os.path.join(Dirpath, F)
c.CheckDeclStructTypedef(FullName)

# Check whether having same Structure
def DeclCheckSameStructure(self):
if EccGlobalData.gConfig.DeclarationDataTypeCheckSameStructure == '1' or EccGlobalData.gConfig.DeclarationDataTypeCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':
EdkLogger.quiet("Checking same struct ...")
AllStructure = {}
for IdentifierTable in EccGlobalData.gIdentifierTableList:
SqlCommand = """select ID, Name, BelongsToFile from %s where Model = %s""" %(IdentifierTable, MODEL_IDENTIFIER_STRUCTURE)
RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)
for Record in RecordSet:
if Record[1] != '':
if Record[1] not in AllStructure.keys():
AllStructure[Record[1]] = Record[2]
else:
ID = AllStructure[Record[1]]
SqlCommand = """select FullPath from File where ID = %s """ % ID
NewRecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)
OtherMsg = "The structure name '%s' is duplicate" % Record[1]
if NewRecordSet != []:
OtherMsg = "The structure name '%s' is duplicate with the one defined in %s" % (Record[1], NewRecordSet[0][0])
EccGlobalData.gDb.TblReport.Insert(ERROR_DECLARATION_DATA_TYPE_CHECK_SAME_STRUCTURE, OtherMsg = OtherMsg, BelongsToTable = IdentifierTable, BelongsToItem = Record[0])

# Check whether Union Type has a 'typedef' and the name is capital
def DeclCheckUnionType(self):
if EccGlobalData.gConfig.DeclarationDataTypeCheckUnionType == '1' or EccGlobalData.gConfig.DeclarationDataTypeCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':
Expand Down Expand Up @@ -293,8 +315,22 @@ def PredicateExpressionCheckComparisonNullType(self):
def IncludeFileCheck(self):
self.IncludeFileCheckIfndef()
self.IncludeFileCheckData()
self.IncludeFileCheckSameName()

#
# Check whether having include files with same name
#
def IncludeFileCheckSameName(self):
if EccGlobalData.gConfig.IncludeFileCheckSameName == '1' or EccGlobalData.gConfig.IncludeFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':
EdkLogger.quiet("Checking same header file name ...")
SqlCommand = """select ID, FullPath from File
where Name in (select Name from File group by Name having count(*) > 1)
and Model = 1002
order by Name """
RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)
for Record in RecordSet:
EccGlobalData.gDb.TblReport.Insert(ERROR_INCLUDE_FILE_CHECK_NAME, OtherMsg = "The file name for '%s' is duplicate" % (Record[1]), BelongsToTable = 'File', BelongsToItem = Record[0])
#
# Check whether all include file contents is guarded by a #ifndef statement.
#
def IncludeFileCheckIfndef(self):
Expand Down
4 changes: 4 additions & 0 deletions Source/Python/Ecc/Configuration.py
Expand Up @@ -139,6 +139,8 @@ def __init__(self, Filename):
#
self.IncludeFileCheckAll = 0

#Check whether having include files with same name
self.IncludeFileCheckSameName = 1
# Check whether all include file contents is guarded by a #ifndef statement.
# the #ifndef must be the first line of code following the file header comment
# the #endif must appear on the last line in the file
Expand All @@ -162,6 +164,8 @@ def __init__(self, Filename):
self.DeclarationDataTypeCheckEnumeratedType = 1
# Check whether Structure Type has a 'typedef' and the name is capital
self.DeclarationDataTypeCheckStructureDeclaration = 1
# Check whether having same Structure
self.DeclarationDataTypeCheckSameStructure = 1
# Check whether Union Type has a 'typedef' and the name is capital
self.DeclarationDataTypeCheckUnionType = 1

Expand Down
4 changes: 4 additions & 0 deletions Source/Python/Ecc/EccToolError.py
Expand Up @@ -46,13 +46,15 @@
ERROR_INCLUDE_FILE_CHECK_IFNDEF_STATEMENT_2 = 6002
ERROR_INCLUDE_FILE_CHECK_IFNDEF_STATEMENT_3 = 6003
ERROR_INCLUDE_FILE_CHECK_DATA = 6004
ERROR_INCLUDE_FILE_CHECK_NAME = 6005

ERROR_DECLARATION_DATA_TYPE_CHECK_ALL = 7000
ERROR_DECLARATION_DATA_TYPE_CHECK_NO_USE_C_TYPE = 7001
ERROR_DECLARATION_DATA_TYPE_CHECK_IN_OUT_MODIFIER = 7002
ERROR_DECLARATION_DATA_TYPE_CHECK_EFI_API_MODIFIER = 7003
ERROR_DECLARATION_DATA_TYPE_CHECK_ENUMERATED_TYPE = 7004
ERROR_DECLARATION_DATA_TYPE_CHECK_STRUCTURE_DECLARATION = 7005
ERROR_DECLARATION_DATA_TYPE_CHECK_SAME_STRUCTURE = 7007
ERROR_DECLARATION_DATA_TYPE_CHECK_UNION_TYPE = 7006

ERROR_NAMING_CONVENTION_CHECK_ALL = 8000
Expand Down Expand Up @@ -124,13 +126,15 @@
ERROR_INCLUDE_FILE_CHECK_IFNDEF_STATEMENT_2 : "The #ifndef must be the first line of code following the file header comment",
ERROR_INCLUDE_FILE_CHECK_IFNDEF_STATEMENT_3 : "The #endif must appear on the last line in the file",
ERROR_INCLUDE_FILE_CHECK_DATA : "Include files should contain only public or only private data and cannot contain code or define data variables",
ERROR_INCLUDE_FILE_CHECK_NAME : "No permission for the inlcude file with same names",

ERROR_DECLARATION_DATA_TYPE_CHECK_ALL : "",
ERROR_DECLARATION_DATA_TYPE_CHECK_NO_USE_C_TYPE : "There should be no use of int, unsigned, char, void, static, long in any .c, .h or .asl files",
ERROR_DECLARATION_DATA_TYPE_CHECK_IN_OUT_MODIFIER : """The modifiers IN, OUT, OPTIONAL, and UNALIGNED should be used only to qualify arguments to a function and should not appear in a data type declaration""",
ERROR_DECLARATION_DATA_TYPE_CHECK_EFI_API_MODIFIER : "The EFIAPI modifier should be used at the entry of drivers, events, and member functions of protocols",
ERROR_DECLARATION_DATA_TYPE_CHECK_ENUMERATED_TYPE : "Enumerated Type should have a 'typedef' and the name must be in capital letters",
ERROR_DECLARATION_DATA_TYPE_CHECK_STRUCTURE_DECLARATION : "Structure Type should have a 'typedef' and the name must be in capital letters",
ERROR_DECLARATION_DATA_TYPE_CHECK_SAME_STRUCTURE : "No permission for the structure with same names",
ERROR_DECLARATION_DATA_TYPE_CHECK_UNION_TYPE : "Union Type should have a 'typedef' and the name must be in capital letters",

ERROR_NAMING_CONVENTION_CHECK_ALL : "",
Expand Down

0 comments on commit 5aa3c38

Please sign in to comment.