diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-01-19 15:59:08 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-01-19 15:59:08 +0000 |
commit | 1b07c344b4bcaacf2bc950a511283be0422c3fe8 (patch) | |
tree | f04ba612684753fee92b5d5e870ec7cbb27a63ef /clang/lib | |
parent | d169911cc02eca4ff335589ddc61ba9e8697816f (diff) | |
download | bcm5719-llvm-1b07c344b4bcaacf2bc950a511283be0422c3fe8.tar.gz bcm5719-llvm-1b07c344b4bcaacf2bc950a511283be0422c3fe8.zip |
For Lexer's isAt[Start/End]OfMacroExpansion add an out parameter for the macro
start/end location.
It is commonly needed after calling the function; with this way we avoid
recalculating it.
llvm-svn: 148479
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/ARCMigrate/Transforms.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Lex/Lexer.cpp | 36 | ||||
-rw-r--r-- | clang/lib/Parse/ParseExpr.cpp | 4 |
3 files changed, 24 insertions, 19 deletions
diff --git a/clang/lib/ARCMigrate/Transforms.cpp b/clang/lib/ARCMigrate/Transforms.cpp index 21df2578727..a64124015cf 100644 --- a/clang/lib/ARCMigrate/Transforms.cpp +++ b/clang/lib/ARCMigrate/Transforms.cpp @@ -111,9 +111,8 @@ SourceLocation trans::findSemiAfterLocation(SourceLocation loc, ASTContext &Ctx) { SourceManager &SM = Ctx.getSourceManager(); if (loc.isMacroID()) { - if (!Lexer::isAtEndOfMacroExpansion(loc, SM, Ctx.getLangOptions())) + if (!Lexer::isAtEndOfMacroExpansion(loc, SM, Ctx.getLangOptions(), &loc)) return SourceLocation(); - loc = SM.getExpansionRange(loc).second; } loc = Lexer::getLocForEndOfToken(loc, /*Offset=*/0, SM, Ctx.getLangOptions()); diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp index bb1bbbbe7e6..ddb5eccff5e 100644 --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -720,11 +720,8 @@ SourceLocation Lexer::getLocForEndOfToken(SourceLocation Loc, unsigned Offset, return SourceLocation(); if (Loc.isMacroID()) { - if (Offset > 0 || !isAtEndOfMacroExpansion(Loc, SM, Features)) + if (Offset > 0 || !isAtEndOfMacroExpansion(Loc, SM, Features, &Loc)) return SourceLocation(); // Points inside the macro expansion. - - // Continue and find the location just after the macro expansion. - Loc = SM.getExpansionRange(Loc).second; } unsigned Len = Lexer::MeasureTokenLength(Loc, SM, Features); @@ -740,7 +737,8 @@ SourceLocation Lexer::getLocForEndOfToken(SourceLocation Loc, unsigned Offset, /// token of the macro expansion. bool Lexer::isAtStartOfMacroExpansion(SourceLocation loc, const SourceManager &SM, - const LangOptions &LangOpts) { + const LangOptions &LangOpts, + SourceLocation *MacroBegin) { assert(loc.isValid() && loc.isMacroID() && "Expected a valid macro loc"); std::pair<FileID, unsigned> infoLoc = SM.getDecomposedLoc(loc); @@ -751,17 +749,22 @@ bool Lexer::isAtStartOfMacroExpansion(SourceLocation loc, SourceLocation expansionLoc = SM.getSLocEntry(infoLoc.first).getExpansion().getExpansionLocStart(); - if (expansionLoc.isFileID()) - return true; // No other macro expansions, this is the first. + if (expansionLoc.isFileID()) { + // No other macro expansions, this is the first. + if (MacroBegin) + *MacroBegin = expansionLoc; + return true; + } - return isAtStartOfMacroExpansion(expansionLoc, SM, LangOpts); + return isAtStartOfMacroExpansion(expansionLoc, SM, LangOpts, MacroBegin); } /// \brief Returns true if the given MacroID location points at the last /// token of the macro expansion. bool Lexer::isAtEndOfMacroExpansion(SourceLocation loc, - const SourceManager &SM, - const LangOptions &LangOpts) { + const SourceManager &SM, + const LangOptions &LangOpts, + SourceLocation *MacroEnd) { assert(loc.isValid() && loc.isMacroID() && "Expected a valid macro loc"); SourceLocation spellLoc = SM.getSpellingLoc(loc); @@ -779,10 +782,14 @@ bool Lexer::isAtEndOfMacroExpansion(SourceLocation loc, SourceLocation expansionLoc = SM.getSLocEntry(FID).getExpansion().getExpansionLocEnd(); - if (expansionLoc.isFileID()) - return true; // No other macro expansions. + if (expansionLoc.isFileID()) { + // No other macro expansions. + if (MacroEnd) + *MacroEnd = expansionLoc; + return true; + } - return isAtEndOfMacroExpansion(expansionLoc, SM, LangOpts); + return isAtEndOfMacroExpansion(expansionLoc, SM, LangOpts, MacroEnd); } StringRef Lexer::getImmediateMacroName(SourceLocation Loc, @@ -1108,9 +1115,8 @@ SourceLocation Lexer::findLocationAfterToken(SourceLocation Loc, const LangOptions &LangOpts, bool SkipTrailingWhitespaceAndNewLine) { if (Loc.isMacroID()) { - if (!Lexer::isAtEndOfMacroExpansion(Loc, SM, LangOpts)) + if (!Lexer::isAtEndOfMacroExpansion(Loc, SM, LangOpts, &Loc)) return SourceLocation(); - Loc = SM.getExpansionRange(Loc).second; } Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts); diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index 7eac9841725..c766bad110d 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -312,8 +312,8 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) { SourceLocation FILoc = Tok.getLocation(); const char *FIText = ": "; const SourceManager &SM = PP.getSourceManager(); - if (FILoc.isFileID() || PP.isAtStartOfMacroExpansion(FILoc)) { - FILoc = SM.getExpansionLoc(FILoc); + if (FILoc.isFileID() || PP.isAtStartOfMacroExpansion(FILoc, &FILoc)) { + assert(FILoc.isFileID()); bool IsInvalid = false; const char *SourcePtr = SM.getCharacterData(FILoc.getLocWithOffset(-1), &IsInvalid); |