]> granicus.if.org Git - clang/commitdiff
Printing for using directives, e.g.,
authorDouglas Gregor <dgregor@apple.com>
Sat, 30 May 2009 06:31:56 +0000 (06:31 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sat, 30 May 2009 06:31:56 +0000 (06:31 +0000)
  using namespace std::debug;

Extended UsingDirectiveDecl to store the nested-name-specifier that
precedes the nominated namespace.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72614 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclCXX.h
lib/AST/DeclCXX.cpp
lib/AST/DeclPrinter.cpp
lib/Sema/SemaDeclCXX.cpp
test/Coverage/ast-printing.cpp [new file with mode: 0644]
test/Coverage/c-language-features.inc
test/Coverage/cxx-language-features.inc [new file with mode: 0644]

index 19adc6d8294893621f8695c469ebfd4937c89d70..7a5233a6af95c3ed47c22d95f1af6088431b9f30 100644 (file)
@@ -878,6 +878,14 @@ class UsingDirectiveDecl : public NamedDecl {
   /// SourceLocation - Location of 'namespace' token.
   SourceLocation NamespaceLoc;
 
+  /// \brief The source range that covers the nested-name-specifier
+  /// preceding the namespace name.
+  SourceRange QualifierRange;
+
+  /// \brief The nested-name-specifier that precedes the namespace
+  /// name, if any.
+  NestedNameSpecifier *Qualifier;
+
   /// IdentLoc - Location of nominated namespace-name identifier.
   // FIXME: We don't store location of scope specifier.
   SourceLocation IdentLoc;
@@ -898,16 +906,27 @@ class UsingDirectiveDecl : public NamedDecl {
 
   UsingDirectiveDecl(DeclContext *DC, SourceLocation L,
                      SourceLocation NamespcLoc,
+                     SourceRange QualifierRange,
+                     NestedNameSpecifier *Qualifier,
                      SourceLocation IdentLoc,
                      NamespaceDecl *Nominated,
                      DeclContext *CommonAncestor)
     : NamedDecl(Decl::UsingDirective, DC, L, getName()),
-      NamespaceLoc(NamespcLoc), IdentLoc(IdentLoc),
+      NamespaceLoc(NamespcLoc), QualifierRange(QualifierRange), 
+      Qualifier(Qualifier), IdentLoc(IdentLoc), 
       NominatedNamespace(Nominated? Nominated->getOriginalNamespace() : 0),
       CommonAncestor(CommonAncestor) {
   }
 
 public:
+  /// \brief Retrieve the source range of the nested-name-specifier
+  /// that qualifiers the namespace name.
+  SourceRange getQualifierRange() const { return QualifierRange; }
+
+  /// \brief Retrieve the nested-name-specifier that qualifies the
+  /// name of the namespace.
+  NestedNameSpecifier *getQualifier() const { return Qualifier; }
+
   /// getNominatedNamespace - Returns namespace nominated by using-directive.
   NamespaceDecl *getNominatedNamespace() { return NominatedNamespace; }
 
@@ -929,6 +948,8 @@ public:
   static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
                                     SourceLocation L,
                                     SourceLocation NamespaceLoc,
+                                    SourceRange QualifierRange,
+                                    NestedNameSpecifier *Qualifier,
                                     SourceLocation IdentLoc,
                                     NamespaceDecl *Nominated,
                                     DeclContext *CommonAncestor);
index 5b806fae7b827725e999ee363925a406c319b16e..5fb2a016b64cadc584fcd5302eaa0f85986364c4 100644 (file)
@@ -402,11 +402,13 @@ LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C,
 UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC,
                                                SourceLocation L,
                                                SourceLocation NamespaceLoc,
+                                               SourceRange QualifierRange,
+                                               NestedNameSpecifier *Qualifier,
                                                SourceLocation IdentLoc,
                                                NamespaceDecl *Used,
                                                DeclContext *CommonAncestor) {
-  return new (C) UsingDirectiveDecl(DC, L, NamespaceLoc, IdentLoc,
-                                    Used, CommonAncestor);
+  return new (C) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierRange, 
+                                    Qualifier, IdentLoc, Used, CommonAncestor);
 }
 
 NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC, 
