Pārlūkot izejas kodu

Comment parsing: handle non-builtin commands correctly. After semantic
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

Dmitri Gribenko 13 gadi atpakaļ
vecāks
revīzija
b0b8a96df2

+ 2 - 2
include/clang/AST/CommentLexer.h

@@ -34,8 +34,8 @@ enum TokenKind {
   eof,
   eof,
   newline,
   newline,
   text,
   text,
-  unknown_command,
-  command,
+  unknown_command, // Command that does not have an ID.
+  command,         // Command with an ID.
   verbatim_block_begin,
   verbatim_block_begin,
   verbatim_block_line,
   verbatim_block_line,
   verbatim_block_end,
   verbatim_block_end,

+ 5 - 1
include/clang/AST/CommentSema.h

@@ -139,7 +139,11 @@ public:
 
 
   InlineContentComment *actOnUnknownCommand(SourceLocation LocBegin,
   InlineContentComment *actOnUnknownCommand(SourceLocation LocBegin,
                                             SourceLocation LocEnd,
                                             SourceLocation LocEnd,
-                                            StringRef Name);
+                                            StringRef CommandName);
+
+  InlineContentComment *actOnUnknownCommand(SourceLocation LocBegin,
+                                            SourceLocation LocEnd,
+                                            unsigned CommandID);
 
 
   TextComment *actOnText(SourceLocation LocBegin,
   TextComment *actOnText(SourceLocation LocBegin,
                          SourceLocation LocEnd,
                          SourceLocation LocEnd,

+ 1 - 0
lib/AST/CommentCommandTraits.cpp

@@ -40,6 +40,7 @@ const CommandInfo *CommandTraits::registerUnknownCommand(StringRef CommandName)
   CommandInfo *Info = new (Allocator) CommandInfo();
   CommandInfo *Info = new (Allocator) CommandInfo();
   Info->Name = Name;
   Info->Name = Name;
   Info->ID = NextID++;
   Info->ID = NextID++;
+  Info->IsUnknownCommand = true;
 
 
   RegisteredCommands.push_back(Info);
   RegisteredCommands.push_back(Info);
 
 

+ 7 - 0
lib/AST/CommentParser.cpp

@@ -554,6 +554,13 @@ BlockContentComment *Parser::parseParagraphOrBlockCommand() {
           return parseBlockCommand();
           return parseBlockCommand();
         break; // Block command ahead, finish this parapgaph.
         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);
       assert(Info->IsInlineCommand);
       Content.push_back(parseInlineCommand());
       Content.push_back(parseInlineCommand());
       continue;
       continue;

+ 8 - 2
lib/AST/CommentSema.cpp

@@ -272,9 +272,15 @@ InlineCommandComment *Sema::actOnInlineCommand(SourceLocation CommandLocBegin,
 
 
 InlineContentComment *Sema::actOnUnknownCommand(SourceLocation LocBegin,
 InlineContentComment *Sema::actOnUnknownCommand(SourceLocation LocBegin,
                                                 SourceLocation LocEnd,
                                                 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;
   ArrayRef<InlineCommandComment::Argument> Args;
-  unsigned CommandID = Traits.registerUnknownCommand(Name)->getID();
   return new (Allocator) InlineCommandComment(
   return new (Allocator) InlineCommandComment(
                                   LocBegin, LocEnd, CommandID,
                                   LocBegin, LocEnd, CommandID,
                                   InlineCommandComment::RenderNormal,
                                   InlineCommandComment::RenderNormal,

+ 5 - 0
test/Sema/warn-documentation.cpp

@@ -761,3 +761,8 @@ inline void test_nocrash6()
 */
 */
 typedef const struct test_nocrash7 * test_nocrash8;
 typedef const struct test_nocrash7 * test_nocrash8;
 
 
+// We used to crash on this.
+
+/// aaa \unknown aaa \unknown aaa
+int test_nocrash9;
+