[cfe-commits] r107312 - in /cfe/trunk: lib/Rewrite/RewriteObjC.cpp test/Rewriter/rewrite-elaborated-type.mm
Daniel Dunbar
daniel at zuster.org
Wed Jun 30 12:16:54 PDT 2010
Author: ddunbar
Date: Wed Jun 30 14:16:53 2010
New Revision: 107312
URL: http://llvm.org/viewvc/llvm-project?rev=107312&view=rev
Log:
Rewriter: Use the appropriate printing context instead of the default
constructed one -- this is necessary to ensure types get printed correctly.
Modified:
cfe/trunk/lib/Rewrite/RewriteObjC.cpp
cfe/trunk/test/Rewriter/rewrite-elaborated-type.mm
Modified: cfe/trunk/lib/Rewrite/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteObjC.cpp?rev=107312&r1=107311&r2=107312&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteObjC.cpp Wed Jun 30 14:16:53 2010
@@ -268,6 +268,8 @@
void RewriteMethodDeclaration(ObjCMethodDecl *Method);
void RewriteProperty(ObjCPropertyDecl *prop);
void RewriteFunctionDecl(FunctionDecl *FD);
+ void RewriteBlockPointerType(std::string& Str, QualType Type);
+ void RewriteBlockPointerTypeVariable(std::string& Str, ValueDecl *VD);
void RewriteBlockLiteralFunctionDecl(FunctionDecl *FD);
void RewriteObjCQualifiedInterfaceTypes(Decl *Dcl);
void RewriteTypeOfDecl(VarDecl *VD);
@@ -835,11 +837,12 @@
Getr += ")"; // close the precedence "scope" for "*".
// Now, emit the argument types (if any).
- if (const FunctionProtoType *FT = dyn_cast<FunctionProtoType>(FPRetType)) {
+ if (const FunctionProtoType *FT = dyn_cast<FunctionProtoType>(FPRetType)){
Getr += "(";
for (unsigned i = 0, e = FT->getNumArgs(); i != e; ++i) {
if (i) Getr += ", ";
- std::string ParamStr = FT->getArgType(i).getAsString();
+ std::string ParamStr = FT->getArgType(i).getAsString(
+ Context->PrintingPolicy);
Getr += ParamStr;
}
if (FT->isVariadic()) {
@@ -1047,11 +1050,12 @@
else if (const BlockPointerType *BPT = retType->getAs<BlockPointerType>())
PointeeTy = BPT->getPointeeType();
if ((FPRetType = PointeeTy->getAs<FunctionType>())) {
- ResultStr += FPRetType->getResultType().getAsString();
+ ResultStr += FPRetType->getResultType().getAsString(
+ Context->PrintingPolicy);
ResultStr += "(*";
}
} else
- ResultStr += T.getAsString();
+ ResultStr += T.getAsString(Context->PrintingPolicy);
}
void RewriteObjC::RewriteObjCMethodDecl(ObjCMethodDecl *OMD,
@@ -1107,10 +1111,11 @@
ResultStr += " *";
}
else
- ResultStr += Context->getObjCClassType().getAsString();
+ ResultStr += Context->getObjCClassType().getAsString(
+ Context->PrintingPolicy);
ResultStr += " self, ";
- ResultStr += Context->getObjCSelType().getAsString();
+ ResultStr += Context->getObjCSelType().getAsString(Context->PrintingPolicy);
ResultStr += " _cmd";
// Method arguments.
@@ -1144,7 +1149,8 @@
ResultStr += "(";
for (unsigned i = 0, e = FT->getNumArgs(); i != e; ++i) {
if (i) ResultStr += ", ";
- std::string ParamStr = FT->getArgType(i).getAsString();
+ std::string ParamStr = FT->getArgType(i).getAsString(
+ Context->PrintingPolicy);
ResultStr += ParamStr;
}
if (FT->isVariadic()) {
@@ -1560,7 +1566,7 @@
// Simply use 'id' for all qualified types.
elementTypeAsString = "id";
else
- elementTypeAsString = ElementType.getAsString();
+ elementTypeAsString = ElementType.getAsString(Context->PrintingPolicy);
buf += elementTypeAsString;
buf += " ";
elementName = D->getNameAsCString();
@@ -1576,7 +1582,7 @@
// Simply use 'id' for all qualified types.
elementTypeAsString = "id";
else
- elementTypeAsString = VD->getType().getAsString();
+ elementTypeAsString = VD->getType().getAsString(Context->PrintingPolicy);
}
// struct __objcFastEnumerationState enumState = { 0 };
@@ -2275,7 +2281,7 @@
}
// FIXME. This will not work for multiple declarators; as in:
// __typeof__(a) b,c,d;
- std::string TypeAsString(QT.getAsString());
+ std::string TypeAsString(QT.getAsString(Context->PrintingPolicy));
SourceLocation DeclLoc = ND->getTypeSpecStartLoc();
const char *startBuf = SM->getCharacterData(DeclLoc);
if (ND->getInit()) {
@@ -2326,8 +2332,8 @@
RewriteObjCQualifiedInterfaceTypes(FD);
}
-static void RewriteBlockPointerType(std::string& Str, QualType Type) {
- std::string TypeString(Type.getAsString());
+void RewriteObjC::RewriteBlockPointerType(std::string& Str, QualType Type) {
+ std::string TypeString(Type.getAsString(Context->PrintingPolicy));
const char *argPtr = TypeString.c_str();
if (!strchr(argPtr, '^')) {
Str += TypeString;
@@ -2340,9 +2346,10 @@
}
// FIXME. Consolidate this routine with RewriteBlockPointerType.
-static void RewriteBlockPointerTypeVariable(std::string& Str, ValueDecl *VD) {
+void RewriteObjC::RewriteBlockPointerTypeVariable(std::string& Str,
+ ValueDecl *VD) {
QualType Type = VD->getType();
- std::string TypeString(Type.getAsString());
+ std::string TypeString(Type.getAsString(Context->PrintingPolicy));
const char *argPtr = TypeString.c_str();
int paren = 0;
while (*argPtr) {
@@ -2376,7 +2383,7 @@
if (!proto)
return;
QualType Type = proto->getResultType();
- std::string FdStr = Type.getAsString();
+ std::string FdStr = Type.getAsString(Context->PrintingPolicy);
FdStr += " ";
FdStr += FD->getNameAsCString();
FdStr += "(";
@@ -4099,7 +4106,7 @@
const FunctionType *AFT = CE->getFunctionType();
QualType RT = AFT->getResultType();
std::string StructRef = "struct " + Tag;
- std::string S = "static " + RT.getAsString() + " __" +
+ std::string S = "static " + RT.getAsString(Context->PrintingPolicy) + " __" +
funcName + "_" + "block_func_" + utostr(i);
BlockDecl *BD = CE->getBlockDecl();
Modified: cfe/trunk/test/Rewriter/rewrite-elaborated-type.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-elaborated-type.mm?rev=107312&r1=107311&r2=107312&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-elaborated-type.mm (original)
+++ cfe/trunk/test/Rewriter/rewrite-elaborated-type.mm Wed Jun 30 14:16:53 2010
@@ -2,6 +2,7 @@
// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D_Bool=bool -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
// radar 8143056
+typedef struct objc_class *Class;
typedef unsigned NSPointerFunctionsOptions;
extern "C" id NSClassFromObject(id object);
void *sel_registerName(const char *);
@@ -28,3 +29,8 @@
}
@end
+ at implementation I1
++ (struct s1 *) f0 {
+ return 0;
+}
+ at end
More information about the cfe-commits
mailing list