diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-02-27 17:53:17 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-02-27 17:53:17 +0000 |
commit | 96977da72c7cce3109cd787f795e586771980562 (patch) | |
tree | 622661cfbb2c78621f44b4f0aba0fd7fa75430ab /clang/lib/Parse/Parser.cpp | |
parent | 7094c15d7e44cd53530752387399d984cf3f4a05 (diff) | |
download | bcm5719-llvm-96977da72c7cce3109cd787f795e586771980562.tar.gz bcm5719-llvm-96977da72c7cce3109cd787f795e586771980562.zip |
Clean up and document code modification hints.
llvm-svn: 65641
Diffstat (limited to 'clang/lib/Parse/Parser.cpp')
-rw-r--r-- | clang/lib/Parse/Parser.cpp | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 134f477634d..4398ef8ea9c 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/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; |