mirror of
https://github.com/intel/llvm.git
synced 2026-01-26 12:26:52 +08:00
Add a flag to StringLiteral to keep track of whether the string is a pascal string or not.
llvm-svn: 129488
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user