]> granicus.if.org Git - clang/commitdiff
modern objective-c translator: rewriter linkage spec.
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 3 Apr 2012 17:35:38 +0000 (17:35 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 3 Apr 2012 17:35:38 +0000 (17:35 +0000)
// rdar://11169733

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153960 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Rewrite/RewriteModernObjC.cpp
test/Rewriter/objc-modern-linkage-spec.mm [new file with mode: 0644]

index 91e89d17590131bf73f6ddf4fbfcd8ff6f6f601a..45369a95deaefc55eeba74479e70cf7c68c32a5c 100644 (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())
diff --git a/test/Rewriter/objc-modern-linkage-spec.mm b/test/Rewriter/objc-modern-linkage-spec.mm
new file mode 100644 (file)
index 0000000..028d787
--- /dev/null
@@ -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
+};
+