Comment lexer: counting backwards from token end is thought to be confusing. We already have a pointer to the beginning of the token, so use it to extract the text instead.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159269 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/CommentLexer.cpp b/lib/AST/CommentLexer.cpp
index e5529da..f9acd2a 100644
--- a/lib/AST/CommentLexer.cpp
+++ b/lib/AST/CommentLexer.cpp
@@ -279,8 +279,9 @@
case '@': {
TokenPtr++;
if (TokenPtr == CommentEnd) {
+ StringRef Text(BufferPtr, TokenPtr - BufferPtr);
formTokenWithChars(T, TokenPtr, tok::text);
- T.setText(StringRef(BufferPtr - T.getLength(), T.getLength()));
+ T.setText(Text);
return;
}
char C = *TokenPtr;
@@ -297,16 +298,17 @@
// This is the \:: escape sequence.
TokenPtr++;
}
+ StringRef UnescapedText(BufferPtr + 1, TokenPtr - (BufferPtr + 1));
formTokenWithChars(T, TokenPtr, tok::text);
- T.setText(StringRef(BufferPtr - (T.getLength() - 1),
- T.getLength() - 1));
+ T.setText(UnescapedText);
return;
}
// Don't make zero-length commands.
if (!isCommandNameCharacter(*TokenPtr)) {
+ StringRef Text(BufferPtr, TokenPtr - BufferPtr);
formTokenWithChars(T, TokenPtr, tok::text);
- T.setText(StringRef(BufferPtr - T.getLength(), T.getLength()));
+ T.setText(Text);
return;
}
@@ -342,8 +344,9 @@
case '<': {
TokenPtr++;
if (TokenPtr == CommentEnd) {
+ StringRef Text(BufferPtr, TokenPtr - BufferPtr);
formTokenWithChars(T, TokenPtr, tok::text);
- T.setText(StringRef(BufferPtr - T.getLength(), T.getLength()));
+ T.setText(Text);
return;
}
const char C = *TokenPtr;
@@ -373,8 +376,9 @@
C == '\\' || C == '@' || C == '<')
break;
}
+ StringRef Text(BufferPtr, TokenPtr - BufferPtr);
formTokenWithChars(T, TokenPtr, tok::text);
- T.setText(StringRef(BufferPtr - T.getLength(), T.getLength()));
+ T.setText(Text);
return;
}
}
@@ -388,9 +392,9 @@
VerbatimBlockEndCommandName.append(Marker == '\\' ? "\\" : "@");
VerbatimBlockEndCommandName.append(EndName);
+ StringRef Name(BufferPtr + 1, TextBegin - (BufferPtr + 1));
formTokenWithChars(T, TextBegin, tok::verbatim_block_begin);
- T.setVerbatimBlockName(StringRef(TextBegin - (T.getLength() - 1),
- T.getLength() - 1));
+ T.setVerbatimBlockName(Name);
State = LS_VerbatimBlockFirstLine;
}
@@ -414,9 +418,9 @@
} else if (Pos == 0) {
// Current line contains just an end command.
const char *End = BufferPtr + VerbatimBlockEndCommandName.size();
+ StringRef Name(BufferPtr + 1, End - (BufferPtr + 1));
formTokenWithChars(T, End, tok::verbatim_block_end);
- T.setVerbatimBlockName(StringRef(End - (T.getLength() - 1),
- T.getLength() - 1));
+ T.setVerbatimBlockName(Name);
State = LS_Normal;
return;
} else {
@@ -424,8 +428,9 @@
NextLine = BufferPtr + Pos;
}
+ StringRef Text(BufferPtr, NextLine - BufferPtr);
formTokenWithChars(T, NextLine, tok::verbatim_block_line);
- T.setVerbatimBlockText(StringRef(NextLine - T.getLength(), T.getLength()));
+ T.setVerbatimBlockText(Text);
State = LS_VerbatimBlockBody;
}
@@ -455,9 +460,9 @@
assert(BufferPtr[0] == '<' && isHTMLIdentifierCharacter(BufferPtr[1]));
const char *TagNameEnd = skipHTMLIdentifier(BufferPtr + 2, CommentEnd);
+ StringRef Name(BufferPtr + 1, TagNameEnd - (BufferPtr + 1));
formTokenWithChars(T, TagNameEnd, tok::html_tag_open);
- T.setHTMLTagOpenName(StringRef(TagNameEnd - (T.getLength() - 1),
- T.getLength() - 1));
+ T.setHTMLTagOpenName(Name);
BufferPtr = skipWhitespace(BufferPtr, CommentEnd);
@@ -477,8 +482,9 @@
char C = *TokenPtr;
if (isHTMLIdentifierCharacter(C)) {
TokenPtr = skipHTMLIdentifier(TokenPtr, CommentEnd);
+ StringRef Ident(BufferPtr, TokenPtr - BufferPtr);
formTokenWithChars(T, TokenPtr, tok::html_ident);
- T.setHTMLIdent(StringRef(TokenPtr - T.getLength(), T.getLength()));
+ T.setHTMLIdent(Ident);
} else {
switch (C) {
case '=':