]> granicus.if.org Git - clang/commitdiff
[Doc parsing] Provide diagnostics for unknown documentation
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 3 May 2013 23:15:20 +0000 (23:15 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 3 May 2013 23:15:20 +0000 (23:15 +0000)
commands. // rdar://12381408

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

include/clang/AST/CommentLexer.h
include/clang/Basic/DiagnosticLexKinds.td
lib/AST/CommentLexer.cpp
lib/AST/RawCommentList.cpp
test/Sema/warn-documentation.cpp
test/Sema/warn-documentation.m
unittests/AST/CommentLexer.cpp
unittests/AST/CommentParser.cpp

index 4179f45e80eea91399d1c7925cb65b6737148748..f152c778c9aa724d4a6a6d6e1c74326716787513 100644 (file)
@@ -15,6 +15,7 @@
 #define LLVM_CLANG_AST_COMMENT_LEXER_H
 
 #include "clang/Basic/SourceManager.h"
+#include "clang/Basic/Diagnostic.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
@@ -227,6 +228,8 @@ private:
   /// computed (for example, resolved decimal character references).
   llvm::BumpPtrAllocator &Allocator;
 
+  DiagnosticsEngine &Diags;
+  
   const CommandTraits &Traits;
 
   const char *const BufferStart;
@@ -316,6 +319,10 @@ private:
     return FileLoc.getLocWithOffset(CharNo);
   }
 
+  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
+    return Diags.Report(Loc, DiagID);
+  }
+
   /// Eat string matching regexp \code \s*\* \endcode.
   void skipLineStartingDecorations();
 
@@ -346,7 +353,8 @@ private:
   void lexHTMLEndTag(Token &T);
 
 public:
-  Lexer(llvm::BumpPtrAllocator &Allocator, const CommandTraits &Traits,
+  Lexer(llvm::BumpPtrAllocator &Allocator, DiagnosticsEngine &Diags,
+        const CommandTraits &Traits,
         SourceLocation FileLoc,
         const char *BufferStart, const char *BufferEnd);
 
index 548823f1f0b84f5ad1d612e78d22cc0573381ae8..fb0ab3c1a441cc11c7284a0684ed8190193f1370 100644 (file)
@@ -27,6 +27,10 @@ def backslash_newline_space : Warning<
   "backslash and newline separated by space">,
   InGroup<DiagGroup<"backslash-newline-escape">>;
 
+// comment parsing
+def warn_unknown_comment_command_name : Warning<
+  "unknown command tag name">, InGroup<DiagGroup<"comment-command-tag">>;
+
 // Digraphs.
 def warn_cxx98_compat_less_colon_colon : Warning<
   "'<::' is treated as digraph '<:' (aka '[') followed by ':' in C++98">,
@@ -586,4 +590,4 @@ def warn_uncovered_module_header : Warning<
 def err_expected_id_building_module : Error<
   "expected a module name in '__building_module' expression">;
   
-}
+}
\ No newline at end of file
index 1194520bf3606a45d1e9d4eb2ecfef316bbe7149..82efac64ff5f5b46f5e968248ee62db007c67ac6 100644 (file)
@@ -1,4 +1,5 @@
 #include "clang/AST/CommentLexer.h"
+#include "clang/Lex/LexDiagnostic.h"
 #include "clang/AST/CommentCommandTraits.h"
 #include "clang/Basic/CharInfo.h"
 #include "llvm/ADT/StringExtras.h"
