[cfe-commits] r72616 - in /cfe/trunk: include/clang/AST/DeclCXX.h lib/AST/DeclCXX.cpp lib/AST/DeclPrinter.cpp lib/Sema/SemaDeclCXX.cpp test/Coverage/cxx-language-features.inc
Douglas Gregor
dgregor at apple.com
Fri May 29 23:48:27 PDT 2009
Author: dgregor
Date: Sat May 30 01:48:27 2009
New Revision: 72616
URL: http://llvm.org/viewvc/llvm-project?rev=72616&view=rev
Log:
Pretty printing and improved representation for namespace alias declarations
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/cxx-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=72616&r1=72615&r2=72616&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Sat May 30 01:48:27 2009
@@ -970,9 +970,16 @@
/// @endcode
class NamespaceAliasDecl : public NamedDecl {
SourceLocation AliasLoc;
+
+ /// \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 namespace identifier.
- /// FIXME: We don't store location of scope specifier.
SourceLocation IdentLoc;
/// Namespace - The Decl that this alias points to. Can either be a
@@ -981,11 +988,21 @@
NamespaceAliasDecl(DeclContext *DC, SourceLocation L,
SourceLocation AliasLoc, IdentifierInfo *Alias,
+ SourceRange QualifierRange,
+ NestedNameSpecifier *Qualifier,
SourceLocation IdentLoc, NamedDecl *Namespace)
: NamedDecl(Decl::NamespaceAlias, DC, L, Alias), AliasLoc(AliasLoc),
+ QualifierRange(QualifierRange), Qualifier(Qualifier),
IdentLoc(IdentLoc), Namespace(Namespace) { }
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; }
NamespaceDecl *getNamespace() {
if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
@@ -997,10 +1014,16 @@
const NamespaceDecl *getNamespace() const {
return const_cast<NamespaceAliasDecl*>(this)->getNamespace();
}
-
+
+ /// \brief Retrieve the namespace that this alias refers to, which
+ /// may either be a NamespaceDecl or a NamespaceAliasDecl.
+ NamedDecl *getAliasedNamespace() const { return Namespace; }
+
static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation L, SourceLocation AliasLoc,
IdentifierInfo *Alias,
+ SourceRange QualifierRange,
+ NestedNameSpecifier *Qualifier,
SourceLocation IdentLoc,
NamedDecl *Namespace);
Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=72616&r1=72615&r2=72616&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Sat May 30 01:48:27 2009
@@ -415,10 +415,12 @@
SourceLocation L,
SourceLocation AliasLoc,
IdentifierInfo *Alias,
+ SourceRange QualifierRange,
+ NestedNameSpecifier *Qualifier,
SourceLocation IdentLoc,
NamedDecl *Namespace) {
- return new (C) NamespaceAliasDecl(DC, L, AliasLoc, Alias, IdentLoc,
- Namespace);
+ return new (C) NamespaceAliasDecl(DC, L, AliasLoc, Alias, QualifierRange,
+ Qualifier, IdentLoc, Namespace);
}
StaticAssertDecl *StaticAssertDecl::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=72616&r1=72615&r2=72616&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Sat May 30 01:48:27 2009
@@ -55,6 +55,7 @@
void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
void VisitOverloadedFunctionDecl(OverloadedFunctionDecl *D);
void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
+ void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
void VisitNamespaceDecl(NamespaceDecl *D);
void VisitLinkageSpecDecl(LinkageSpecDecl *D);
void VisitTemplateDecl(TemplateDecl *D);
@@ -435,6 +436,13 @@
Out << D->getNominatedNamespace()->getNameAsString();
}
+void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
+ Out << "namespace " << D->getNameAsString() << " = ";
+ if (D->getQualifier())
+ D->getQualifier()->print(Out, Policy);
+ Out << D->getAliasedNamespace()->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=72616&r1=72615&r2=72616&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sat May 30 01:48:27 2009
@@ -1787,7 +1787,9 @@
}
NamespaceAliasDecl *AliasDecl =
- NamespaceAliasDecl::Create(Context, CurContext, NamespaceLoc, AliasLoc, Alias,
+ NamespaceAliasDecl::Create(Context, CurContext, NamespaceLoc, AliasLoc,
+ Alias, SS.getRange(),
+ (NestedNameSpecifier *)SS.getScopeRep(),
IdentLoc, R);
CurContext->addDecl(Context, AliasDecl);
Modified: cfe/trunk/test/Coverage/cxx-language-features.inc
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/cxx-language-features.inc?rev=72616&r1=72615&r2=72616&view=diff
==============================================================================
--- cfe/trunk/test/Coverage/cxx-language-features.inc (original)
+++ cfe/trunk/test/Coverage/cxx-language-features.inc Sat May 30 01:48:27 2009
@@ -10,3 +10,5 @@
using namespace std::debug;
using namespace std;
+
+namespace safestl = ::std::debug;
More information about the cfe-commits
mailing list