<br><br>On Saturday, March 2, 2013, Fariborz Jahanian wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: fjahanian<br>
Date: Fri Mar 1 16:51:30 2013<br>
New Revision: 176387<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=176387&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=176387&view=rev</a><br>
Log:<br>
comment parsing. Keep the original command format<br>
in AST for source fidelity and use it in diagnostics<br>
to refer to the original format. // rdar://13066276<br>
<br>
Modified:<br>
cfe/trunk/include/clang/AST/Comment.h<br>
cfe/trunk/include/clang/AST/CommentLexer.h<br>
cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td<br>
cfe/trunk/lib/AST/CommentLexer.cpp<br>
cfe/trunk/lib/AST/CommentParser.cpp<br>
cfe/trunk/lib/AST/CommentSema.cpp<br>
cfe/trunk/test/Sema/warn-documentation.cpp<br>
<br>
Modified: cfe/trunk/include/clang/AST/Comment.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Comment.h?rev=176387&r1=176386&r2=176387&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Comment.h?rev=176387&r1=176386&r2=176387&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/Comment.h (original)<br>
+++ cfe/trunk/include/clang/AST/Comment.h Fri Mar 1 16:51:30 2013<br>
@@ -570,13 +570,16 @@ protected:<br>
<br>
/// Paragraph argument.<br>
ParagraphComment *Paragraph;<br>
-<br>
+<br>
+ /// Header Doc command, if true<br>
+ bool HDCommand;<br>
+<br>
BlockCommandComment(CommentKind K,<br>
SourceLocation LocBegin,<br>
SourceLocation LocEnd,<br>
unsigned CommandID) :<br>
BlockContentComment(K, LocBegin, LocEnd),<br>
- Paragraph(NULL) {<br>
+ Paragraph(NULL), HDCommand(false) {<br>
setLocation(getCommandNameBeginLoc());<br>
BlockCommandCommentBits.CommandID = CommandID;<br>
}<br>
@@ -586,7 +589,7 @@ public:<br>
SourceLocation LocEnd,<br>
unsigned CommandID) :<br>
BlockContentComment(BlockCommandCommentKind, LocBegin, LocEnd),<br>
- Paragraph(NULL) {<br>
+ Paragraph(NULL), HDCommand(false) {<br>
setLocation(getCommandNameBeginLoc());<br>
BlockCommandCommentBits.CommandID = CommandID;<br>
}<br>
@@ -657,6 +660,14 @@ public:<br>
if (NewLocEnd.isValid())<br>
setSourceRange(SourceRange(getLocStart(), NewLocEnd));<br>
}<br>
+<br>
+ bool getHDCommand() const LLVM_READONLY {<br>
+ return HDCommand;<br>
+ }<br>
+<br>
+ void setHDCommand(bool HDC) {<br>
+ HDCommand = HDC;<br>
+ }<br>
};<br>
<br>
/// Doxygen \\param command.<br>
<br>
Modified: cfe/trunk/include/clang/AST/CommentLexer.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CommentLexer.h?rev=176387&r1=176386&r2=176387&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CommentLexer.h?rev=176387&r1=176386&r2=176387&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/CommentLexer.h (original)<br>
+++ cfe/trunk/include/clang/AST/CommentLexer.h Fri Mar 1 16:51:30 2013<br>
@@ -75,6 +75,9 @@ class Token {<br>
/// unused (command spelling can be found with CommandTraits). Otherwise,<br>
/// contains the length of the string that starts at TextPtr.<br>
unsigned IntVal;<br>
+<br>
+ /// This command is a Header Doc command (command starts with '@').<br>
+ bool HDCommand;</blockquote><div><br></div><div>This is unfortunate that we increase sizeof Token. We use Token as a value type that should be cheap to copy. I think we could carry this information in the token kind, by defining 'backslash command' and 'at command' tokens.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
public:<br>
SourceLocation getLocation() const LLVM_READONLY { return Loc; }<br>
@@ -122,6 +125,10 @@ public:<br>
return IntVal;<br>
}<br>
<br>
+ bool getHDCommand() const LLVM_READONLY {<br>
+ return HDCommand;<br>
+ }<br>
+<br>
void setCommandID(unsigned ID) {<br>
assert(is(tok::command));<br>
IntVal = ID;<br>
<br>
Modified: cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td?rev=176387&r1=176386&r2=176387&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td?rev=176387&r1=176386&r2=176387&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td (original)<br>
+++ cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td Fri Mar 1 16:51:30 2013<br>
@@ -44,18 +44,18 @@ def note_doc_html_end_tag : Note<<br>
// Commands<br>
<br>
def warn_doc_block_command_empty_paragraph : Warning<<br>
- "empty paragraph passed to '\\%0' command">,<br>
+ "empty paragraph passed to '%select{\\|@}0%1' command">,<br>
InGroup<Documentation>, DefaultIgnore;<br>
<br>
def warn_doc_block_command_duplicate : Warning<<br>
- "duplicated command '\\%0'">,<br>
+ "duplicated command '%select{\\|@}0%1'">,<br>
InGroup<Documentation>, DefaultIgnore;<br>
<br>
def note_doc_block_command_previous : Note<<br>
- "previous command '\\%0' here">;<br>
+ "previous command '%select{\\|@}0%1' here">;<br>
<br>
def note_doc_block_command_previous_alias : Note<<br>
- "previous command '\\%0' (an alias of '\\%1') here">;<br>
+ "previous command '%select{\\|@}0%1' (an alias of '\\%2') here">;<br>
<br>
// \param command<br>
<br>
@@ -111,14 +111,14 @@ def note_doc_tparam_name_suggestion : No<br>
// \returns command<br>
<br>
def warn_doc_returns_not_attached_to_a_function_decl : Warning<<br>
- "'\\%0' command used in a comment that is not attached to "<br>
+ "'%select{\\|@}0%1' command used in a comment that is not attached to "<br>
"a function or method declaration">,<br>
InGroup<Documentation>, DefaultIgnore;<br>
<br>
def warn_doc_returns_attached_to_a_void_function : Warning<<br>
- "'\\%0' command used in a comment that is attached to a "<br>
+ "'%select{\\|@}0%1' command used in a comment that is attached to a "<br>
"%select{function returning void|constructor|destructor|"<br>
- "method returning void}1">,<br>
+ "method returning void}2">,<br>
InGroup<Documentation>, DefaultIgnore;<br>
<br>
// \deprecated command<br>
@@ -134,7 +134,7 @@ def note_add_deprecation_attr : Note<<br>
// verbatim block commands<br>
<br>
def warn_verbatim_block_end_without_start : Warning<<br>
- "'\\%0' command does not terminate a verbatim text block">,<br>
+ "'%select{\\|@}0%1' command does not terminate a verbatim text block">,<br>
InGroup<Documentation>, DefaultIgnore;<br>
<br>
} // end of documentation issue category<br>
<br>
Modified: cfe/trunk/lib/AST/CommentLexer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentLexer.cpp?rev=176387&r1=176386&r2=176387&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentLexer.cpp?rev=176387&r1=176386&r2=176387&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/CommentLexer.cpp (original)<br>
+++ cfe/trunk/lib/AST/CommentLexer.cpp Fri Mar 1 16:51:30 2013<br>
@@ -298,6 +298,7 @@ void Lexer::lexCommentText(Token &T) {<br>
switch(*TokenPtr) {<br>
case '\\':<br>
case '@': {<br>
+ T.HDCommand = (*TokenPtr == '@');<br>
TokenPtr++;<br>
if (TokenPtr == CommentEnd) {<br>
formTextToken(T, TokenPtr);<br>
<br>
Modified: cfe/trunk/lib/AST/CommentParser.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentParser.cpp?rev=176387&r1=176386&r2=176387&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentParser.cpp?rev=176387&r1=176386&r2=176387&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/CommentParser.cpp (original)<br>
+++ cfe/trunk/lib/AST/CommentParser.cpp Fri Mar 1 16:51:30 2013<br>
@@ -313,15 +313,18 @@ BlockCommandComment *Parser::parseBlockC<br>
PC = S.actOnParamCommandStart(Tok.getLocation(),<br>
Tok.getEndLocation(),<br>
Tok.getCommandID());<br>
+ PC->setHDCommand(Tok.getHDCommand());</blockquote><div><br></div><div>This kind of fixups that are done after AST node is created is fragile -- we could forget to insert a fixup in a new place where we create ASTnodes. This flag (or an enum?!) should be an argument for the onstructor.</div>
<div><br></div><div>Dmitri<span></span></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
} else if (Info->IsTParamCommand) {<br>
IsTParam = true;<br>
TPC = S.actOnTParamCommandStart(Tok.getLocation(),<br>
Tok.getEndLocation(),<br>
Tok.getCommandID());<br>
+ TPC->setHDCommand(Tok.getHDCommand());<br>
} else {<br>
BC = S.actOnBlockCommandStart(Tok.getLocation(),<br>
Tok.getEndLocation(),<br>
Tok.getCommandID());<br>
+ BC->setHDCommand(Tok.getHDCommand());<br>
}<br>
consumeToken();<br>
<br>
@@ -569,6 +572,7 @@ BlockContentComment *Parser::parseParagr<br>
if (Info->IsVerbatimBlockEndCommand) {<br>
Diag(Tok.getLocation(),<br>
diag::warn_verbatim_block_end_without_start)<br>
+ << Tok.getHDCommand()<br>
<< Info->Name<br>
<< SourceRange(Tok.getLocation(), Tok.getEndLocation());<br>
consumeToken();<br>
<br>
Modified: cfe/trunk/lib/AST/CommentSema.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentSema.cpp?rev=176387&r1=176386&r2=176387&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentSema.cpp?rev=176387&r1=176386&r2=176387&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/CommentSema.cpp (original)<br>
+++ cfe/trunk/lib/AST/CommentSema.cpp Fri Mar 1 16:51:30 2013<br>
@@ -432,6 +432,7 @@ void Sema::checkBlockCommandEmptyParagra<br>
if (!DiagLoc.isValid())<br>
DiagLoc = Command->getCommandNameRange(Traits).getEnd();<br>
Diag(DiagLoc, diag::warn_doc_block_command_empty_paragraph)<br>
+ << Command->getHDCommand()<br>
<< Command->getCommandName(Traits)<br>
<< Command->getSourceRange();<br>
}<br>
@@ -459,6 +460,7 @@ void Sema::checkReturnsCommand(const Blo<br>
}<br>
Diag(Command->getLocation(),<br>
diag::warn_doc_returns_attached_to_a_void_function)<br>
+ << Command->getHDCommand()<br>
<< Command->getCommandName(Traits)<br>
<< DiagKind<br>
<< Command->getSourceRange();<br>
@@ -470,6 +472,7 @@ void Sema::checkReturnsCommand(const Blo<br>
<br>
Diag(Command->getLocation(),<br>
diag::warn_doc_returns_not_attached_to_a_function_decl)<br>
+ << Command->getHDCommand()<br>
<< Command->getCommandName(Traits)<br>
<< Command->getSourceRange();<br>
}<br>
@@ -502,15 +505,18 @@ void Sema::checkBlockCommandDuplicate(co<br>
StringRef CommandName = Command->getCommandName(Traits);<br>
StringRef PrevCommandName = PrevCommand->getCommandName(Traits);<br>
Diag(Command->getLocation(), diag::warn_doc_block_command_duplicate)<br>
+ << Command->getHDCommand()<br>
<< CommandName<br>
<< Command->getSourceRange();<br>
if (CommandName == PrevCommandName)<br>
Diag(PrevCommand->getLocation(), diag::note_doc_block_command_previous)<br>
+ << PrevCommand->getHDCommand()<br>
<< PrevCommandName<br>
<< PrevCommand->getSourceRange();<br>
else<br>
Diag(PrevCommand->getLocation(),<br>
diag::note_doc_block_command_previous_alias)<br>
+ << PrevCommand->getHDCommand()<br>
<< PrevCommandName<br>
<< CommandName;<br>
}<br>
<br>
Modified: cfe/trunk/test/Sema/warn-documentation.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-documentation.cpp?rev=176387&r1=176386&r2=176387&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-documentation.cpp?rev=176387&r1=176386&r2=176387&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Sema/warn-documentation.cpp (original)<br>
+++ cfe/trunk/test/Sema/warn-documentation.cpp Fri Mar 1 16:51:30 2013<br>
@@ -862,28 +862,28 @@ int test_nocrash9;<br>
<br>
// We used to crash on this. PR15068<br>
<br>
-// expected-warning@+2 {{empty paragraph passed to '\param' command}}<br>
-// expected-warning@+2 {{empty paragraph passed to '\param' command}}<br>
+// expected-warning@+2 {{empty paragraph passed to '@param' command}}<br>
+// expected-warning@+2 {{empty paragraph passed to '@param' command}}<br>
///@param x<br>
///@param y<br>
int test_nocrash10(int x, int y);<br>
<br>
-// expected-warning@+2 {{empty paragraph passed to '\param' command}} expected-warning@+2 {{parameter 'x' not found in the function declaration}}<br>
-// expected-warning@+2 {{empty paragraph passed to '\param' command}} expected-warning@+2 {{parameter 'y' not found in the function declaration}}<br>
+// expected-warning@+2 {{empty paragraph passed to '@param' command}} expected-warning@+2 {{parameter 'x' not found in the function declaration}}<br>
+// expected-warning@+2 {{empty paragraph passed to '@param' command}} expected-warning@+2 {{parameter 'y' not found in the function declaration}}<br>
///@param x<br>
///@param y<br>
int test_nocrash11();<br>
<br>
-// expected-warning@+3 {{empty paragraph passed to '\param' command}} expected-warning@+3 {{parameter 'x' not found in the function declaration}}<br>
-// expected-warning@+3 {{empty paragraph passed to '\param' command}} expected-warning@+3 {{parameter 'y' not found in the function declaration}}<br>
+// expected-warning@+3 {{empty paragraph passed to '@param' command}} expected-warning@+3 {{parameter 'x' not found in the function declaration}}<br>
+// expected-warning@+3 {{empty paragraph passed to '@param' command}} expected-warning@+3 {{parameter 'y' not found in the function declaration}}<br>
/**<br>
@param x<br>
@param y<br>
**/<br>
int test_nocrash12();<br>
<br>
-// expected-warning@+2 {{empty paragraph passed to '\param' command}}<br>
-// expected-warning@+1 {{empty paragraph passed to '\param' command}}<br>
+// expected-warning@+2 {{empty paragraph passed to '@param' command}}<br>
+// expected-warning@+1 {{empty paragraph passed to '@param' command}}<br>
///@param x@param y<br>
int test_nocrash13(int x, int y);<br>
<br>
@@ -895,3 +895,15 @@ int test_nocrash13(int x, int y);<br>
/// \headerfile foo.h<br>
int test_duplicate_headerfile1(int);<br>
<br>
+<br>
+// rdar://13066276<br>
+// expected-warning@+1 {{'@return' command used in a comment that is not attached to a function or method declaration}}<br>
+/** @return s */<br>
+struct s* f(void);<br>
+struct s;<br>
+<br>
+// expected-warning@+1 {{'\return' command used in a comment that is not attached to a function or method declaration}}<br>
+/** \return s */<br>
+struct q* g(void);<br>
+struct q;<br>
+<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="javascript:;" onclick="_e(event, 'cvml', 'cfe-commits@cs.uiuc.edu')">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote><br><br>-- <br>main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if<br>(j){printf("%d\n",i);}}} /*Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.com</a>>*/<br>