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