From: Anders Carlsson Date: Thu, 14 Apr 2011 00:40:03 +0000 (+0000) Subject: Add a flag to StringLiteral to keep track of whether the string is a pascal string... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3e2193ce5feb2feb092e5ae615e85148e06e9fd2;p=clang Add a flag to StringLiteral to keep track of whether the string is a pascal string or not. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129488 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index a6c3d49a2f..ef677610e6 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -1135,9 +1135,12 @@ public: /// In this case, getByteLength() will return 6, but the string literal will /// have type "char[2]". class StringLiteral : public Expr { + friend class ASTStmtReader; + const char *StrData; unsigned ByteLength; bool IsWide; + bool IsPascal; unsigned NumConcatenated; SourceLocation TokLocs[1]; @@ -1148,14 +1151,15 @@ public: /// This is the "fully general" constructor that allows representation of /// strings formed from multiple concatenated tokens. static StringLiteral *Create(ASTContext &C, const char *StrData, - unsigned ByteLength, bool Wide, QualType Ty, + unsigned ByteLength, bool Wide, bool Pascal, + QualType Ty, const SourceLocation *Loc, unsigned NumStrs); /// Simple constructor for string literals made from one token. static StringLiteral *Create(ASTContext &C, const char *StrData, - unsigned ByteLength, - bool Wide, QualType Ty, SourceLocation Loc) { - return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1); + unsigned ByteLength, bool Wide, + bool Pascal, QualType Ty, SourceLocation Loc) { + return Create(C, StrData, ByteLength, Wide, Pascal, Ty, &Loc, 1); } /// \brief Construct an empty string literal. @@ -1171,8 +1175,8 @@ public: void setString(ASTContext &C, llvm::StringRef Str); bool isWide() const { return IsWide; } - void setWide(bool W) { IsWide = W; } - + bool isPascal() const { return IsPascal; } + bool containsNonAsciiOrNull() const { llvm::StringRef Str = getString(); for (unsigned i = 0, e = Str.size(); i != e; ++i) diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 59de3fe6ee..259c39c7d8 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -511,7 +511,7 @@ double FloatingLiteral::getValueAsApproximateDouble() const { StringLiteral *StringLiteral::Create(ASTContext &C, const char *StrData, unsigned ByteLength, bool Wide, - QualType Ty, + bool Pascal, QualType Ty, const SourceLocation *Loc, unsigned NumStrs) { // Allocate enough space for the StringLiteral plus an array of locations for @@ -527,6 +527,7 @@ StringLiteral *StringLiteral::Create(ASTContext &C, const char *StrData, SL->StrData = AStrData; SL->ByteLength = ByteLength; SL->IsWide = Wide; + SL->IsPascal = Pascal; SL->TokLocs[0] = Loc[0]; SL->NumConcatenated = NumStrs; diff --git a/lib/Rewrite/RewriteObjC.cpp b/lib/Rewrite/RewriteObjC.cpp index ff4c5e9152..6ab96effe3 100644 --- a/lib/Rewrite/RewriteObjC.cpp +++ b/lib/Rewrite/RewriteObjC.cpp @@ -2111,7 +2111,8 @@ Stmt *RewriteObjC::RewriteAtEncode(ObjCEncodeExpr *Exp) { std::string StrEncoding; Context->getObjCEncodingForType(Exp->getEncodedType(), StrEncoding); Expr *Replacement = StringLiteral::Create(*Context,StrEncoding.c_str(), - StrEncoding.length(), false,StrType, + StrEncoding.length(), + false, false, StrType, SourceLocation()); ReplaceStmt(Exp, Replacement); @@ -2130,7 +2131,8 @@ Stmt *RewriteObjC::RewriteAtSelector(ObjCSelectorExpr *Exp) { SelExprs.push_back(StringLiteral::Create(*Context, Exp->getSelector().getAsString().c_str(), Exp->getSelector().getAsString().size(), - false, argType, SourceLocation())); + false, false, argType, + SourceLocation())); CallExpr *SelExp = SynthesizeCallToFunctionDecl(SelGetUidFunctionDecl, &SelExprs[0], SelExprs.size()); ReplaceStmt(Exp, SelExp); @@ -2796,7 +2798,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, ClsExprs.push_back(StringLiteral::Create(*Context, ClassDecl->getIdentifier()->getNameStart(), ClassDecl->getIdentifier()->getLength(), - false, argType, SourceLocation())); + false, false, argType, SourceLocation())); CallExpr *Cls = SynthesizeCallToFunctionDecl(GetMetaClassFunctionDecl, &ClsExprs[0], ClsExprs.size(), @@ -2875,8 +2877,8 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, ClsExprs.push_back(StringLiteral::Create(*Context, clsName->getNameStart(), clsName->getLength(), - false, argType, - SourceLocation())); + false, false, + argType, SourceLocation())); CallExpr *Cls = SynthesizeCallToFunctionDecl(GetClassFunctionDecl, &ClsExprs[0], ClsExprs.size(), @@ -2907,7 +2909,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, ClsExprs.push_back(StringLiteral::Create(*Context, ClassDecl->getIdentifier()->getNameStart(), ClassDecl->getIdentifier()->getLength(), - false, argType, SourceLocation())); + false, false, argType, SourceLocation())); CallExpr *Cls = SynthesizeCallToFunctionDecl(GetClassFunctionDecl, &ClsExprs[0], ClsExprs.size(), @@ -2989,7 +2991,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, SelExprs.push_back(StringLiteral::Create(*Context, Exp->getSelector().getAsString().c_str(), Exp->getSelector().getAsString().size(), - false, argType, SourceLocation())); + false, false, argType, SourceLocation())); CallExpr *SelExp = SynthesizeCallToFunctionDecl(SelGetUidFunctionDecl, &SelExprs[0], SelExprs.size(), StartLoc, diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index ac1128b361..eb84cff999 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -786,7 +786,7 @@ Sema::ActOnStringLiteral(const Token *StringToks, unsigned NumStringToks) { // Pass &StringTokLocs[0], StringTokLocs.size() to factory! return Owned(StringLiteral::Create(Context, Literal.GetString(), Literal.GetStringLength(), - Literal.AnyWide, StrTy, + Literal.AnyWide, Literal.Pascal, StrTy, &StringTokLocs[0], StringTokLocs.size())); } diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 3cc9754b06..c769b856cd 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -62,7 +62,8 @@ ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs, // Create the aggregate string with the appropriate content and location // information. - S = StringLiteral::Create(Context, &StrBuf[0], StrBuf.size(), false, + S = StringLiteral::Create(Context, &StrBuf[0], StrBuf.size(), + /*Wide=*/false, /*Pascal=*/false, Context.getPointerType(Context.CharTy), &StrLocs[0], StrLocs.size()); } diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp index 70104cb18b..557cb38195 100644 --- a/lib/Serialization/ASTReaderStmt.cpp +++ b/lib/Serialization/ASTReaderStmt.cpp @@ -468,7 +468,8 @@ void ASTStmtReader::VisitStringLiteral(StringLiteral *E) { assert(Record[Idx] == E->getNumConcatenated() && "Wrong number of concatenated tokens!"); ++Idx; - E->setWide(Record[Idx++]); + E->IsWide = Record[Idx++]; + E->IsPascal = Record[Idx++]; // Read string data llvm::SmallString<16> Str(&Record[Idx], &Record[Idx] + Len); diff --git a/lib/Serialization/ASTWriterStmt.cpp b/lib/Serialization/ASTWriterStmt.cpp index a66b550385..875d662929 100644 --- a/lib/Serialization/ASTWriterStmt.cpp +++ b/lib/Serialization/ASTWriterStmt.cpp @@ -425,6 +425,7 @@ void ASTStmtWriter::VisitStringLiteral(StringLiteral *E) { Record.push_back(E->getByteLength()); Record.push_back(E->getNumConcatenated()); Record.push_back(E->isWide()); + Record.push_back(E->isPascal()); // FIXME: String data should be stored as a blob at the end of the // StringLiteral. However, we can't do so now because we have no // provision for coping with abbreviations when we're jumping around