forked from OSchip/llvm-project
add a static version of PP::AdvanceToTokenCharacter.
llvm-svn: 119472
This commit is contained in:
parent
bde1b81eb8
commit
b1ab2c2d3d
|
@ -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'
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue