Selector LoadSel = Context->Selectors.getSelector(0, &II);
return OD->getClassMethod(LoadSel) != 0;
}
+
+ 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());
+ }
};
}
Stmt *RewriteModernObjC::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.
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);
// Synthesize a call to objc_msgSend().
SmallVector<Expr*, 4> MsgExprs;
SmallVector<Expr*, 4> ClsExprs;
- QualType argType = Context->getPointerType(Context->CharTy);
// Create a call to objc_getClass("<BoxingClass>"). It will be the 1st argument.
ObjCMethodDecl *BoxingMethod = Exp->getBoxingMethod();
ObjCInterfaceDecl *BoxingClass = BoxingMethod->getClassInterface();
IdentifierInfo *clsName = BoxingClass->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(),
// Create a call to sel_registerName("<BoxingMethod>:"), etc.
// it will be the 2nd argument.
SmallVector<Expr*, 4> SelExprs;
- SelExprs.push_back(StringLiteral::Create(*Context,
- BoxingMethod->getSelector().getAsString(),
- StringLiteral::Ascii, false,
- argType, SourceLocation()));
+ SelExprs.push_back(
+ getStringLiteral(BoxingMethod->getSelector().getAsString()));
CallExpr *SelExp = SynthesizeCallToFunctionDecl(SelGetUidFunctionDecl,
&SelExprs[0], SelExprs.size(),
StartLoc, EndLoc);
// Synthesize a call to objc_msgSend().
SmallVector<Expr*, 32> MsgExprs;
SmallVector<Expr*, 4> ClsExprs;
- QualType argType = Context->getPointerType(Context->CharTy);
QualType expType = Exp->getType();
// Create a call to objc_getClass("NSArray"). It will be th 1st argument.
expType->getPointeeType()->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(),
// it will be the 2nd argument.
SmallVector<Expr*, 4> SelExprs;
ObjCMethodDecl *ArrayMethod = Exp->getArrayWithObjectsMethod();
- SelExprs.push_back(StringLiteral::Create(*Context,
- ArrayMethod->getSelector().getAsString(),
- StringLiteral::Ascii, false,
- argType, SourceLocation()));
+ SelExprs.push_back(
+ getStringLiteral(ArrayMethod->getSelector().getAsString()));
CallExpr *SelExp = SynthesizeCallToFunctionDecl(SelGetUidFunctionDecl,
&SelExprs[0], SelExprs.size(),
StartLoc, EndLoc);
// Synthesize a call to objc_msgSend().
SmallVector<Expr*, 32> MsgExprs;
SmallVector<Expr*, 4> ClsExprs;
- QualType argType = Context->getPointerType(Context->CharTy);
QualType expType = Exp->getType();
// Create a call to objc_getClass("NSArray"). It will be th 1st argument.
expType->getPointeeType()->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(),
// it will be the 2nd argument.
SmallVector<Expr*, 4> SelExprs;
ObjCMethodDecl *DictMethod = Exp->getDictWithObjectsMethod();
- SelExprs.push_back(StringLiteral::Create(*Context,
- DictMethod->getSelector().getAsString(),
- StringLiteral::Ascii, false,
- argType, SourceLocation()));
+ SelExprs.push_back(getStringLiteral(DictMethod->getSelector().getAsString()));
CallExpr *SelExp = SynthesizeCallToFunctionDecl(SelGetUidFunctionDecl,
&SelExprs[0], SelExprs.size(),
StartLoc, EndLoc);
// (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()));
// (Class)objc_getClass("CurrentClass")
CallExpr *Cls = SynthesizeCallToFunctionDecl(GetMetaClassFunctionDecl,
&ClsExprs[0],
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(),
// (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()));
// (Class)objc_getClass("CurrentClass")
CallExpr *Cls = SynthesizeCallToFunctionDecl(GetClassFunctionDecl,
&ClsExprs[0],
// 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,
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 {
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.
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);
// (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(),
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(),
// (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(),
// 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,