forked from OSchip/llvm-project
modern objective-c translator: writing objc boolean literals.
// rdar://11124775 llvm-svn: 153535
This commit is contained in:
parent
5b3939fae6
commit
307b7ad50c
|
@ -317,6 +317,7 @@ namespace {
|
||||||
Stmt *RewriteAtSelector(ObjCSelectorExpr *Exp);
|
Stmt *RewriteAtSelector(ObjCSelectorExpr *Exp);
|
||||||
Stmt *RewriteMessageExpr(ObjCMessageExpr *Exp);
|
Stmt *RewriteMessageExpr(ObjCMessageExpr *Exp);
|
||||||
Stmt *RewriteObjCStringLiteral(ObjCStringLiteral *Exp);
|
Stmt *RewriteObjCStringLiteral(ObjCStringLiteral *Exp);
|
||||||
|
Stmt *RewriteObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Exp);
|
||||||
Stmt *RewriteObjCProtocolExpr(ObjCProtocolExpr *Exp);
|
Stmt *RewriteObjCProtocolExpr(ObjCProtocolExpr *Exp);
|
||||||
Stmt *RewriteObjCTryStmt(ObjCAtTryStmt *S);
|
Stmt *RewriteObjCTryStmt(ObjCAtTryStmt *S);
|
||||||
Stmt *RewriteObjCSynchronizedStmt(ObjCAtSynchronizedStmt *S);
|
Stmt *RewriteObjCSynchronizedStmt(ObjCAtSynchronizedStmt *S);
|
||||||
|
@ -2450,6 +2451,21 @@ Stmt *RewriteModernObjC::RewriteObjCStringLiteral(ObjCStringLiteral *Exp) {
|
||||||
return cast;
|
return cast;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Stmt *RewriteModernObjC::RewriteObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Exp) {
|
||||||
|
unsigned IntSize =
|
||||||
|
static_cast<unsigned>(Context->getTypeSize(Context->IntTy));
|
||||||
|
|
||||||
|
Expr *FlagExp = IntegerLiteral::Create(*Context,
|
||||||
|
llvm::APInt(IntSize, Exp->getValue()),
|
||||||
|
Context->IntTy, Exp->getLocation());
|
||||||
|
CastExpr *cast = NoTypeInfoCStyleCastExpr(Context, Context->ObjCBuiltinBoolTy,
|
||||||
|
CK_BitCast, FlagExp);
|
||||||
|
ParenExpr *PE = new (Context) ParenExpr(Exp->getLocation(), Exp->getExprLoc(),
|
||||||
|
cast);
|
||||||
|
ReplaceStmt(Exp, PE);
|
||||||
|
return PE;
|
||||||
|
}
|
||||||
|
|
||||||
// struct objc_super { struct objc_object *receiver; struct objc_class *super; };
|
// struct objc_super { struct objc_object *receiver; struct objc_class *super; };
|
||||||
QualType RewriteModernObjC::getSuperStructType() {
|
QualType RewriteModernObjC::getSuperStructType() {
|
||||||
if (!SuperStructDecl) {
|
if (!SuperStructDecl) {
|
||||||
|
@ -4741,6 +4757,9 @@ Stmt *RewriteModernObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) {
|
||||||
|
|
||||||
if (ObjCStringLiteral *AtString = dyn_cast<ObjCStringLiteral>(S))
|
if (ObjCStringLiteral *AtString = dyn_cast<ObjCStringLiteral>(S))
|
||||||
return RewriteObjCStringLiteral(AtString);
|
return RewriteObjCStringLiteral(AtString);
|
||||||
|
|
||||||
|
if (ObjCBoolLiteralExpr *BoolLitExpr = dyn_cast<ObjCBoolLiteralExpr>(S))
|
||||||
|
return RewriteObjCBoolLiteralExpr(BoolLitExpr);
|
||||||
|
|
||||||
if (ObjCMessageExpr *MessExpr = dyn_cast<ObjCMessageExpr>(S)) {
|
if (ObjCMessageExpr *MessExpr = dyn_cast<ObjCMessageExpr>(S)) {
|
||||||
#if 0
|
#if 0
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
// RUN: %clang_cc1 -E %s -o %t.mm
|
||||||
|
// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s
|
||||||
|
// rdar://11124775
|
||||||
|
|
||||||
|
typedef signed char BOOL;
|
||||||
|
|
||||||
|
BOOL yes() {
|
||||||
|
return __objc_yes;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL no() {
|
||||||
|
return __objc_no;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL which (int flag) {
|
||||||
|
return flag ? yes() : no();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
which (__objc_yes);
|
||||||
|
which (__objc_no);
|
||||||
|
return __objc_yes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// CHECK: return ((signed char)1);
|
||||||
|
// CHECK: return ((signed char)0);
|
||||||
|
// CHECK: which (((signed char)1));
|
||||||
|
// CHECK: which (((signed char)0));
|
||||||
|
// CHECK: return ((signed char)1);
|
|
@ -0,0 +1,23 @@
|
||||||
|
// RUN: %clang_cc1 -x objective-c++ -fms-extensions -rewrite-objc %s -o %t-rw.cpp
|
||||||
|
// RUN: %clang_cc1 -fsyntax-only -D"__declspec(X)=" %t-rw.cpp
|
||||||
|
// rdar://11124775
|
||||||
|
|
||||||
|
typedef signed char BOOL;
|
||||||
|
|
||||||
|
BOOL yes() {
|
||||||
|
return __objc_yes;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL no() {
|
||||||
|
return __objc_no;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL which (int flag) {
|
||||||
|
return flag ? yes() : no();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
which (__objc_yes);
|
||||||
|
which (__objc_no);
|
||||||
|
return __objc_yes;
|
||||||
|
}
|
Loading…
Reference in New Issue