]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Ecc/c.py
dcb37e5632fb88b96991ad04f2978f7421b4d57d
[mirror_edk2.git] / BaseTools / Source / Python / Ecc / c.py
1 ## @file
2 # This file is used to be the c coding style checking of ECC tool
3 #
4 # Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
9 #
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 #
13
14 import sys
15 import Common.LongFilePathOs as os
16 import re
17 import string
18 import CodeFragmentCollector
19 import FileProfile
20 from CommonDataClass import DataClass
21 import Database
22 from Common import EdkLogger
23 from EccToolError import *
24 import EccGlobalData
25 import MetaDataParser
26
27 IncludeFileListDict = {}
28 AllIncludeFileListDict = {}
29 IncludePathListDict = {}
30 ComplexTypeDict = {}
31 SUDict = {}
32 IgnoredKeywordList = ['EFI_ERROR']
33
34 def GetIgnoredDirListPattern():
35 skipList = list(EccGlobalData.gConfig.SkipDirList) + ['.svn']
36 DirString = string.join(skipList, '|')
37 p = re.compile(r'.*[\\/](?:%s)[\\/]?.*' % DirString)
38 return p
39
40 def GetFuncDeclPattern():
41 p = re.compile(r'(?:EFIAPI|EFI_BOOT_SERVICE|EFI_RUNTIME_SERVICE)?\s*[_\w]+\s*\(.*\)$', re.DOTALL)
42 return p
43
44 def GetArrayPattern():
45 p = re.compile(r'[_\w]*\s*[\[.*\]]+')
46 return p
47
48 def GetTypedefFuncPointerPattern():
49 p = re.compile('[_\w\s]*\([\w\s]*\*+\s*[_\w]+\s*\)\s*\(.*\)', re.DOTALL)
50 return p
51
52 def GetDB():
53 return EccGlobalData.gDb
54
55 def GetConfig():
56 return EccGlobalData.gConfig
57
58 def PrintErrorMsg(ErrorType, Msg, TableName, ItemId):
59 Msg = Msg.replace('\n', '').replace('\r', '')
60 MsgPartList = Msg.split()
61 Msg = ''
62 for Part in MsgPartList:
63 Msg += Part
64 Msg += ' '
65 GetDB().TblReport.Insert(ErrorType, OtherMsg=Msg, BelongsToTable=TableName, BelongsToItem=ItemId)
66
67 def GetIdType(Str):
68 Type = DataClass.MODEL_UNKNOWN
69 Str = Str.replace('#', '# ')
70 List = Str.split()
71 if List[1] == 'include':
72 Type = DataClass.MODEL_IDENTIFIER_INCLUDE
73 elif List[1] == 'define':
74 Type = DataClass.MODEL_IDENTIFIER_MACRO_DEFINE
75 elif List[1] == 'ifdef':
76 Type = DataClass.MODEL_IDENTIFIER_MACRO_IFDEF
77 elif List[1] == 'ifndef':
78 Type = DataClass.MODEL_IDENTIFIER_MACRO_IFNDEF
79 elif List[1] == 'endif':
80 Type = DataClass.MODEL_IDENTIFIER_MACRO_ENDIF
81 elif List[1] == 'pragma':
82 Type = DataClass.MODEL_IDENTIFIER_MACRO_PROGMA
83 else:
84 Type = DataClass.MODEL_UNKNOWN
85 return Type
86
87 def SuOccurInTypedef (Su, TdList):
88 for Td in TdList:
89 if Su.StartPos[0] == Td.StartPos[0] and Su.EndPos[0] == Td.EndPos[0]:
90 return True
91 return False
92
93 def GetIdentifierList():
94 IdList = []
95 for comment in FileProfile.CommentList:
96 IdComment = DataClass.IdentifierClass(-1, '', '', '', comment.Content, DataClass.MODEL_IDENTIFIER_COMMENT, -1, -1, comment.StartPos[0], comment.StartPos[1], comment.EndPos[0], comment.EndPos[1])
97 IdList.append(IdComment)
98
99 for pp in FileProfile.PPDirectiveList:
100 Type = GetIdType(pp.Content)
101 IdPP = DataClass.IdentifierClass(-1, '', '', '', pp.Content, Type, -1, -1, pp.StartPos[0], pp.StartPos[1], pp.EndPos[0], pp.EndPos[1])
102 IdList.append(IdPP)
103
104 for pe in FileProfile.PredicateExpressionList:
105 IdPE = DataClass.IdentifierClass(-1, '', '', '', pe.Content, DataClass.MODEL_IDENTIFIER_PREDICATE_EXPRESSION, -1, -1, pe.StartPos[0], pe.StartPos[1], pe.EndPos[0], pe.EndPos[1])
106 IdList.append(IdPE)
107
108 FuncDeclPattern = GetFuncDeclPattern()
109 ArrayPattern = GetArrayPattern()
110 for var in FileProfile.VariableDeclarationList:
111 DeclText = var.Declarator.lstrip()
112 FuncPointerPattern = GetTypedefFuncPointerPattern()
113 if FuncPointerPattern.match(DeclText):
114 continue
115 VarNameStartLine = var.NameStartPos[0]
116 VarNameStartColumn = var.NameStartPos[1]
117 FirstChar = DeclText[0]
118 while not FirstChar.isalpha() and FirstChar != '_':
119 if FirstChar == '*':
120 var.Modifier += '*'
121 VarNameStartColumn += 1
122 DeclText = DeclText.lstrip('*')
123 elif FirstChar == '\r':
124 DeclText = DeclText.lstrip('\r\n').lstrip('\r')
125 VarNameStartLine += 1
126 VarNameStartColumn = 0
127 elif FirstChar == '\n':
128 DeclText = DeclText.lstrip('\n')
129 VarNameStartLine += 1
130 VarNameStartColumn = 0
131 elif FirstChar == ' ':
132 DeclText = DeclText.lstrip(' ')
133 VarNameStartColumn += 1
134 elif FirstChar == '\t':
135 DeclText = DeclText.lstrip('\t')
136 VarNameStartColumn += 8
137 else:
138 DeclText = DeclText[1:]
139 VarNameStartColumn += 1
140 FirstChar = DeclText[0]
141
142 var.Declarator = DeclText
143 if FuncDeclPattern.match(var.Declarator):
144 DeclSplitList = var.Declarator.split('(')
145 FuncName = DeclSplitList[0].strip()
146 FuncNamePartList = FuncName.split()
147 if len(FuncNamePartList) > 1:
148 FuncName = FuncNamePartList[-1].strip()
149 NameStart = DeclSplitList[0].rfind(FuncName)
150 var.Declarator = var.Declarator[NameStart:]
151 if NameStart > 0:
152 var.Modifier += ' ' + DeclSplitList[0][0:NameStart]
153 Index = 0
154 PreChar = ''
155 while Index < NameStart:
156 FirstChar = DeclSplitList[0][Index]
157 if DeclSplitList[0][Index:].startswith('EFIAPI'):
158 Index += 6
159 VarNameStartColumn += 6
160 PreChar = ''
161 continue
162 elif FirstChar == '\r':
163 Index += 1
164 VarNameStartLine += 1
165 VarNameStartColumn = 0
166 elif FirstChar == '\n':
167 Index += 1
168 if PreChar != '\r':
169 VarNameStartLine += 1
170 VarNameStartColumn = 0
171 elif FirstChar == ' ':
172 Index += 1
173 VarNameStartColumn += 1
174 elif FirstChar == '\t':
175 Index += 1
176 VarNameStartColumn += 8
177 else:
178 Index += 1
179 VarNameStartColumn += 1
180 PreChar = FirstChar
181 IdVar = DataClass.IdentifierClass(-1, var.Modifier, '', var.Declarator, FuncName, DataClass.MODEL_IDENTIFIER_FUNCTION_DECLARATION, -1, -1, var.StartPos[0], var.StartPos[1], VarNameStartLine, VarNameStartColumn)
182 IdList.append(IdVar)
183 continue
184
185 if var.Declarator.find('{') == -1:
186 for decl in var.Declarator.split(','):
187 DeclList = decl.split('=')
188 Name = DeclList[0].strip()
189 if ArrayPattern.match(Name):
190 LSBPos = var.Declarator.find('[')
191 var.Modifier += ' ' + Name[LSBPos:]
192 Name = Name[0:LSBPos]
193
194 IdVar = DataClass.IdentifierClass(-1, var.Modifier, '', Name, (len(DeclList) > 1 and [DeclList[1]]or [''])[0], DataClass.MODEL_IDENTIFIER_VARIABLE, -1, -1, var.StartPos[0], var.StartPos[1], VarNameStartLine, VarNameStartColumn)
195 IdList.append(IdVar)
196 else:
197 DeclList = var.Declarator.split('=')
198 Name = DeclList[0].strip()
199 if ArrayPattern.match(Name):
200 LSBPos = var.Declarator.find('[')
201 var.Modifier += ' ' + Name[LSBPos:]
202 Name = Name[0:LSBPos]
203 IdVar = DataClass.IdentifierClass(-1, var.Modifier, '', Name, (len(DeclList) > 1 and [DeclList[1]]or [''])[0], DataClass.MODEL_IDENTIFIER_VARIABLE, -1, -1, var.StartPos[0], var.StartPos[1], VarNameStartLine, VarNameStartColumn)
204 IdList.append(IdVar)
205
206 for enum in FileProfile.EnumerationDefinitionList:
207 LBPos = enum.Content.find('{')
208 RBPos = enum.Content.find('}')
209 Name = enum.Content[4:LBPos].strip()
210 Value = enum.Content[LBPos + 1:RBPos]
211 IdEnum = DataClass.IdentifierClass(-1, '', '', Name, Value, DataClass.MODEL_IDENTIFIER_ENUMERATE, -1, -1, enum.StartPos[0], enum.StartPos[1], enum.EndPos[0], enum.EndPos[1])
212 IdList.append(IdEnum)
213
214 for su in FileProfile.StructUnionDefinitionList:
215 if SuOccurInTypedef(su, FileProfile.TypedefDefinitionList):
216 continue
217 Type = DataClass.MODEL_IDENTIFIER_STRUCTURE
218 SkipLen = 6
219 if su.Content.startswith('union'):
220 Type = DataClass.MODEL_IDENTIFIER_UNION
221 SkipLen = 5
222 LBPos = su.Content.find('{')
223 RBPos = su.Content.find('}')
224 if LBPos == -1 or RBPos == -1:
225 Name = su.Content[SkipLen:].strip()
226 Value = ''
227 else:
228 Name = su.Content[SkipLen:LBPos].strip()
229 Value = su.Content[LBPos:RBPos + 1]
230 IdPE = DataClass.IdentifierClass(-1, '', '', Name, Value, Type, -1, -1, su.StartPos[0], su.StartPos[1], su.EndPos[0], su.EndPos[1])
231 IdList.append(IdPE)
232
233 TdFuncPointerPattern = GetTypedefFuncPointerPattern()
234 for td in FileProfile.TypedefDefinitionList:
235 Modifier = ''
236 Name = td.ToType
237 Value = td.FromType
238 if TdFuncPointerPattern.match(td.ToType):
239 Modifier = td.FromType
240 LBPos = td.ToType.find('(')
241 TmpStr = td.ToType[LBPos + 1:].strip()
242 StarPos = TmpStr.find('*')
243 if StarPos != -1:
244 Modifier += ' ' + TmpStr[0:StarPos]
245 while TmpStr[StarPos] == '*':
246 # Modifier += ' ' + '*'
247 StarPos += 1
248 TmpStr = TmpStr[StarPos:].strip()
249 RBPos = TmpStr.find(')')
250 Name = TmpStr[0:RBPos]
251 Value = 'FP' + TmpStr[RBPos + 1:]
252 else:
253 while Name.startswith('*'):
254 Value += ' ' + '*'
255 Name = Name.lstrip('*').strip()
256
257 if Name.find('[') != -1:
258 LBPos = Name.find('[')
259 RBPos = Name.rfind(']')
260 Value += Name[LBPos : RBPos + 1]
261 Name = Name[0 : LBPos]
262
263 IdTd = DataClass.IdentifierClass(-1, Modifier, '', Name, Value, DataClass.MODEL_IDENTIFIER_TYPEDEF, -1, -1, td.StartPos[0], td.StartPos[1], td.EndPos[0], td.EndPos[1])
264 IdList.append(IdTd)
265
266 for funcCall in FileProfile.FunctionCallingList:
267 IdFC = DataClass.IdentifierClass(-1, '', '', funcCall.FuncName, funcCall.ParamList, DataClass.MODEL_IDENTIFIER_FUNCTION_CALLING, -1, -1, funcCall.StartPos[0], funcCall.StartPos[1], funcCall.EndPos[0], funcCall.EndPos[1])
268 IdList.append(IdFC)
269 return IdList
270
271 def StripNonAlnumChars(Str):
272 StrippedStr = ''
273 for Char in Str:
274 if Char.isalnum():
275 StrippedStr += Char
276 return StrippedStr
277
278 def GetParamList(FuncDeclarator, FuncNameLine=0, FuncNameOffset=0):
279 FuncDeclarator = StripComments(FuncDeclarator)
280 ParamIdList = []
281 #DeclSplitList = FuncDeclarator.split('(')
282 LBPos = FuncDeclarator.find('(')
283 #if len(DeclSplitList) < 2:
284 if LBPos == -1:
285 return ParamIdList
286 #FuncName = DeclSplitList[0]
287 FuncName = FuncDeclarator[0:LBPos]
288 #ParamStr = DeclSplitList[1].rstrip(')')
289 ParamStr = FuncDeclarator[LBPos + 1:].rstrip(')')
290 LineSkipped = 0
291 OffsetSkipped = 0
292 TailChar = FuncName[-1]
293 while not TailChar.isalpha() and TailChar != '_':
294
295 if TailChar == '\n':
296 FuncName = FuncName.rstrip('\r\n').rstrip('\n')
297 LineSkipped += 1
298 OffsetSkipped = 0
299 elif TailChar == '\r':
300 FuncName = FuncName.rstrip('\r')
301 LineSkipped += 1
302 OffsetSkipped = 0
303 elif TailChar == ' ':
304 FuncName = FuncName.rstrip(' ')
305 OffsetSkipped += 1
306 elif TailChar == '\t':
307 FuncName = FuncName.rstrip('\t')
308 OffsetSkipped += 8
309 else:
310 FuncName = FuncName[:-1]
311 TailChar = FuncName[-1]
312
313 OffsetSkipped += 1 #skip '('
314
315 for p in ParamStr.split(','):
316 ListP = p.split()
317 if len(ListP) == 0:
318 continue
319 ParamName = ListP[-1]
320 DeclText = ParamName.strip()
321 RightSpacePos = p.rfind(ParamName)
322 ParamModifier = p[0:RightSpacePos]
323 if ParamName == 'OPTIONAL':
324 if ParamModifier == '':
325 ParamModifier += ' ' + 'OPTIONAL'
326 DeclText = ''
327 else:
328 ParamName = ListP[-2]
329 DeclText = ParamName.strip()
330 RightSpacePos = p.rfind(ParamName)
331 ParamModifier = p[0:RightSpacePos]
332 ParamModifier += 'OPTIONAL'
333 while DeclText.startswith('*'):
334 ParamModifier += ' ' + '*'
335 DeclText = DeclText.lstrip('*').strip()
336 ParamName = DeclText
337 # ignore array length if exists.
338 LBIndex = ParamName.find('[')
339 if LBIndex != -1:
340 ParamName = ParamName[0:LBIndex]
341
342 Start = RightSpacePos
343 Index = 0
344 PreChar = ''
345 while Index < Start:
346 FirstChar = p[Index]
347
348 if FirstChar == '\r':
349 Index += 1
350 LineSkipped += 1
351 OffsetSkipped = 0
352 elif FirstChar == '\n':
353 Index += 1
354 if PreChar != '\r':
355 LineSkipped += 1
356 OffsetSkipped = 0
357 elif FirstChar == ' ':
358 Index += 1
359 OffsetSkipped += 1
360 elif FirstChar == '\t':
361 Index += 1
362 OffsetSkipped += 8
363 else:
364 Index += 1
365 OffsetSkipped += 1
366 PreChar = FirstChar
367
368 ParamBeginLine = FuncNameLine + LineSkipped
369 ParamBeginOffset = FuncNameOffset + OffsetSkipped
370
371 Index = Start + len(ParamName)
372 PreChar = ''
373 while Index < len(p):
374 FirstChar = p[Index]
375
376 if FirstChar == '\r':
377 Index += 1
378 LineSkipped += 1
379 OffsetSkipped = 0
380 elif FirstChar == '\n':
381 Index += 1
382 if PreChar != '\r':
383 LineSkipped += 1
384 OffsetSkipped = 0
385 elif FirstChar == ' ':
386 Index += 1
387 OffsetSkipped += 1
388 elif FirstChar == '\t':
389 Index += 1
390 OffsetSkipped += 8
391 else:
392 Index += 1
393 OffsetSkipped += 1
394 PreChar = FirstChar
395
396 ParamEndLine = FuncNameLine + LineSkipped
397 ParamEndOffset = FuncNameOffset + OffsetSkipped
398 if ParamName != '...':
399 ParamName = StripNonAlnumChars(ParamName)
400 IdParam = DataClass.IdentifierClass(-1, ParamModifier, '', ParamName, '', DataClass.MODEL_IDENTIFIER_PARAMETER, -1, -1, ParamBeginLine, ParamBeginOffset, ParamEndLine, ParamEndOffset)
401 ParamIdList.append(IdParam)
402
403 OffsetSkipped += 1 #skip ','
404
405 return ParamIdList
406
407 def GetFunctionList():
408 FuncObjList = []
409 for FuncDef in FileProfile.FunctionDefinitionList:
410 ParamIdList = []
411 DeclText = FuncDef.Declarator.lstrip()
412 FuncNameStartLine = FuncDef.NamePos[0]
413 FuncNameStartColumn = FuncDef.NamePos[1]
414 FirstChar = DeclText[0]
415 while not FirstChar.isalpha() and FirstChar != '_':
416 if FirstChar == '*':
417 FuncDef.Modifier += '*'
418 FuncNameStartColumn += 1
419 DeclText = DeclText.lstrip('*')
420 elif FirstChar == '\r':
421 DeclText = DeclText.lstrip('\r\n').lstrip('\r')
422 FuncNameStartLine += 1
423 FuncNameStartColumn = 0
424 elif FirstChar == '\n':
425 DeclText = DeclText.lstrip('\n')
426 FuncNameStartLine += 1
427 FuncNameStartColumn = 0
428 elif FirstChar == ' ':
429 DeclText = DeclText.lstrip(' ')
430 FuncNameStartColumn += 1
431 elif FirstChar == '\t':
432 DeclText = DeclText.lstrip('\t')
433 FuncNameStartColumn += 8
434 else:
435 DeclText = DeclText[1:]
436 FuncNameStartColumn += 1
437 FirstChar = DeclText[0]
438
439 FuncDef.Declarator = DeclText
440 DeclSplitList = FuncDef.Declarator.split('(')
441 if len(DeclSplitList) < 2:
442 continue
443
444 FuncName = DeclSplitList[0]
445 FuncNamePartList = FuncName.split()
446 if len(FuncNamePartList) > 1:
447 FuncName = FuncNamePartList[-1]
448 NameStart = DeclSplitList[0].rfind(FuncName)
449 if NameStart > 0:
450 FuncDef.Modifier += ' ' + DeclSplitList[0][0:NameStart]
451 Index = 0
452 PreChar = ''
453 while Index < NameStart:
454 FirstChar = DeclSplitList[0][Index]
455 if DeclSplitList[0][Index:].startswith('EFIAPI'):
456 Index += 6
457 FuncNameStartColumn += 6
458 PreChar = ''
459 continue
460 elif FirstChar == '\r':
461 Index += 1
462 FuncNameStartLine += 1
463 FuncNameStartColumn = 0
464 elif FirstChar == '\n':
465 Index += 1
466 if PreChar != '\r':
467 FuncNameStartLine += 1
468 FuncNameStartColumn = 0
469 elif FirstChar == ' ':
470 Index += 1
471 FuncNameStartColumn += 1
472 elif FirstChar == '\t':
473 Index += 1
474 FuncNameStartColumn += 8
475 else:
476 Index += 1
477 FuncNameStartColumn += 1
478 PreChar = FirstChar
479
480 FuncObj = DataClass.FunctionClass(-1, FuncDef.Declarator, FuncDef.Modifier, FuncName.strip(), '', FuncDef.StartPos[0], FuncDef.StartPos[1], FuncDef.EndPos[0], FuncDef.EndPos[1], FuncDef.LeftBracePos[0], FuncDef.LeftBracePos[1], -1, ParamIdList, [], FuncNameStartLine, FuncNameStartColumn)
481 FuncObjList.append(FuncObj)
482
483 return FuncObjList
484
485 def GetFileModificationTimeFromDB(FullFileName):
486 TimeValue = 0.0
487 Db = GetDB()
488 SqlStatement = """ select TimeStamp
489 from File
490 where FullPath = \'%s\'
491 """ % (FullFileName)
492 ResultSet = Db.TblFile.Exec(SqlStatement)
493 for Result in ResultSet:
494 TimeValue = Result[0]
495 return TimeValue
496
497 def CollectSourceCodeDataIntoDB(RootDir):
498 FileObjList = []
499 tuple = os.walk(RootDir)
500 IgnoredPattern = GetIgnoredDirListPattern()
501 ParseErrorFileList = []
502
503 for dirpath, dirnames, filenames in tuple:
504 if IgnoredPattern.match(dirpath.upper()):
505 continue
506
507 for Dir in dirnames:
508 Dirname = os.path.join(dirpath, Dir)
509 if os.path.islink(Dirname):
510 Dirname = os.path.realpath(Dirname)
511 if os.path.isdir(Dirname):
512 # symlinks to directories are treated as directories
513 dirnames.remove(Dir)
514 dirnames.append(Dirname)
515
516 for f in filenames:
517 if f.lower() in EccGlobalData.gConfig.SkipFileList:
518 continue
519 collector = None
520 FullName = os.path.normpath(os.path.join(dirpath, f))
521 model = DataClass.MODEL_FILE_OTHERS
522 if os.path.splitext(f)[1] in ('.h', '.c'):
523 EdkLogger.info("Parsing " + FullName)
524 model = f.endswith('c') and DataClass.MODEL_FILE_C or DataClass.MODEL_FILE_H
525 collector = CodeFragmentCollector.CodeFragmentCollector(FullName)
526 try:
527 collector.ParseFile()
528 except UnicodeError:
529 ParseErrorFileList.append(FullName)
530 collector.CleanFileProfileBuffer()
531 collector.ParseFileWithClearedPPDirective()
532 # collector.PrintFragments()
533 BaseName = os.path.basename(f)
534 DirName = os.path.dirname(FullName)
535 Ext = os.path.splitext(f)[1].lstrip('.')
536 ModifiedTime = os.path.getmtime(FullName)
537 FileObj = DataClass.FileClass(-1, BaseName, Ext, DirName, FullName, model, ModifiedTime, GetFunctionList(), GetIdentifierList(), [])
538 FileObjList.append(FileObj)
539 if collector:
540 collector.CleanFileProfileBuffer()
541
542 if len(ParseErrorFileList) > 0:
543 EdkLogger.info("Found unrecoverable error during parsing:\n\t%s\n" % "\n\t".join(ParseErrorFileList))
544
545 Db = GetDB()
546 for file in FileObjList:
547 if file.ExtName.upper() not in ['INF', 'DEC', 'DSC', 'FDF']:
548 Db.InsertOneFile(file)
549
550 Db.UpdateIdentifierBelongsToFunction()
551
552 def GetTableID(FullFileName, ErrorMsgList=None):
553 if ErrorMsgList == None:
554 ErrorMsgList = []
555
556 Db = GetDB()
557 SqlStatement = """ select ID
558 from File
559 where FullPath like '%s'
560 """ % FullFileName
561 ResultSet = Db.TblFile.Exec(SqlStatement)
562
563 FileID = -1
564 for Result in ResultSet:
565 if FileID != -1:
566 ErrorMsgList.append('Duplicate file ID found in DB for file %s' % FullFileName)
567 return - 2
568 FileID = Result[0]
569 if FileID == -1:
570 ErrorMsgList.append('NO file ID found in DB for file %s' % FullFileName)
571 return - 1
572 return FileID
573
574 def GetIncludeFileList(FullFileName):
575 if os.path.splitext(FullFileName)[1].upper() not in ('.H'):
576 return []
577 IFList = IncludeFileListDict.get(FullFileName)
578 if IFList != None:
579 return IFList
580
581 FileID = GetTableID(FullFileName)
582 if FileID < 0:
583 return []
584
585 Db = GetDB()
586 FileTable = 'Identifier' + str(FileID)
587 SqlStatement = """ select Value
588 from %s
589 where Model = %d
590 """ % (FileTable, DataClass.MODEL_IDENTIFIER_INCLUDE)
591 ResultSet = Db.TblFile.Exec(SqlStatement)
592 IncludeFileListDict[FullFileName] = ResultSet
593 return ResultSet
594
595 def GetFullPathOfIncludeFile(Str, IncludePathList):
596 for IncludePath in IncludePathList:
597 FullPath = os.path.join(IncludePath, Str)
598 FullPath = os.path.normpath(FullPath)
599 if os.path.exists(FullPath):
600 return FullPath
601 return None
602
603 def GetAllIncludeFiles(FullFileName):
604 if AllIncludeFileListDict.get(FullFileName) != None:
605 return AllIncludeFileListDict.get(FullFileName)
606
607 FileDirName = os.path.dirname(FullFileName)
608 IncludePathList = IncludePathListDict.get(FileDirName)
609 if IncludePathList == None:
610 IncludePathList = MetaDataParser.GetIncludeListOfFile(EccGlobalData.gWorkspace, FullFileName, GetDB())
611 if FileDirName not in IncludePathList:
612 IncludePathList.insert(0, FileDirName)
613 IncludePathListDict[FileDirName] = IncludePathList
614 IncludeFileQueue = []
615 for IncludeFile in GetIncludeFileList(FullFileName):
616 FileName = IncludeFile[0].lstrip('#').strip()
617 FileName = FileName.lstrip('include').strip()
618 FileName = FileName.strip('\"')
619 FileName = FileName.lstrip('<').rstrip('>').strip()
620 FullPath = GetFullPathOfIncludeFile(FileName, IncludePathList)
621 if FullPath != None:
622 IncludeFileQueue.append(FullPath)
623
624 i = 0
625 while i < len(IncludeFileQueue):
626 for IncludeFile in GetIncludeFileList(IncludeFileQueue[i]):
627 FileName = IncludeFile[0].lstrip('#').strip()
628 FileName = FileName.lstrip('include').strip()
629 FileName = FileName.strip('\"')
630 FileName = FileName.lstrip('<').rstrip('>').strip()
631 FullPath = GetFullPathOfIncludeFile(FileName, IncludePathList)
632 if FullPath != None and FullPath not in IncludeFileQueue:
633 IncludeFileQueue.insert(i + 1, FullPath)
634 i += 1
635
636 AllIncludeFileListDict[FullFileName] = IncludeFileQueue
637 return IncludeFileQueue
638
639 def GetPredicateListFromPredicateExpStr(PES):
640
641 PredicateList = []
642 i = 0
643 PredicateBegin = 0
644 #PredicateEnd = 0
645 LogicOpPos = -1
646 p = GetFuncDeclPattern()
647 while i < len(PES) - 1:
648 if (PES[i].isalnum() or PES[i] == '_' or PES[i] == '*') and LogicOpPos > PredicateBegin:
649 PredicateBegin = i
650 if (PES[i] == '&' and PES[i + 1] == '&') or (PES[i] == '|' and PES[i + 1] == '|'):
651 LogicOpPos = i
652 Exp = PES[PredicateBegin:i].strip()
653 # Exp may contain '.' or '->'
654 TmpExp = Exp.replace('.', '').replace('->', '')
655 if p.match(TmpExp):
656 PredicateList.append(Exp)
657 else:
658 PredicateList.append(Exp.rstrip(';').rstrip(')').strip())
659 i += 1
660
661 if PredicateBegin > LogicOpPos:
662 while PredicateBegin < len(PES):
663 if PES[PredicateBegin].isalnum() or PES[PredicateBegin] == '_' or PES[PredicateBegin] == '*':
664 break
665 PredicateBegin += 1
666 Exp = PES[PredicateBegin:len(PES)].strip()
667 # Exp may contain '.' or '->'
668 TmpExp = Exp.replace('.', '').replace('->', '')
669 if p.match(TmpExp):
670 PredicateList.append(Exp)
671 else:
672 PredicateList.append(Exp.rstrip(';').rstrip(')').strip())
673 return PredicateList
674
675 def GetCNameList(Lvalue, StarList=[]):
676 Lvalue += ' '
677 i = 0
678 SearchBegin = 0
679 VarStart = -1
680 VarEnd = -1
681 VarList = []
682
683 while SearchBegin < len(Lvalue):
684 while i < len(Lvalue):
685 if Lvalue[i].isalnum() or Lvalue[i] == '_':
686 if VarStart == -1:
687 VarStart = i
688 VarEnd = i
689 i += 1
690 elif VarEnd != -1:
691 VarList.append(Lvalue[VarStart:VarEnd + 1])
692 i += 1
693 break
694 else:
695 if VarStart == -1 and Lvalue[i] == '*':
696 StarList.append('*')
697 i += 1
698 if VarEnd == -1:
699 break
700
701
702 DotIndex = Lvalue[VarEnd:].find('.')
703 ArrowIndex = Lvalue[VarEnd:].find('->')
704 if DotIndex == -1 and ArrowIndex == -1:
705 break
706 elif DotIndex == -1 and ArrowIndex != -1:
707 SearchBegin = VarEnd + ArrowIndex
708 elif ArrowIndex == -1 and DotIndex != -1:
709 SearchBegin = VarEnd + DotIndex
710 else:
711 SearchBegin = VarEnd + ((DotIndex < ArrowIndex) and DotIndex or ArrowIndex)
712
713 i = SearchBegin
714 VarStart = -1
715 VarEnd = -1
716
717 return VarList
718
719 def SplitPredicateByOp(Str, Op, IsFuncCalling=False):
720
721 Name = Str.strip()
722 Value = None
723
724 if IsFuncCalling:
725 Index = 0
726 LBFound = False
727 UnmatchedLBCount = 0
728 while Index < len(Str):
729 while not LBFound and Str[Index] != '_' and not Str[Index].isalnum():
730 Index += 1
731
732 while not LBFound and (Str[Index].isalnum() or Str[Index] == '_'):
733 Index += 1
734 # maybe type-cast at the begining, skip it.
735 RemainingStr = Str[Index:].lstrip()
736 if RemainingStr.startswith(')') and not LBFound:
737 Index += 1
738 continue
739
740 if RemainingStr.startswith('(') and not LBFound:
741 LBFound = True
742
743 if Str[Index] == '(':
744 UnmatchedLBCount += 1
745 Index += 1
746 continue
747
748 if Str[Index] == ')':
749 UnmatchedLBCount -= 1
750 Index += 1
751 if UnmatchedLBCount == 0:
752 break
753 continue
754
755 Index += 1
756
757 if UnmatchedLBCount > 0:
758 return [Name]
759
760 IndexInRemainingStr = Str[Index:].find(Op)
761 if IndexInRemainingStr == -1:
762 return [Name]
763
764 Name = Str[0:Index + IndexInRemainingStr].strip()
765 Value = Str[Index + IndexInRemainingStr + len(Op):].strip().strip(')')
766 return [Name, Value]
767
768 TmpStr = Str.rstrip(';').rstrip(')')
769 while True:
770 Index = TmpStr.rfind(Op)
771 if Index == -1:
772 return [Name]
773
774 if Str[Index - 1].isalnum() or Str[Index - 1].isspace() or Str[Index - 1] == ')' or Str[Index - 1] == ']':
775 Name = Str[0:Index].strip()
776 Value = Str[Index + len(Op):].strip()
777 return [Name, Value]
778
779 TmpStr = Str[0:Index - 1]
780
781 def SplitPredicateStr(Str):
782
783 Str = Str.lstrip('(')
784 IsFuncCalling = False
785 p = GetFuncDeclPattern()
786 TmpStr = Str.replace('.', '').replace('->', '')
787 if p.match(TmpStr):
788 IsFuncCalling = True
789
790 PredPartList = SplitPredicateByOp(Str, '==', IsFuncCalling)
791 if len(PredPartList) > 1:
792 return [PredPartList, '==']
793
794 PredPartList = SplitPredicateByOp(Str, '!=', IsFuncCalling)
795 if len(PredPartList) > 1:
796 return [PredPartList, '!=']
797
798 PredPartList = SplitPredicateByOp(Str, '>=', IsFuncCalling)
799 if len(PredPartList) > 1:
800 return [PredPartList, '>=']
801
802 PredPartList = SplitPredicateByOp(Str, '<=', IsFuncCalling)
803 if len(PredPartList) > 1:
804 return [PredPartList, '<=']
805
806 PredPartList = SplitPredicateByOp(Str, '>', IsFuncCalling)
807 if len(PredPartList) > 1:
808 return [PredPartList, '>']
809
810 PredPartList = SplitPredicateByOp(Str, '<', IsFuncCalling)
811 if len(PredPartList) > 1:
812 return [PredPartList, '<']
813
814 return [[Str, None], None]
815
816 def GetFuncContainsPE(ExpLine, ResultSet):
817 for Result in ResultSet:
818 if Result[0] < ExpLine and Result[1] > ExpLine:
819 return Result
820 return None
821
822 def PatternInModifier(Modifier, SubStr):
823 PartList = Modifier.split()
824 for Part in PartList:
825 if Part == SubStr:
826 return True
827 return False
828
829 def GetDataTypeFromModifier(ModifierStr):
830 MList = ModifierStr.split()
831 ReturnType = ''
832 for M in MList:
833 if M in EccGlobalData.gConfig.ModifierList:
834 continue
835 # remove array sufix
836 if M.startswith('[') or M.endswith(']'):
837 continue
838 ReturnType += M + ' '
839
840 ReturnType = ReturnType.strip()
841 if len(ReturnType) == 0:
842 ReturnType = 'VOID'
843 return ReturnType
844
845 def DiffModifier(Str1, Str2):
846 PartList1 = Str1.split()
847 PartList2 = Str2.split()
848 if PartList1 == PartList2:
849 return False
850 else:
851 return True
852
853 def GetTypedefDict(FullFileName):
854
855 Dict = ComplexTypeDict.get(FullFileName)
856 if Dict != None:
857 return Dict
858
859 FileID = GetTableID(FullFileName)
860 FileTable = 'Identifier' + str(FileID)
861 Db = GetDB()
862 SqlStatement = """ select Modifier, Name, Value, ID
863 from %s
864 where Model = %d
865 """ % (FileTable, DataClass.MODEL_IDENTIFIER_TYPEDEF)
866 ResultSet = Db.TblFile.Exec(SqlStatement)
867
868 Dict = {}
869 for Result in ResultSet:
870 if len(Result[0]) == 0:
871 Dict[Result[1]] = Result[2]
872
873 IncludeFileList = GetAllIncludeFiles(FullFileName)
874 for F in IncludeFileList:
875 FileID = GetTableID(F)
876 if FileID < 0:
877 continue
878
879 FileTable = 'Identifier' + str(FileID)
880 SqlStatement = """ select Modifier, Name, Value, ID
881 from %s
882 where Model = %d
883 """ % (FileTable, DataClass.MODEL_IDENTIFIER_TYPEDEF)
884 ResultSet = Db.TblFile.Exec(SqlStatement)
885
886 for Result in ResultSet:
887 if not Result[2].startswith('FP ('):
888 Dict[Result[1]] = Result[2]
889 else:
890 if len(Result[0]) == 0:
891 Dict[Result[1]] = 'VOID'
892 else:
893 Dict[Result[1]] = GetDataTypeFromModifier(Result[0])
894
895 ComplexTypeDict[FullFileName] = Dict
896 return Dict
897
898 def GetSUDict(FullFileName):
899
900 Dict = SUDict.get(FullFileName)
901 if Dict != None:
902 return Dict
903
904 FileID = GetTableID(FullFileName)
905 FileTable = 'Identifier' + str(FileID)
906 Db = GetDB()
907 SqlStatement = """ select Name, Value, ID
908 from %s
909 where Model = %d or Model = %d
910 """ % (FileTable, DataClass.MODEL_IDENTIFIER_STRUCTURE, DataClass.MODEL_IDENTIFIER_UNION)
911 ResultSet = Db.TblFile.Exec(SqlStatement)
912
913 Dict = {}
914 for Result in ResultSet:
915 if len(Result[1]) > 0:
916 Dict[Result[0]] = Result[1]
917
918 IncludeFileList = GetAllIncludeFiles(FullFileName)
919 for F in IncludeFileList:
920 FileID = GetTableID(F)
921 if FileID < 0:
922 continue
923
924 FileTable = 'Identifier' + str(FileID)
925 SqlStatement = """ select Name, Value, ID
926 from %s
927 where Model = %d or Model = %d
928 """ % (FileTable, DataClass.MODEL_IDENTIFIER_STRUCTURE, DataClass.MODEL_IDENTIFIER_UNION)
929 ResultSet = Db.TblFile.Exec(SqlStatement)
930
931 for Result in ResultSet:
932 if len(Result[1]) > 0:
933 Dict[Result[0]] = Result[1]
934
935 SUDict[FullFileName] = Dict
936 return Dict
937
938 def StripComments(Str):
939 Str += ' '
940 ListFromStr = list(Str)
941
942 InComment = False
943 DoubleSlashComment = False
944 Index = 0
945 while Index < len(ListFromStr):
946 # meet new line, then no longer in a comment for //
947 if ListFromStr[Index] == '\n':
948 if InComment and DoubleSlashComment:
949 InComment = False
950 DoubleSlashComment = False
951 Index += 1
952 # check for */ comment end
953 elif InComment and not DoubleSlashComment and ListFromStr[Index] == '*' and ListFromStr[Index + 1] == '/':
954 ListFromStr[Index] = ' '
955 Index += 1
956 ListFromStr[Index] = ' '
957 Index += 1
958 InComment = False
959 # set comments to spaces
960 elif InComment:
961 ListFromStr[Index] = ' '
962 Index += 1
963 # check for // comment
964 elif ListFromStr[Index] == '/' and ListFromStr[Index + 1] == '/' and ListFromStr[Index + 2] != '\n':
965 InComment = True
966 DoubleSlashComment = True
967
968 # check for /* comment start
969 elif ListFromStr[Index] == '/' and ListFromStr[Index + 1] == '*':
970 ListFromStr[Index] = ' '
971 Index += 1
972 ListFromStr[Index] = ' '
973 Index += 1
974 InComment = True
975 else:
976 Index += 1
977
978 # restore from List to String
979 Str = "".join(ListFromStr)
980 Str = Str.rstrip(' ')
981
982 return Str
983
984 def GetFinalTypeValue(Type, FieldName, TypedefDict, SUDict):
985 Value = TypedefDict.get(Type)
986 if Value == None:
987 Value = SUDict.get(Type)
988 if Value == None:
989 return None
990
991 LBPos = Value.find('{')
992 while LBPos == -1:
993 FTList = Value.split()
994 for FT in FTList:
995 if FT not in ('struct', 'union'):
996 Value = TypedefDict.get(FT)
997 if Value == None:
998 Value = SUDict.get(FT)
999 break
1000
1001 if Value == None:
1002 return None
1003
1004 LBPos = Value.find('{')
1005
1006 # RBPos = Value.find('}')
1007 Fields = Value[LBPos + 1:]
1008 Fields = StripComments(Fields)
1009 FieldsList = Fields.split(';')
1010 for Field in FieldsList:
1011 Field = Field.strip()
1012 Index = Field.rfind(FieldName)
1013 if Index < 1:
1014 continue
1015 if not Field[Index - 1].isalnum():
1016 if Index + len(FieldName) == len(Field):
1017 Type = GetDataTypeFromModifier(Field[0:Index])
1018 return Type.strip()
1019 else:
1020 # For the condition that the field in struct is an array with [] sufixes...
1021 if not Field[Index + len(FieldName)].isalnum():
1022 Type = GetDataTypeFromModifier(Field[0:Index])
1023 return Type.strip()
1024
1025 return None
1026
1027 def GetRealType(Type, TypedefDict, TargetType=None):
1028 if TargetType != None and Type == TargetType:
1029 return Type
1030 while TypedefDict.get(Type):
1031 Type = TypedefDict.get(Type)
1032 if TargetType != None and Type == TargetType:
1033 return Type
1034 return Type
1035
1036 def GetTypeInfo(RefList, Modifier, FullFileName, TargetType=None):
1037 TypedefDict = GetTypedefDict(FullFileName)
1038 SUDict = GetSUDict(FullFileName)
1039 Type = GetDataTypeFromModifier(Modifier).replace('*', '').strip()
1040
1041 Type = Type.split()[-1]
1042 Index = 0
1043 while Index < len(RefList):
1044 FieldName = RefList[Index]
1045 FromType = GetFinalTypeValue(Type, FieldName, TypedefDict, SUDict)
1046 if FromType == None:
1047 return None
1048 # we want to determine the exact type.
1049 if TargetType != None:
1050 Type = FromType.split()[0]
1051 # we only want to check if it is a pointer
1052 else:
1053 Type = FromType
1054 if Type.find('*') != -1 and Index == len(RefList) - 1:
1055 return Type
1056 Type = FromType.split()[0]
1057
1058 Index += 1
1059
1060 Type = GetRealType(Type, TypedefDict, TargetType)
1061
1062 return Type
1063
1064 def GetVarInfo(PredVarList, FuncRecord, FullFileName, IsFuncCall=False, TargetType=None, StarList=None):
1065
1066 PredVar = PredVarList[0]
1067 FileID = GetTableID(FullFileName)
1068
1069 Db = GetDB()
1070 FileTable = 'Identifier' + str(FileID)
1071 # search variable in include files
1072
1073 # it is a function call, search function declarations and definitions
1074 if IsFuncCall:
1075 SqlStatement = """ select Modifier, ID
1076 from %s
1077 where Model = %d and Value = \'%s\'
1078 """ % (FileTable, DataClass.MODEL_IDENTIFIER_FUNCTION_DECLARATION, PredVar)
1079 ResultSet = Db.TblFile.Exec(SqlStatement)
1080
1081 for Result in ResultSet:
1082 Type = GetDataTypeFromModifier(Result[0]).split()[-1]
1083 TypedefDict = GetTypedefDict(FullFileName)
1084 Type = GetRealType(Type, TypedefDict, TargetType)
1085 return Type
1086
1087 IncludeFileList = GetAllIncludeFiles(FullFileName)
1088 for F in IncludeFileList:
1089 FileID = GetTableID(F)
1090 if FileID < 0:
1091 continue
1092
1093 FileTable = 'Identifier' + str(FileID)
1094 SqlStatement = """ select Modifier, ID
1095 from %s
1096 where Model = %d and Value = \'%s\'
1097 """ % (FileTable, DataClass.MODEL_IDENTIFIER_FUNCTION_DECLARATION, PredVar)
1098 ResultSet = Db.TblFile.Exec(SqlStatement)
1099
1100 for Result in ResultSet:
1101 Type = GetDataTypeFromModifier(Result[0]).split()[-1]
1102 TypedefDict = GetTypedefDict(FullFileName)
1103 Type = GetRealType(Type, TypedefDict, TargetType)
1104 return Type
1105
1106 FileID = GetTableID(FullFileName)
1107 SqlStatement = """ select Modifier, ID
1108 from Function
1109 where BelongsToFile = %d and Name = \'%s\'
1110 """ % (FileID, PredVar)
1111 ResultSet = Db.TblFile.Exec(SqlStatement)
1112
1113 for Result in ResultSet:
1114 Type = GetDataTypeFromModifier(Result[0]).split()[-1]
1115 TypedefDict = GetTypedefDict(FullFileName)
1116 Type = GetRealType(Type, TypedefDict, TargetType)
1117 return Type
1118
1119 for F in IncludeFileList:
1120 FileID = GetTableID(F)
1121 if FileID < 0:
1122 continue
1123
1124 FileTable = 'Identifier' + str(FileID)
1125 SqlStatement = """ select Modifier, ID
1126 from Function
1127 where BelongsToFile = %d and Name = \'%s\'
1128 """ % (FileID, PredVar)
1129 ResultSet = Db.TblFile.Exec(SqlStatement)
1130
1131 for Result in ResultSet:
1132 Type = GetDataTypeFromModifier(Result[0]).split()[-1]
1133 TypedefDict = GetTypedefDict(FullFileName)
1134 Type = GetRealType(Type, TypedefDict, TargetType)
1135 return Type
1136
1137 return None
1138
1139 # really variable, search local variable first
1140 SqlStatement = """ select Modifier, ID
1141 from %s
1142 where Model = %d and Name = \'%s\' and StartLine >= %d and StartLine <= %d
1143 """ % (FileTable, DataClass.MODEL_IDENTIFIER_VARIABLE, PredVar, FuncRecord[0], FuncRecord[1])
1144 ResultSet = Db.TblFile.Exec(SqlStatement)
1145 VarFound = False
1146 for Result in ResultSet:
1147 if len(PredVarList) > 1:
1148 Type = GetTypeInfo(PredVarList[1:], Result[0], FullFileName, TargetType)
1149 return Type
1150 else:
1151 # Type = GetDataTypeFromModifier(Result[0]).split()[-1]
1152 TypeList = GetDataTypeFromModifier(Result[0]).split()
1153 Type = TypeList[-1]
1154 if len(TypeList) > 1 and StarList != None:
1155 for Star in StarList:
1156 Type = Type.strip()
1157 Type = Type.rstrip(Star)
1158 # Get real type after de-reference pointers.
1159 if len(Type.strip()) == 0:
1160 Type = TypeList[-2]
1161 TypedefDict = GetTypedefDict(FullFileName)
1162 Type = GetRealType(Type, TypedefDict, TargetType)
1163 return Type
1164
1165 # search function parameters second
1166 ParamList = GetParamList(FuncRecord[2])
1167 for Param in ParamList:
1168 if Param.Name.strip() == PredVar:
1169 if len(PredVarList) > 1:
1170 Type = GetTypeInfo(PredVarList[1:], Param.Modifier, FullFileName, TargetType)
1171 return Type
1172 else:
1173 TypeList = GetDataTypeFromModifier(Param.Modifier).split()
1174 Type = TypeList[-1]
1175 if Type == '*' and len(TypeList) >= 2:
1176 Type = TypeList[-2]
1177 if len(TypeList) > 1 and StarList != None:
1178 for Star in StarList:
1179 Type = Type.strip()
1180 Type = Type.rstrip(Star)
1181 # Get real type after de-reference pointers.
1182 if len(Type.strip()) == 0:
1183 Type = TypeList[-2]
1184 TypedefDict = GetTypedefDict(FullFileName)
1185 Type = GetRealType(Type, TypedefDict, TargetType)
1186 return Type
1187
1188 # search global variable next
1189 SqlStatement = """ select Modifier, ID
1190 from %s
1191 where Model = %d and Name = \'%s\' and BelongsToFunction = -1
1192 """ % (FileTable, DataClass.MODEL_IDENTIFIER_VARIABLE, PredVar)
1193 ResultSet = Db.TblFile.Exec(SqlStatement)
1194
1195 for Result in ResultSet:
1196 if len(PredVarList) > 1:
1197 Type = GetTypeInfo(PredVarList[1:], Result[0], FullFileName, TargetType)
1198 return Type
1199 else:
1200 TypeList = GetDataTypeFromModifier(Result[0]).split()
1201 Type = TypeList[-1]
1202 if len(TypeList) > 1 and StarList != None:
1203 for Star in StarList:
1204 Type = Type.strip()
1205 Type = Type.rstrip(Star)
1206 # Get real type after de-reference pointers.
1207 if len(Type.strip()) == 0:
1208 Type = TypeList[-2]
1209 TypedefDict = GetTypedefDict(FullFileName)
1210 Type = GetRealType(Type, TypedefDict, TargetType)
1211 return Type
1212
1213 IncludeFileList = GetAllIncludeFiles(FullFileName)
1214 for F in IncludeFileList:
1215 FileID = GetTableID(F)
1216 if FileID < 0:
1217 continue
1218
1219 FileTable = 'Identifier' + str(FileID)
1220 SqlStatement = """ select Modifier, ID
1221 from %s
1222 where Model = %d and BelongsToFunction = -1 and Name = \'%s\'
1223 """ % (FileTable, DataClass.MODEL_IDENTIFIER_VARIABLE, PredVar)
1224 ResultSet = Db.TblFile.Exec(SqlStatement)
1225
1226 for Result in ResultSet:
1227 if len(PredVarList) > 1:
1228 Type = GetTypeInfo(PredVarList[1:], Result[0], FullFileName, TargetType)
1229 return Type
1230 else:
1231 TypeList = GetDataTypeFromModifier(Result[0]).split()
1232 Type = TypeList[-1]
1233 if len(TypeList) > 1 and StarList != None:
1234 for Star in StarList:
1235 Type = Type.strip()
1236 Type = Type.rstrip(Star)
1237 # Get real type after de-reference pointers.
1238 if len(Type.strip()) == 0:
1239 Type = TypeList[-2]
1240 TypedefDict = GetTypedefDict(FullFileName)
1241 Type = GetRealType(Type, TypedefDict, TargetType)
1242 return Type
1243
1244 def GetTypeFromArray(Type, Var):
1245 Count = Var.count('[')
1246
1247 while Count > 0:
1248 Type = Type.strip()
1249 Type = Type.rstrip('*')
1250 Count = Count - 1
1251
1252 return Type
1253
1254 def CheckFuncLayoutReturnType(FullFileName):
1255 ErrorMsgList = []
1256
1257 FileID = GetTableID(FullFileName, ErrorMsgList)
1258 if FileID < 0:
1259 return ErrorMsgList
1260
1261 Db = GetDB()
1262 FileTable = 'Identifier' + str(FileID)
1263 SqlStatement = """ select Modifier, ID, StartLine, StartColumn, EndLine, Value
1264 from %s
1265 where Model = %d
1266 """ % (FileTable, DataClass.MODEL_IDENTIFIER_FUNCTION_DECLARATION)
1267 ResultSet = Db.TblFile.Exec(SqlStatement)
1268 for Result in ResultSet:
1269 ReturnType = GetDataTypeFromModifier(Result[0])
1270 TypeStart = ReturnType.split()[0]
1271 FuncName = Result[5]
1272 if EccGlobalData.gException.IsException(ERROR_C_FUNCTION_LAYOUT_CHECK_RETURN_TYPE, FuncName):
1273 continue
1274 Index = Result[0].find(TypeStart)
1275 if Index != 0 or Result[3] != 0:
1276 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_RETURN_TYPE, '[%s] Return Type should appear at the start of line' % FuncName, FileTable, Result[1])
1277
1278 if Result[2] == Result[4]:
1279 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_RETURN_TYPE, '[%s] Return Type should appear on its own line' % FuncName, FileTable, Result[1])
1280
1281 SqlStatement = """ select Modifier, ID, StartLine, StartColumn, FunNameStartLine, Name
1282 from Function
1283 where BelongsToFile = %d
1284 """ % (FileID)
1285 ResultSet = Db.TblFile.Exec(SqlStatement)
1286 for Result in ResultSet:
1287 ReturnType = GetDataTypeFromModifier(Result[0])
1288 TypeStart = ReturnType.split()[0]
1289 FuncName = Result[5]
1290 if EccGlobalData.gException.IsException(ERROR_C_FUNCTION_LAYOUT_CHECK_RETURN_TYPE, FuncName):
1291 continue
1292 Result0 = Result[0]
1293 if Result0.upper().startswith('STATIC'):
1294 Result0 = Result0[6:].strip()
1295 Index = Result0.find(ReturnType)
1296 if Index != 0 or Result[3] != 0:
1297 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_RETURN_TYPE, '[%s] Return Type should appear at the start of line' % FuncName, 'Function', Result[1])
1298
1299 def CheckFuncLayoutModifier(FullFileName):
1300 ErrorMsgList = []
1301
1302 FileID = GetTableID(FullFileName, ErrorMsgList)
1303 if FileID < 0:
1304 return ErrorMsgList
1305
1306 Db = GetDB()
1307 FileTable = 'Identifier' + str(FileID)
1308 SqlStatement = """ select Modifier, ID
1309 from %s
1310 where Model = %d
1311 """ % (FileTable, DataClass.MODEL_IDENTIFIER_FUNCTION_DECLARATION)
1312 ResultSet = Db.TblFile.Exec(SqlStatement)
1313 for Result in ResultSet:
1314 ReturnType = GetDataTypeFromModifier(Result[0])
1315 TypeStart = ReturnType.split()[0]
1316 # if len(ReturnType) == 0:
1317 # continue
1318 Index = Result[0].find(TypeStart)
1319 if Index != 0:
1320 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_OPTIONAL_FUNCTIONAL_MODIFIER, '', FileTable, Result[1])
1321
1322 SqlStatement = """ select Modifier, ID
1323 from Function
1324 where BelongsToFile = %d
1325 """ % (FileID)
1326 ResultSet = Db.TblFile.Exec(SqlStatement)
1327 for Result in ResultSet:
1328 ReturnType = GetDataTypeFromModifier(Result[0])
1329 TypeStart = ReturnType.split()[0]
1330 # if len(ReturnType) == 0:
1331 # continue
1332 Result0 = Result[0]
1333 if Result0.upper().startswith('STATIC'):
1334 Result0 = Result0[6:].strip()
1335 Index = Result0.find(TypeStart)
1336 if Index != 0:
1337 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_OPTIONAL_FUNCTIONAL_MODIFIER, '', 'Function', Result[1])
1338
1339 def CheckFuncLayoutName(FullFileName):
1340 ErrorMsgList = []
1341 # Parameter variable format pattern.
1342 Pattern = re.compile(r'^[A-Z]+\S*[a-z]\S*$')
1343 ParamIgnoreList = ('VOID', '...')
1344 FileID = GetTableID(FullFileName, ErrorMsgList)
1345 if FileID < 0:
1346 return ErrorMsgList
1347
1348 Db = GetDB()
1349 FileTable = 'Identifier' + str(FileID)
1350 SqlStatement = """ select Name, ID, EndColumn, Value
1351 from %s
1352 where Model = %d
1353 """ % (FileTable, DataClass.MODEL_IDENTIFIER_FUNCTION_DECLARATION)
1354 ResultSet = Db.TblFile.Exec(SqlStatement)
1355 for Result in ResultSet:
1356 FuncName = Result[3]
1357 if EccGlobalData.gException.IsException(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, FuncName):
1358 continue
1359 if Result[2] != 0:
1360 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, 'Function name [%s] should appear at the start of a line' % FuncName, FileTable, Result[1])
1361 ParamList = GetParamList(Result[0])
1362 if len(ParamList) == 0:
1363 continue
1364 StartLine = 0
1365 for Param in ParamList:
1366 if Param.StartLine <= StartLine:
1367 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, 'Parameter %s should be in its own line.' % Param.Name, FileTable, Result[1])
1368 if Param.StartLine - StartLine > 1:
1369 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, 'Empty line appears before Parameter %s.' % Param.Name, FileTable, Result[1])
1370 if not Pattern.match(Param.Name) and not Param.Name in ParamIgnoreList and not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME, Param.Name):
1371 PrintErrorMsg(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME, 'Parameter [%s] NOT follow naming convention.' % Param.Name, FileTable, Result[1])
1372 StartLine = Param.StartLine
1373
1374 if not Result[0].endswith('\n )') and not Result[0].endswith('\r )'):
1375 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, '\')\' should be on a new line and indented two spaces', FileTable, Result[1])
1376
1377 SqlStatement = """ select Modifier, ID, FunNameStartColumn, Name
1378 from Function
1379 where BelongsToFile = %d
1380 """ % (FileID)
1381 ResultSet = Db.TblFile.Exec(SqlStatement)
1382 for Result in ResultSet:
1383 FuncName = Result[3]
1384 if EccGlobalData.gException.IsException(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, FuncName):
1385 continue
1386 if Result[2] != 0:
1387 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, 'Function name [%s] should appear at the start of a line' % FuncName, 'Function', Result[1])
1388 ParamList = GetParamList(Result[0])
1389 if len(ParamList) == 0:
1390 continue
1391 StartLine = 0
1392 for Param in ParamList:
1393 if Param.StartLine <= StartLine:
1394 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, 'Parameter %s should be in its own line.' % Param.Name, 'Function', Result[1])
1395 if Param.StartLine - StartLine > 1:
1396 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, 'Empty line appears before Parameter %s.' % Param.Name, 'Function', Result[1])
1397 if not Pattern.match(Param.Name) and not Param.Name in ParamIgnoreList and not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME, Param.Name):
1398 PrintErrorMsg(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME, 'Parameter [%s] NOT follow naming convention.' % Param.Name, FileTable, Result[1])
1399 StartLine = Param.StartLine
1400 if not Result[0].endswith('\n )') and not Result[0].endswith('\r )'):
1401 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, '\')\' should be on a new line and indented two spaces', 'Function', Result[1])
1402
1403 def CheckFuncLayoutPrototype(FullFileName):
1404 ErrorMsgList = []
1405
1406 FileID = GetTableID(FullFileName, ErrorMsgList)
1407 if FileID < 0:
1408 return ErrorMsgList
1409
1410 FileTable = 'Identifier' + str(FileID)
1411 Db = GetDB()
1412 SqlStatement = """ select Modifier, Header, Name, ID
1413 from Function
1414 where BelongsToFile = %d
1415 """ % (FileID)
1416 ResultSet = Db.TblFile.Exec(SqlStatement)
1417 if len(ResultSet) == 0:
1418 return ErrorMsgList
1419
1420 FuncDefList = []
1421 for Result in ResultSet:
1422 FuncDefList.append(Result)
1423
1424 SqlStatement = """ select Modifier, Name, ID
1425 from %s
1426 where Model = %d
1427 """ % (FileTable, DataClass.MODEL_IDENTIFIER_FUNCTION_DECLARATION)
1428 ResultSet = Db.TblFile.Exec(SqlStatement)
1429 FuncDeclList = []
1430 for Result in ResultSet:
1431 FuncDeclList.append(Result)
1432
1433 UndeclFuncList = []
1434 for FuncDef in FuncDefList:
1435 FuncName = FuncDef[2].strip()
1436 FuncModifier = FuncDef[0]
1437 FuncDefHeader = FuncDef[1]
1438 for FuncDecl in FuncDeclList:
1439 LBPos = FuncDecl[1].find('(')
1440 DeclName = FuncDecl[1][0:LBPos].strip()
1441 DeclModifier = FuncDecl[0]
1442 if DeclName == FuncName:
1443 if DiffModifier(FuncModifier, DeclModifier) and not EccGlobalData.gException.IsException(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_PROTO_TYPE, FuncName):
1444 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_PROTO_TYPE, 'Function [%s] modifier different with prototype.' % FuncName, 'Function', FuncDef[3])
1445 ParamListOfDef = GetParamList(FuncDefHeader)
1446 ParamListOfDecl = GetParamList(FuncDecl[1])
1447 if len(ParamListOfDef) != len(ParamListOfDecl) and not EccGlobalData.gException.IsException(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_PROTO_TYPE_2, FuncName):
1448 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_PROTO_TYPE_2, 'Parameter number different in function [%s].' % FuncName, 'Function', FuncDef[3])
1449 break
1450
1451 Index = 0
1452 while Index < len(ParamListOfDef):
1453 if DiffModifier(ParamListOfDef[Index].Modifier, ParamListOfDecl[Index].Modifier) and not EccGlobalData.gException.IsException(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_PROTO_TYPE_3, FuncName):
1454 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_PROTO_TYPE_3, 'Parameter %s has different modifier with prototype in function [%s].' % (ParamListOfDef[Index].Name, FuncName), 'Function', FuncDef[3])
1455 Index += 1
1456 break
1457 else:
1458 UndeclFuncList.append(FuncDef)
1459
1460 IncludeFileList = GetAllIncludeFiles(FullFileName)
1461 FuncDeclList = []
1462 for F in IncludeFileList:
1463 FileID = GetTableID(F, ErrorMsgList)
1464 if FileID < 0:
1465 continue
1466
1467 FileTable = 'Identifier' + str(FileID)
1468 SqlStatement = """ select Modifier, Name, ID
1469 from %s
1470 where Model = %d
1471 """ % (FileTable, DataClass.MODEL_IDENTIFIER_FUNCTION_DECLARATION)
1472 ResultSet = Db.TblFile.Exec(SqlStatement)
1473
1474 for Result in ResultSet:
1475 FuncDeclList.append(Result)
1476
1477 for FuncDef in UndeclFuncList:
1478 FuncName = FuncDef[2].strip()
1479 FuncModifier = FuncDef[0]
1480 FuncDefHeader = FuncDef[1]
1481 for FuncDecl in FuncDeclList:
1482 LBPos = FuncDecl[1].find('(')
1483 DeclName = FuncDecl[1][0:LBPos].strip()
1484 DeclModifier = FuncDecl[0]
1485 if DeclName == FuncName:
1486 if DiffModifier(FuncModifier, DeclModifier) and not EccGlobalData.gException.IsException(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_PROTO_TYPE, FuncName):
1487 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_PROTO_TYPE, 'Function [%s] modifier different with prototype.' % FuncName, 'Function', FuncDef[3])
1488 ParamListOfDef = GetParamList(FuncDefHeader)
1489 ParamListOfDecl = GetParamList(FuncDecl[1])
1490 if len(ParamListOfDef) != len(ParamListOfDecl) and not EccGlobalData.gException.IsException(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_PROTO_TYPE_2, FuncName):
1491 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_PROTO_TYPE_2, 'Parameter number different in function [%s].' % FuncName, 'Function', FuncDef[3])
1492 break
1493
1494 Index = 0
1495 while Index < len(ParamListOfDef):
1496 if DiffModifier(ParamListOfDef[Index].Modifier, ParamListOfDecl[Index].Modifier) and not EccGlobalData.gException.IsException(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_PROTO_TYPE_3, FuncName):
1497 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_PROTO_TYPE_3, 'Parameter %s has different modifier with prototype in function [%s].' % (ParamListOfDef[Index].Name, FuncName), 'Function', FuncDef[3])
1498 Index += 1
1499 break
1500
1501 def CheckFuncLayoutBody(FullFileName):
1502 ErrorMsgList = []
1503
1504 FileID = GetTableID(FullFileName, ErrorMsgList)
1505 if FileID < 0:
1506 return ErrorMsgList
1507
1508 FileTable = 'Identifier' + str(FileID)
1509 Db = GetDB()
1510 SqlStatement = """ select BodyStartColumn, EndColumn, ID
1511 from Function
1512 where BelongsToFile = %d
1513 """ % (FileID)
1514 ResultSet = Db.TblFile.Exec(SqlStatement)
1515 if len(ResultSet) == 0:
1516 return ErrorMsgList
1517 for Result in ResultSet:
1518 if Result[0] != 0:
1519 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_BODY, 'open brace should be at the very beginning of a line.', 'Function', Result[2])
1520 if Result[1] != 0:
1521 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_BODY, 'close brace should be at the very beginning of a line.', 'Function', Result[2])
1522
1523 def CheckFuncLayoutLocalVariable(FullFileName):
1524 ErrorMsgList = []
1525
1526 FileID = GetTableID(FullFileName, ErrorMsgList)
1527 if FileID < 0:
1528 return ErrorMsgList
1529
1530 Db = GetDB()
1531 FileTable = 'Identifier' + str(FileID)
1532 SqlStatement = """ select ID
1533 from Function
1534 where BelongsToFile = %d
1535 """ % (FileID)
1536 ResultSet = Db.TblFile.Exec(SqlStatement)
1537 if len(ResultSet) == 0:
1538 return ErrorMsgList
1539 FL = []
1540 for Result in ResultSet:
1541 FL.append(Result)
1542
1543 for F in FL:
1544 SqlStatement = """ select Name, Value, ID, Modifier
1545 from %s
1546 where Model = %d and BelongsToFunction = %d
1547 """ % (FileTable, DataClass.MODEL_IDENTIFIER_VARIABLE, F[0])
1548 ResultSet = Db.TblFile.Exec(SqlStatement)
1549 if len(ResultSet) == 0:
1550 continue
1551
1552 for Result in ResultSet:
1553 if len(Result[1]) > 0 and 'CONST' not in Result[3]:
1554 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_NO_INIT_OF_VARIABLE, 'Variable Name: %s' % Result[0], FileTable, Result[2])
1555
1556 def CheckMemberVariableFormat(Name, Value, FileTable, TdId, ModelId):
1557 ErrMsgList = []
1558 # Member variable format pattern.
1559 Pattern = re.compile(r'^[A-Z]+\S*[a-z]\S*$')
1560
1561 LBPos = Value.find('{')
1562 RBPos = Value.rfind('}')
1563 if LBPos == -1 or RBPos == -1:
1564 return ErrMsgList
1565
1566 Fields = Value[LBPos + 1 : RBPos]
1567 Fields = StripComments(Fields).strip()
1568 NestPos = Fields.find ('struct')
1569 if NestPos != -1 and (NestPos + len('struct') < len(Fields)):
1570 if not Fields[NestPos + len('struct') + 1].isalnum():
1571 if not EccGlobalData.gException.IsException(ERROR_DECLARATION_DATA_TYPE_CHECK_NESTED_STRUCTURE, Name):
1572 PrintErrorMsg(ERROR_DECLARATION_DATA_TYPE_CHECK_NESTED_STRUCTURE, 'Nested struct in [%s].' % (Name), FileTable, TdId)
1573 return ErrMsgList
1574 NestPos = Fields.find ('union')
1575 if NestPos != -1 and (NestPos + len('union') < len(Fields)):
1576 if not Fields[NestPos + len('union') + 1].isalnum():
1577 if not EccGlobalData.gException.IsException(ERROR_DECLARATION_DATA_TYPE_CHECK_NESTED_STRUCTURE, Name):
1578 PrintErrorMsg(ERROR_DECLARATION_DATA_TYPE_CHECK_NESTED_STRUCTURE, 'Nested union in [%s].' % (Name), FileTable, TdId)
1579 return ErrMsgList
1580 NestPos = Fields.find ('enum')
1581 if NestPos != -1 and (NestPos + len('enum') < len(Fields)):
1582 if not Fields[NestPos + len('enum') + 1].isalnum():
1583 if not EccGlobalData.gException.IsException(ERROR_DECLARATION_DATA_TYPE_CHECK_NESTED_STRUCTURE, Name):
1584 PrintErrorMsg(ERROR_DECLARATION_DATA_TYPE_CHECK_NESTED_STRUCTURE, 'Nested enum in [%s].' % (Name), FileTable, TdId)
1585 return ErrMsgList
1586
1587 if ModelId == DataClass.MODEL_IDENTIFIER_ENUMERATE:
1588 FieldsList = Fields.split(',')
1589 # deal with enum is pre-assigned a value by function call ( , , , ...)
1590 QuoteCount = 0
1591 Index = 0
1592 RemoveCurrentElement = False
1593 while Index < len(FieldsList):
1594 Field = FieldsList[Index]
1595
1596 if Field.find('(') != -1:
1597 QuoteCount += 1
1598 RemoveCurrentElement = True
1599 Index += 1
1600 continue
1601
1602 if Field.find(')') != -1 and QuoteCount > 0:
1603 QuoteCount -= 1
1604
1605 if RemoveCurrentElement:
1606 FieldsList.remove(Field)
1607 if QuoteCount == 0:
1608 RemoveCurrentElement = False
1609 continue
1610
1611 if QuoteCount == 0:
1612 RemoveCurrentElement = False
1613
1614 Index += 1
1615 else:
1616 FieldsList = Fields.split(';')
1617
1618 for Field in FieldsList:
1619 Field = Field.strip()
1620 if Field == '':
1621 continue
1622 # For the condition that the field in struct is an array with [] sufixes...
1623 if Field[-1] == ']':
1624 LBPos = Field.find('[')
1625 Field = Field[0:LBPos]
1626 # For the condition that bit field ": Number"
1627 if Field.find(':') != -1:
1628 ColonPos = Field.find(':')
1629 Field = Field[0:ColonPos]
1630
1631 Field = Field.strip()
1632 if Field == '':
1633 continue
1634 # Enum could directly assign value to variable
1635 Field = Field.split('=')[0].strip()
1636 TokenList = Field.split()
1637 # Remove pointers before variable
1638 Token = TokenList[-1]
1639 if Token in ['OPTIONAL']:
1640 Token = TokenList[-2]
1641 if not Pattern.match(Token.lstrip('*')):
1642 ErrMsgList.append(Token.lstrip('*'))
1643
1644 return ErrMsgList
1645
1646 def CheckDeclTypedefFormat(FullFileName, ModelId):
1647 ErrorMsgList = []
1648
1649 FileID = GetTableID(FullFileName, ErrorMsgList)
1650 if FileID < 0:
1651 return ErrorMsgList
1652
1653 Db = GetDB()
1654 FileTable = 'Identifier' + str(FileID)
1655 SqlStatement = """ select Name, StartLine, EndLine, ID, Value
1656 from %s
1657 where Model = %d
1658 """ % (FileTable, ModelId)
1659 ResultSet = Db.TblFile.Exec(SqlStatement)
1660 ResultList = []
1661 for Result in ResultSet:
1662 ResultList.append(Result)
1663
1664 ErrorType = ERROR_DECLARATION_DATA_TYPE_CHECK_ALL
1665 if ModelId == DataClass.MODEL_IDENTIFIER_STRUCTURE:
1666 ErrorType = ERROR_DECLARATION_DATA_TYPE_CHECK_STRUCTURE_DECLARATION
1667 elif ModelId == DataClass.MODEL_IDENTIFIER_ENUMERATE:
1668 ErrorType = ERROR_DECLARATION_DATA_TYPE_CHECK_ENUMERATED_TYPE
1669 elif ModelId == DataClass.MODEL_IDENTIFIER_UNION:
1670 ErrorType = ERROR_DECLARATION_DATA_TYPE_CHECK_UNION_TYPE
1671
1672 SqlStatement = """ select Modifier, Name, Value, StartLine, EndLine, ID
1673 from %s
1674 where Model = %d
1675 """ % (FileTable, DataClass.MODEL_IDENTIFIER_TYPEDEF)
1676 TdSet = Db.TblFile.Exec(SqlStatement)
1677 TdList = []
1678 for Td in TdSet:
1679 TdList.append(Td)
1680 # Check member variable name format that from typedefs of ONLY this file.
1681 for Td in TdList:
1682 Name = Td[1].strip()
1683 Value = Td[2].strip()
1684 if Value.startswith('enum'):
1685 ValueModelId = DataClass.MODEL_IDENTIFIER_ENUMERATE
1686 elif Value.startswith('struct'):
1687 ValueModelId = DataClass.MODEL_IDENTIFIER_STRUCTURE
1688 elif Value.startswith('union'):
1689 ValueModelId = DataClass.MODEL_IDENTIFIER_UNION
1690 else:
1691 continue
1692
1693 if ValueModelId != ModelId:
1694 continue
1695 # Check member variable format.
1696 ErrMsgList = CheckMemberVariableFormat(Name, Value, FileTable, Td[5], ModelId)
1697 for ErrMsg in ErrMsgList:
1698 if EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME, Name + '.' + ErrMsg):
1699 continue
1700 PrintErrorMsg(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME, 'Member variable [%s] NOT follow naming convention.' % (Name + '.' + ErrMsg), FileTable, Td[5])
1701
1702 # First check in current file to see whether struct/union/enum is typedef-ed.
1703 UntypedefedList = []
1704 for Result in ResultList:
1705 # Check member variable format.
1706 Name = Result[0].strip()
1707 Value = Result[4].strip()
1708 if Value.startswith('enum'):
1709 ValueModelId = DataClass.MODEL_IDENTIFIER_ENUMERATE
1710 elif Value.startswith('struct'):
1711 ValueModelId = DataClass.MODEL_IDENTIFIER_STRUCTURE
1712 elif Value.startswith('union'):
1713 ValueModelId = DataClass.MODEL_IDENTIFIER_UNION
1714 else:
1715 continue
1716
1717 if ValueModelId != ModelId:
1718 continue
1719 ErrMsgList = CheckMemberVariableFormat(Name, Value, FileTable, Result[3], ModelId)
1720 for ErrMsg in ErrMsgList:
1721 if EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME, Result[0] + '.' + ErrMsg):
1722 continue
1723 PrintErrorMsg(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME, 'Member variable [%s] NOT follow naming convention.' % (Result[0] + '.' + ErrMsg), FileTable, Result[3])
1724 # Check whether it is typedefed.
1725 Found = False
1726 for Td in TdList:
1727 # skip function pointer
1728 if len(Td[0]) > 0:
1729 continue
1730 if Result[1] >= Td[3] and Td[4] >= Result[2]:
1731 Found = True
1732 if not Td[1].isupper():
1733 PrintErrorMsg(ErrorType, 'Typedef should be UPPER case', FileTable, Td[5])
1734 if Result[0] in Td[2].split():
1735 Found = True
1736 if not Td[1].isupper():
1737 PrintErrorMsg(ErrorType, 'Typedef should be UPPER case', FileTable, Td[5])
1738 if Found:
1739 break
1740
1741 if not Found:
1742 UntypedefedList.append(Result)
1743 continue
1744
1745 if len(UntypedefedList) == 0:
1746 return
1747
1748 IncludeFileList = GetAllIncludeFiles(FullFileName)
1749 TdList = []
1750 for F in IncludeFileList:
1751 FileID = GetTableID(F, ErrorMsgList)
1752 if FileID < 0:
1753 continue
1754
1755 IncludeFileTable = 'Identifier' + str(FileID)
1756 SqlStatement = """ select Modifier, Name, Value, StartLine, EndLine, ID
1757 from %s
1758 where Model = %d
1759 """ % (IncludeFileTable, DataClass.MODEL_IDENTIFIER_TYPEDEF)
1760 ResultSet = Db.TblFile.Exec(SqlStatement)
1761 TdList.extend(ResultSet)
1762
1763 for Result in UntypedefedList:
1764
1765 # Check whether it is typedefed.
1766 Found = False
1767 for Td in TdList:
1768
1769 if len(Td[0]) > 0:
1770 continue
1771 if Result[1] >= Td[3] and Td[4] >= Result[2]:
1772 Found = True
1773 if not Td[1].isupper():
1774 PrintErrorMsg(ErrorType, 'Typedef should be UPPER case', FileTable, Td[5])
1775 if Result[0] in Td[2].split():
1776 Found = True
1777 if not Td[1].isupper():
1778 PrintErrorMsg(ErrorType, 'Typedef should be UPPER case', FileTable, Td[5])
1779 if Found:
1780 break
1781
1782 if not Found:
1783 PrintErrorMsg(ErrorType, 'No Typedef for %s' % Result[0], FileTable, Result[3])
1784 continue
1785
1786 def CheckDeclStructTypedef(FullFileName):
1787 CheckDeclTypedefFormat(FullFileName, DataClass.MODEL_IDENTIFIER_STRUCTURE)
1788
1789 def CheckDeclEnumTypedef(FullFileName):
1790 CheckDeclTypedefFormat(FullFileName, DataClass.MODEL_IDENTIFIER_ENUMERATE)
1791
1792 def CheckDeclUnionTypedef(FullFileName):
1793 CheckDeclTypedefFormat(FullFileName, DataClass.MODEL_IDENTIFIER_UNION)
1794
1795 def CheckDeclArgModifier(FullFileName):
1796 ErrorMsgList = []
1797
1798 FileID = GetTableID(FullFileName, ErrorMsgList)
1799 if FileID < 0:
1800 return ErrorMsgList
1801
1802 Db = GetDB()
1803 FileTable = 'Identifier' + str(FileID)
1804 SqlStatement = """ select Modifier, Name, ID
1805 from %s
1806 where Model = %d
1807 """ % (FileTable, DataClass.MODEL_IDENTIFIER_VARIABLE)
1808 ResultSet = Db.TblFile.Exec(SqlStatement)
1809 ModifierTuple = ('IN', 'OUT', 'OPTIONAL', 'UNALIGNED')
1810 MAX_MODIFIER_LENGTH = 100
1811 for Result in ResultSet:
1812 for Modifier in ModifierTuple:
1813 if PatternInModifier(Result[0], Modifier) and len(Result[0]) < MAX_MODIFIER_LENGTH:
1814 PrintErrorMsg(ERROR_DECLARATION_DATA_TYPE_CHECK_IN_OUT_MODIFIER, 'Variable Modifier %s' % Result[0], FileTable, Result[2])
1815 break
1816
1817 SqlStatement = """ select Modifier, Name, ID
1818 from %s
1819 where Model = %d
1820 """ % (FileTable, DataClass.MODEL_IDENTIFIER_FUNCTION_DECLARATION)
1821 ResultSet = Db.TblFile.Exec(SqlStatement)
1822 for Result in ResultSet:
1823 for Modifier in ModifierTuple:
1824 if PatternInModifier(Result[0], Modifier):
1825 PrintErrorMsg(ERROR_DECLARATION_DATA_TYPE_CHECK_IN_OUT_MODIFIER, 'Return Type Modifier %s' % Result[0], FileTable, Result[2])
1826 break
1827
1828 SqlStatement = """ select Modifier, Header, ID
1829 from Function
1830 where BelongsToFile = %d
1831 """ % (FileID)
1832 ResultSet = Db.TblFile.Exec(SqlStatement)
1833 for Result in ResultSet:
1834 for Modifier in ModifierTuple:
1835 if PatternInModifier(Result[0], Modifier):
1836 PrintErrorMsg(ERROR_DECLARATION_DATA_TYPE_CHECK_IN_OUT_MODIFIER, 'Return Type Modifier %s' % Result[0], FileTable, Result[2])
1837 break
1838
1839 def CheckDeclNoUseCType(FullFileName):
1840 ErrorMsgList = []
1841
1842 FileID = GetTableID(FullFileName, ErrorMsgList)
1843 if FileID < 0:
1844 return ErrorMsgList
1845
1846 Db = GetDB()
1847 FileTable = 'Identifier' + str(FileID)
1848 SqlStatement = """ select Modifier, Name, ID
1849 from %s
1850 where Model = %d
1851 """ % (FileTable, DataClass.MODEL_IDENTIFIER_VARIABLE)
1852 ResultSet = Db.TblFile.Exec(SqlStatement)
1853 CTypeTuple = ('int', 'unsigned', 'char', 'void', 'static', 'long')
1854 for Result in ResultSet:
1855 for Type in CTypeTuple:
1856 if PatternInModifier(Result[0], Type):
1857 PrintErrorMsg(ERROR_DECLARATION_DATA_TYPE_CHECK_NO_USE_C_TYPE, 'Variable type %s' % Type, FileTable, Result[2])
1858 break
1859
1860 SqlStatement = """ select Modifier, Name, ID, Value
1861 from %s
1862 where Model = %d
1863 """ % (FileTable, DataClass.MODEL_IDENTIFIER_FUNCTION_DECLARATION)
1864 ResultSet = Db.TblFile.Exec(SqlStatement)
1865 for Result in ResultSet:
1866 ParamList = GetParamList(Result[1])
1867 FuncName = Result[3]
1868 if EccGlobalData.gException.IsException(ERROR_DECLARATION_DATA_TYPE_CHECK_NO_USE_C_TYPE, FuncName):
1869 continue
1870 for Type in CTypeTuple:
1871 if PatternInModifier(Result[0], Type):
1872 PrintErrorMsg(ERROR_DECLARATION_DATA_TYPE_CHECK_NO_USE_C_TYPE, '%s Return type %s' % (FuncName, Result[0]), FileTable, Result[2])
1873
1874 for Param in ParamList:
1875 if PatternInModifier(Param.Modifier, Type):
1876 PrintErrorMsg(ERROR_DECLARATION_DATA_TYPE_CHECK_NO_USE_C_TYPE, 'Parameter %s' % Param.Name, FileTable, Result[2])
1877
1878 SqlStatement = """ select Modifier, Header, ID, Name
1879 from Function
1880 where BelongsToFile = %d
1881 """ % (FileID)
1882 ResultSet = Db.TblFile.Exec(SqlStatement)
1883 for Result in ResultSet:
1884 ParamList = GetParamList(Result[1])
1885 FuncName = Result[3]
1886 if EccGlobalData.gException.IsException(ERROR_DECLARATION_DATA_TYPE_CHECK_NO_USE_C_TYPE, FuncName):
1887 continue
1888 for Type in CTypeTuple:
1889 if PatternInModifier(Result[0], Type):
1890 PrintErrorMsg(ERROR_DECLARATION_DATA_TYPE_CHECK_NO_USE_C_TYPE, '[%s] Return type %s' % (FuncName, Result[0]), FileTable, Result[2])
1891
1892 for Param in ParamList:
1893 if PatternInModifier(Param.Modifier, Type):
1894 PrintErrorMsg(ERROR_DECLARATION_DATA_TYPE_CHECK_NO_USE_C_TYPE, 'Parameter %s' % Param.Name, FileTable, Result[2])
1895
1896
1897 def CheckPointerNullComparison(FullFileName):
1898 ErrorMsgList = []
1899
1900 FileID = GetTableID(FullFileName, ErrorMsgList)
1901 if FileID < 0:
1902 return ErrorMsgList
1903
1904 # cache the found function return type to accelerate later checking in this file.
1905 FuncReturnTypeDict = {}
1906
1907 Db = GetDB()
1908 FileTable = 'Identifier' + str(FileID)
1909 SqlStatement = """ select Value, StartLine, ID
1910 from %s
1911 where Model = %d
1912 """ % (FileTable, DataClass.MODEL_IDENTIFIER_PREDICATE_EXPRESSION)
1913 ResultSet = Db.TblFile.Exec(SqlStatement)
1914 if len(ResultSet) == 0:
1915 return
1916 PSL = []
1917 for Result in ResultSet:
1918 PSL.append([Result[0], Result[1], Result[2]])
1919
1920 SqlStatement = """ select BodyStartLine, EndLine, Header, Modifier, ID
1921 from Function
1922 where BelongsToFile = %d
1923 """ % (FileID)
1924 ResultSet = Db.TblFile.Exec(SqlStatement)
1925 FL = []
1926 for Result in ResultSet:
1927 FL.append([Result[0], Result[1], Result[2], Result[3], Result[4]])
1928
1929 p = GetFuncDeclPattern()
1930 for Str in PSL:
1931 FuncRecord = GetFuncContainsPE(Str[1], FL)
1932 if FuncRecord == None:
1933 continue
1934
1935 for Exp in GetPredicateListFromPredicateExpStr(Str[0]):
1936 PredInfo = SplitPredicateStr(Exp)
1937 if PredInfo[1] == None:
1938 PredVarStr = PredInfo[0][0].strip()
1939 IsFuncCall = False
1940 SearchInCache = False
1941 # PredVarStr may contain '.' or '->'
1942 TmpStr = PredVarStr.replace('.', '').replace('->', '')
1943 if p.match(TmpStr):
1944 PredVarStr = PredVarStr[0:PredVarStr.find('(')]
1945 SearchInCache = True
1946 # Only direct function call using IsFuncCall branch. Multi-level ref. function call is considered a variable.
1947 if TmpStr.startswith(PredVarStr):
1948 IsFuncCall = True
1949
1950 if PredVarStr.strip() in IgnoredKeywordList:
1951 continue
1952 StarList = []
1953 PredVarList = GetCNameList(PredVarStr, StarList)
1954 # No variable found, maybe value first? like (0 == VarName)
1955 if len(PredVarList) == 0:
1956 continue
1957 if SearchInCache:
1958 Type = FuncReturnTypeDict.get(PredVarStr)
1959 if Type != None:
1960 if Type.find('*') != -1 and Type != 'BOOLEAN*':
1961 PrintErrorMsg(ERROR_PREDICATE_EXPRESSION_CHECK_COMPARISON_NULL_TYPE, 'Predicate Expression: %s' % Exp, FileTable, Str[2])
1962 continue
1963
1964 if PredVarStr in FuncReturnTypeDict:
1965 continue
1966
1967 Type = GetVarInfo(PredVarList, FuncRecord, FullFileName, IsFuncCall, None, StarList)
1968 if SearchInCache:
1969 FuncReturnTypeDict[PredVarStr] = Type
1970 if Type == None:
1971 continue
1972 Type = GetTypeFromArray(Type, PredVarStr)
1973 if Type.find('*') != -1 and Type != 'BOOLEAN*':
1974 PrintErrorMsg(ERROR_PREDICATE_EXPRESSION_CHECK_COMPARISON_NULL_TYPE, 'Predicate Expression: %s' % Exp, FileTable, Str[2])
1975
1976 def CheckNonBooleanValueComparison(FullFileName):
1977 ErrorMsgList = []
1978
1979 FileID = GetTableID(FullFileName, ErrorMsgList)
1980 if FileID < 0:
1981 return ErrorMsgList
1982
1983 # cache the found function return type to accelerate later checking in this file.
1984 FuncReturnTypeDict = {}
1985
1986 Db = GetDB()
1987 FileTable = 'Identifier' + str(FileID)
1988 SqlStatement = """ select Value, StartLine, ID
1989 from %s
1990 where Model = %d
1991 """ % (FileTable, DataClass.MODEL_IDENTIFIER_PREDICATE_EXPRESSION)
1992 ResultSet = Db.TblFile.Exec(SqlStatement)
1993 if len(ResultSet) == 0:
1994 return
1995 PSL = []
1996 for Result in ResultSet:
1997 PSL.append([Result[0], Result[1], Result[2]])
1998
1999 SqlStatement = """ select BodyStartLine, EndLine, Header, Modifier, ID
2000 from Function
2001 where BelongsToFile = %d
2002 """ % (FileID)
2003 ResultSet = Db.TblFile.Exec(SqlStatement)
2004 FL = []
2005 for Result in ResultSet:
2006 FL.append([Result[0], Result[1], Result[2], Result[3], Result[4]])
2007
2008 p = GetFuncDeclPattern()
2009 for Str in PSL:
2010 FuncRecord = GetFuncContainsPE(Str[1], FL)
2011 if FuncRecord == None:
2012 continue
2013
2014 for Exp in GetPredicateListFromPredicateExpStr(Str[0]):
2015 PredInfo = SplitPredicateStr(Exp)
2016 if PredInfo[1] == None:
2017 PredVarStr = PredInfo[0][0].strip()
2018 IsFuncCall = False
2019 SearchInCache = False
2020 # PredVarStr may contain '.' or '->'
2021 TmpStr = PredVarStr.replace('.', '').replace('->', '')
2022 if p.match(TmpStr):
2023 PredVarStr = PredVarStr[0:PredVarStr.find('(')]
2024 SearchInCache = True
2025 # Only direct function call using IsFuncCall branch. Multi-level ref. function call is considered a variable.
2026 if TmpStr.startswith(PredVarStr):
2027 IsFuncCall = True
2028
2029 if PredVarStr.strip() in IgnoredKeywordList:
2030 continue
2031 StarList = []
2032 PredVarList = GetCNameList(PredVarStr, StarList)
2033 # No variable found, maybe value first? like (0 == VarName)
2034 if len(PredVarList) == 0:
2035 continue
2036
2037 if SearchInCache:
2038 Type = FuncReturnTypeDict.get(PredVarStr)
2039 if Type != None:
2040 if Type.find('BOOLEAN') == -1:
2041 PrintErrorMsg(ERROR_PREDICATE_EXPRESSION_CHECK_NO_BOOLEAN_OPERATOR, 'Predicate Expression: %s' % Exp, FileTable, Str[2])
2042 continue
2043
2044 if PredVarStr in FuncReturnTypeDict:
2045 continue
2046 Type = GetVarInfo(PredVarList, FuncRecord, FullFileName, IsFuncCall, 'BOOLEAN', StarList)
2047 if SearchInCache:
2048 FuncReturnTypeDict[PredVarStr] = Type
2049 if Type == None:
2050 continue
2051 if Type.find('BOOLEAN') == -1:
2052 PrintErrorMsg(ERROR_PREDICATE_EXPRESSION_CHECK_NO_BOOLEAN_OPERATOR, 'Predicate Expression: %s' % Exp, FileTable, Str[2])
2053
2054
2055 def CheckBooleanValueComparison(FullFileName):
2056 ErrorMsgList = []
2057
2058 FileID = GetTableID(FullFileName, ErrorMsgList)
2059 if FileID < 0:
2060 return ErrorMsgList
2061
2062 # cache the found function return type to accelerate later checking in this file.
2063 FuncReturnTypeDict = {}
2064
2065 Db = GetDB()
2066 FileTable = 'Identifier' + str(FileID)
2067 SqlStatement = """ select Value, StartLine, ID
2068 from %s
2069 where Model = %d
2070 """ % (FileTable, DataClass.MODEL_IDENTIFIER_PREDICATE_EXPRESSION)
2071 ResultSet = Db.TblFile.Exec(SqlStatement)
2072 if len(ResultSet) == 0:
2073 return
2074 PSL = []
2075 for Result in ResultSet:
2076 PSL.append([Result[0], Result[1], Result[2]])
2077
2078 SqlStatement = """ select BodyStartLine, EndLine, Header, Modifier, ID
2079 from Function
2080 where BelongsToFile = %d
2081 """ % (FileID)
2082 ResultSet = Db.TblFile.Exec(SqlStatement)
2083 FL = []
2084 for Result in ResultSet:
2085 FL.append([Result[0], Result[1], Result[2], Result[3], Result[4]])
2086
2087 p = GetFuncDeclPattern()
2088 for Str in PSL:
2089 FuncRecord = GetFuncContainsPE(Str[1], FL)
2090 if FuncRecord == None:
2091 continue
2092
2093 for Exp in GetPredicateListFromPredicateExpStr(Str[0]):
2094 PredInfo = SplitPredicateStr(Exp)
2095 if PredInfo[1] in ('==', '!=') and PredInfo[0][1] in ('TRUE', 'FALSE'):
2096 PredVarStr = PredInfo[0][0].strip()
2097 IsFuncCall = False
2098 SearchInCache = False
2099 # PredVarStr may contain '.' or '->'
2100 TmpStr = PredVarStr.replace('.', '').replace('->', '')
2101 if p.match(TmpStr):
2102 PredVarStr = PredVarStr[0:PredVarStr.find('(')]
2103 SearchInCache = True
2104 # Only direct function call using IsFuncCall branch. Multi-level ref. function call is considered a variable.
2105 if TmpStr.startswith(PredVarStr):
2106 IsFuncCall = True
2107
2108 if PredVarStr.strip() in IgnoredKeywordList:
2109 continue
2110 StarList = []
2111 PredVarList = GetCNameList(PredVarStr, StarList)
2112 # No variable found, maybe value first? like (0 == VarName)
2113 if len(PredVarList) == 0:
2114 continue
2115
2116 if SearchInCache:
2117 Type = FuncReturnTypeDict.get(PredVarStr)
2118 if Type != None:
2119 if Type.find('BOOLEAN') != -1:
2120 PrintErrorMsg(ERROR_PREDICATE_EXPRESSION_CHECK_BOOLEAN_VALUE, 'Predicate Expression: %s' % Exp, FileTable, Str[2])
2121 continue
2122
2123 if PredVarStr in FuncReturnTypeDict:
2124 continue
2125
2126 Type = GetVarInfo(PredVarList, FuncRecord, FullFileName, IsFuncCall, 'BOOLEAN', StarList)
2127 if SearchInCache:
2128 FuncReturnTypeDict[PredVarStr] = Type
2129 if Type == None:
2130 continue
2131 if Type.find('BOOLEAN') != -1:
2132 PrintErrorMsg(ERROR_PREDICATE_EXPRESSION_CHECK_BOOLEAN_VALUE, 'Predicate Expression: %s' % Exp, FileTable, Str[2])
2133
2134
2135 def CheckHeaderFileData(FullFileName):
2136 ErrorMsgList = []
2137
2138 FileID = GetTableID(FullFileName, ErrorMsgList)
2139 if FileID < 0:
2140 return ErrorMsgList
2141
2142 Db = GetDB()
2143 FileTable = 'Identifier' + str(FileID)
2144 SqlStatement = """ select ID, Modifier
2145 from %s
2146 where Model = %d
2147 """ % (FileTable, DataClass.MODEL_IDENTIFIER_VARIABLE)
2148 ResultSet = Db.TblFile.Exec(SqlStatement)
2149 for Result in ResultSet:
2150 if not Result[1].startswith('extern'):
2151 PrintErrorMsg(ERROR_INCLUDE_FILE_CHECK_DATA, 'Variable definition appears in header file', FileTable, Result[0])
2152
2153 SqlStatement = """ select ID
2154 from Function
2155 where BelongsToFile = %d
2156 """ % FileID
2157 ResultSet = Db.TblFile.Exec(SqlStatement)
2158 for Result in ResultSet:
2159 PrintErrorMsg(ERROR_INCLUDE_FILE_CHECK_DATA, 'Function definition appears in header file', 'Function', Result[0])
2160
2161 return ErrorMsgList
2162
2163 def CheckHeaderFileIfndef(FullFileName):
2164 ErrorMsgList = []
2165
2166 FileID = GetTableID(FullFileName, ErrorMsgList)
2167 if FileID < 0:
2168 return ErrorMsgList
2169
2170 Db = GetDB()
2171 FileTable = 'Identifier' + str(FileID)
2172 SqlStatement = """ select Value, StartLine
2173 from %s
2174 where Model = %d order by StartLine
2175 """ % (FileTable, DataClass.MODEL_IDENTIFIER_MACRO_IFNDEF)
2176 ResultSet = Db.TblFile.Exec(SqlStatement)
2177 if len(ResultSet) == 0:
2178 PrintErrorMsg(ERROR_INCLUDE_FILE_CHECK_IFNDEF_STATEMENT_1, '', 'File', FileID)
2179 return ErrorMsgList
2180 for Result in ResultSet:
2181 SqlStatement = """ select Value, EndLine
2182 from %s
2183 where EndLine < %d
2184 """ % (FileTable, Result[1])
2185 ResultSet = Db.TblFile.Exec(SqlStatement)
2186 for Result in ResultSet:
2187 if not Result[0].startswith('/*') and not Result[0].startswith('//'):
2188 PrintErrorMsg(ERROR_INCLUDE_FILE_CHECK_IFNDEF_STATEMENT_2, '', 'File', FileID)
2189 break
2190
2191 SqlStatement = """ select Value
2192 from %s
2193 where StartLine > (select max(EndLine) from %s where Model = %d)
2194 """ % (FileTable, FileTable, DataClass.MODEL_IDENTIFIER_MACRO_ENDIF)
2195 ResultSet = Db.TblFile.Exec(SqlStatement)
2196 for Result in ResultSet:
2197 if not Result[0].startswith('/*') and not Result[0].startswith('//'):
2198 PrintErrorMsg(ERROR_INCLUDE_FILE_CHECK_IFNDEF_STATEMENT_3, '', 'File', FileID)
2199 return ErrorMsgList
2200
2201 def CheckDoxygenCommand(FullFileName):
2202 ErrorMsgList = []
2203
2204 FileID = GetTableID(FullFileName, ErrorMsgList)
2205 if FileID < 0:
2206 return ErrorMsgList
2207
2208 Db = GetDB()
2209 FileTable = 'Identifier' + str(FileID)
2210 SqlStatement = """ select Value, ID
2211 from %s
2212 where Model = %d or Model = %d
2213 """ % (FileTable, DataClass.MODEL_IDENTIFIER_COMMENT, DataClass.MODEL_IDENTIFIER_FUNCTION_HEADER)
2214 ResultSet = Db.TblFile.Exec(SqlStatement)
2215 DoxygenCommandList = ['bug', 'todo', 'example', 'file', 'attention', 'param', 'post', 'pre', 'retval', 'return', 'sa', 'since', 'test', 'note', 'par']
2216 for Result in ResultSet:
2217 CommentStr = Result[0]
2218 CommentPartList = CommentStr.split()
2219 for Part in CommentPartList:
2220 if Part.upper() == 'BUGBUG':
2221 PrintErrorMsg(ERROR_DOXYGEN_CHECK_COMMAND, 'Bug should be marked with doxygen tag @bug', FileTable, Result[1])
2222 if Part.upper() == 'TODO':
2223 PrintErrorMsg(ERROR_DOXYGEN_CHECK_COMMAND, 'ToDo should be marked with doxygen tag @todo', FileTable, Result[1])
2224 if Part.startswith('@'):
2225 if EccGlobalData.gException.IsException(ERROR_DOXYGEN_CHECK_COMMAND, Part):
2226 continue
2227 if Part.lstrip('@').isalpha():
2228 if Part.lstrip('@') not in DoxygenCommandList:
2229 PrintErrorMsg(ERROR_DOXYGEN_CHECK_COMMAND, 'Unknown doxygen command %s' % Part, FileTable, Result[1])
2230 else:
2231 Index = Part.find('[')
2232 if Index == -1:
2233 PrintErrorMsg(ERROR_DOXYGEN_CHECK_COMMAND, 'Unknown doxygen command %s' % Part, FileTable, Result[1])
2234 RealCmd = Part[1:Index]
2235 if RealCmd not in DoxygenCommandList:
2236 PrintErrorMsg(ERROR_DOXYGEN_CHECK_COMMAND, 'Unknown doxygen command %s' % Part, FileTable, Result[1])
2237
2238
2239 def CheckDoxygenTripleForwardSlash(FullFileName):
2240 ErrorMsgList = []
2241
2242 FileID = GetTableID(FullFileName, ErrorMsgList)
2243 if FileID < 0:
2244 return ErrorMsgList
2245
2246 Db = GetDB()
2247
2248 SqlStatement = """ select ID, BodyStartLine, BodyStartColumn, EndLine, EndColumn
2249 from Function
2250 where BelongsToFile = %d
2251 """ % (FileID)
2252 ResultSet = Db.TblFile.Exec(SqlStatement)
2253 if len(ResultSet) == 0:
2254 return
2255
2256 FuncDefSet = []
2257 for Result in ResultSet:
2258 FuncDefSet.append(Result)
2259
2260
2261 FileTable = 'Identifier' + str(FileID)
2262 SqlStatement = """ select Value, ID, StartLine, StartColumn, EndLine, EndColumn
2263 from %s
2264 where Model = %d
2265
2266 """ % (FileTable, DataClass.MODEL_IDENTIFIER_COMMENT)
2267 ResultSet = Db.TblFile.Exec(SqlStatement)
2268 CommentSet = []
2269 try:
2270 for Result in ResultSet:
2271 CommentSet.append(Result)
2272 except:
2273 print 'Unrecognized chars in comment of file %s', FullFileName
2274
2275
2276 for Result in CommentSet:
2277 CommentStr = Result[0]
2278 StartLine = Result[2]
2279 StartColumn = Result[3]
2280 EndLine = Result[4]
2281 EndColumn = Result[5]
2282 if not CommentStr.startswith('///<'):
2283 continue
2284
2285 Found = False
2286 for FuncDef in FuncDefSet:
2287 if StartLine == FuncDef[1] and StartColumn > FuncDef[2] and EndLine == FuncDef[3] and EndColumn < FuncDef[4]:
2288 Found = True
2289 break
2290 if StartLine > FuncDef[1] and EndLine < FuncDef[3]:
2291 Found = True
2292 break
2293 if StartLine == FuncDef[1] and StartColumn > FuncDef[2] and EndLine < FuncDef[3]:
2294 Found = True
2295 break
2296 if StartLine > FuncDef[1] and EndLine == FuncDef[3] and EndColumn < FuncDef[4]:
2297 Found = True
2298 break
2299 if Found:
2300 PrintErrorMsg(ERROR_DOXYGEN_CHECK_COMMENT_FORMAT, '', FileTable, Result[1])
2301
2302
2303 def CheckFileHeaderDoxygenComments(FullFileName):
2304 ErrorMsgList = []
2305
2306 FileID = GetTableID(FullFileName, ErrorMsgList)
2307 if FileID < 0:
2308 return ErrorMsgList
2309
2310 Db = GetDB()
2311 FileTable = 'Identifier' + str(FileID)
2312 SqlStatement = """ select Value, ID
2313 from %s
2314 where Model = %d and (StartLine = 1 or StartLine = 7 or StartLine = 8) and StartColumn = 0
2315 """ % (FileTable, DataClass.MODEL_IDENTIFIER_COMMENT)
2316 ResultSet = Db.TblFile.Exec(SqlStatement)
2317 if len(ResultSet) == 0:
2318 PrintErrorMsg(ERROR_HEADER_CHECK_FILE, 'No File License header appear at the very beginning of file.', 'File', FileID)
2319 return ErrorMsgList
2320
2321 NoHeaderCommentStartFlag = True
2322 NoHeaderCommentEndFlag = True
2323 NoHeaderCommentPeriodFlag = True
2324 NoCopyrightFlag = True
2325 NoLicenseFlag = True
2326 NoRevReferFlag = True
2327 NextLineIndex = 0
2328 for Result in ResultSet:
2329 FileStartFlag = False
2330 CommentStrList = []
2331 CommentStr = Result[0].strip()
2332 CommentStrListTemp = CommentStr.split('\n')
2333 if (len(CommentStrListTemp) <= 1):
2334 # For Mac
2335 CommentStrListTemp = CommentStr.split('\r')
2336 # Skip the content before the file header
2337 for CommentLine in CommentStrListTemp:
2338 if CommentLine.strip().startswith('/** @file'):
2339 FileStartFlag = True
2340 if FileStartFlag == True:
2341 CommentStrList.append(CommentLine)
2342
2343 ID = Result[1]
2344 Index = 0
2345 if CommentStrList and CommentStrList[0].strip().startswith('/** @file'):
2346 NoHeaderCommentStartFlag = False
2347 else:
2348 continue
2349 if CommentStrList and CommentStrList[-1].strip().endswith('**/'):
2350 NoHeaderCommentEndFlag = False
2351 else:
2352 continue
2353
2354 for CommentLine in CommentStrList:
2355 Index = Index + 1
2356 NextLineIndex = Index
2357 if CommentLine.startswith('/** @file'):
2358 continue
2359 if CommentLine.startswith('**/'):
2360 break
2361 # Check whether C File header Comment content start with two spaces.
2362 if EccGlobalData.gConfig.HeaderCheckCFileCommentStartSpacesNum == '1' or EccGlobalData.gConfig.HeaderCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':
2363 if CommentLine.startswith('/** @file') == False and CommentLine.startswith('**/') == False and CommentLine.strip() and CommentLine.startswith(' ') == False:
2364 PrintErrorMsg(ERROR_HEADER_CHECK_FILE, 'File header comment content should start with two spaces at each line', FileTable, ID)
2365
2366 CommentLine = CommentLine.strip()
2367 if CommentLine.startswith('Copyright'):
2368 NoCopyrightFlag = False
2369 if CommentLine.find('All rights reserved') == -1:
2370 for Copyright in EccGlobalData.gConfig.Copyright:
2371 if CommentLine.find(Copyright) > -1:
2372 PrintErrorMsg(ERROR_HEADER_CHECK_FILE, '""All rights reserved"" announcement should be following the ""Copyright"" at the same line', FileTable, ID)
2373 break
2374 if CommentLine.endswith('<BR>') == -1:
2375 PrintErrorMsg(ERROR_HEADER_CHECK_FILE, 'The ""<BR>"" at the end of the Copyright line is required', FileTable, ID)
2376 if NextLineIndex < len(CommentStrList) and CommentStrList[NextLineIndex].strip().startswith('Copyright') == False and CommentStrList[NextLineIndex].strip():
2377 NoLicenseFlag = False
2378 if CommentLine.startswith('@par Revision Reference:'):
2379 NoRevReferFlag = False
2380 RefListFlag = False
2381 for RefLine in CommentStrList[NextLineIndex:]:
2382 if RefLine.strip() and (NextLineIndex + 1) < len(CommentStrList) and CommentStrList[NextLineIndex+1].strip() and CommentStrList[NextLineIndex+1].strip().startswith('**/') == False:
2383 RefListFlag = True
2384 if RefLine.strip() == False or RefLine.strip().startswith('**/'):
2385 RefListFlag = False
2386 break
2387 # Check whether C File header Comment's each reference at list should begin with a bullet character.
2388 if EccGlobalData.gConfig.HeaderCheckCFileCommentReferenceFormat == '1' or EccGlobalData.gConfig.HeaderCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':
2389 if RefListFlag == True:
2390 if RefLine.strip() and RefLine.strip().startswith('**/') == False and RefLine.startswith(' -') == False:
2391 PrintErrorMsg(ERROR_HEADER_CHECK_FILE, 'Each reference on a separate line should begin with a bullet character ""-"" ', FileTable, ID)
2392
2393 if NoHeaderCommentStartFlag:
2394 PrintErrorMsg(ERROR_DOXYGEN_CHECK_FILE_HEADER, 'File header comment should begin with ""/** @file""', FileTable, ID)
2395 return
2396 if NoHeaderCommentEndFlag:
2397 PrintErrorMsg(ERROR_HEADER_CHECK_FILE, 'File header comment should end with ""**/""', FileTable, ID)
2398 return
2399 if NoCopyrightFlag:
2400 PrintErrorMsg(ERROR_HEADER_CHECK_FILE, 'File header comment missing the ""Copyright""', FileTable, ID)
2401 #Check whether C File header Comment have the License immediately after the ""Copyright"" line.
2402 if EccGlobalData.gConfig.HeaderCheckCFileCommentLicenseFormat == '1' or EccGlobalData.gConfig.HeaderCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':
2403 if NoLicenseFlag:
2404 PrintErrorMsg(ERROR_HEADER_CHECK_FILE, 'File header comment should have the License immediately after the ""Copyright"" line', FileTable, ID)
2405
2406 def CheckFuncHeaderDoxygenComments(FullFileName):
2407 ErrorMsgList = []
2408
2409 FileID = GetTableID(FullFileName, ErrorMsgList)
2410 if FileID < 0:
2411 return ErrorMsgList
2412
2413 Db = GetDB()
2414 FileTable = 'Identifier' + str(FileID)
2415 SqlStatement = """ select Value, StartLine, EndLine, ID
2416 from %s
2417 where Model = %d
2418 """ % (FileTable, DataClass.MODEL_IDENTIFIER_COMMENT)
2419
2420 ResultSet = Db.TblFile.Exec(SqlStatement)
2421 CommentSet = []
2422 try:
2423 for Result in ResultSet:
2424 CommentSet.append(Result)
2425 except:
2426 print 'Unrecognized chars in comment of file %s', FullFileName
2427
2428 # Func Decl check
2429 SqlStatement = """ select Modifier, Name, StartLine, ID, Value
2430 from %s
2431 where Model = %d
2432 """ % (FileTable, DataClass.MODEL_IDENTIFIER_FUNCTION_DECLARATION)
2433 ResultSet = Db.TblFile.Exec(SqlStatement)
2434 for Result in ResultSet:
2435 FuncName = Result[4]
2436 FunctionHeaderComment = CheckCommentImmediatelyPrecedeFunctionHeader(Result[1], Result[2], CommentSet)
2437 if FunctionHeaderComment:
2438 CheckFunctionHeaderConsistentWithDoxygenComment(Result[0], Result[1], Result[2], FunctionHeaderComment[0], FunctionHeaderComment[1], ErrorMsgList, FunctionHeaderComment[3], FileTable)
2439 else:
2440 if EccGlobalData.gException.IsException(ERROR_HEADER_CHECK_FUNCTION, FuncName):
2441 continue
2442 ErrorMsgList.append('Line %d :Function %s has NO comment immediately preceding it.' % (Result[2], Result[1]))
2443 PrintErrorMsg(ERROR_HEADER_CHECK_FUNCTION, 'Function [%s] has NO comment immediately preceding it.' % (FuncName), FileTable, Result[3])
2444
2445 # Func Def check
2446 SqlStatement = """ select Value, StartLine, EndLine, ID
2447 from %s
2448 where Model = %d
2449 """ % (FileTable, DataClass.MODEL_IDENTIFIER_FUNCTION_HEADER)
2450
2451 ResultSet = Db.TblFile.Exec(SqlStatement)
2452 CommentSet = []
2453 try:
2454 for Result in ResultSet:
2455 CommentSet.append(Result)
2456 except:
2457 print 'Unrecognized chars in comment of file %s', FullFileName
2458
2459 SqlStatement = """ select Modifier, Header, StartLine, ID, Name
2460 from Function
2461 where BelongsToFile = %d
2462 """ % (FileID)
2463 ResultSet = Db.TblFile.Exec(SqlStatement)
2464 for Result in ResultSet:
2465 FuncName = Result[4]
2466 FunctionHeaderComment = CheckCommentImmediatelyPrecedeFunctionHeader(Result[1], Result[2], CommentSet)
2467 if FunctionHeaderComment:
2468 CheckFunctionHeaderConsistentWithDoxygenComment(Result[0], Result[1], Result[2], FunctionHeaderComment[0], FunctionHeaderComment[1], ErrorMsgList, FunctionHeaderComment[3], FileTable)
2469 else:
2470 if EccGlobalData.gException.IsException(ERROR_HEADER_CHECK_FUNCTION, FuncName):
2471 continue
2472 ErrorMsgList.append('Line %d :Function [%s] has NO comment immediately preceding it.' % (Result[2], Result[1]))
2473 PrintErrorMsg(ERROR_HEADER_CHECK_FUNCTION, 'Function [%s] has NO comment immediately preceding it.' % (FuncName), 'Function', Result[3])
2474 return ErrorMsgList
2475
2476 def CheckCommentImmediatelyPrecedeFunctionHeader(FuncName, FuncStartLine, CommentSet):
2477
2478 for Comment in CommentSet:
2479 if Comment[2] == FuncStartLine - 1:
2480 return Comment
2481 return None
2482
2483 def GetDoxygenStrFromComment(Str):
2484 DoxygenStrList = []
2485 ParamTagList = Str.split('@param')
2486 if len(ParamTagList) > 1:
2487 i = 1
2488 while i < len(ParamTagList):
2489 DoxygenStrList.append('@param' + ParamTagList[i])
2490 i += 1
2491
2492 Str = ParamTagList[0]
2493
2494 RetvalTagList = ParamTagList[-1].split('@retval')
2495 if len(RetvalTagList) > 1:
2496 if len(ParamTagList) > 1:
2497 DoxygenStrList[-1] = '@param' + RetvalTagList[0]
2498 i = 1
2499 while i < len(RetvalTagList):
2500 DoxygenStrList.append('@retval' + RetvalTagList[i])
2501 i += 1
2502
2503 ReturnTagList = RetvalTagList[-1].split('@return')
2504 if len(ReturnTagList) > 1:
2505 if len(RetvalTagList) > 1:
2506 DoxygenStrList[-1] = '@retval' + ReturnTagList[0]
2507 elif len(ParamTagList) > 1:
2508 DoxygenStrList[-1] = '@param' + ReturnTagList[0]
2509 i = 1
2510 while i < len(ReturnTagList):
2511 DoxygenStrList.append('@return' + ReturnTagList[i])
2512 i += 1
2513
2514 if len(DoxygenStrList) > 0:
2515 DoxygenStrList[-1] = DoxygenStrList[-1].rstrip('--*/')
2516
2517 return DoxygenStrList
2518
2519 def CheckGeneralDoxygenCommentLayout(Str, StartLine, ErrorMsgList, CommentId= -1, TableName=''):
2520 #/** --*/ @retval after @param
2521 if not Str.startswith('/**'):
2522 ErrorMsgList.append('Line %d : Comment does NOT have prefix /** ' % StartLine)
2523 PrintErrorMsg(ERROR_DOXYGEN_CHECK_FUNCTION_HEADER, 'Comment does NOT have prefix /** ', TableName, CommentId)
2524 if not Str.endswith('**/'):
2525 ErrorMsgList.append('Line %d : Comment does NOT have tail **/ ' % StartLine)
2526 PrintErrorMsg(ERROR_DOXYGEN_CHECK_FUNCTION_HEADER, 'Comment does NOT have tail **/ ', TableName, CommentId)
2527 FirstRetvalIndex = Str.find('@retval')
2528 LastParamIndex = Str.rfind('@param')
2529 if (FirstRetvalIndex > 0) and (LastParamIndex > 0) and (FirstRetvalIndex < LastParamIndex):
2530 ErrorMsgList.append('Line %d : @retval appear before @param ' % StartLine)
2531 PrintErrorMsg(ERROR_DOXYGEN_CHECK_FUNCTION_HEADER, 'in Comment, @retval appear before @param ', TableName, CommentId)
2532
2533 def CheckFunctionHeaderConsistentWithDoxygenComment(FuncModifier, FuncHeader, FuncStartLine, CommentStr, CommentStartLine, ErrorMsgList, CommentId= -1, TableName=''):
2534
2535 ParamList = GetParamList(FuncHeader)
2536 CheckGeneralDoxygenCommentLayout(CommentStr, CommentStartLine, ErrorMsgList, CommentId, TableName)
2537 DescriptionStr = CommentStr
2538 DoxygenStrList = GetDoxygenStrFromComment(DescriptionStr)
2539 if DescriptionStr.find('.') == -1:
2540 PrintErrorMsg(ERROR_DOXYGEN_CHECK_COMMENT_DESCRIPTION, 'Comment description should end with period \'.\'', TableName, CommentId)
2541 DoxygenTagNumber = len(DoxygenStrList)
2542 ParamNumber = len(ParamList)
2543 for Param in ParamList:
2544 if Param.Name.upper() == 'VOID' and ParamNumber == 1:
2545 ParamNumber -= 1
2546 Index = 0
2547 if ParamNumber > 0 and DoxygenTagNumber > 0:
2548 while Index < ParamNumber and Index < DoxygenTagNumber:
2549 ParamModifier = ParamList[Index].Modifier
2550 ParamName = ParamList[Index].Name.strip()
2551 Tag = DoxygenStrList[Index].strip(' ')
2552 if (not Tag[-1] == ('\n')) and (not Tag[-1] == ('\r')):
2553 ErrorMsgList.append('Line %d : in Comment, <%s> does NOT end with new line ' % (CommentStartLine, Tag.replace('\n', '').replace('\r', '')))
2554 PrintErrorMsg(ERROR_HEADER_CHECK_FUNCTION, 'in Comment, <%s> does NOT end with new line ' % (Tag.replace('\n', '').replace('\r', '')), TableName, CommentId)
2555 TagPartList = Tag.split()
2556 if len(TagPartList) < 2:
2557 ErrorMsgList.append('Line %d : in Comment, <%s> does NOT contain doxygen contents ' % (CommentStartLine, Tag.replace('\n', '').replace('\r', '')))
2558 PrintErrorMsg(ERROR_DOXYGEN_CHECK_FUNCTION_HEADER, 'in Comment, <%s> does NOT contain doxygen contents ' % (Tag.replace('\n', '').replace('\r', '')), TableName, CommentId)
2559 Index += 1
2560 continue
2561 LBPos = Tag.find('[')
2562 RBPos = Tag.find(']')
2563 ParamToLBContent = Tag[len('@param'):LBPos].strip()
2564 if LBPos > 0 and len(ParamToLBContent) == 0 and RBPos > LBPos:
2565 InOutStr = ''
2566 ModifierPartList = ParamModifier.split()
2567 for Part in ModifierPartList:
2568 if Part.strip() == 'IN':
2569 InOutStr += 'in'
2570 if Part.strip() == 'OUT':
2571 if InOutStr != '':
2572 InOutStr += ', out'
2573 else:
2574 InOutStr = 'out'
2575
2576 if InOutStr != '':
2577 if Tag.find('[' + InOutStr + ']') == -1:
2578 if InOutStr != 'in, out':
2579 ErrorMsgList.append('Line %d : in Comment, <%s> does NOT have %s ' % (CommentStartLine, (TagPartList[0] + ' ' + TagPartList[1]).replace('\n', '').replace('\r', ''), '[' + InOutStr + ']'))
2580 PrintErrorMsg(ERROR_DOXYGEN_CHECK_FUNCTION_HEADER, 'in Comment, <%s> does NOT have %s ' % ((TagPartList[0] + ' ' + TagPartList[1]).replace('\n', '').replace('\r', ''), '[' + InOutStr + ']'), TableName, CommentId)
2581 else:
2582 if Tag.find('[in,out]') == -1:
2583 ErrorMsgList.append('Line %d : in Comment, <%s> does NOT have %s ' % (CommentStartLine, (TagPartList[0] + ' ' + TagPartList[1]).replace('\n', '').replace('\r', ''), '[' + InOutStr + ']'))
2584 PrintErrorMsg(ERROR_DOXYGEN_CHECK_FUNCTION_HEADER, 'in Comment, <%s> does NOT have %s ' % ((TagPartList[0] + ' ' + TagPartList[1]).replace('\n', '').replace('\r', ''), '[' + InOutStr + ']'), TableName, CommentId)
2585
2586
2587 if Tag.find(ParamName) == -1 and ParamName != 'VOID' and ParamName != 'void':
2588 ErrorMsgList.append('Line %d : in Comment, <%s> does NOT consistent with parameter name %s ' % (CommentStartLine, (TagPartList[0] + ' ' + TagPartList[1]).replace('\n', '').replace('\r', ''), ParamName))
2589 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)
2590 Index += 1
2591
2592 if Index < ParamNumber:
2593 ErrorMsgList.append('Line %d : Number of doxygen tags in comment less than number of function parameters' % CommentStartLine)
2594 PrintErrorMsg(ERROR_DOXYGEN_CHECK_FUNCTION_HEADER, 'Number of doxygen tags in comment less than number of function parameters ', TableName, CommentId)
2595 # VOID return type, NOT VOID*. VOID* should be matched with a doxygen tag.
2596 if (FuncModifier.find('VOID') != -1 or FuncModifier.find('void') != -1) and FuncModifier.find('*') == -1:
2597
2598 # assume we allow a return description tag for void func. return. that's why 'DoxygenTagNumber - 1' is used instead of 'DoxygenTagNumber'
2599 if Index < DoxygenTagNumber - 1 or (Index < DoxygenTagNumber and DoxygenStrList[Index].startswith('@retval')):
2600 ErrorMsgList.append('Line %d : VOID return type need NO doxygen tags in comment' % CommentStartLine)
2601 PrintErrorMsg(ERROR_DOXYGEN_CHECK_FUNCTION_HEADER, 'VOID return type need no doxygen tags in comment ', TableName, CommentId)
2602 else:
2603 if Index < DoxygenTagNumber and not DoxygenStrList[Index].startswith('@retval') and not DoxygenStrList[Index].startswith('@return'):
2604 ErrorMsgList.append('Line %d : Number of @param doxygen tags in comment does NOT match number of function parameters' % CommentStartLine)
2605 PrintErrorMsg(ERROR_DOXYGEN_CHECK_FUNCTION_HEADER, 'Number of @param doxygen tags in comment does NOT match number of function parameters ', TableName, CommentId)
2606 else:
2607 if ParamNumber == 0 and DoxygenTagNumber != 0 and ((FuncModifier.find('VOID') != -1 or FuncModifier.find('void') != -1) and FuncModifier.find('*') == -1):
2608 ErrorMsgList.append('Line %d : VOID return type need NO doxygen tags in comment' % CommentStartLine)
2609 PrintErrorMsg(ERROR_DOXYGEN_CHECK_FUNCTION_HEADER, 'VOID return type need NO doxygen tags in comment ', TableName, CommentId)
2610 if ParamNumber != 0 and DoxygenTagNumber == 0:
2611 ErrorMsgList.append('Line %d : No doxygen tags in comment' % CommentStartLine)
2612 PrintErrorMsg(ERROR_DOXYGEN_CHECK_FUNCTION_HEADER, 'No doxygen tags in comment ', TableName, CommentId)
2613
2614 if __name__ == '__main__':
2615
2616 # EdkLogger.Initialize()
2617 # EdkLogger.SetLevel(EdkLogger.QUIET)
2618 # CollectSourceCodeDataIntoDB(sys.argv[1])
2619 try:
2620 test_file = sys.argv[1]
2621 except IndexError, v:
2622 print "Usage: %s filename" % sys.argv[0]
2623 sys.exit(1)
2624 MsgList = CheckFuncHeaderDoxygenComments(test_file)
2625 for Msg in MsgList:
2626 print Msg
2627 print 'Done!'