aboutsummaryrefslogtreecommitdiff
path: root/lib/Parse/Parser.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-02-27 17:53:17 +0000
committerDouglas Gregor <dgregor@apple.com>2009-02-27 17:53:17 +0000
commitb2fb6de9070fea9abc56c8e8d5469066e964cefe (patch)
tree43e23d4d24ae483d9f8113d57f06fedb19d239c5 /lib/Parse/Parser.cpp
parent51a75d0cc7651753399efdc3176feaee6214c3ca (diff)
Clean up and document code modification hints.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65641 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/Parser.cpp')
-rw-r--r--lib/Parse/Parser.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index 134f477634..4398ef8ea9 100644
--- a/lib/Parse/Parser.cpp
+++ b/lib/Parse/Parser.cpp
@@ -76,18 +76,17 @@ DiagnosticBuilder Parser::Diag(const Token &Tok, unsigned DiagID) {
/// \param ParenRange Source range enclosing code that should be parenthesized.
void Parser::SuggestParentheses(SourceLocation Loc, unsigned DK,
SourceRange ParenRange) {
- if (!ParenRange.getEnd().isFileID()) {
+ SourceLocation EndLoc = PP.getLocForEndOfToken(ParenRange.getEnd());
+ if (!ParenRange.getEnd().isFileID() || EndLoc.isInvalid()) {
// We can't display the parentheses, so just dig the
// warning/error and return.
Diag(Loc, DK);
return;
}
- unsigned Len = Lexer::MeasureTokenLength(ParenRange.getEnd(),
- PP.getSourceManager());
Diag(Loc, DK)
- << CodeInsertionHint(ParenRange.getBegin(), "(")
- << CodeInsertionHint(ParenRange.getEnd().getFileLocWithOffset(Len), ")");
+ << CodeModificationHint::CreateInsertion(ParenRange.getBegin(), "(")
+ << CodeModificationHint::CreateInsertion(EndLoc, ")");
}
/// MatchRHSPunctuation - For punctuation with a LHS and RHS (e.g. '['/']'),
@@ -131,14 +130,13 @@ bool Parser::ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned DiagID,
}
const char *Spelling = 0;
- if (PrevTokLocation.isValid() && PrevTokLocation.isFileID() &&
- (Spelling = tok::getTokenSpelling(ExpectedTok))) {
+ SourceLocation EndLoc = PP.getLocForEndOfToken(PrevTokLocation);
+ if (EndLoc.isValid() &&
+ (Spelling = tok::getTokenSimpleSpelling(ExpectedTok))) {
// Show what code to insert to fix this problem.
- SourceLocation DiagLoc
- = PrevTokLocation.getFileLocWithOffset(strlen(Spelling));
- Diag(DiagLoc, DiagID)
+ Diag(EndLoc, DiagID)
<< Msg
- << CodeInsertionHint(DiagLoc, Spelling);
+ << CodeModificationHint::CreateInsertion(EndLoc, Spelling);
} else
Diag(Tok, DiagID) << Msg;