]> granicus.if.org Git - clang/commitdiff
Comment parsing: handle non-builtin commands correctly. After semantic
authorDmitri Gribenko <gribozavr@gmail.com>
Tue, 11 Sep 2012 19:22:03 +0000 (19:22 +0000)
committerDmitri Gribenko <gribozavr@gmail.com>
Tue, 11 Sep 2012 19:22:03 +0000 (19:22 +0000)
analysis registers a command, it becomes a "known" command for the lexer, since
it has an ID.  Having this freedom of choice to register a command is a good
thing since BriefParser does not need this.

But the parser should still invoke the correct semantic analysis method
(actOnUnknownCommand) in this case.

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

include/clang/AST/CommentLexer.h
include/clang/AST/CommentSema.h
lib/AST/CommentCommandTraits.cpp
lib/AST/CommentParser.cpp
lib/AST/CommentSema.cpp
test/Sema/warn-documentation.cpp

index 99b95d340497b9825d346d05e84d6e12554631fc..f2636973ff270b10f0b933d491376d9d90301f66 100644 (file)
@@ -34,8 +34,8 @@ enum TokenKind {
   eof,
   newline,
   text,
-  unknown_command,
-  command,
+  unknown_command, // Command that does not have an ID.
+  command,         // Command with an ID.
   verbatim_block_begin,
   verbatim_block_line,
   verbatim_block_end,
index 5ebf5f0afac780f78de607e63947f3ee9d6c4d6a..c913d28daeffbc338b0cb4c347555954425289d8 100644 (file)
@@ -139,7 +139,11 @@ public:
 
   InlineContentComment *actOnUnknownCommand(SourceLocation LocBegin,
                                             SourceLocation LocEnd,
-                                            StringRef Name);
+                                            StringRef CommandName);
+
+  InlineContentComment *actOnUnknownCommand(SourceLocation LocBegin,
+                                            SourceLocation LocEnd,
+                                            unsigned CommandID);
 
   TextComment *actOnText(SourceLocation LocBegin,
                          SourceLocation LocEnd,
index ba0aa9ae12ef91508ed5dc65732660b8b3252aaf..e7e40fd1090f756aa3a2603e098aae04a37a3920 100644 (file)
@@ -40,6 +40,7 @@ const CommandInfo *CommandTraits::registerUnknownCommand(StringRef CommandName)
   CommandInfo *Info = new (Allocator) CommandInfo();
   Info->Name = Name;
   Info->ID = NextID++;
+  Info->IsUnknownCommand = true;
 
   RegisteredCommands.push_back(Info);
 
index f6acd9645fb5244200d9b77f5e1767369e885c89..d053dc0f18008bf4a3a233ee7e8816981d314718 100644 (file)
@@ -554,6 +554,13 @@ BlockContentComment *Parser::parseParagraphOrBlockCommand() {
           return parseBlockCommand();
         break; // Block command ahead, finish this parapgaph.
       }
+      if (Info->IsUnknownCommand) {
+        Content.push_back(S.actOnUnknownCommand(Tok.getLocation(),
+                                                Tok.getEndLocation(),
+                                                Info->getID()));
+        consumeToken();
+        continue;
+      }
       assert(Info->IsInlineCommand);
       Content.push_back(parseInlineCommand());
       continue;
index e57dac71044d245aba0193bf14a9d78f682fbfd4..477717f735ef4475cecd1c716b0687df95df9342 100644 (file)
@@ -272,9 +272,15 @@ InlineCommandComment *Sema::actOnInlineCommand(SourceLocation CommandLocBegin,
 
 InlineContentComment *Sema::actOnUnknownCommand(SourceLocation LocBegin,
                                                 SourceLocation LocEnd,
-                                                StringRef Name) {
+                                                StringRef CommandName) {
+  unsigned CommandID = Traits.registerUnknownCommand(CommandName)->getID();
+  return actOnUnknownCommand(LocBegin, LocEnd, CommandID);
+}
+
+InlineContentComment *Sema::actOnUnknownCommand(SourceLocation LocBegin,
+                                                SourceLocation LocEnd,
+                                                unsigned CommandID) {
   ArrayRef<InlineCommandComment::Argument> Args;
-  unsigned CommandID = Traits.registerUnknownCommand(Name)->getID();
   return new (Allocator) InlineCommandComment(
                                   LocBegin, LocEnd, CommandID,
                                   InlineCommandComment::RenderNormal,
index 80880d453a4fad728dfdc4ec4810f8444d38ef6b..28544e0a81b1a867ed5c2654b218d12ba2b96aa6 100644 (file)
@@ -761,3 +761,8 @@ inline void test_nocrash6()
 */
 typedef const struct test_nocrash7 * test_nocrash8;
 
+// We used to crash on this.
+
+/// aaa \unknown aaa \unknown aaa
+int test_nocrash9;
+