modern objective-c translator: rewriter linkage spec.

// rdar://11169733


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153960 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Fariborz Jahanian 2012-04-03 17:35:38 +00:00
parent 14e645557a
commit b3f904f79b
2 changed files with 45 additions and 0 deletions

View File

@ -329,6 +329,7 @@ namespace {
Stmt *RewriteBreakStmt(BreakStmt *S);
Stmt *RewriteContinueStmt(ContinueStmt *S);
void RewriteCastExpr(CStyleCastExpr *CE);
void RewriteLinkageSpec(LinkageSpecDecl *LSD);
// Block rewriting.
void RewriteBlocksInFunctionProtoType(QualType funcType, NamedDecl *D);
@ -672,6 +673,7 @@ void RewriteModernObjC::HandleTopLevelSingleDecl(Decl *D) {
if (PD->isThisDeclarationADefinition())
RewriteProtocolDecl(PD);
} else if (LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(D)) {
RewriteLinkageSpec(LSD);
// Recurse into linkage specifications
for (DeclContext::decl_iterator DI = LSD->decls_begin(),
DIEnd = LSD->decls_end();
@ -693,6 +695,12 @@ void RewriteModernObjC::HandleTopLevelSingleDecl(Decl *D) {
RewriteForwardClassDecl(DG);
continue;
}
else {
// Keep track of all interface declarations seen.
ObjCInterfacesSeen.push_back(IFace);
++DI;
continue;
}
}
if (ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>((*DI))) {
@ -1058,6 +1066,22 @@ RewriteModernObjC::RewriteForwardProtocolDecl(const llvm::SmallVector<Decl*, 8>
ReplaceText(LocStart, 0, "// ");
}
void
RewriteModernObjC::RewriteLinkageSpec(LinkageSpecDecl *LSD) {
SourceLocation LocStart = LSD->getExternLoc();
if (LocStart.isInvalid())
llvm_unreachable("Invalid extern SourceLocation");
ReplaceText(LocStart, 0, "// ");
if (!LSD->hasBraces())
return;
// FIXME. We don't rewrite well if '{' is not on same line as 'extern'.
SourceLocation LocRBrace = LSD->getRBraceLoc();
if (LocRBrace.isInvalid())
llvm_unreachable("Invalid rbrace SourceLocation");
ReplaceText(LocRBrace, 0, "// ");
}
void RewriteModernObjC::RewriteTypeIntoString(QualType T, std::string &ResultStr,
const FunctionType *&FPRetType) {
if (T->isObjCQualifiedIdType())

View File

@ -0,0 +1,21 @@
// RUN: %clang_cc1 -x objective-c++ -fms-extensions -rewrite-objc %s -o %t-rw.cpp
// RUN: %clang_cc1 -fsyntax-only -Wno-attributes -D"__declspec(X)=" %t-rw.cpp
// rdar://11169733
extern "C" __declspec(dllexport)
@interface Test @end
@implementation Test @end
extern "C" {
__declspec(dllexport)
@interface Test1 @end
@implementation Test1 @end
__declspec(dllexport)
@interface Test2 @end
@implementation Test2 @end
};