ECC: fix the mis-report of function parameter position.
authorjlin16 <jlin16@7335b38e-4728-0410-8992-fb3ffe349368>
Thu, 22 May 2008 08:25:14 +0000 (08:25 +0000)
committerjlin16 <jlin16@7335b38e-4728-0410-8992-fb3ffe349368>
Thu, 22 May 2008 08:25:14 +0000 (08:25 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1241 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/Ecc/Check.py
Source/Python/Ecc/c.py

index ad02339..7f1755f 100644 (file)
@@ -61,7 +61,7 @@ class Check(object):
                 if IgnoredPattern.match(Dirpath.upper()) or Dirpath.find('.svn') != -1:\r
                     continue\r
                 for F in Filenames:\r
-                    if os.path.splitext(F)[1] in ('.c'):\r
+                    if os.path.splitext(F)[1] in ('.c', '.h'):\r
                         FullName = os.path.join(Dirpath, F)\r
                         c.CheckFuncLayoutReturnType(FullName)\r
     \r
@@ -76,7 +76,7 @@ class Check(object):
                 if IgnoredPattern.match(Dirpath.upper()) or Dirpath.find('.svn') != -1:\r
                     continue\r
                 for F in Filenames:\r
-                    if os.path.splitext(F)[1] in ('.c'):\r
+                    if os.path.splitext(F)[1] in ('.c', '.h'):\r
                         FullName = os.path.join(Dirpath, F)\r
                         c.CheckFuncLayoutModifier(FullName)\r
                         \r
@@ -92,7 +92,7 @@ class Check(object):
                 if IgnoredPattern.match(Dirpath.upper()) or Dirpath.find('.svn') != -1:\r
                     continue\r
                 for F in Filenames:\r
-                    if os.path.splitext(F)[1] in ('.c'):\r
+                    if os.path.splitext(F)[1] in ('.c', '.h'):\r
                         FullName = os.path.join(Dirpath, F)\r
                         c.CheckFuncLayoutName(FullName)\r
     # Check whether the function prototypes in include files have the same form as function definitions\r
index a5cf144..b9aeec4 100644 (file)
@@ -112,6 +112,7 @@ def GetIdentifierList():
                 VarNameStartColumn += 8\r
             else:\r
                 DeclText = DeclText[1:]\r
+                VarNameStartColumn += 1\r
             FirstChar = DeclText[0]\r
             \r
         var.Declarator = DeclText\r
@@ -151,6 +152,7 @@ def GetIdentifierList():
                             VarNameStartColumn += 8\r
                         else:\r
                             Index += 1\r
+                            VarNameStartColumn += 1\r
                         PreChar = FirstChar\r
             IdVar = DataClass.IdentifierClass(-1, var.Modifier, '', var.Declarator, '', DataClass.MODEL_IDENTIFIER_FUNCTION_DECLARATION, -1, -1, var.StartPos[0], var.StartPos[1], VarNameStartLine, VarNameStartColumn)\r
             IdList.append(IdVar)\r
@@ -239,16 +241,29 @@ def GetParamList(FuncDeclarator, FuncNameLine = 0, FuncNameOffset = 0):
     ParamStr = DeclSplitList[1].rstrip(')')\r
     LineSkipped = 0\r
     OffsetSkipped = 0\r
-    Start = 0\r
-    while FuncName.find('\n', Start) != -1:\r
-        LineSkipped += 1\r
-        OffsetSkipped = 0\r
-        Start += FuncName.find('\n', Start)\r
-        Start += 1       \r
-    OffsetSkipped += len(FuncName[Start:])\r
+    TailChar = FuncName[-1]\r
+    while not TailChar.isalpha() and TailChar != '_':\r
+        \r
+        if TailChar == '\n':\r
+            FuncName = FuncName.rstrip('\r\n').rstrip('\n')\r
+            LineSkipped += 1\r
+            OffsetSkipped = 0\r
+        elif TailChar == '\r':\r
+            FuncName = FuncName.rstrip('\r')\r
+            LineSkipped += 1\r
+            OffsetSkipped = 0\r
+        elif TailChar == ' ':\r
+            FuncName = FuncName.rstrip(' ')\r
+            OffsetSkipped += 1\r
+        elif TailChar == '\t':\r
+            FuncName = FuncName.rstrip('\t')\r
+            OffsetSkipped += 8\r
+        else:\r
+            FuncName = FuncName[:-1]\r
+        TailChar = FuncName[-1]\r
+               \r
     OffsetSkipped += 1 #skip '('\r
-    ParamBeginLine = FuncNameLine + LineSkipped\r
-    ParamBeginOffset = OffsetSkipped\r
+    \r
     for p in ParamStr.split(','):\r
         ListP = p.split()\r
         if len(ListP) == 0:\r
@@ -272,20 +287,67 @@ def GetParamList(FuncDeclarator, FuncNameLine = 0, FuncNameOffset = 0):
             DeclText = DeclText.lstrip('*').strip()\r
         ParamName = DeclText\r
         \r
-        Start = 0\r
-        while p.find('\n', Start) != -1:\r
-            LineSkipped += 1\r
-            OffsetSkipped = 0\r
-            Start += p.find('\n', Start)\r
-            Start += 1\r
-        OffsetSkipped += len(p[Start:])\r
+        Start = RightSpacePos\r
+        Index = 0\r
+        PreChar = ''\r
+        while Index < Start:\r
+            FirstChar = p[Index]\r
+                \r
+            if FirstChar == '\r':\r
+                Index += 1\r
+                LineSkipped += 1\r
+                OffsetSkipped = 0\r
+            elif FirstChar == '\n':\r
+                Index += 1\r
+                if PreChar != '\r':\r
+                    LineSkipped += 1\r
+                    OffsetSkipped = 0\r
+            elif FirstChar == ' ':\r
+                Index += 1\r
+                OffsetSkipped += 1\r
+            elif FirstChar == '\t':\r
+                Index += 1\r
+                OffsetSkipped += 8\r
+            else:\r
+                Index += 1\r
+                OffsetSkipped += 1\r
+            PreChar = FirstChar\r
+            \r
+        ParamBeginLine = FuncNameLine + LineSkipped\r
+        ParamBeginOffset = FuncNameOffset + OffsetSkipped\r
+        \r
+        Index = Start + len(ParamName)\r
+        PreChar = ''\r
+        while Index < len(p):\r
+            FirstChar = p[Index]\r
+                \r
+            if FirstChar == '\r':\r
+                Index += 1\r
+                LineSkipped += 1\r
+                OffsetSkipped = 0\r
+            elif FirstChar == '\n':\r
+                Index += 1\r
+                if PreChar != '\r':\r
+                    LineSkipped += 1\r
+                    OffsetSkipped = 0\r
+            elif FirstChar == ' ':\r
+                Index += 1\r
+                OffsetSkipped += 1\r
+            elif FirstChar == '\t':\r
+                Index += 1\r
+                OffsetSkipped += 8\r
+            else:\r
+                Index += 1\r
+                OffsetSkipped += 1\r
+            PreChar = FirstChar\r
+        \r
+        ParamEndLine = FuncNameLine + LineSkipped\r
+        ParamEndOffset = FuncNameOffset + OffsetSkipped\r
         \r
-        ParamEndLine = ParamBeginLine + LineSkipped\r
-        ParamEndOffset = OffsetSkipped\r
         IdParam = DataClass.IdentifierClass(-1, ParamModifier, '', ParamName, '', DataClass.MODEL_IDENTIFIER_PARAMETER, -1, -1, ParamBeginLine, ParamBeginOffset, ParamEndLine, ParamEndOffset)\r
         ParamIdList.append(IdParam)\r
-        ParamBeginLine = ParamEndLine\r
-        ParamBeginOffset = OffsetSkipped + 1 #skip ','\r
+        \r
+        OffsetSkipped += 1 #skip ','\r
     \r
     return ParamIdList\r
     \r
@@ -318,6 +380,7 @@ def GetFunctionList():
                 FuncNameStartColumn += 8\r
             else:\r
                 DeclText = DeclText[1:]\r
+                FuncNameStartColumn += 1\r
             FirstChar = DeclText[0]\r
         \r
         FuncDef.Declarator = DeclText\r
@@ -358,6 +421,7 @@ def GetFunctionList():
                         FuncNameStartColumn += 8\r
                     else:\r
                         Index += 1\r
+                        FuncNameStartColumn += 1\r
                     PreChar = FirstChar\r
                 \r
         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
@@ -634,7 +698,11 @@ def GetDataTypeFromModifier(ModifierStr):
     ReturnType = ''\r
     for M in MList:\r
         ReturnType += M + ' '\r
-    return ReturnType.strip()    \r
+        \r
+    ReturnType = ReturnType.strip()\r
+    if len(ReturnType) == 0:\r
+        ReturnType = 'VOID'\r
+    return ReturnType\r
 \r
 def DiffModifier(Str1, Str2):\r
     PartList1 = Str1.split()\r
@@ -773,6 +841,8 @@ def GetTypeInfo(RefList, Modifier, FullFileName):
     TypedefDict = GetTypedefDict(FullFileName)\r
     SUDict = GetSUDict(FullFileName)\r
     Type = GetDataTypeFromModifier(Modifier).rstrip('*').strip()\r
+    \r
+    Type = Type.split()[-1]\r
     Index = 0\r
     while Index < len(RefList):\r
         FieldName = RefList[Index]\r
@@ -803,7 +873,7 @@ def GetVarInfo(PredVarList, FuncRecord, FullFileName):
             Type = GetTypeInfo(PredVarList[1:], Result[0], FullFileName)\r
             return Type\r
         else:\r
-            Type = GetDataTypeFromModifier(Result[0])\r
+            Type = GetDataTypeFromModifier(Result[0]).split()[-1]\r
             return Type\r
                 \r
     # search function parameters second\r
@@ -814,7 +884,7 @@ def GetVarInfo(PredVarList, FuncRecord, FullFileName):
                 Type = GetTypeInfo(PredVarList[1:], Param.Modifier, FullFileName)\r
                 return Type\r
             else:\r
-                Type = GetDataTypeFromModifier(Param.Modifier)\r
+                Type = GetDataTypeFromModifier(Param.Modifier).split()[-1]\r
                 return Type\r
           \r
     # search global variable next\r
@@ -829,7 +899,7 @@ def GetVarInfo(PredVarList, FuncRecord, FullFileName):
             Type = GetTypeInfo(PredVarList[1:], Result[0], FullFileName)\r
             return Type\r
         else:\r
-            Type = GetDataTypeFromModifier(Result[0])\r
+            Type = GetDataTypeFromModifier(Result[0]).split()[-1]\r
             return Type\r
     \r
     # search variable in include files\r
@@ -851,7 +921,7 @@ def GetVarInfo(PredVarList, FuncRecord, FullFileName):
                 Type = GetTypeInfo(PredVarList[1:], Result[0], FullFileName)\r
                 return Type\r
             else:\r
-                Type = GetDataTypeFromModifier(Result[0])\r
+                Type = GetDataTypeFromModifier(Result[0]).split()[-1]\r
                 return Type\r
 \r
 def CheckFuncLayoutReturnType(FullFileName):\r
@@ -869,7 +939,7 @@ def CheckFuncLayoutReturnType(FullFileName):
                    """ % (FileTable, DataClass.MODEL_IDENTIFIER_FUNCTION_DECLARATION)\r
     ResultSet = Db.TblFile.Exec(SqlStatement)\r
     for Result in ResultSet:\r
-        ReturnType = GetDataTypeFromModifier(Result[0])\r
+        ReturnType = GetDataTypeFromModifier(Result[0]).split()[-1]\r
         if len(ReturnType) == 0:\r
             PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_RETURN_TYPE, 'Function has No Return Type', FileTable, Result[1])\r
             continue\r
@@ -886,7 +956,7 @@ def CheckFuncLayoutReturnType(FullFileName):
                    """ % (FileID)\r
     ResultSet = Db.TblFile.Exec(SqlStatement)\r
     for Result in ResultSet:\r
-        ReturnType = GetDataTypeFromModifier(Result[0])\r
+        ReturnType = GetDataTypeFromModifier(Result[0]).split()[-1]\r
         if len(ReturnType) == 0:\r
             PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_RETURN_TYPE, 'Function has No Return Type', 'Function', Result[1])\r
             continue\r
