[cfe-commits] r106404 - in /cfe/trunk: include/clang/AST/DeclCXX.h lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHWriterDecl.cpp test/PCH/cxx-using.cpp test/PCH/cxx-using.h

Argyrios Kyrtzidis akyrtzi at gmail.com
Sun Jun 20 07:40:59 PDT 2010


Author: akirtzidis
Date: Sun Jun 20 09:40:59 2010
New Revision: 106404

URL: http://llvm.org/viewvc/llvm-project?rev=106404&view=rev
Log:
Support PCH emitting/reading of using declarations.

Added:
    cfe/trunk/test/PCH/cxx-using.cpp
    cfe/trunk/test/PCH/cxx-using.h
Modified:
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
    cfe/trunk/lib/Frontend/PCHWriterDecl.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=106404&r1=106403&r2=106404&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Sun Jun 20 09:40:59 2010
@@ -1854,9 +1854,12 @@
 
   UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using,
                   NamedDecl *Target)
-    : NamedDecl(UsingShadow, DC, Loc, Target->getDeclName()),
+    : NamedDecl(UsingShadow, DC, Loc, DeclarationName()),
       Underlying(Target), Using(Using) {
-    IdentifierNamespace = Target->getIdentifierNamespace();
+    if (Target) {
+      setDeclName(Target->getDeclName());
+      IdentifierNamespace = Target->getIdentifierNamespace();
+    }
     setImplicit();
   }
 
@@ -1873,7 +1876,11 @@
 
   /// \brief Sets the underlying declaration which has been brought into the
   /// local scope.
-  void setTargetDecl(NamedDecl* ND) { Underlying = ND; }
+  void setTargetDecl(NamedDecl* ND) {
+    assert(ND && "Target decl is null!");
+    Underlying = ND;
+    IdentifierNamespace = ND->getIdentifierNamespace();
+  }
 
   /// \brief Gets the using declaration to which this declaration is tied.
   UsingDecl *getUsingDecl() const { return Using; }

Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=106404&r1=106403&r2=106404&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Sun Jun 20 09:40:59 2010
@@ -76,8 +76,8 @@
     void VisitClassTemplateDecl(ClassTemplateDecl *D);
     void visitFunctionTemplateDecl(FunctionTemplateDecl *D);
     void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
-    void VisitUsing(UsingDecl *D);
-    void VisitUsingShadow(UsingShadowDecl *D);
+    void VisitUsingDecl(UsingDecl *D);
+    void VisitUsingShadowDecl(UsingShadowDecl *D);
     void VisitLinkageSpecDecl(LinkageSpecDecl *D);
     void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
     void VisitAccessSpecDecl(AccessSpecDecl *D);
@@ -505,7 +505,7 @@
   D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
 }
 
-void PCHDeclReader::VisitUsing(UsingDecl *D) {
+void PCHDeclReader::VisitUsingDecl(UsingDecl *D) {
   VisitNamedDecl(D);
   D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
   D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
@@ -521,7 +521,7 @@
   D->setTypeName(Record[Idx++]);
 }
 
-void PCHDeclReader::VisitUsingShadow(UsingShadowDecl *D) {
+void PCHDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
   VisitNamedDecl(D);
   D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
   D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));

Modified: cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterDecl.cpp?rev=106404&r1=106403&r2=106404&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterDecl.cpp Sun Jun 20 09:40:59 2010
@@ -77,8 +77,8 @@
     void VisitClassTemplateDecl(ClassTemplateDecl *D);
     void visitFunctionTemplateDecl(FunctionTemplateDecl *D);
     void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
-    void VisitUsing(UsingDecl *D);
-    void VisitUsingShadow(UsingShadowDecl *D);
+    void VisitUsingDecl(UsingDecl *D);
+    void VisitUsingShadowDecl(UsingShadowDecl *D);
     void VisitLinkageSpecDecl(LinkageSpecDecl *D);
     void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
     void VisitAccessSpecDecl(AccessSpecDecl *D);
@@ -521,7 +521,7 @@
   Code = pch::DECL_NAMESPACE_ALIAS;
 }
 
-void PCHDeclWriter::VisitUsing(UsingDecl *D) {
+void PCHDeclWriter::VisitUsingDecl(UsingDecl *D) {
   VisitNamedDecl(D);
   Writer.AddSourceRange(D->getNestedNameRange(), Record);
   Writer.AddSourceLocation(D->getUsingLocation(), Record);
@@ -534,7 +534,7 @@
   Code = pch::DECL_USING;
 }
 
-void PCHDeclWriter::VisitUsingShadow(UsingShadowDecl *D) {
+void PCHDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) {
   VisitNamedDecl(D);
   Writer.AddDeclRef(D->getTargetDecl(), Record);
   Writer.AddDeclRef(D->getUsingDecl(), Record);

Added: cfe/trunk/test/PCH/cxx-using.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/cxx-using.cpp?rev=106404&view=auto
==============================================================================
--- cfe/trunk/test/PCH/cxx-using.cpp (added)
+++ cfe/trunk/test/PCH/cxx-using.cpp Sun Jun 20 09:40:59 2010
@@ -0,0 +1,15 @@
+// Test this without pch.
+// RUN: %clang_cc1 -include %S/cxx-using.h -fsyntax-only -verify %s
+
+// Test with pch.
+// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-using.h
+// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s 
+
+void m() {
+    D s;   // expected-note {{candidate function}}
+    s.f(); // expected-error {{no matching member}}
+}
+
+
+
+// expected-note {{candidate function}}

Added: cfe/trunk/test/PCH/cxx-using.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/cxx-using.h?rev=106404&view=auto
==============================================================================
--- cfe/trunk/test/PCH/cxx-using.h (added)
+++ cfe/trunk/test/PCH/cxx-using.h Sun Jun 20 09:40:59 2010
@@ -0,0 +1,16 @@
+// Header for PCH test cxx-using.cpp
+
+
+
+
+
+
+struct B {
+    void f(char c);
+};
+
+struct D : B 
+{
+    using B::f;
+    void f(int);
+};





More information about the cfe-commits mailing list