ECC: ignore '#' in string and char literal '...'
authorjlin16 <jlin16@7335b38e-4728-0410-8992-fb3ffe349368>
Mon, 28 Jan 2008 05:14:26 +0000 (05:14 +0000)
committerjlin16 <jlin16@7335b38e-4728-0410-8992-fb3ffe349368>
Mon, 28 Jan 2008 05:14:26 +0000 (05:14 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@977 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/Ecc/CodeFragmentCollector.py

index d9b0815..30e6c5e 100644 (file)
@@ -271,10 +271,18 @@ class CodeFragmentCollector:
         HashComment = False\r
         PPExtend = False\r
         CommentObj = None\r
-        PPDirectiveObj = None \r
+        PPDirectiveObj = None\r
+        # HashComment in quoted string " " is ignored.\r
+        InString = False\r
+        InCharLiteral = False \r
 \r
         while not self.__EndOfFile():\r
             \r
+            if self.__CurrentChar() == T_CHAR_DOUBLE_QUOTE:\r
+                InString = not InString\r
+                \r
+            if self.__CurrentChar() == T_CHAR_SINGLE_QUOTE:\r
+                InCharLiteral = not InCharLiteral\r
             # meet new line, then no longer in a comment for // and '#'\r
             if self.__CurrentChar() == T_CHAR_LF:\r
                 if HashComment and PPDirectiveObj != None:\r
@@ -337,7 +345,7 @@ class CodeFragmentCollector:
                 DoubleSlashComment = True\r
                 CommentObj = Comment('', (self.CurrentLineNumber, self.CurrentOffsetWithinLine), None, T_COMMENT_TWO_SLASH)\r
             # check for '#' comment\r
-            elif self.__CurrentChar() == T_CHAR_HASH:\r
+            elif self.__CurrentChar() == T_CHAR_HASH and not InString and not InCharLiteral:\r
                 InComment = True\r
                 HashComment = True\r
                 #insert ',' at hash line to workaround PP effects on C grammar check. C parser also adjusted to accomodate the inserted comma.\r