[cfe-commits] r72614 - in /cfe/trunk: include/clang/AST/DeclCXX.h lib/AST/DeclCXX.cpp lib/AST/DeclPrinter.cpp lib/Sema/SemaDeclCXX.cpp test/Coverage/ast-printing.cpp test/Coverage/c-language-features.inc test/Coverage/cxx-language-features.inc
Douglas Gregor
dgregor at apple.com
Fri May 29 23:31:57 PDT 2009
Author: dgregor
Date: Sat May 30 01:31:56 2009
New Revision: 72614
URL: http://llvm.org/viewvc/llvm-project?rev=72614&view=rev
Log:
Printing for using directives, e.g.,
using namespace std::debug;
Extended UsingDirectiveDecl to store the nested-name-specifier that
precedes the nominated namespace.
Added:
cfe/trunk/test/Coverage/ast-printing.cpp (with props)
cfe/trunk/test/Coverage/cxx-language-features.inc
Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/Coverage/c-language-features.inc
Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=72614&r1=72613&r2=72614&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Sat May 30 01:31:56 2009
@@ -878,6 +878,14 @@
/// 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 @@
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 @@
static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation L,
SourceLocation NamespaceLoc,
+ SourceRange QualifierRange,
+ NestedNameSpecifier *Qualifier,
SourceLocation IdentLoc,
NamespaceDecl *Nominated,
DeclContext *CommonAncestor);
Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=72614&r1=72613&r2=72614&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Sat May 30 01:31:56 2009
@@ -402,11 +402,13 @@
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,
Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=72614&r1=72613&r2=72614&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Sat May 30 01:31:56 2009
@@ -51,12 +51,15 @@
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 @@
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 @@
//----------------------------------------------------------------------------
// 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);
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=72614&r1=72613&r2=72614&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sat May 30 01:31:56 2009
@@ -1711,8 +1711,12 @@
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);
Added: cfe/trunk/test/Coverage/ast-printing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/ast-printing.cpp?rev=72614&view=auto
==============================================================================
--- cfe/trunk/test/Coverage/ast-printing.cpp (added)
+++ cfe/trunk/test/Coverage/ast-printing.cpp Sat May 30 01:31:56 2009
@@ -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"
Propchange: cfe/trunk/test/Coverage/ast-printing.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/Coverage/ast-printing.cpp
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cfe/trunk/test/Coverage/ast-printing.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: cfe/trunk/test/Coverage/c-language-features.inc
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/c-language-features.inc?rev=72614&r1=72613&r2=72614&view=diff
==============================================================================
--- cfe/trunk/test/Coverage/c-language-features.inc (original)
+++ cfe/trunk/test/Coverage/c-language-features.inc Sat May 30 01:31:56 2009
@@ -140,6 +140,7 @@
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
Added: cfe/trunk/test/Coverage/cxx-language-features.inc
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/cxx-language-features.inc?rev=72614&view=auto
==============================================================================
--- cfe/trunk/test/Coverage/cxx-language-features.inc (added)
+++ cfe/trunk/test/Coverage/cxx-language-features.inc Sat May 30 01:31:56 2009
@@ -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;
More information about the cfe-commits
mailing list