Generalize printing of nested-name-specifier sequences for use in both
QualifiedNameType and QualifiedDeclRefExpr. We now keep track of the
exact nested-name-specifier spelling for a QualifiedDeclRefExpr, and
use that spelling when printing ASTs. This fixes PR3493.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67283 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp
index 1d4a3ba..f18a288 100644
--- a/lib/AST/ExprCXX.cpp
+++ b/lib/AST/ExprCXX.cpp
@@ -24,6 +24,31 @@
C.Deallocate(this);
}
+QualifiedDeclRefExpr::QualifiedDeclRefExpr(NamedDecl *d, QualType t,
+ SourceLocation l, bool TD,
+ bool VD, SourceRange R,
+ const NestedNameSpecifier *Components,
+ unsigned NumComponents)
+ : DeclRefExpr(QualifiedDeclRefExprClass, d, t, l, TD, VD),
+ QualifierRange(R), NumComponents(NumComponents) {
+ NestedNameSpecifier *Data
+ = reinterpret_cast<NestedNameSpecifier *>(this + 1);
+ for (unsigned I = 0; I < NumComponents; ++I)
+ Data[I] = Components[I];
+}
+
+QualifiedDeclRefExpr *
+QualifiedDeclRefExpr::Create(ASTContext &Context, NamedDecl *d, QualType t,
+ SourceLocation l, bool TD,
+ bool VD, SourceRange R,
+ const NestedNameSpecifier *Components,
+ unsigned NumComponents) {
+ void *Mem = Context.Allocate((sizeof(QualifiedDeclRefExpr) +
+ sizeof(NestedNameSpecifier) * NumComponents));
+ return new (Mem) QualifiedDeclRefExpr(d, t, l, TD, VD, R, Components,
+ NumComponents);
+}
+
//===----------------------------------------------------------------------===//
// Child Iterators for iterating over subexpressions/substatements
//===----------------------------------------------------------------------===//