diff options
| author | Benjamin Kramer <benny.kra@googlemail.com> | 2014-02-25 12:26:11 +0000 |
|---|---|---|
| committer | Benjamin Kramer <benny.kra@googlemail.com> | 2014-02-25 12:26:11 +0000 |
| commit | fc188424376671277266f2c4fb5e37498b512bfb (patch) | |
| tree | a8b57e2748ac74ab094fa158836fb3be56e3b061 /clang/lib/Rewrite/Frontend/RewriteObjC.cpp | |
| parent | 98aa08c0e97c40f955c0ea4bf28e456d3d3ad839 (diff) | |
| download | bcm5719-llvm-fc188424376671277266f2c4fb5e37498b512bfb.tar.gz bcm5719-llvm-fc188424376671277266f2c4fb5e37498b512bfb.zip | |
RewriteObjC: Factor string literal creation into a helper and make sure it gets a proper constant array type.
No change in output.
llvm-svn: 202146
Diffstat (limited to 'clang/lib/Rewrite/Frontend/RewriteObjC.cpp')
| -rw-r--r-- | clang/lib/Rewrite/Frontend/RewriteObjC.cpp | 43 |
1 files changed, 14 insertions, 29 deletions
diff --git a/clang/lib/Rewrite/Frontend/RewriteObjC.cpp b/clang/lib/Rewrite/Frontend/RewriteObjC.cpp index b7f54a8c8d3..036b2c88aee 100644 --- a/clang/lib/Rewrite/Frontend/RewriteObjC.cpp +++ b/clang/lib/Rewrite/Frontend/RewriteObjC.cpp @@ -501,6 +501,14 @@ namespace { return CStyleCastExpr::Create(*Ctx, Ty, VK_RValue, Kind, E, 0, TInfo, SourceLocation(), SourceLocation()); } + + StringLiteral *getStringLiteral(StringRef Str) { + QualType StrType = Context->getConstantArrayType( + Context->CharTy, llvm::APInt(32, Str.size() + 1), ArrayType::Normal, + 0); + return StringLiteral::Create(*Context, Str, StringLiteral::Ascii, + /*Pascal=*/false, StrType, SourceLocation()); + } }; class RewriteObjCFragileABI : public RewriteObjC { @@ -2012,12 +2020,9 @@ Stmt *RewriteObjC::RewriteObjCThrowStmt(ObjCAtThrowStmt *S) { Stmt *RewriteObjC::RewriteAtEncode(ObjCEncodeExpr *Exp) { // Create a new string expression. - QualType StrType = Context->getPointerType(Context->CharTy); std::string StrEncoding; Context->getObjCEncodingForType(Exp->getEncodedType(), StrEncoding); - Expr *Replacement = StringLiteral::Create(*Context, StrEncoding, - StringLiteral::Ascii, false, - StrType, SourceLocation()); + Expr *Replacement = getStringLiteral(StrEncoding); ReplaceStmt(Exp, Replacement); // Replace this subexpr in the parent. @@ -2031,11 +2036,7 @@ Stmt *RewriteObjC::RewriteAtSelector(ObjCSelectorExpr *Exp) { assert(SelGetUidFunctionDecl && "Can't find sel_registerName() decl"); // Create a call to sel_registerName("selName"). SmallVector<Expr*, 8> SelExprs; - QualType argType = Context->getPointerType(Context->CharTy); - SelExprs.push_back(StringLiteral::Create(*Context, - Exp->getSelector().getAsString(), - StringLiteral::Ascii, false, - argType, SourceLocation())); + SelExprs.push_back(getStringLiteral(Exp->getSelector().getAsString())); CallExpr *SelExp = SynthesizeCallToFunctionDecl(SelGetUidFunctionDecl, &SelExprs[0], SelExprs.size()); ReplaceStmt(Exp, SelExp); @@ -2717,11 +2718,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, // (id)class_getSuperclass((Class)objc_getClass("CurrentClass")) SmallVector<Expr*, 8> ClsExprs; - QualType argType = Context->getPointerType(Context->CharTy); - ClsExprs.push_back(StringLiteral::Create(*Context, - ClassDecl->getIdentifier()->getName(), - StringLiteral::Ascii, false, - argType, SourceLocation())); + ClsExprs.push_back(getStringLiteral(ClassDecl->getIdentifier()->getName())); CallExpr *Cls = SynthesizeCallToFunctionDecl(GetMetaClassFunctionDecl, &ClsExprs[0], ClsExprs.size(), @@ -2791,14 +2788,10 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, case ObjCMessageExpr::Class: { SmallVector<Expr*, 8> ClsExprs; - QualType argType = Context->getPointerType(Context->CharTy); ObjCInterfaceDecl *Class = Exp->getClassReceiver()->getAs<ObjCObjectType>()->getInterface(); IdentifierInfo *clsName = Class->getIdentifier(); - ClsExprs.push_back(StringLiteral::Create(*Context, - clsName->getName(), - StringLiteral::Ascii, false, - argType, SourceLocation())); + ClsExprs.push_back(getStringLiteral(clsName->getName())); CallExpr *Cls = SynthesizeCallToFunctionDecl(GetClassFunctionDecl, &ClsExprs[0], ClsExprs.size(), @@ -2826,11 +2819,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, // (id)class_getSuperclass((Class)objc_getClass("CurrentClass")) SmallVector<Expr*, 8> ClsExprs; - QualType argType = Context->getPointerType(Context->CharTy); - ClsExprs.push_back(StringLiteral::Create(*Context, - ClassDecl->getIdentifier()->getName(), - StringLiteral::Ascii, false, argType, - SourceLocation())); + ClsExprs.push_back(getStringLiteral(ClassDecl->getIdentifier()->getName())); CallExpr *Cls = SynthesizeCallToFunctionDecl(GetClassFunctionDecl, &ClsExprs[0], ClsExprs.size(), @@ -2911,11 +2900,7 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, // Create a call to sel_registerName("selName"), it will be the 2nd argument. SmallVector<Expr*, 8> SelExprs; - QualType argType = Context->getPointerType(Context->CharTy); - SelExprs.push_back(StringLiteral::Create(*Context, - Exp->getSelector().getAsString(), - StringLiteral::Ascii, false, - argType, SourceLocation())); + SelExprs.push_back(getStringLiteral(Exp->getSelector().getAsString())); CallExpr *SelExp = SynthesizeCallToFunctionDecl(SelGetUidFunctionDecl, &SelExprs[0], SelExprs.size(), StartLoc, |