@@ -912,7 +982,7 @@ def CheckFuncLayoutModifier(FullFileName):
                    """ % (FileTable, DataClass.MODEL_IDENTIFIER_FUNCTION_DECLARATION)\r
     ResultSet = Db.TblFile.Exec(SqlStatement)\r
     for Result in ResultSet:\r
-        ReturnType = GetDataTypeFromModifier(Result[0])\r
+        ReturnType = GetDataTypeFromModifier(Result[0]).split()[-1]\r
         if len(ReturnType) == 0:\r
             continue\r
         Index = Result[0].find(ReturnType)\r
@@ -925,12 +995,12 @@ def CheckFuncLayoutModifier(FullFileName):
                    """ % (FileID)\r
     ResultSet = Db.TblFile.Exec(SqlStatement)\r
     for Result in ResultSet:\r
-        ReturnType = GetDataTypeFromModifier(Result[0])\r
+        ReturnType = GetDataTypeFromModifier(Result[0]).split()[-1]\r
         if len(ReturnType) == 0:\r
             continue\r
         Index = Result[0].find(ReturnType)\r
         if Index != 0:\r
-            PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_OPTIONAL_FUNCTIONAL_MODIFIER, '', FileTable, Result[1])\r
+            PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_OPTIONAL_FUNCTIONAL_MODIFIER, '', 'Function', Result[1])\r
 \r
 def CheckFuncLayoutName(FullFileName):\r
     ErrorMsgList = []\r