@@ -353,6 +354,8 @@ void Lexer::lexCommentText(Token &T) {
         if (!Info) {
           formTokenWithChars(T, TokenPtr, tok::unknown_command);
           T.setUnknownCommandName(CommandName);
+          Diag(T.getLocation(),
+               diag::warn_unknown_comment_command_name);
           return;
         }
         if (Info->IsVerbatimBlockCommand) {
@@ -685,10 +688,11 @@ void Lexer::lexHTMLEndTag(Token &T) {
   State = LS_Normal;
 }
 
-Lexer::Lexer(llvm::BumpPtrAllocator &Allocator, const CommandTraits &Traits,
+Lexer::Lexer(llvm::BumpPtrAllocator &Allocator, DiagnosticsEngine &Diags,
+             const CommandTraits &Traits,
              SourceLocation FileLoc,
              const char *BufferStart, const char *BufferEnd):
-    Allocator(Allocator), Traits(Traits),
+    Allocator(Allocator), Diags(Diags), Traits(Traits),
     BufferStart(BufferStart), BufferEnd(BufferEnd),
     FileLoc(FileLoc), BufferPtr(BufferStart),
     CommentState(LCS_BeforeComment), State(LS_Normal) {
index fb85c142e3f99d7369e29eb58ec36a51032aa5c6..92b96dc8e5a159220c24a3be347f57d27e92ef25 100644 (file)
@@ -146,7 +146,8 @@ const char *RawComment::extractBriefText(const ASTContext &Context) const {
   // a separate allocator for all temporary stuff.
   llvm::BumpPtrAllocator Allocator;
 
-  comments::Lexer L(Allocator, Context.getCommentCommandTraits(),
+  comments::Lexer L(Allocator, Context.getDiagnostics(),
+                    Context.getCommentCommandTraits(),
                     Range.getBegin(),
                     RawText.begin(), RawText.end());
   comments::BriefParser P(L, Context.getCommentCommandTraits());
@@ -167,7 +168,8 @@ comments::FullComment *RawComment::parse(const ASTContext &Context,
   // Make sure that RawText is valid.
   getRawText(Context.getSourceManager());
 
-  comments::Lexer L(Context.getAllocator(), Context.getCommentCommandTraits(),
+  comments::Lexer L(Context.getAllocator(), Context.getDiagnostics(),
+                    Context.getCommentCommandTraits(),
                     getSourceRange().getBegin(),
                     RawText.begin(), RawText.end());
   comments::Sema S(Context.getAllocator(), Context.getSourceManager(),
index 0132ef280c47ac45dee9cb9aba54257147faaf87..b3ab0199dcb42d2a1d8066f00c8f5912103706ca 100644 (file)
@@ -892,10 +892,10 @@ typedef const struct test_nocrash7 * test_nocrash8;
 
 // We used to crash on this.
 
+// expected-warning@+1 {{unknown command tag name}}
 /// aaa \unknown aaa \unknown aaa
 int test_nocrash9;
 
-
 // We used to crash on this.  PR15068
 
 // expected-warning@+2 {{empty paragraph passed to '@param' command}}
index 1e3acf1d7238a84d932ad9d4ddcb371286adf784..0737a8dedd0386175649c7b37055b3902203f6bb 100644 (file)
@@ -149,6 +149,7 @@ struct S;
 @class NSArray;
 @interface NSArray @end
 
+// expected-warning@+3 {{unknown command tag name}}
 /*!
 @interface NSMutableArray 
 @super NSArray
index 507daf8391312429f6fd82a59b9f415d58d07e73..fc0fd77275087d8e6edfb92bd7ed3a59721c0eec 100644 (file)
@@ -64,7 +64,7 @@ void CommentLexerTest::lexString(const char *Source,
   FileID File = SourceMgr.createFileIDForMemBuffer(Buf);
   SourceLocation Begin = SourceMgr.getLocForStartOfFile(File);
 
-  Lexer L(Allocator, Traits, Begin, Source, Source + strlen(Source));
+  Lexer L(Allocator, Diags, Traits, Begin, Source, Source + strlen(Source));
 
   while (1) {
     Token Tok;
index 3dce60ab731f555cc1d0e142857187c51807d1a9..d05fb58fafaa7d450e2f82495e5178145a9a46f7 100644 (file)
@@ -58,7 +58,7 @@ FullComment *CommentParserTest::parseString(const char *Source) {
   FileID File = SourceMgr.createFileIDForMemBuffer(Buf);
   SourceLocation Begin = SourceMgr.getLocForStartOfFile(File);
 
-  Lexer L(Allocator, Traits, Begin, Source, Source + strlen(Source));
+  Lexer L(Allocator, Diags, Traits, Begin, Source, Source + strlen(Source));
 
   Sema S(Allocator, SourceMgr, Diags, Traits, /*PP=*/ NULL);
   Parser P(L, S, Allocator, SourceMgr, Diags, Traits);