summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@gmail.com>2014-06-26 04:58:39 +0000
committerCraig Topper <craig.topper@gmail.com>2014-06-26 04:58:39 +0000
commitba3d7511363852fe6969bba7f3be128b3a49d576 (patch)
tree505b6fd725a92a3c05123a53506e1723c88d39a6
parent3e833a8a8c90b1e9eedb995413a79b4259be90ab (diff)
downloadclang-ba3d7511363852fe6969bba7f3be128b3a49d576.tar.gz
clang-ba3d7511363852fe6969bba7f3be128b3a49d576.tar.bz2
clang-ba3d7511363852fe6969bba7f3be128b3a49d576.tar.xz
Convert StringLiteralParser constructor to use ArrayRef instead of a pointer and count.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211763 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Lex/LiteralSupport.h8
-rw-r--r--include/clang/Sema/Sema.h2
-rw-r--r--lib/AST/Expr.cpp2
-rw-r--r--lib/Lex/LiteralSupport.cpp26
-rw-r--r--lib/Lex/ModuleMap.cpp2
-rw-r--r--lib/Lex/PPDirectives.cpp4
-rw-r--r--lib/Lex/Preprocessor.cpp2
-rw-r--r--lib/Parse/ParseExpr.cpp2
-rw-r--r--lib/Parse/ParseExprCXX.cpp2
-rw-r--r--lib/Sema/SemaExpr.cpp9
10 files changed, 29 insertions, 30 deletions
diff --git a/include/clang/Lex/LiteralSupport.h b/include/clang/Lex/LiteralSupport.h
index acfd174b63..b7fcc5d34d 100644
--- a/include/clang/Lex/LiteralSupport.h
+++ b/include/clang/Lex/LiteralSupport.h
@@ -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);
diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h
index cec318d055..6d0eef5d56 100644
--- a/include/clang/Sema/Sema.h
+++ b/include/clang/Sema/Sema.h
@@ -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,
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index 7e1b2d9436..0cc046c6d2 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -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.
diff --git a/lib/Lex/LiteralSupport.cpp b/lib/Lex/LiteralSupport.cpp
index c55054be30..6417d0f0f5 100644
--- a/lib/Lex/LiteralSupport.cpp
+++ b/lib/Lex/LiteralSupport.cpp
@@ -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());
}
}
diff --git a/lib/Lex/ModuleMap.cpp b/lib/Lex/ModuleMap.cpp
index 1416a26bd5..a6d1d82a36 100644
--- a/lib/Lex/ModuleMap.cpp
+++ b/lib/Lex/ModuleMap.cpp
@@ -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;
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index 35c2aaf69d..1741c302f3 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -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();
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index aead148b66..4a11803aa9 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -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)
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp
index 3fea464c68..0c231d63ea 100644
--- a/lib/Parse/ParseExpr.cpp
+++ b/lib/Parse/ParseExpr.cpp
@@ -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);
}
diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp
index d4f686b5e1..3d1925c25d 100644
--- a/lib/Parse/ParseExprCXX.cpp
+++ b/lib/Parse/ParseExprCXX.cpp
@@ -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;
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index c7ea55219a..8153dff497 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -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;