]> granicus.if.org Git - clang/commitdiff
minor refactoring of modern objc translator.
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 30 Apr 2012 19:46:53 +0000 (19:46 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 30 Apr 2012 19:46:53 +0000 (19:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155843 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Rewrite/RewriteModernObjC.cpp

index d463cb021c3c40da1ebd6adaa6b90f629c94bc85..5cd6836cc3507880197c344f99231480abfdc74f 100644 (file)
@@ -3494,6 +3494,22 @@ bool RewriteModernObjC::BufferContainsPPDirectives(const char *startBuf,
   return false;
 }
 
+static bool IsTagDefinedInsideClass(ASTContext *Context,
+                                    ObjCInterfaceDecl *IDecl, TagDecl *Tag) {
+  if (!IDecl)
+    return false;
+  SourceLocation TagLocation;
+  if (RecordDecl *RD = dyn_cast<RecordDecl>(Tag)) {
+    RD = RD->getDefinition();
+    if (!RD)
+      return false;
+    TagLocation = RD->getLocation();
+    return Context->getSourceManager().isBeforeInTranslationUnit(
+             IDecl->getLocation(), TagLocation);
+  }
+  return false;
+}
+
 /// RewriteObjCFieldDeclType - This routine rewrites a type into the buffer.
 /// It handles elaborated types, as well as enum types in the process.
 bool RewriteModernObjC::RewriteObjCFieldDeclType(QualType &Type, 
@@ -7248,11 +7264,7 @@ Stmt *RewriteModernObjC::RewriteObjCIvarRefExpr(ObjCIvarRefExpr *IV) {
 
       if (IvarT->isRecordType()) {
         RecordDecl *RD = IvarT->getAs<RecordType>()->getDecl();
-        RD = RD->getDefinition();
-        bool structIsInside = RD &&
-          Context->getSourceManager().isBeforeInTranslationUnit(
-            iFaceDecl->getDecl()->getLocation(), RD->getLocation());
-        if (structIsInside) {
+        if (IsTagDefinedInsideClass(Context, iFaceDecl->getDecl(), RD)) {
           // decltype(((Foo_IMPL*)0)->bar) *
           std::string RecName = iFaceDecl->getDecl()->getName();
           RecName += "_IMPL";