[cfe-commits] r119476 - in /cfe/trunk: include/clang/Lex/LiteralSupport.h lib/Lex/LiteralSupport.cpp lib/Sema/SemaChecking.cpp
Chris Lattner
sabre at nondot.org
Tue Nov 16 23:21:13 PST 2010
Author: lattner
Date: Wed Nov 17 01:21:13 2010
New Revision: 119476
URL: http://llvm.org/viewvc/llvm-project?rev=119476&view=rev
Log:
propagate preprocessor out of StringLiteralParser. It is now
possible to create one without a preprocessor.
Modified:
cfe/trunk/include/clang/Lex/LiteralSupport.h
cfe/trunk/lib/Lex/LiteralSupport.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
Modified: cfe/trunk/include/clang/Lex/LiteralSupport.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/LiteralSupport.h?rev=119476&r1=119475&r2=119476&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/LiteralSupport.h (original)
+++ cfe/trunk/include/clang/Lex/LiteralSupport.h Wed Nov 17 01:21:13 2010
@@ -140,7 +140,6 @@
/// wide string analysis and Translation Phase #6 (concatenation of string
/// literals) (C99 5.1.1.2p1).
class StringLiteralParser {
- Preprocessor &PP;
const SourceManager &SM;
const LangOptions &Features;
const TargetInfo &Target;
@@ -154,6 +153,14 @@
public:
StringLiteralParser(const Token *StringToks, unsigned NumStringToks,
Preprocessor &PP, bool Complain = true);
+ StringLiteralParser(const Token *StringToks, unsigned NumStringToks,
+ const SourceManager &sm, const LangOptions &features,
+ const TargetInfo &target, Diagnostic *diags = 0)
+ : SM(sm), Features(features), Target(target), Diags(diags) {
+ init(StringToks, NumStringToks);
+ }
+
+
bool hadError;
bool AnyWide;
bool Pascal;
@@ -173,6 +180,9 @@
/// If the Diagnostics pointer is non-null, then this will do semantic
/// checking of the string literal and emit errors and warnings.
unsigned getOffsetOfStringByte(const Token &TheTok, unsigned ByteNo) const;
+
+private:
+ void init(const Token *StringToks, unsigned NumStringToks);
};
} // end namespace clang
Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=119476&r1=119475&r2=119476&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/trunk/lib/Lex/LiteralSupport.cpp Wed Nov 17 01:21:13 2010
@@ -827,9 +827,13 @@
///
StringLiteralParser::
StringLiteralParser(const Token *StringToks, unsigned NumStringToks,
- Preprocessor &pp, bool Complain)
- : PP(pp), SM(PP.getSourceManager()), Features(PP.getLangOptions()),
+ Preprocessor &PP, bool Complain)
+ : SM(PP.getSourceManager()), Features(PP.getLangOptions()),
Target(PP.getTargetInfo()), Diags(Complain ? &PP.getDiagnostics() : 0) {
+ init(StringToks, NumStringToks);
+}
+
+void StringLiteralParser::init(const Token *StringToks, unsigned NumStringToks){
// 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
@@ -893,8 +897,9 @@
// that ThisTokBuf points to a buffer that is big enough for the whole token
// and 'spelled' tokens can only shrink.
bool StringInvalid = false;
- unsigned ThisTokLen = PP.getSpelling(StringToks[i], ThisTokBuf,
- &StringInvalid);
+ unsigned ThisTokLen =
+ Preprocessor::getSpelling(StringToks[i], ThisTokBuf, SM, Features,
+ &StringInvalid);
if (StringInvalid) {
hadError = 1;
continue;
@@ -979,19 +984,22 @@
ResultBuf[0] /= wchar_tByteWidth;
// Verify that pascal strings aren't too large.
- if (GetStringLength() > 256 && Complain) {
- PP.Diag(StringToks[0].getLocation(), diag::err_pascal_string_too_long)
- << SourceRange(StringToks[0].getLocation(),
- StringToks[NumStringToks-1].getLocation());
+ if (GetStringLength() > 256) {
+ if (Diags)
+ Diags->Report(FullSourceLoc(StringToks[0].getLocation(), SM),
+ diag::err_pascal_string_too_long)
+ << SourceRange(StringToks[0].getLocation(),
+ StringToks[NumStringToks-1].getLocation());
hadError = 1;
return;
}
- } else if (Complain) {
+ } else if (Diags) {
// Complain if this string literal has too many characters.
unsigned MaxChars = Features.CPlusPlus? 65536 : Features.C99 ? 4095 : 509;
if (GetNumStringChars() > MaxChars)
- PP.Diag(StringToks[0].getLocation(), diag::ext_string_too_long)
+ Diags->Report(FullSourceLoc(StringToks[0].getLocation(), SM),
+ diag::ext_string_too_long)
<< GetNumStringChars() << MaxChars
<< (Features.CPlusPlus ? 2 : Features.C99 ? 1 : 0)
<< SourceRange(StringToks[0].getLocation(),
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=119476&r1=119475&r2=119476&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Nov 17 01:21:13 2010
@@ -83,8 +83,8 @@
TheLexer.LexFromRawLexer(TheTok);
// Use the StringLiteralParser to compute the length of the string in bytes.
- StringLiteralParser SLP(&TheTok, 1, PP, /*Complain=*/false);
- // PP.getSourceManager(), PP.getLangOptions(), PP.getTargetInfo());
+ StringLiteralParser SLP(&TheTok, 1, PP.getSourceManager(),
+ PP.getLangOptions(), PP.getTargetInfo());
unsigned TokNumBytes = SLP.GetStringLength();
// If the byte is in this token, return the location of the byte.
More information about the cfe-commits
mailing list