]> granicus.if.org Git - clang/commitdiff
Comment parsing: retokenized text tokens are now pushed back in correct (not
authorDmitri Gribenko <gribozavr@gmail.com>
Tue, 24 Jul 2012 16:10:47 +0000 (16:10 +0000)
committerDmitri Gribenko <gribozavr@gmail.com>
Tue, 24 Jul 2012 16:10:47 +0000 (16:10 +0000)
reverse) order

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160675 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/CommentParser.h
lib/AST/CommentParser.cpp
unittests/AST/CommentParser.cpp

index 47cab25f25062a782017df41b9e1f09351c8ac49..1e4e4f8694ba4a2a02d22ba4a286cba3f86b6698 100644 (file)
@@ -83,7 +83,7 @@ class Parser {
 
     MoreLATokens.push_back(Tok);
     for (const Token *I = &Toks.back(),
-         *B = &Toks.front() + 1;
+         *B = &Toks.front();
          I != B; --I) {
       MoreLATokens.push_back(*I);
     }
index 6b7e0ab49d40a297804304d70064e47df9851465..92ea7042ff16124e03e706aa20c90a5abc84e639 100644 (file)
@@ -105,9 +105,12 @@ BlockCommandComment *Parser::parseBlockCommand() {
       BC = parseBlockCommandArgs(BC, Retokenizer, NumArgs);
 
     // Put back tokens we didn't use.
+    SmallVector<Token, 16> TextToks;
     Token Text;
-    while (Retokenizer.lexText(Text))
-      putBack(Text);
+    while (Retokenizer.lexText(Text)) {
+      TextToks.push_back(Text);
+    }
+    putBack(TextToks);
   }
 
   BlockContentComment *Block = parseParagraphOrBlockCommand();
index 87e10cebc06bb94d2bb1d87e8106052a0cbff460..ed7681d5c58ff856678006e9f821c3309854a983 100644 (file)
@@ -755,6 +755,31 @@ TEST_F(CommentParserTest, ParamCommand4) {
   }
 }
 
+TEST_F(CommentParserTest, ParamCommand5) {
+  const char *Source =
+    "// \\param aaa \\% Bbb \\$ ccc\n";
+
+  FullComment *FC = parseString(Source);
+  ASSERT_TRUE(HasChildCount(FC, 2));
+
+  ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " "));
+  {
+    ParamCommandComment *PCC;
+    ParagraphComment *PC;
+    ASSERT_TRUE(HasParamCommandAt(FC, 1, PCC, "param",
+                                  ParamCommandComment::In,
+                                  /* IsDirectionExplicit = */ false,
+                                  "aaa", PC));
+    ASSERT_TRUE(HasChildCount(PCC, 1));
+
+    ASSERT_TRUE(HasChildCount(PC, 5));
+      ASSERT_TRUE(HasTextAt(PC, 0, " "));
+      ASSERT_TRUE(HasTextAt(PC, 1, "%"));
+      ASSERT_TRUE(HasTextAt(PC, 2, " Bbb "));
+      ASSERT_TRUE(HasTextAt(PC, 3, "$"));
+      ASSERT_TRUE(HasTextAt(PC, 4, " ccc"));
+  }
+}
 
 TEST_F(CommentParserTest, InlineCommand1) {
   const char *Source = "// \\c";