index 6412f750ae9713f201fe60e9a1c8e454ae874adf..bfd3dca3e6d3260d03c740bd38dd0802d705a822 100644 (file)
@@ -51,12 +51,15 @@ namespace {
     void VisitFieldDecl(FieldDecl *D);
     void VisitVarDecl(VarDecl *D);
     void VisitParmVarDecl(ParmVarDecl *D);
+    void VisitOriginalParmVarDecl(OriginalParmVarDecl *D);
     void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
+    void VisitOverloadedFunctionDecl(OverloadedFunctionDecl *D);
+    void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
     void VisitNamespaceDecl(NamespaceDecl *D);
     void VisitLinkageSpecDecl(LinkageSpecDecl *D);
     void VisitTemplateDecl(TemplateDecl *D);
-    void VisitObjCClassDecl(ObjCClassDecl *D);
     void VisitObjCMethodDecl(ObjCMethodDecl *D);
+    void VisitObjCClassDecl(ObjCClassDecl *D);
     void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
     void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
     void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
@@ -402,6 +405,10 @@ void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) {
   VisitVarDecl(D);
 }
 
+void DeclPrinter::VisitOriginalParmVarDecl(OriginalParmVarDecl *D) {
+  VisitVarDecl(D);
+}
+
 void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
   Out << "__asm (";
   D->getAsmString()->printPretty(Out, Context, 0, Policy, Indentation);
@@ -411,6 +418,18 @@ void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
 //----------------------------------------------------------------------------
 // C++ declarations
 //----------------------------------------------------------------------------
+void DeclPrinter::VisitOverloadedFunctionDecl(OverloadedFunctionDecl *D) {
+  assert(false && 
+         "OverloadedFunctionDecls aren't really decls and are never printed");
+}
+
+void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
+  Out << "using namespace ";
+  if (D->getQualifier())
+    D->getQualifier()->print(Out, Policy);
+  Out << D->getNominatedNamespace()->getNameAsString();
+}
+
 void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
   Out << "namespace " << D->getNameAsString() << " {\n";
   VisitDeclContext(D);
index 0bf97f560d548392a51e1b8be95c5f0235241470..cd722fe1693167ba045cf8f27dec18e738fa535c 100644 (file)
@@ -1711,8 +1711,12 @@ Sema::DeclPtrTy Sema::ActOnUsingDirective(Scope *S,
     while (CommonAncestor && !CommonAncestor->Encloses(CurContext))
       CommonAncestor = CommonAncestor->getParent();
 
-    UDir = UsingDirectiveDecl::Create(Context, CurContext, UsingLoc,
-                                      NamespcLoc, IdentLoc,
+    UDir = UsingDirectiveDecl::Create(Context, 
+                                      CurContext, UsingLoc,
+                                      NamespcLoc, 
+                                      SS.getRange(),
+                                      (NestedNameSpecifier *)SS.getScopeRep(),
+                                      IdentLoc,
                                       cast<NamespaceDecl>(NS),
                                       CommonAncestor);
     PushUsingDirective(S, UDir);
diff --git a/test/Coverage/ast-printing.cpp b/test/Coverage/ast-printing.cpp
new file mode 100644 (file)
index 0000000..10d01c7
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: clang-cc --fsyntax-only %s &&
+// RUN: clang-cc --ast-print %s &&
+// RUN: clang-cc --ast-dump %s
+// FIXME: clang-cc --ast-print-xml -o %t %s
+
+#include "cxx-language-features.inc"
index 5258040cc11c27a5956f0c4631eac0dbc01c6a4c..bcf4127299f0badef4e197f544fe4980078b3b9f 100644 (file)
@@ -140,6 +140,7 @@ void f4(int a0, int a1, int a2, va_list ap) {
   int t32 = __real (t32_cond ? t32_a : t32_b);
 
   struct { int x, y; } t33, *t34, t35[12], t36(int, float);
+  float t37, *t38, t39[9], t40(double);
 }
 
 // Extended vectors
diff --git a/test/Coverage/cxx-language-features.inc b/test/Coverage/cxx-language-features.inc
new file mode 100644 (file)
index 0000000..92c9fd6
--- /dev/null
@@ -0,0 +1,12 @@
+//-*- C++ -*-
+
+// Intended to exercise all syntactic parts of the C++ language that
+// aren't part of C.
+
+namespace std {
+  namespace debug {
+  }
+}
+
+using namespace std::debug;
+using namespace std;