[cfe-commits] r72482 - in /cfe/trunk: include/clang/AST/Decl.h lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHWriterDecl.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaTemplate/instantiate-declref.cpp

Douglas Gregor dgregor at apple.com
Wed May 27 10:20:45 PDT 2009


Author: dgregor
Date: Wed May 27 12:20:35 2009
New Revision: 72482

URL: http://llvm.org/viewvc/llvm-project?rev=72482&view=rev
Log:
Enumeration declarations that were instantiated from an enumeration
within a template now have a link back to the enumeration from which
they were instantiated. This means that we can now find the
instantiation of an anonymous enumeration.


Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
    cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/trunk/test/SemaTemplate/instantiate-declref.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=72482&r1=72481&r2=72482&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Wed May 27 12:20:35 2009
@@ -1149,10 +1149,15 @@
   /// to for code generation purposes.  Note that the enumerator constants may
   /// have a different type than this does.
   QualType IntegerType;
-  
+
+  /// \brief If the enumeration was instantiated from an enumeration
+  /// within a class or function template, this pointer refers to the
+  /// enumeration declared within the template.
+  EnumDecl *InstantiatedFrom;
+
   EnumDecl(DeclContext *DC, SourceLocation L,
            IdentifierInfo *Id)
-    : TagDecl(Enum, TK_enum, DC, L, Id) {
+    : TagDecl(Enum, TK_enum, DC, L, Id), InstantiatedFrom(0) {
       IntegerType = QualType();
     }
 public:
@@ -1188,6 +1193,15 @@
   /// \brief Set the underlying integer type.
   void setIntegerType(QualType T) { IntegerType = T; }
 
+  /// \brief Returns the enumeration (declared within the template)
+  /// from which this enumeration type was instantiated, or NULL if
+  /// this enumeration was not instantiated from any template.
+  EnumDecl *getInstantiatedFromMemberEnum() const {
+    return InstantiatedFrom;
+  }
+
+  void setInstantiationOfMemberEnum(EnumDecl *IF) { InstantiatedFrom = IF; }
+
   static bool classof(const Decl *D) { return D->getKind() == Enum; }
   static bool classof(const EnumDecl *D) { return true; }
 };

Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=72482&r1=72481&r2=72482&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Wed May 27 12:20:35 2009
@@ -120,6 +120,7 @@
 void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
   VisitTagDecl(ED);
   ED->setIntegerType(Reader.GetType(Record[Idx++]));
+  // FIXME: C++ InstantiatedFrom
 }
 
 void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {

Modified: cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterDecl.cpp?rev=72482&r1=72481&r2=72482&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterDecl.cpp Wed May 27 12:20:35 2009
@@ -116,6 +116,7 @@
 void PCHDeclWriter::VisitEnumDecl(EnumDecl *D) {
   VisitTagDecl(D);
   Writer.AddTypeRef(D->getIntegerType(), Record);
+  // FIXME: C++ InstantiatedFrom
   Code = pch::DECL_ENUM;
 }
 

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=72482&r1=72481&r2=72482&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Wed May 27 12:20:35 2009
@@ -208,6 +208,7 @@
   EnumDecl *Enum = EnumDecl::Create(SemaRef.Context, Owner, 
                                     D->getLocation(), D->getIdentifier(),
                                     /*PrevDecl=*/0);
+  Enum->setInstantiationOfMemberEnum(D);
   Enum->setAccess(D->getAccess());
   Owner->addDecl(SemaRef.Context, Enum);
   Enum->startDefinition();
@@ -648,7 +649,9 @@
     return Ctx.getCanonicalDecl(Function->getInstantiatedFromMemberFunction())
              == Ctx.getCanonicalDecl(D);
 
-  // FIXME: Need something similar to the above for EnumDecls.
+  if (EnumDecl *Enum = dyn_cast<EnumDecl>(Other))
+    return Ctx.getCanonicalDecl(Enum->getInstantiatedFromMemberEnum())
+             == Ctx.getCanonicalDecl(D);
 
   // FIXME: How can we find instantiations of anonymous unions?
 

Modified: cfe/trunk/test/SemaTemplate/instantiate-declref.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-declref.cpp?rev=72482&r1=72481&r2=72482&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-declref.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-declref.cpp Wed May 27 12:20:35 2009
@@ -9,8 +9,7 @@
           typedef T type;
 
           static enum K1 { K1Val = sizeof(T) } Kind1;
-          // FIXME: Remove the name K2, below
-          static enum K2 { K2Val = sizeof(T)*2 } Kind2;
+          static enum { K2Val = sizeof(T)*2 } Kind2;
 
           void foo() {
             K1 k1 = K1Val;





More information about the cfe-commits mailing list