[cfe-commits] r159325 - in /cfe/trunk: lib/AST/CommentBriefParser.cpp test/Index/annotate-comments-unterminated.c test/Index/annotate-comments.cpp
Dmitri Gribenko
gribozavr at gmail.com
Wed Jun 27 18:38:22 PDT 2012
Author: gribozavr
Date: Wed Jun 27 20:38:21 2012
New Revision: 159325
URL: http://llvm.org/viewvc/llvm-project?rev=159325&view=rev
Log:
Cleanup \brief comment. Since it is a single paragraph, no need to save newlines there.
Modified:
cfe/trunk/lib/AST/CommentBriefParser.cpp
cfe/trunk/test/Index/annotate-comments-unterminated.c
cfe/trunk/test/Index/annotate-comments.cpp
Modified: cfe/trunk/lib/AST/CommentBriefParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentBriefParser.cpp?rev=159325&r1=159324&r2=159325&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CommentBriefParser.cpp (original)
+++ cfe/trunk/lib/AST/CommentBriefParser.cpp Wed Jun 27 20:38:21 2012
@@ -12,6 +12,34 @@
namespace clang {
namespace comments {
+namespace {
+/// Convert all whitespace into spaces, remove leading and trailing spaces,
+/// compress multiple spaces into one.
+void cleanupBrief(std::string &S) {
+ bool PrevWasSpace = true;
+ std::string::iterator O = S.begin();
+ for (std::string::iterator I = S.begin(), E = S.end();
+ I != E; ++I) {
+ const char C = *I;
+ if (C == ' ' || C == '\n' || C == '\r' ||
+ C == '\t' || C == '\v' || C == '\f') {
+ if (!PrevWasSpace) {
+ *O++ = ' ';
+ PrevWasSpace = true;
+ }
+ continue;
+ } else {
+ *O++ = C;
+ PrevWasSpace = false;
+ }
+ }
+ if (O != S.begin() && *(O - 1) == ' ')
+ --O;
+
+ S.resize(O - S.begin());
+}
+} // unnamed namespace
+
std::string BriefParser::Parse() {
std::string Paragraph;
bool InFirstParagraph = true;
@@ -47,7 +75,7 @@
if (Tok.is(tok::newline)) {
if (InFirstParagraph || InBrief)
- Paragraph += '\n';
+ Paragraph += ' ';
ConsumeToken();
if (Tok.is(tok::newline)) {
@@ -66,6 +94,7 @@
ConsumeToken();
}
+ cleanupBrief(Paragraph);
return Paragraph;
}
Modified: cfe/trunk/test/Index/annotate-comments-unterminated.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-comments-unterminated.c?rev=159325&r1=159324&r2=159325&view=diff
==============================================================================
--- cfe/trunk/test/Index/annotate-comments-unterminated.c (original)
+++ cfe/trunk/test/Index/annotate-comments-unterminated.c Wed Jun 27 20:38:21 2012
@@ -1,8 +1,8 @@
// RUN: c-index-test -test-load-source all %s | FileCheck %s
// RUN: %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck -check-prefix=ERR %s
-// CHECK: annotate-comments-unterminated.c:9:5: VarDecl=x:{{.*}} RawComment=[/** Aaa. */]{{.*}} BriefComment=[ Aaa. \n]
-// CHECK: annotate-comments-unterminated.c:11:5: VarDecl=y:{{.*}} RawComment=[/**< Bbb. */]{{.*}} BriefComment=[ Bbb. \n]
+// CHECK: annotate-comments-unterminated.c:9:5: VarDecl=x:{{.*}} RawComment=[/** Aaa. */]{{.*}} BriefComment=[Aaa.]
+// CHECK: annotate-comments-unterminated.c:11:5: VarDecl=y:{{.*}} RawComment=[/**< Bbb. */]{{.*}} BriefComment=[Bbb.]
// CHECK-ERR: error: unterminated
/** Aaa. */
Modified: cfe/trunk/test/Index/annotate-comments.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-comments.cpp?rev=159325&r1=159324&r2=159325&view=diff
==============================================================================
--- cfe/trunk/test/Index/annotate-comments.cpp (original)
+++ cfe/trunk/test/Index/annotate-comments.cpp Wed Jun 27 20:38:21 2012
@@ -268,7 +268,7 @@
// CHECK: annotate-comments.cpp:163:7: FieldDecl=isdoxy42:{{.*}} isdoxy42 IS_DOXYGEN_SINGLE
// CHECK: annotate-comments.cpp:176:6: FunctionDecl=isdoxy43:{{.*}} IS_DOXYGEN_START{{.*}} IS_DOXYGEN_END
-// CHECK: annotate-comments.cpp:185:6: FunctionDecl=isdoxy44:{{.*}} BriefComment=[ IS_DOXYGEN_START Aaa bbb\n ccc.\n]
-// CHECK: annotate-comments.cpp:195:6: FunctionDecl=isdoxy45:{{.*}} BriefComment=[\n Ddd eee.\n Fff.\n]
-// CHECK: annotate-comments.cpp:204:6: FunctionDecl=isdoxy47:{{.*}} BriefComment=[ IS_DOXYGEN_START Aaa bbb\n ]
+// CHECK: annotate-comments.cpp:185:6: FunctionDecl=isdoxy44:{{.*}} BriefComment=[IS_DOXYGEN_START Aaa bbb ccc.]
+// CHECK: annotate-comments.cpp:195:6: FunctionDecl=isdoxy45:{{.*}} BriefComment=[Ddd eee. Fff.]
+// CHECK: annotate-comments.cpp:204:6: FunctionDecl=isdoxy47:{{.*}} BriefComment=[IS_DOXYGEN_START Aaa bbb]
More information about the cfe-commits
mailing list