From: Chris Lattner Date: Wed, 17 Nov 2010 06:55:10 +0000 (+0000) Subject: add a static version of PP::AdvanceToTokenCharacter. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=872a45e91778eb0b706ff57272fe547d4512eb19;p=clang add a static version of PP::AdvanceToTokenCharacter. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119472 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 380d116386..c3e7349011 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -727,7 +727,15 @@ public: /// AdvanceToTokenCharacter - Given a location that specifies the start of a /// token, return a new location that specifies a character within the token. - SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart,unsigned Char); + SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, + unsigned Char) const { + return AdvanceToTokenCharacter(FullSourceLoc(TokStart, SourceMgr), Char, + Features); + } + static FullSourceLoc AdvanceToTokenCharacter(FullSourceLoc TokStart, + unsigned Char, + const LangOptions &Features); + /// IncrementPasteCounter - Increment the counters for the number of token /// paste operations performed. If fast was specified, this is a 'fast paste' diff --git a/lib/Lex/LiteralSupport.cpp b/lib/Lex/LiteralSupport.cpp index 35eaddeea4..8ad1669647 100644 --- a/lib/Lex/LiteralSupport.cpp +++ b/lib/Lex/LiteralSupport.cpp @@ -167,11 +167,10 @@ static unsigned ProcessCharEscape(const char *&ThisTokBuf, /// return the UTF32. static bool ProcessUCNEscape(const char *&ThisTokBuf, const char *ThisTokEnd, uint32_t &UcnVal, unsigned short &UcnLen, - SourceLocation Loc, Preprocessor &PP, - Diagnostic *Diags, + FullSourceLoc Loc, Diagnostic *Diags, const LangOptions &Features) { if (!Features.CPlusPlus && !Features.C99 && Diags) - PP.Diag(Loc, diag::warn_ucn_not_valid_in_c89); + Diags->Report(Loc, diag::warn_ucn_not_valid_in_c89); // Save the beginning of the string (for error diagnostics). const char *ThisTokBegin = ThisTokBuf; @@ -181,7 +180,7 @@ static bool ProcessUCNEscape(const char *&ThisTokBuf, const char *ThisTokEnd, if (ThisTokBuf == ThisTokEnd || !isxdigit(*ThisTokBuf)) { if (Diags) - PP.Diag(Loc, diag::err_ucn_escape_no_digits); + Diags->Report(Loc, diag::err_ucn_escape_no_digits); return false; } UcnLen = (ThisTokBuf[-1] == 'u' ? 4 : 8); @@ -194,9 +193,11 @@ static bool ProcessUCNEscape(const char *&ThisTokBuf, const char *ThisTokEnd, } // If we didn't consume the proper number of digits, there is a problem. if (UcnLenSave) { - if (Diags) - PP.Diag(PP.AdvanceToTokenCharacter(Loc, ThisTokBuf-ThisTokBegin), - diag::err_ucn_escape_incomplete); + if (Diags) { + Loc = Preprocessor::AdvanceToTokenCharacter(Loc, ThisTokBuf-ThisTokBegin, + Features); + Diags->Report(Loc, diag::err_ucn_escape_incomplete); + } return false; } // Check UCN constraints (C99 6.4.3p2). @@ -205,7 +206,7 @@ static bool ProcessUCNEscape(const char *&ThisTokBuf, const char *ThisTokEnd, || (UcnVal >= 0xD800 && UcnVal <= 0xDFFF) || (UcnVal > 0x10FFFF)) /* the maximum legal UTF32 value */ { if (Diags) - PP.Diag(Loc, diag::err_ucn_escape_invalid); + Diags->Report(Loc, diag::err_ucn_escape_invalid); return false; } return true; @@ -222,7 +223,8 @@ static void EncodeUCNEscape(const char *&ThisTokBuf, const char *ThisTokEnd, typedef uint32_t UTF32; UTF32 UcnVal = 0; unsigned short UcnLen = 0; - if (!ProcessUCNEscape(ThisTokBuf, ThisTokEnd, UcnVal, UcnLen, Loc, PP, + if (!ProcessUCNEscape(ThisTokBuf, ThisTokEnd, UcnVal, UcnLen, + FullSourceLoc(Loc, PP.getSourceManager()), Complain ? &PP.getDiagnostics() : 0, PP.getLangOptions())){ HadError = 1; @@ -724,7 +726,8 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end, if (begin[1] == 'u' || begin[1] == 'U') { uint32_t utf32 = 0; unsigned short UcnLen = 0; - if (!ProcessUCNEscape(begin, end, utf32, UcnLen, Loc, PP, + if (!ProcessUCNEscape(begin, end, utf32, UcnLen, + FullSourceLoc(Loc, PP.getSourceManager()), &PP.getDiagnostics(), PP.getLangOptions())) { HadError = 1; } diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index e9b854306a..332c95679b 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -431,13 +431,14 @@ void Preprocessor::CreateString(const char *Buf, unsigned Len, Token &Tok, /// AdvanceToTokenCharacter - Given a location that specifies the start of a /// token, return a new location that specifies a character within the token. -SourceLocation Preprocessor::AdvanceToTokenCharacter(SourceLocation TokStart, - unsigned CharNo) { +FullSourceLoc Preprocessor::AdvanceToTokenCharacter(FullSourceLoc TokStart, + unsigned CharNo, + const LangOptions &Features) { // Figure out how many physical characters away the specified instantiation // character is. This needs to take into consideration newlines and // trigraphs. bool Invalid = false; - const char *TokPtr = SourceMgr.getCharacterData(TokStart, &Invalid); + const char *TokPtr = TokStart.getCharacterData(&Invalid); // If they request the first char of the token, we're trivially done. if (Invalid || (CharNo == 0 && Lexer::isObviouslySimpleCharacter(*TokPtr))) @@ -450,7 +451,8 @@ SourceLocation Preprocessor::AdvanceToTokenCharacter(SourceLocation TokStart, // chars, this method is extremely fast. while (Lexer::isObviouslySimpleCharacter(*TokPtr)) { if (CharNo == 0) - return TokStart.getFileLocWithOffset(PhysOffset); + return FullSourceLoc(TokStart.getFileLocWithOffset(PhysOffset), + TokStart.getManager()); ++TokPtr, --CharNo, ++PhysOffset; } @@ -470,7 +472,8 @@ SourceLocation Preprocessor::AdvanceToTokenCharacter(SourceLocation TokStart, if (!Lexer::isObviouslySimpleCharacter(*TokPtr)) PhysOffset += Lexer::SkipEscapedNewLines(TokPtr)-TokPtr; - return TokStart.getFileLocWithOffset(PhysOffset); + return FullSourceLoc(TokStart.getFileLocWithOffset(PhysOffset), + TokStart.getManager()); } SourceLocation Preprocessor::getLocForEndOfToken(SourceLocation Loc,