[cfe-commits] r148831 - /cfe/trunk/lib/AST/ASTImporter.cpp

Douglas Gregor dgregor at apple.com
Tue Jan 24 10:36:05 PST 2012


Author: dgregor
Date: Tue Jan 24 12:36:04 2012
New Revision: 148831

URL: http://llvm.org/viewvc/llvm-project?rev=148831&view=rev
Log:
When importing a RecordDecl as a DeclContext, make sure that we pull
in the definition as well.

Modified:
    cfe/trunk/lib/AST/ASTImporter.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=148831&r1=148830&r2=148831&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Jan 24 12:36:04 2012
@@ -78,7 +78,7 @@
     QualType VisitObjCObjectType(const ObjCObjectType *T);
     QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T);
                             
-    // Importing declarations
+    // Importing declarations                            
     bool ImportDeclParts(NamedDecl *D, DeclContext *&DC, 
                          DeclContext *&LexicalDC, DeclarationName &Name, 
                          SourceLocation &Loc);
@@ -86,8 +86,22 @@
     void ImportDeclarationNameLoc(const DeclarationNameInfo &From,
                                   DeclarationNameInfo& To);
     void ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
+                            
+    /// \brief What we should import from the definition.
+    enum ImportDefinitionKind { 
+      /// \brief Import the default subset of the definition, which might be
+      /// nothing (if minimal import is set) or might be everything (if minimal
+      /// import is not set).
+      IDK_Default,
+      /// \brief Import everything.
+      IDK_Everything,
+      /// \brief Import only the bare bones needed to establish a valid
+      /// DeclContext.
+      IDK_Basic
+    };
+
     bool ImportDefinition(RecordDecl *From, RecordDecl *To, 
-                          bool ForceImport = false);
+                          ImportDefinitionKind Kind = IDK_Default);
     bool ImportDefinition(EnumDecl *From, EnumDecl *To,
                           bool ForceImport = false);
     bool ImportDefinition(ObjCInterfaceDecl *From, ObjCInterfaceDecl *To,
@@ -1793,9 +1807,13 @@
 }
 
 bool ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To, 
-                                       bool ForceImport) {
-  if (To->getDefinition() || To->isBeingDefined())
+                                       ImportDefinitionKind Kind) {
+  if (To->getDefinition() || To->isBeingDefined()) {
+    if (Kind == IDK_Everything)
+      ImportDeclContext(From, /*ForceImport=*/true);
+    
     return false;
+  }
   
   To->startDefinition();
   
@@ -1874,7 +1892,10 @@
       ToCXX->setBases(Bases.data(), Bases.size());
   }
   
-  ImportDeclContext(From, ForceImport);
+  if (Kind == IDK_Everything || 
+      (Kind == IDK_Default && !Importer.isMinimalImport()))
+    ImportDeclContext(From, /*ForceImport=*/true);
+  
   To->completeDefinition();
   return false;
 }
@@ -2350,7 +2371,7 @@
   
   Importer.Imported(D, D2);
 
-  if (D->isCompleteDefinition() && ImportDefinition(D, D2))
+  if (D->isCompleteDefinition() && ImportDefinition(D, D2, IDK_Default))
     return 0;
   
   return D2;
@@ -4167,7 +4188,16 @@
   if (!FromDC)
     return FromDC;
 
-  return cast_or_null<DeclContext>(Import(cast<Decl>(FromDC)));
+  DeclContext *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC)));
+  if (RecordDecl *ToRecord = dyn_cast_or_null<RecordDecl>(ToDC)) {
+    // When we're using a record declaration as a context, we need it to have
+    // a definition.
+    ASTNodeImporter Importer(*this);
+    Importer.ImportDefinition(cast<RecordDecl>(FromDC), ToRecord,
+                              ASTNodeImporter::IDK_Basic);
+  }
+  
+  return ToDC;
 }
 
 Expr *ASTImporter::Import(Expr *FromE) {
@@ -4408,7 +4438,7 @@
     if (RecordDecl *ToRecord = dyn_cast<RecordDecl>(To)) {
       if (!ToRecord->getDefinition()) {
         Importer.ImportDefinition(cast<RecordDecl>(FromDC), ToRecord, 
-                                  /*ForceImport=*/true);
+                                  ASTNodeImporter::IDK_Everything);
         return;
       }      
     }





More information about the cfe-commits mailing list