r176401 - Some refactoring in my patch on document
Fariborz Jahanian
fjahanian at apple.com
Fri Mar 1 18:39:58 PST 2013
Author: fjahanian
Date: Fri Mar 1 20:39:57 2013
New Revision: 176401
URL: http://llvm.org/viewvc/llvm-project?rev=176401&view=rev
Log:
Some refactoring in my patch on document
command source fidelity. // rdar://13066276
Modified:
cfe/trunk/include/clang/AST/Comment.h
cfe/trunk/include/clang/AST/CommentLexer.h
cfe/trunk/include/clang/AST/CommentParser.h
cfe/trunk/include/clang/AST/CommentSema.h
cfe/trunk/lib/AST/CommentBriefParser.cpp
cfe/trunk/lib/AST/CommentLexer.cpp
cfe/trunk/lib/AST/CommentParser.cpp
cfe/trunk/lib/AST/CommentSema.cpp
cfe/trunk/unittests/AST/CommentLexer.cpp
Modified: cfe/trunk/include/clang/AST/Comment.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Comment.h?rev=176401&r1=176400&r2=176401&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Comment.h (original)
+++ cfe/trunk/include/clang/AST/Comment.h Fri Mar 1 20:39:57 2013
@@ -572,14 +572,15 @@ protected:
ParagraphComment *Paragraph;
/// Header Doc command, if true
- bool HDCommand;
+ bool AtCommand;
BlockCommandComment(CommentKind K,
SourceLocation LocBegin,
SourceLocation LocEnd,
- unsigned CommandID) :
+ unsigned CommandID,
+ bool AtCommand) :
BlockContentComment(K, LocBegin, LocEnd),
- Paragraph(NULL), HDCommand(false) {
+ Paragraph(NULL), AtCommand(AtCommand) {
setLocation(getCommandNameBeginLoc());
BlockCommandCommentBits.CommandID = CommandID;
}
@@ -587,9 +588,10 @@ protected:
public:
BlockCommandComment(SourceLocation LocBegin,
SourceLocation LocEnd,
- unsigned CommandID) :
+ unsigned CommandID,
+ bool AtCommand) :
BlockContentComment(BlockCommandCommentKind, LocBegin, LocEnd),
- Paragraph(NULL), HDCommand(false) {
+ Paragraph(NULL), AtCommand(AtCommand) {
setLocation(getCommandNameBeginLoc());
BlockCommandCommentBits.CommandID = CommandID;
}
@@ -661,12 +663,8 @@ public:
setSourceRange(SourceRange(getLocStart(), NewLocEnd));
}
- bool getHDCommand() const LLVM_READONLY {
- return HDCommand;
- }
-
- void setHDCommand(bool HDC) {
- HDCommand = HDC;
+ bool getAtCommand() const LLVM_READONLY {
+ return AtCommand;
}
};
@@ -681,9 +679,10 @@ public:
ParamCommandComment(SourceLocation LocBegin,
SourceLocation LocEnd,
- unsigned CommandID) :
+ unsigned CommandID,
+ bool AtCommand) :
BlockCommandComment(ParamCommandCommentKind, LocBegin, LocEnd,
- CommandID),
+ CommandID, AtCommand),
ParamIndex(InvalidParamIndex) {
ParamCommandCommentBits.Direction = In;
ParamCommandCommentBits.IsDirectionExplicit = false;
@@ -763,8 +762,10 @@ private:
public:
TParamCommandComment(SourceLocation LocBegin,
SourceLocation LocEnd,
- unsigned CommandID) :
- BlockCommandComment(TParamCommandCommentKind, LocBegin, LocEnd, CommandID)
+ unsigned CommandID,
+ bool AtCommand) :
+ BlockCommandComment(TParamCommandCommentKind, LocBegin, LocEnd, CommandID,
+ AtCommand)
{ }
static bool classof(const Comment *C) {
@@ -845,7 +846,7 @@ public:
SourceLocation LocEnd,
unsigned CommandID) :
BlockCommandComment(VerbatimBlockCommentKind,
- LocBegin, LocEnd, CommandID)
+ LocBegin, LocEnd, CommandID, false)
{ }
static bool classof(const Comment *C) {
@@ -898,7 +899,7 @@ public:
StringRef Text) :
BlockCommandComment(VerbatimLineCommentKind,
LocBegin, LocEnd,
- CommandID),
+ CommandID, false),
Text(Text),
TextBegin(TextBegin)
{ }
Modified: cfe/trunk/include/clang/AST/CommentLexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CommentLexer.h?rev=176401&r1=176400&r2=176401&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/CommentLexer.h (original)
+++ cfe/trunk/include/clang/AST/CommentLexer.h Fri Mar 1 20:39:57 2013
@@ -35,7 +35,8 @@ enum TokenKind {
newline,
text,
unknown_command, // Command that does not have an ID.
- command, // Command with an ID.
+ backslash_command, // \Command with an ID.
+ at_command, // @command with an ID.
verbatim_block_begin,
verbatim_block_line,
verbatim_block_end,
@@ -76,9 +77,6 @@ class Token {
/// contains the length of the string that starts at TextPtr.
unsigned IntVal;
- /// This command is a Header Doc command (command starts with '@').
- bool HDCommand;
-
public:
SourceLocation getLocation() const LLVM_READONLY { return Loc; }
void setLocation(SourceLocation SL) { Loc = SL; }
@@ -121,16 +119,12 @@ public:
}
unsigned getCommandID() const LLVM_READONLY {
- assert(is(tok::command));
+ assert(is(tok::backslash_command) || is(tok::at_command));
return IntVal;
}
- bool getHDCommand() const LLVM_READONLY {
- return HDCommand;
- }
-
void setCommandID(unsigned ID) {
- assert(is(tok::command));
+ assert(is(tok::backslash_command) || is(tok::at_command));
IntVal = ID;
}
Modified: cfe/trunk/include/clang/AST/CommentParser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CommentParser.h?rev=176401&r1=176400&r2=176401&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/CommentParser.h (original)
+++ cfe/trunk/include/clang/AST/CommentParser.h Fri Mar 1 20:39:57 2013
@@ -87,7 +87,7 @@ class Parser {
}
bool isTokBlockCommand() {
- return Tok.is(tok::command) &&
+ return (Tok.is(tok::backslash_command) || Tok.is(tok::at_command)) &&
Traits.getCommandInfo(Tok.getCommandID())->IsBlockCommand;
}
Modified: cfe/trunk/include/clang/AST/CommentSema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CommentSema.h?rev=176401&r1=176400&r2=176401&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/CommentSema.h (original)
+++ cfe/trunk/include/clang/AST/CommentSema.h Fri Mar 1 20:39:57 2013
@@ -96,7 +96,8 @@ public:
BlockCommandComment *actOnBlockCommandStart(SourceLocation LocBegin,
SourceLocation LocEnd,
- unsigned CommandID);
+ unsigned CommandID,
+ bool AtCommand);
void actOnBlockCommandArgs(BlockCommandComment *Command,
ArrayRef<BlockCommandComment::Argument> Args);
@@ -106,7 +107,8 @@ public:
ParamCommandComment *actOnParamCommandStart(SourceLocation LocBegin,
SourceLocation LocEnd,
- unsigned CommandID);
+ unsigned CommandID,
+ bool AtCommand);
void actOnParamCommandDirectionArg(ParamCommandComment *Command,
SourceLocation ArgLocBegin,
@@ -123,7 +125,8 @@ public:
TParamCommandComment *actOnTParamCommandStart(SourceLocation LocBegin,
SourceLocation LocEnd,
- unsigned CommandID);
+ unsigned CommandID,
+ bool AtCommand);
void actOnTParamCommandParamNameArg(TParamCommandComment *Command,
SourceLocation ArgLocBegin,
Modified: cfe/trunk/lib/AST/CommentBriefParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentBriefParser.cpp?rev=176401&r1=176400&r2=176401&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CommentBriefParser.cpp (original)
+++ cfe/trunk/lib/AST/CommentBriefParser.cpp Fri Mar 1 20:39:57 2013
@@ -78,7 +78,7 @@ std::string BriefParser::Parse() {
continue;
}
- if (Tok.is(tok::command)) {
+ if (Tok.is(tok::backslash_command) || Tok.is(tok::at_command)) {
const CommandInfo *Info = Traits.getCommandInfo(Tok.getCommandID());
if (Info->IsBriefCommand) {
FirstParagraphOrBrief.clear();
Modified: cfe/trunk/lib/AST/CommentLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentLexer.cpp?rev=176401&r1=176400&r2=176401&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CommentLexer.cpp (original)
+++ cfe/trunk/lib/AST/CommentLexer.cpp Fri Mar 1 20:39:57 2013
@@ -298,7 +298,7 @@ void Lexer::lexCommentText(Token &T) {
switch(*TokenPtr) {
case '\\':
case '@': {
- T.HDCommand = (*TokenPtr == '@');
+ bool AtCommand = (*TokenPtr == '@');
TokenPtr++;
if (TokenPtr == CommentEnd) {
formTextToken(T, TokenPtr);
@@ -359,7 +359,9 @@ void Lexer::lexCommentText(Token &T) {
setupAndLexVerbatimLine(T, TokenPtr, Info);
return;
}
- formTokenWithChars(T, TokenPtr, tok::command);
+ formTokenWithChars(T, TokenPtr,
+ (AtCommand ? tok::at_command
+ : tok::backslash_command));
T.setCommandID(Info->getID());
return;
}
Modified: cfe/trunk/lib/AST/CommentParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentParser.cpp?rev=176401&r1=176400&r2=176401&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CommentParser.cpp (original)
+++ cfe/trunk/lib/AST/CommentParser.cpp Fri Mar 1 20:39:57 2013
@@ -300,7 +300,7 @@ void Parser::parseBlockCommandArgs(Block
}
BlockCommandComment *Parser::parseBlockCommand() {
- assert(Tok.is(tok::command));
+ assert(Tok.is(tok::backslash_command) || Tok.is(tok::at_command));
ParamCommandComment *PC;
TParamCommandComment *TPC;
@@ -312,19 +312,19 @@ BlockCommandComment *Parser::parseBlockC
IsParam = true;
PC = S.actOnParamCommandStart(Tok.getLocation(),
Tok.getEndLocation(),
- Tok.getCommandID());
- PC->setHDCommand(Tok.getHDCommand());
+ Tok.getCommandID(),
+ Tok.is(tok::at_command));
} else if (Info->IsTParamCommand) {
IsTParam = true;
TPC = S.actOnTParamCommandStart(Tok.getLocation(),
Tok.getEndLocation(),
- Tok.getCommandID());
- TPC->setHDCommand(Tok.getHDCommand());
+ Tok.getCommandID(),
+ Tok.is(tok::at_command));
} else {
BC = S.actOnBlockCommandStart(Tok.getLocation(),
Tok.getEndLocation(),
- Tok.getCommandID());
- BC->setHDCommand(Tok.getHDCommand());
+ Tok.getCommandID(),
+ Tok.is(tok::at_command));
}
consumeToken();
@@ -395,7 +395,7 @@ BlockCommandComment *Parser::parseBlockC
}
InlineCommandComment *Parser::parseInlineCommand() {
- assert(Tok.is(tok::command));
+ assert(Tok.is(tok::backslash_command) || Tok.is(tok::at_command));
const Token CommandTok = Tok;
consumeToken();
@@ -562,7 +562,8 @@ BlockContentComment *Parser::parseParagr
consumeToken();
continue;
- case tok::command: {
+ case tok::backslash_command:
+ case tok::at_command: {
const CommandInfo *Info = Traits.getCommandInfo(Tok.getCommandID());
if (Info->IsBlockCommand) {
if (Content.size() == 0)
@@ -572,7 +573,7 @@ BlockContentComment *Parser::parseParagr
if (Info->IsVerbatimBlockEndCommand) {
Diag(Tok.getLocation(),
diag::warn_verbatim_block_end_without_start)
- << Tok.getHDCommand()
+ << Tok.is(tok::at_command)
<< Info->Name
<< SourceRange(Tok.getLocation(), Tok.getEndLocation());
consumeToken();
@@ -710,7 +711,8 @@ BlockContentComment *Parser::parseBlockC
switch (Tok.getKind()) {
case tok::text:
case tok::unknown_command:
- case tok::command:
+ case tok::backslash_command:
+ case tok::at_command:
case tok::html_start_tag:
case tok::html_end_tag:
return parseParagraphOrBlockCommand();
Modified: cfe/trunk/lib/AST/CommentSema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentSema.cpp?rev=176401&r1=176400&r2=176401&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CommentSema.cpp (original)
+++ cfe/trunk/lib/AST/CommentSema.cpp Fri Mar 1 20:39:57 2013
@@ -49,8 +49,9 @@ ParagraphComment *Sema::actOnParagraphCo
BlockCommandComment *Sema::actOnBlockCommandStart(SourceLocation LocBegin,
SourceLocation LocEnd,
- unsigned CommandID) {
- return new (Allocator) BlockCommandComment(LocBegin, LocEnd, CommandID);
+ unsigned CommandID,
+ bool AtCommand) {
+ return new (Allocator) BlockCommandComment(LocBegin, LocEnd, CommandID, AtCommand);
}
void Sema::actOnBlockCommandArgs(BlockCommandComment *Command,
@@ -69,9 +70,10 @@ void Sema::actOnBlockCommandFinish(Block
ParamCommandComment *Sema::actOnParamCommandStart(SourceLocation LocBegin,
SourceLocation LocEnd,
- unsigned CommandID) {
+ unsigned CommandID,
+ bool AtCommand) {
ParamCommandComment *Command =
- new (Allocator) ParamCommandComment(LocBegin, LocEnd, CommandID);
+ new (Allocator) ParamCommandComment(LocBegin, LocEnd, CommandID, AtCommand);
if (!isFunctionDecl())
Diag(Command->getLocation(),
@@ -162,9 +164,10 @@ void Sema::actOnParamCommandFinish(Param
TParamCommandComment *Sema::actOnTParamCommandStart(SourceLocation LocBegin,
SourceLocation LocEnd,
- unsigned CommandID) {
+ unsigned CommandID,
+ bool AtCommand) {
TParamCommandComment *Command =
- new (Allocator) TParamCommandComment(LocBegin, LocEnd, CommandID);
+ new (Allocator) TParamCommandComment(LocBegin, LocEnd, CommandID, AtCommand);
if (!isTemplateOrSpecialization())
Diag(Command->getLocation(),
@@ -432,7 +435,7 @@ void Sema::checkBlockCommandEmptyParagra
if (!DiagLoc.isValid())
DiagLoc = Command->getCommandNameRange(Traits).getEnd();
Diag(DiagLoc, diag::warn_doc_block_command_empty_paragraph)
- << Command->getHDCommand()
+ << Command->getAtCommand()
<< Command->getCommandName(Traits)
<< Command->getSourceRange();
}
@@ -460,7 +463,7 @@ void Sema::checkReturnsCommand(const Blo
}
Diag(Command->getLocation(),
diag::warn_doc_returns_attached_to_a_void_function)
- << Command->getHDCommand()
+ << Command->getAtCommand()
<< Command->getCommandName(Traits)
<< DiagKind
<< Command->getSourceRange();
@@ -472,7 +475,7 @@ void Sema::checkReturnsCommand(const Blo
Diag(Command->getLocation(),
diag::warn_doc_returns_not_attached_to_a_function_decl)
- << Command->getHDCommand()
+ << Command->getAtCommand()
<< Command->getCommandName(Traits)
<< Command->getSourceRange();
}
@@ -505,18 +508,18 @@ void Sema::checkBlockCommandDuplicate(co
StringRef CommandName = Command->getCommandName(Traits);
StringRef PrevCommandName = PrevCommand->getCommandName(Traits);
Diag(Command->getLocation(), diag::warn_doc_block_command_duplicate)
- << Command->getHDCommand()
+ << Command->getAtCommand()
<< CommandName
<< Command->getSourceRange();
if (CommandName == PrevCommandName)
Diag(PrevCommand->getLocation(), diag::note_doc_block_command_previous)
- << PrevCommand->getHDCommand()
+ << PrevCommand->getAtCommand()
<< PrevCommandName
<< PrevCommand->getSourceRange();
else
Diag(PrevCommand->getLocation(),
diag::note_doc_block_command_previous_alias)
- << PrevCommand->getHDCommand()
+ << PrevCommand->getAtCommand()
<< PrevCommandName
<< CommandName;
}
Modified: cfe/trunk/unittests/AST/CommentLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/CommentLexer.cpp?rev=176401&r1=176400&r2=176401&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/CommentLexer.cpp (original)
+++ cfe/trunk/unittests/AST/CommentLexer.cpp Fri Mar 1 20:39:57 2013
@@ -362,7 +362,7 @@ TEST_F(CommentLexerTest, DoxygenCommand6
ASSERT_EQ(tok::text, Toks[0].getKind());
ASSERT_EQ(StringRef(" "), Toks[0].getText());
- ASSERT_EQ(tok::command, Toks[1].getKind());
+ ASSERT_EQ(tok::backslash_command, Toks[1].getKind());
ASSERT_EQ(StringRef("brief"), getCommandName(Toks[1]));
ASSERT_EQ(tok::text, Toks[2].getKind());
@@ -382,22 +382,22 @@ TEST_F(CommentLexerTest, DoxygenCommand7
ASSERT_EQ(tok::text, Toks[0].getKind());
ASSERT_EQ(StringRef(" "), Toks[0].getText());
- ASSERT_EQ(tok::command, Toks[1].getKind());
+ ASSERT_EQ(tok::backslash_command, Toks[1].getKind());
ASSERT_EQ(StringRef("em"), getCommandName(Toks[1]));
- ASSERT_EQ(tok::command, Toks[2].getKind());
+ ASSERT_EQ(tok::backslash_command, Toks[2].getKind());
ASSERT_EQ(StringRef("em"), getCommandName(Toks[2]));
ASSERT_EQ(tok::text, Toks[3].getKind());
ASSERT_EQ(StringRef(" "), Toks[3].getText());
- ASSERT_EQ(tok::command, Toks[4].getKind());
+ ASSERT_EQ(tok::backslash_command, Toks[4].getKind());
ASSERT_EQ(StringRef("em"), getCommandName(Toks[4]));
ASSERT_EQ(tok::text, Toks[5].getKind());
ASSERT_EQ(StringRef("\t"), Toks[5].getText());
- ASSERT_EQ(tok::command, Toks[6].getKind());
+ ASSERT_EQ(tok::backslash_command, Toks[6].getKind());
ASSERT_EQ(StringRef("em"), getCommandName(Toks[6]));
ASSERT_EQ(tok::newline, Toks[7].getKind());
@@ -446,7 +446,7 @@ TEST_F(CommentLexerTest, DoxygenCommand9
ASSERT_EQ(tok::text, Toks[0].getKind());
ASSERT_EQ(StringRef(" "), Toks[0].getText());
- ASSERT_EQ(tok::command, Toks[1].getKind());
+ ASSERT_EQ(tok::backslash_command, Toks[1].getKind());
ASSERT_EQ(StringRef("c"), getCommandName(Toks[1]));
ASSERT_EQ(tok::newline, Toks[2].getKind());
@@ -466,7 +466,7 @@ TEST_F(CommentLexerTest, RegisterCustomB
ASSERT_EQ(tok::text, Toks[0].getKind());
ASSERT_EQ(StringRef(" "), Toks[0].getText());
- ASSERT_EQ(tok::command, Toks[1].getKind());
+ ASSERT_EQ(tok::backslash_command, Toks[1].getKind());
ASSERT_EQ(StringRef("NewBlockCommand"), getCommandName(Toks[1]));
ASSERT_EQ(tok::text, Toks[2].getKind());
@@ -494,7 +494,7 @@ TEST_F(CommentLexerTest, RegisterMultipl
ASSERT_EQ(tok::text, Toks[0].getKind());
ASSERT_EQ(StringRef(" "), Toks[0].getText());
- ASSERT_EQ(tok::command, Toks[1].getKind());
+ ASSERT_EQ(tok::backslash_command, Toks[1].getKind());
ASSERT_EQ(StringRef("Foo"), getCommandName(Toks[1]));
ASSERT_EQ(tok::newline, Toks[2].getKind());
@@ -502,7 +502,7 @@ TEST_F(CommentLexerTest, RegisterMultipl
ASSERT_EQ(tok::text, Toks[3].getKind());
ASSERT_EQ(StringRef(" "), Toks[3].getText());
- ASSERT_EQ(tok::command, Toks[4].getKind());
+ ASSERT_EQ(tok::backslash_command, Toks[4].getKind());
ASSERT_EQ(StringRef("Bar"), getCommandName(Toks[4]));
ASSERT_EQ(tok::text, Toks[5].getKind());
@@ -513,7 +513,7 @@ TEST_F(CommentLexerTest, RegisterMultipl
ASSERT_EQ(tok::text, Toks[7].getKind());
ASSERT_EQ(StringRef(" "), Toks[7].getText());
- ASSERT_EQ(tok::command, Toks[8].getKind());
+ ASSERT_EQ(tok::backslash_command, Toks[8].getKind());
ASSERT_EQ(StringRef("Blech"), getCommandName(Toks[8]));
ASSERT_EQ(tok::text, Toks[9].getKind());
More information about the cfe-commits
mailing list