@@ -956,9 +1026,12 @@ def CheckFuncLayoutName(FullFileName):
         for Param in ParamList:\r
             if Param.StartLine <= StartLine:\r
                 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, 'Parameter %s should be in its own line.' % Param.Name, FileTable, Result[1])\r
+            if Param.StartLine - StartLine > 1:\r
+                PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, 'Empty line appears before Parameter %s.' % Param.Name, FileTable, Result[1])\r
             StartLine = Param.StartLine\r
-            if not Result[0].endswith('\n  )') and not Result[0].endswith('\r  )'):\r
-                PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, '\')\' should be on a new line and indented two spaces', FileTable, Result[1])\r
+            \r
+        if not Result[0].endswith('\n  )') and not Result[0].endswith('\r  )'):\r
+            PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, '\')\' should be on a new line and indented two spaces', FileTable, Result[1])\r
             \r
     SqlStatement = """ select Modifier, ID, FunNameStartColumn\r
                        from Function\r
@@ -967,7 +1040,7 @@ def CheckFuncLayoutName(FullFileName):
     ResultSet = Db.TblFile.Exec(SqlStatement)\r
     for Result in ResultSet:\r
         if Result[2] != 0:\r
-                PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, 'Function name should appear at the start of a line', FileTable, Result[1])\r
+                PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, 'Function name should appear at the start of a line', 'Function', Result[1])\r
         ParamList = GetParamList(Result[0])\r
         if len(ParamList) == 0:\r
             continue\r
@@ -975,9 +1048,11 @@ def CheckFuncLayoutName(FullFileName):
         for Param in ParamList:\r
             if Param.StartLine <= StartLine:\r
                 PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, 'Parameter %s should be in its own line.' % Param.Name, 'Function', Result[1])\r
+            if Param.StartLine - StartLine > 1:\r
+                PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, 'Empty line appears before Parameter %s.' % Param.Name, 'Function', Result[1])\r
             StartLine = Param.StartLine\r
-            if not Result[0].endswith('\n  )') and not Result[0].endswith('\r  )'):\r
-                PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, '\')\' should be on a new line and indented two spaces', 'Function', Result[1])\r
+        if not Result[0].endswith('\n  )') and not Result[0].endswith('\r  )'):\r
+            PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_NAME, '\')\' should be on a new line and indented two spaces', 'Function', Result[1])\r
 \r
 def CheckFuncLayoutPrototype(FullFileName):\r
     ErrorMsgList = []\r