Convert StringLiteralParser constructor to use ArrayRef instead of a pointer and count.

llvm-svn: 211763
This commit is contained in:
Craig Topper 2014-06-26 04:58:39 +00:00
parent 6098b2f519
commit 9d5583ef0a
10 changed files with 29 additions and 30 deletions

View File

@ -196,16 +196,16 @@ class StringLiteralParser {
unsigned UDSuffixToken;
unsigned UDSuffixOffset;
public:
StringLiteralParser(const Token *StringToks, unsigned NumStringToks,
StringLiteralParser(ArrayRef<Token> StringToks,
Preprocessor &PP, bool Complain = true);
StringLiteralParser(const Token *StringToks, unsigned NumStringToks,
StringLiteralParser(ArrayRef<Token> StringToks,
const SourceManager &sm, const LangOptions &features,
const TargetInfo &target,
DiagnosticsEngine *diags = nullptr)
: SM(sm), Features(features), Target(target), Diags(diags),
MaxTokenLength(0), SizeBound(0), CharByteWidth(0), Kind(tok::unknown),
ResultPtr(ResultBuf.data()), hadError(false), Pascal(false) {
init(StringToks, NumStringToks);
init(StringToks);
}
@ -249,7 +249,7 @@ public:
}
private:
void init(const Token *StringToks, unsigned NumStringToks);
void init(ArrayRef<Token> StringToks);
bool CopyStringFragment(const Token &Tok, const char *TokBegin,
StringRef Fragment);
void DiagnoseLexingError(SourceLocation Loc);

View File

@ -3446,7 +3446,7 @@ public:
/// ActOnStringLiteral - The specified tokens were lexed as pasted string
/// fragments (e.g. "foo" "bar" L"baz").
ExprResult ActOnStringLiteral(const Token *StringToks, unsigned NumStringToks,
ExprResult ActOnStringLiteral(ArrayRef<Token> StringToks,
Scope *UDLScope = nullptr);
ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc,

View File

@ -998,7 +998,7 @@ getLocationOfByte(unsigned ByteNo, const SourceManager &SM,
TheLexer.LexFromRawLexer(TheTok);
// Use the StringLiteralParser to compute the length of the string in bytes.
StringLiteralParser SLP(&TheTok, 1, SM, Features, Target);
StringLiteralParser SLP(TheTok, SM, Features, Target);
unsigned TokNumBytes = SLP.GetStringLength();
// If the byte is in this token, return the location of the byte.

View File

@ -1255,26 +1255,26 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end,
/// \endverbatim
///
StringLiteralParser::
StringLiteralParser(const Token *StringToks, unsigned NumStringToks,
StringLiteralParser(ArrayRef<Token> StringToks,
Preprocessor &PP, bool Complain)
: SM(PP.getSourceManager()), Features(PP.getLangOpts()),
Target(PP.getTargetInfo()), Diags(Complain ? &PP.getDiagnostics() :nullptr),
MaxTokenLength(0), SizeBound(0), CharByteWidth(0), Kind(tok::unknown),
ResultPtr(ResultBuf.data()), hadError(false), Pascal(false) {
init(StringToks, NumStringToks);
init(StringToks);
}
void StringLiteralParser::init(const Token *StringToks, unsigned NumStringToks){
void StringLiteralParser::init(ArrayRef<Token> StringToks){
// The literal token may have come from an invalid source location (e.g. due
// to a PCH error), in which case the token length will be 0.
if (NumStringToks == 0 || StringToks[0].getLength() < 2)
if (StringToks.empty() || StringToks[0].getLength() < 2)
return DiagnoseLexingError(SourceLocation());
// Scan all of the string portions, remember the max individual token length,
// computing a bound on the concatenated string length, and see whether any
// piece is a wide-string. If any of the string portions is a wide-string
// literal, the result is a wide-string literal [C99 6.4.5p4].
assert(NumStringToks && "expected at least one token");
assert(!StringToks.empty() && "expected at least one token");
MaxTokenLength = StringToks[0].getLength();
assert(StringToks[0].getLength() >= 2 && "literal token is invalid!");
SizeBound = StringToks[0].getLength()-2; // -2 for "".
@ -1284,7 +1284,7 @@ void StringLiteralParser::init(const Token *StringToks, unsigned NumStringToks){
// Implement Translation Phase #6: concatenation of string literals
/// (C99 5.1.1.2p1). The common case is only one string fragment.
for (unsigned i = 1; i != NumStringToks; ++i) {
for (unsigned i = 1; i != StringToks.size(); ++i) {
if (StringToks[i].getLength() < 2)
return DiagnoseLexingError(StringToks[i].getLocation());
@ -1340,7 +1340,7 @@ void StringLiteralParser::init(const Token *StringToks, unsigned NumStringToks){
SourceLocation UDSuffixTokLoc;
for (unsigned i = 0, e = NumStringToks; i != e; ++i) {
for (unsigned i = 0, e = StringToks.size(); i != e; ++i) {
const char *ThisTokBuf = &TokenBuf[0];
// Get the spelling of the token, which eliminates trigraphs, etc. We know
// that ThisTokBuf points to a buffer that is big enough for the whole token
@ -1514,10 +1514,10 @@ void StringLiteralParser::init(const Token *StringToks, unsigned NumStringToks){
// Verify that pascal strings aren't too large.
if (GetStringLength() > 256) {
if (Diags)
Diags->Report(StringToks[0].getLocation(),
Diags->Report(StringToks.front().getLocation(),
diag::err_pascal_string_too_long)
<< SourceRange(StringToks[0].getLocation(),
StringToks[NumStringToks-1].getLocation());
<< SourceRange(StringToks.front().getLocation(),
StringToks.back().getLocation());
hadError = true;
return;
}
@ -1526,12 +1526,12 @@ void StringLiteralParser::init(const Token *StringToks, unsigned NumStringToks){
unsigned MaxChars = Features.CPlusPlus? 65536 : Features.C99 ? 4095 : 509;
if (GetNumStringChars() > MaxChars)
Diags->Report(StringToks[0].getLocation(),
Diags->Report(StringToks.front().getLocation(),
diag::ext_string_too_long)
<< GetNumStringChars() << MaxChars
<< (Features.CPlusPlus ? 2 : Features.C99 ? 1 : 0)
<< SourceRange(StringToks[0].getLocation(),
StringToks[NumStringToks-1].getLocation());
<< SourceRange(StringToks.front().getLocation(),
StringToks.back().getLocation());
}
}

View File

@ -1122,7 +1122,7 @@ retry:
// Parse the string literal.
LangOptions LangOpts;
StringLiteralParser StringLiteral(&LToken, 1, SourceMgr, LangOpts, *Target);
StringLiteralParser StringLiteral(LToken, SourceMgr, LangOpts, *Target);
if (StringLiteral.hadError)
goto retry;

View File

@ -955,7 +955,7 @@ void Preprocessor::HandleLineDirective(Token &Tok) {
return DiscardUntilEndOfDirective();
} else {
// Parse and validate the string, converting it into a unique ID.
StringLiteralParser Literal(&StrTok, 1, *this);
StringLiteralParser Literal(StrTok, *this);
assert(Literal.isAscii() && "Didn't allow wide strings in");
if (Literal.hadError)
return DiscardUntilEndOfDirective();
@ -1091,7 +1091,7 @@ void Preprocessor::HandleDigitDirective(Token &DigitTok) {
return DiscardUntilEndOfDirective();
} else {
// Parse and validate the string, converting it into a unique ID.
StringLiteralParser Literal(&StrTok, 1, *this);
StringLiteralParser Literal(StrTok, *this);
assert(Literal.isAscii() && "Didn't allow wide strings in");
if (Literal.hadError)
return DiscardUntilEndOfDirective();

View File

@ -757,7 +757,7 @@ bool Preprocessor::FinishLexStringLiteral(Token &Result, std::string &String,
} while (Result.is(tok::string_literal));
// Concatenate and parse the strings.
StringLiteralParser Literal(&StrToks[0], StrToks.size(), *this);
StringLiteralParser Literal(StrToks, *this);
assert(Literal.isAscii() && "Didn't allow wide strings in");
if (Literal.hadError)

View File

@ -2183,7 +2183,7 @@ ExprResult Parser::ParseStringLiteralExpression(bool AllowUserDefinedLiteral) {
} while (isTokenStringLiteral());
// Pass the set of string tokens, ready for concatenation, to the actions.
return Actions.ActOnStringLiteral(&StringToks[0], StringToks.size(),
return Actions.ActOnStringLiteral(StringToks,
AllowUserDefinedLiteral ? getCurScope()
: nullptr);
}

View File

@ -2195,7 +2195,7 @@ bool Parser::ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext,
TokLocs.push_back(ConsumeStringToken());
}
StringLiteralParser Literal(Toks.data(), Toks.size(), PP);
StringLiteralParser Literal(Toks, PP);
if (Literal.hadError)
return true;

View File

@ -1499,16 +1499,15 @@ static ExprResult BuildCookedLiteralOperatorCall(Sema &S, Scope *Scope,
/// string.
///
ExprResult
Sema::ActOnStringLiteral(const Token *StringToks, unsigned NumStringToks,
Scope *UDLScope) {
assert(NumStringToks && "Must have at least one string!");
Sema::ActOnStringLiteral(ArrayRef<Token> StringToks, Scope *UDLScope) {
assert(!StringToks.empty() && "Must have at least one string!");
StringLiteralParser Literal(StringToks, NumStringToks, PP);
StringLiteralParser Literal(StringToks, PP);
if (Literal.hadError)
return ExprError();
SmallVector<SourceLocation, 4> StringTokLocs;
for (unsigned i = 0; i != NumStringToks; ++i)
for (unsigned i = 0; i != StringToks.size(); ++i)
StringTokLocs.push_back(StringToks[i].getLocation());
QualType CharTy = Context.CharTy;