]> granicus.if.org Git - clang/commitdiff
Add an ExternalASTSource hook to complete a type on demand.
authorJohn McCall <rjmccall@apple.com>
Tue, 16 Nov 2010 01:44:35 +0000 (01:44 +0000)
committerJohn McCall <rjmccall@apple.com>
Tue, 16 Nov 2010 01:44:35 +0000 (01:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119316 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ExternalASTSource.h
lib/Sema/SemaType.cpp

index 39363787b4cab933c3b7d0ef3042c9850eac47c8..557f8ab36c2d69e85a044c32b7cf471341ae2905 100644 (file)
@@ -34,6 +34,7 @@ class ExternalSemaSource; // layering violation required for downcasting
 class NamedDecl;
 class Selector;
 class Stmt;
+class TagDecl;
 
 /// \brief Abstract interface for external sources of AST nodes.
 ///
@@ -142,6 +143,10 @@ public:
     return FindExternalLexicalDecls(DC, DeclTy::classofKind, Result);
   }
 
+  /// \brief Gives the external AST source an opportunity to complete
+  /// an incomplete type.
+  virtual void CompleteType(TagDecl *Tag) {}
+
   /// \brief Notify ExternalASTSource that we started deserialization of
   /// a decl or type so until FinishedDeserializing is called there may be
   /// decls that are initializing. Must be paired with FinishedDeserializing.
index 6e857a7f3b04e748da6560211e611ab69a7a6324..fe0916e78708dfb21954ee28b24900ce74bf7b69 100644 (file)
@@ -2227,16 +2227,19 @@ bool Sema::RequireCompleteType(SourceLocation Loc, QualType T,
   if (diag == 0)
     return true;
 
-  const TagType *Tag = 0;
-  if (const RecordType *Record = T->getAs<RecordType>())
-    Tag = Record;
-  else if (const EnumType *Enum = T->getAs<EnumType>())
-    Tag = Enum;
+  const TagType *Tag = T->getAs<TagType>();
 
   // Avoid diagnosing invalid decls as incomplete.
   if (Tag && Tag->getDecl()->isInvalidDecl())
     return true;
 
+  // Give the external AST source a chance to complete the type.
+  if (Tag && Tag->getDecl()->hasExternalLexicalStorage()) {
+    Context.getExternalSource()->CompleteType(Tag->getDecl());
+    if (!Tag->isIncompleteType())
+      return false;
+  }
+
   // We have an incomplete type. Produce a diagnostic.
   Diag(Loc, PD) << T;