2017-11-22 07:26:08 +08:00
|
|
|
//===- NestedNameSpecifier.cpp - C++ nested name specifiers ---------------===//
|
Introduce a representation for types that we referred to via a
qualified name, e.g.,
foo::x
so that we retain the nested-name-specifier as written in the source
code and can reproduce that qualified name when printing the types
back (e.g., in diagnostics). This is PR3493, which won't be complete
until finished the other tasks mentioned near the end of this commit.
The parser's representation of nested-name-specifiers, CXXScopeSpec,
is now a bit fatter, because it needs to contain the scopes that
precede each '::' and keep track of whether the global scoping
operator '::' was at the beginning. For example, we need to keep track
of the leading '::', 'foo', and 'bar' in
::foo::bar::x
The Action's CXXScopeTy * is no longer a DeclContext *. It's now the
opaque version of the new NestedNameSpecifier, which contains a single
component of a nested-name-specifier (either a DeclContext * or a Type
*, bitmangled).
The new sugar type QualifiedNameType composes a sequence of
NestedNameSpecifiers with a representation of the type we're actually
referring to. At present, we only build QualifiedNameType nodes within
Sema::getTypeName. This will be extended to other type-constructing
actions (e.g., ActOnClassTemplateId).
Also on the way: QualifiedDeclRefExprs will also store a sequence of
NestedNameSpecifiers, so that we can print out the property
nested-name-specifier. I expect to also use this for handling
dependent names like Fibonacci<I - 1>::value.
llvm-svn: 67265
2009-03-19 08:18:19 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the NestedNameSpecifier class, which represents
|
|
|
|
// a C++ nested-name-specifier.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2017-11-22 07:26:08 +08:00
|
|
|
|
Introduce a representation for types that we referred to via a
qualified name, e.g.,
foo::x
so that we retain the nested-name-specifier as written in the source
code and can reproduce that qualified name when printing the types
back (e.g., in diagnostics). This is PR3493, which won't be complete
until finished the other tasks mentioned near the end of this commit.
The parser's representation of nested-name-specifiers, CXXScopeSpec,
is now a bit fatter, because it needs to contain the scopes that
precede each '::' and keep track of whether the global scoping
operator '::' was at the beginning. For example, we need to keep track
of the leading '::', 'foo', and 'bar' in
::foo::bar::x
The Action's CXXScopeTy * is no longer a DeclContext *. It's now the
opaque version of the new NestedNameSpecifier, which contains a single
component of a nested-name-specifier (either a DeclContext * or a Type
*, bitmangled).
The new sugar type QualifiedNameType composes a sequence of
NestedNameSpecifiers with a representation of the type we're actually
referring to. At present, we only build QualifiedNameType nodes within
Sema::getTypeName. This will be extended to other type-constructing
actions (e.g., ActOnClassTemplateId).
Also on the way: QualifiedDeclRefExprs will also store a sequence of
NestedNameSpecifiers, so that we can print out the property
nested-name-specifier. I expect to also use this for handling
dependent names like Fibonacci<I - 1>::value.
llvm-svn: 67265
2009-03-19 08:18:19 +08:00
|
|
|
#include "clang/AST/NestedNameSpecifier.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/Decl.h"
|
2011-02-24 10:36:08 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2009-05-30 04:38:28 +08:00
|
|
|
#include "clang/AST/PrettyPrinter.h"
|
2017-11-22 07:26:08 +08:00
|
|
|
#include "clang/AST/TemplateName.h"
|
Introduce a representation for types that we referred to via a
qualified name, e.g.,
foo::x
so that we retain the nested-name-specifier as written in the source
code and can reproduce that qualified name when printing the types
back (e.g., in diagnostics). This is PR3493, which won't be complete
until finished the other tasks mentioned near the end of this commit.
The parser's representation of nested-name-specifiers, CXXScopeSpec,
is now a bit fatter, because it needs to contain the scopes that
precede each '::' and keep track of whether the global scoping
operator '::' was at the beginning. For example, we need to keep track
of the leading '::', 'foo', and 'bar' in
::foo::bar::x
The Action's CXXScopeTy * is no longer a DeclContext *. It's now the
opaque version of the new NestedNameSpecifier, which contains a single
component of a nested-name-specifier (either a DeclContext * or a Type
*, bitmangled).
The new sugar type QualifiedNameType composes a sequence of
NestedNameSpecifiers with a representation of the type we're actually
referring to. At present, we only build QualifiedNameType nodes within
Sema::getTypeName. This will be extended to other type-constructing
actions (e.g., ActOnClassTemplateId).
Also on the way: QualifiedDeclRefExprs will also store a sequence of
NestedNameSpecifiers, so that we can print out the property
nested-name-specifier. I expect to also use this for handling
dependent names like Fibonacci<I - 1>::value.
llvm-svn: 67265
2009-03-19 08:18:19 +08:00
|
|
|
#include "clang/AST/Type.h"
|
2011-02-25 01:54:50 +08:00
|
|
|
#include "clang/AST/TypeLoc.h"
|
2017-11-22 07:26:08 +08:00
|
|
|
#include "clang/Basic/LLVM.h"
|
|
|
|
#include "clang/Basic/LangOptions.h"
|
|
|
|
#include "clang/Basic/SourceLocation.h"
|
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-03-19 11:51:16 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2017-11-22 07:26:08 +08:00
|
|
|
#include <algorithm>
|
2009-03-27 07:50:42 +08:00
|
|
|
#include <cassert>
|
2017-11-22 07:26:08 +08:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
2009-03-19 11:51:16 +08:00
|
|
|
|
Introduce a representation for types that we referred to via a
qualified name, e.g.,
foo::x
so that we retain the nested-name-specifier as written in the source
code and can reproduce that qualified name when printing the types
back (e.g., in diagnostics). This is PR3493, which won't be complete
until finished the other tasks mentioned near the end of this commit.
The parser's representation of nested-name-specifiers, CXXScopeSpec,
is now a bit fatter, because it needs to contain the scopes that
precede each '::' and keep track of whether the global scoping
operator '::' was at the beginning. For example, we need to keep track
of the leading '::', 'foo', and 'bar' in
::foo::bar::x
The Action's CXXScopeTy * is no longer a DeclContext *. It's now the
opaque version of the new NestedNameSpecifier, which contains a single
component of a nested-name-specifier (either a DeclContext * or a Type
*, bitmangled).
The new sugar type QualifiedNameType composes a sequence of
NestedNameSpecifiers with a representation of the type we're actually
referring to. At present, we only build QualifiedNameType nodes within
Sema::getTypeName. This will be extended to other type-constructing
actions (e.g., ActOnClassTemplateId).
Also on the way: QualifiedDeclRefExprs will also store a sequence of
NestedNameSpecifiers, so that we can print out the property
nested-name-specifier. I expect to also use this for handling
dependent names like Fibonacci<I - 1>::value.
llvm-svn: 67265
2009-03-19 08:18:19 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
2009-03-27 07:50:42 +08:00
|
|
|
NestedNameSpecifier *
|
2011-01-12 17:06:06 +08:00
|
|
|
NestedNameSpecifier::FindOrInsert(const ASTContext &Context,
|
2009-03-27 07:50:42 +08:00
|
|
|
const NestedNameSpecifier &Mockup) {
|
|
|
|
llvm::FoldingSetNodeID ID;
|
|
|
|
Mockup.Profile(ID);
|
|
|
|
|
2014-05-12 13:36:57 +08:00
|
|
|
void *InsertPos = nullptr;
|
2009-09-09 23:08:12 +08:00
|
|
|
NestedNameSpecifier *NNS
|
2009-03-27 07:50:42 +08:00
|
|
|
= Context.NestedNameSpecifiers.FindNodeOrInsertPos(ID, InsertPos);
|
|
|
|
if (!NNS) {
|
2016-10-20 22:27:22 +08:00
|
|
|
NNS =
|
|
|
|
new (Context, alignof(NestedNameSpecifier)) NestedNameSpecifier(Mockup);
|
2009-03-27 07:50:42 +08:00
|
|
|
Context.NestedNameSpecifiers.InsertNode(NNS, InsertPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NNS;
|
|
|
|
}
|
|
|
|
|
|
|
|
NestedNameSpecifier *
|
2011-01-12 17:06:06 +08:00
|
|
|
NestedNameSpecifier::Create(const ASTContext &Context,
|
|
|
|
NestedNameSpecifier *Prefix, IdentifierInfo *II) {
|
2009-03-27 07:50:42 +08:00
|
|
|
assert(II && "Identifier cannot be NULL");
|
2009-09-09 08:23:06 +08:00
|
|
|
assert((!Prefix || Prefix->isDependent()) && "Prefix must be dependent");
|
2009-03-27 07:50:42 +08:00
|
|
|
|
|
|
|
NestedNameSpecifier Mockup;
|
2009-04-01 08:28:59 +08:00
|
|
|
Mockup.Prefix.setPointer(Prefix);
|
2011-02-24 10:36:08 +08:00
|
|
|
Mockup.Prefix.setInt(StoredIdentifier);
|
2009-04-01 08:28:59 +08:00
|
|
|
Mockup.Specifier = II;
|
2009-03-27 07:50:42 +08:00
|
|
|
return FindOrInsert(Context, Mockup);
|
|
|
|
}
|
|
|
|
|
|
|
|
NestedNameSpecifier *
|
2011-01-12 17:06:06 +08:00
|
|
|
NestedNameSpecifier::Create(const ASTContext &Context,
|
2013-01-24 01:06:56 +08:00
|
|
|
NestedNameSpecifier *Prefix,
|
|
|
|
const NamespaceDecl *NS) {
|
2009-03-27 07:50:42 +08:00
|
|
|
assert(NS && "Namespace cannot be NULL");
|
2009-09-09 23:08:12 +08:00
|
|
|
assert((!Prefix ||
|
2014-05-12 13:36:57 +08:00
|
|
|
(Prefix->getAsType() == nullptr &&
|
|
|
|
Prefix->getAsIdentifier() == nullptr)) &&
|
2009-03-27 07:50:42 +08:00
|
|
|
"Broken nested name specifier");
|
|
|
|
NestedNameSpecifier Mockup;
|
2009-04-01 08:28:59 +08:00
|
|
|
Mockup.Prefix.setPointer(Prefix);
|
2014-09-26 08:28:20 +08:00
|
|
|
Mockup.Prefix.setInt(StoredDecl);
|
2013-01-24 01:06:56 +08:00
|
|
|
Mockup.Specifier = const_cast<NamespaceDecl *>(NS);
|
2009-03-27 07:50:42 +08:00
|
|
|
return FindOrInsert(Context, Mockup);
|
|
|
|
}
|
|
|
|
|
2011-02-24 10:36:08 +08:00
|
|
|
NestedNameSpecifier *
|
|
|
|
NestedNameSpecifier::Create(const ASTContext &Context,
|
2018-07-31 03:24:48 +08:00
|
|
|
NestedNameSpecifier *Prefix,
|
2011-02-24 10:36:08 +08:00
|
|
|
NamespaceAliasDecl *Alias) {
|
|
|
|
assert(Alias && "Namespace alias cannot be NULL");
|
|
|
|
assert((!Prefix ||
|
2014-05-12 13:36:57 +08:00
|
|
|
(Prefix->getAsType() == nullptr &&
|
|
|
|
Prefix->getAsIdentifier() == nullptr)) &&
|
2011-02-24 10:36:08 +08:00
|
|
|
"Broken nested name specifier");
|
|
|
|
NestedNameSpecifier Mockup;
|
|
|
|
Mockup.Prefix.setPointer(Prefix);
|
2014-09-26 08:28:20 +08:00
|
|
|
Mockup.Prefix.setInt(StoredDecl);
|
2011-02-24 10:36:08 +08:00
|
|
|
Mockup.Specifier = Alias;
|
|
|
|
return FindOrInsert(Context, Mockup);
|
|
|
|
}
|
|
|
|
|
2009-03-27 07:50:42 +08:00
|
|
|
NestedNameSpecifier *
|
2011-01-12 17:06:06 +08:00
|
|
|
NestedNameSpecifier::Create(const ASTContext &Context,
|
|
|
|
NestedNameSpecifier *Prefix,
|
2011-01-19 14:33:43 +08:00
|
|
|
bool Template, const Type *T) {
|
2009-03-27 07:50:42 +08:00
|
|
|
assert(T && "Type cannot be NULL");
|
|
|
|
NestedNameSpecifier Mockup;
|
2009-04-01 08:28:59 +08:00
|
|
|
Mockup.Prefix.setPointer(Prefix);
|
2011-02-24 10:36:08 +08:00
|
|
|
Mockup.Prefix.setInt(Template? StoredTypeSpecWithTemplate : StoredTypeSpec);
|
2011-01-19 14:33:43 +08:00
|
|
|
Mockup.Specifier = const_cast<Type*>(T);
|
2009-03-27 07:50:42 +08:00
|
|
|
return FindOrInsert(Context, Mockup);
|
|
|
|
}
|
2009-09-03 07:58:38 +08:00
|
|
|
|
|
|
|
NestedNameSpecifier *
|
2011-01-12 17:06:06 +08:00
|
|
|
NestedNameSpecifier::Create(const ASTContext &Context, IdentifierInfo *II) {
|
2009-09-03 07:58:38 +08:00
|
|
|
assert(II && "Identifier cannot be NULL");
|
|
|
|
NestedNameSpecifier Mockup;
|
2014-05-12 13:36:57 +08:00
|
|
|
Mockup.Prefix.setPointer(nullptr);
|
2011-02-24 10:36:08 +08:00
|
|
|
Mockup.Prefix.setInt(StoredIdentifier);
|
2009-09-03 07:58:38 +08:00
|
|
|
Mockup.Specifier = II;
|
|
|
|
return FindOrInsert(Context, Mockup);
|
|
|
|
}
|
|
|
|
|
2011-01-12 17:06:06 +08:00
|
|
|
NestedNameSpecifier *
|
|
|
|
NestedNameSpecifier::GlobalSpecifier(const ASTContext &Context) {
|
2009-03-27 07:50:42 +08:00
|
|
|
if (!Context.GlobalNestedNameSpecifier)
|
2012-08-15 09:41:43 +08:00
|
|
|
Context.GlobalNestedNameSpecifier =
|
2016-10-20 22:27:22 +08:00
|
|
|
new (Context, alignof(NestedNameSpecifier)) NestedNameSpecifier();
|
2009-03-27 07:50:42 +08:00
|
|
|
return Context.GlobalNestedNameSpecifier;
|
|
|
|
}
|
|
|
|
|
2014-09-26 08:28:20 +08:00
|
|
|
NestedNameSpecifier *
|
|
|
|
NestedNameSpecifier::SuperSpecifier(const ASTContext &Context,
|
|
|
|
CXXRecordDecl *RD) {
|
|
|
|
NestedNameSpecifier Mockup;
|
|
|
|
Mockup.Prefix.setPointer(nullptr);
|
|
|
|
Mockup.Prefix.setInt(StoredDecl);
|
|
|
|
Mockup.Specifier = RD;
|
|
|
|
return FindOrInsert(Context, Mockup);
|
|
|
|
}
|
|
|
|
|
2011-02-24 10:36:08 +08:00
|
|
|
NestedNameSpecifier::SpecifierKind NestedNameSpecifier::getKind() const {
|
2014-05-12 13:36:57 +08:00
|
|
|
if (!Specifier)
|
2011-02-24 10:36:08 +08:00
|
|
|
return Global;
|
|
|
|
|
|
|
|
switch (Prefix.getInt()) {
|
|
|
|
case StoredIdentifier:
|
|
|
|
return Identifier;
|
|
|
|
|
2014-09-26 08:28:20 +08:00
|
|
|
case StoredDecl: {
|
|
|
|
NamedDecl *ND = static_cast<NamedDecl *>(Specifier);
|
|
|
|
if (isa<CXXRecordDecl>(ND))
|
|
|
|
return Super;
|
|
|
|
return isa<NamespaceDecl>(ND) ? Namespace : NamespaceAlias;
|
|
|
|
}
|
2011-02-24 10:36:08 +08:00
|
|
|
|
|
|
|
case StoredTypeSpec:
|
|
|
|
return TypeSpec;
|
|
|
|
|
|
|
|
case StoredTypeSpecWithTemplate:
|
|
|
|
return TypeSpecWithTemplate;
|
|
|
|
}
|
|
|
|
|
2012-01-21 05:50:17 +08:00
|
|
|
llvm_unreachable("Invalid NNS Kind!");
|
2011-02-24 10:36:08 +08:00
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Retrieve the namespace stored in this nested name specifier.
|
2011-02-24 10:36:08 +08:00
|
|
|
NamespaceDecl *NestedNameSpecifier::getAsNamespace() const {
|
2016-10-08 14:45:10 +08:00
|
|
|
if (Prefix.getInt() == StoredDecl)
|
2011-02-24 10:36:08 +08:00
|
|
|
return dyn_cast<NamespaceDecl>(static_cast<NamedDecl *>(Specifier));
|
|
|
|
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2011-02-24 10:36:08 +08:00
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Retrieve the namespace alias stored in this nested name specifier.
|
2011-02-24 10:36:08 +08:00
|
|
|
NamespaceAliasDecl *NestedNameSpecifier::getAsNamespaceAlias() const {
|
2016-10-08 14:45:10 +08:00
|
|
|
if (Prefix.getInt() == StoredDecl)
|
2011-02-24 10:36:08 +08:00
|
|
|
return dyn_cast<NamespaceAliasDecl>(static_cast<NamedDecl *>(Specifier));
|
|
|
|
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2011-02-24 10:36:08 +08:00
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Retrieve the record declaration stored in this nested name specifier.
|
2014-09-26 08:28:20 +08:00
|
|
|
CXXRecordDecl *NestedNameSpecifier::getAsRecordDecl() const {
|
P0136R1, DR1573, DR1645, DR1715, DR1736, DR1903, DR1941, DR1959, DR1991:
Replace inheriting constructors implementation with new approach, voted into
C++ last year as a DR against C++11.
Instead of synthesizing a set of derived class constructors for each inherited
base class constructor, we make the constructors of the base class visible to
constructor lookup in the derived class, using the normal rules for
using-declarations.
For constructors, UsingShadowDecl now has a ConstructorUsingShadowDecl derived
class that tracks the requisite additional information. We create shadow
constructors (not found by name lookup) in the derived class to model the
actual initialization, and have a new expression node,
CXXInheritedCtorInitExpr, to model the initialization of a base class from such
a constructor. (This initialization is special because it performs real perfect
forwarding of arguments.)
In cases where argument forwarding is not possible (for inalloca calls,
variadic calls, and calls with callee parameter cleanup), the shadow inheriting
constructor is not emitted and instead we directly emit the initialization code
into the caller of the inherited constructor.
Note that this new model is not perfectly compatible with the old model in some
corner cases. In particular:
* if B inherits a private constructor from A, and C uses that constructor to
construct a B, then we previously required that A befriends B and B
befriends C, but the new rules require A to befriend C directly, and
* if a derived class has its own constructors (and so its implicit default
constructor is suppressed), it may still inherit a default constructor from
a base class
llvm-svn: 274049
2016-06-29 03:03:57 +08:00
|
|
|
switch (Prefix.getInt()) {
|
|
|
|
case StoredIdentifier:
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
case StoredDecl:
|
2014-09-26 08:28:20 +08:00
|
|
|
return dyn_cast<CXXRecordDecl>(static_cast<NamedDecl *>(Specifier));
|
|
|
|
|
P0136R1, DR1573, DR1645, DR1715, DR1736, DR1903, DR1941, DR1959, DR1991:
Replace inheriting constructors implementation with new approach, voted into
C++ last year as a DR against C++11.
Instead of synthesizing a set of derived class constructors for each inherited
base class constructor, we make the constructors of the base class visible to
constructor lookup in the derived class, using the normal rules for
using-declarations.
For constructors, UsingShadowDecl now has a ConstructorUsingShadowDecl derived
class that tracks the requisite additional information. We create shadow
constructors (not found by name lookup) in the derived class to model the
actual initialization, and have a new expression node,
CXXInheritedCtorInitExpr, to model the initialization of a base class from such
a constructor. (This initialization is special because it performs real perfect
forwarding of arguments.)
In cases where argument forwarding is not possible (for inalloca calls,
variadic calls, and calls with callee parameter cleanup), the shadow inheriting
constructor is not emitted and instead we directly emit the initialization code
into the caller of the inherited constructor.
Note that this new model is not perfectly compatible with the old model in some
corner cases. In particular:
* if B inherits a private constructor from A, and C uses that constructor to
construct a B, then we previously required that A befriends B and B
befriends C, but the new rules require A to befriend C directly, and
* if a derived class has its own constructors (and so its implicit default
constructor is suppressed), it may still inherit a default constructor from
a base class
llvm-svn: 274049
2016-06-29 03:03:57 +08:00
|
|
|
case StoredTypeSpec:
|
|
|
|
case StoredTypeSpecWithTemplate:
|
|
|
|
return getAsType()->getAsCXXRecordDecl();
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("Invalid NNS Kind!");
|
2014-09-26 08:28:20 +08:00
|
|
|
}
|
2011-02-24 10:36:08 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Whether this nested name specifier refers to a dependent
|
2009-03-27 07:50:42 +08:00
|
|
|
/// type or not.
|
|
|
|
bool NestedNameSpecifier::isDependent() const {
|
|
|
|
switch (getKind()) {
|
|
|
|
case Identifier:
|
|
|
|
// Identifier specifiers always represent dependent types
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case Namespace:
|
2011-02-24 10:36:08 +08:00
|
|
|
case NamespaceAlias:
|
2009-03-27 07:50:42 +08:00
|
|
|
case Global:
|
|
|
|
return false;
|
|
|
|
|
2014-09-26 08:28:20 +08:00
|
|
|
case Super: {
|
|
|
|
CXXRecordDecl *RD = static_cast<CXXRecordDecl *>(Specifier);
|
|
|
|
for (const auto &Base : RD->bases())
|
|
|
|
if (Base.getType()->isDependentType())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-03-27 07:50:42 +08:00
|
|
|
case TypeSpec:
|
|
|
|
case TypeSpecWithTemplate:
|
|
|
|
return getAsType()->isDependentType();
|
2009-03-19 11:51:16 +08:00
|
|
|
}
|
2009-03-27 07:50:42 +08:00
|
|
|
|
2012-01-21 05:50:17 +08:00
|
|
|
llvm_unreachable("Invalid NNS Kind!");
|
2009-03-27 07:50:42 +08:00
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Whether this nested name specifier refers to a dependent
|
2011-07-01 09:22:09 +08:00
|
|
|
/// type or not.
|
|
|
|
bool NestedNameSpecifier::isInstantiationDependent() const {
|
|
|
|
switch (getKind()) {
|
|
|
|
case Identifier:
|
|
|
|
// Identifier specifiers always represent dependent types
|
|
|
|
return true;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-07-01 09:22:09 +08:00
|
|
|
case Namespace:
|
|
|
|
case NamespaceAlias:
|
|
|
|
case Global:
|
2014-09-26 08:28:20 +08:00
|
|
|
case Super:
|
2011-07-01 09:22:09 +08:00
|
|
|
return false;
|
2014-09-26 08:28:20 +08:00
|
|
|
|
2011-07-01 09:22:09 +08:00
|
|
|
case TypeSpec:
|
|
|
|
case TypeSpecWithTemplate:
|
|
|
|
return getAsType()->isInstantiationDependentType();
|
|
|
|
}
|
2012-01-21 05:50:17 +08:00
|
|
|
|
|
|
|
llvm_unreachable("Invalid NNS Kind!");
|
2011-07-01 09:22:09 +08:00
|
|
|
}
|
|
|
|
|
Variadic templates: extend Type, NestedNameSpecifier, TemplateName,
and TemplateArgument with an operation that determines whether there
are any unexpanded parameter packs within that construct. Use this
information to diagnose the appearance of the names of parameter packs
that have not been expanded (C++ [temp.variadic]p5). Since this
property is checked often (every declaration, ever expression
statement, etc.), we extend Type and Expr with a bit storing the
result of this computation, rather than walking the AST each time to
determine whether any unexpanded parameter packs occur.
This commit is deficient in several ways, which will be remedied with
future commits:
- Expr has a bit to store the presence of an unexpanded parameter
pack, but it is never set.
- The error messages don't point out where the unexpanded parameter
packs were named in the type/expression, but they should.
- We don't check for unexpanded parameter packs in all of the places
where we should.
- Testing is sparse, pending the resolution of the above three
issues.
llvm-svn: 121724
2010-12-14 06:49:22 +08:00
|
|
|
bool NestedNameSpecifier::containsUnexpandedParameterPack() const {
|
|
|
|
switch (getKind()) {
|
|
|
|
case Identifier:
|
|
|
|
return getPrefix() && getPrefix()->containsUnexpandedParameterPack();
|
|
|
|
|
|
|
|
case Namespace:
|
2011-02-24 10:36:08 +08:00
|
|
|
case NamespaceAlias:
|
Variadic templates: extend Type, NestedNameSpecifier, TemplateName,
and TemplateArgument with an operation that determines whether there
are any unexpanded parameter packs within that construct. Use this
information to diagnose the appearance of the names of parameter packs
that have not been expanded (C++ [temp.variadic]p5). Since this
property is checked often (every declaration, ever expression
statement, etc.), we extend Type and Expr with a bit storing the
result of this computation, rather than walking the AST each time to
determine whether any unexpanded parameter packs occur.
This commit is deficient in several ways, which will be remedied with
future commits:
- Expr has a bit to store the presence of an unexpanded parameter
pack, but it is never set.
- The error messages don't point out where the unexpanded parameter
packs were named in the type/expression, but they should.
- We don't check for unexpanded parameter packs in all of the places
where we should.
- Testing is sparse, pending the resolution of the above three
issues.
llvm-svn: 121724
2010-12-14 06:49:22 +08:00
|
|
|
case Global:
|
2014-09-26 08:28:20 +08:00
|
|
|
case Super:
|
Variadic templates: extend Type, NestedNameSpecifier, TemplateName,
and TemplateArgument with an operation that determines whether there
are any unexpanded parameter packs within that construct. Use this
information to diagnose the appearance of the names of parameter packs
that have not been expanded (C++ [temp.variadic]p5). Since this
property is checked often (every declaration, ever expression
statement, etc.), we extend Type and Expr with a bit storing the
result of this computation, rather than walking the AST each time to
determine whether any unexpanded parameter packs occur.
This commit is deficient in several ways, which will be remedied with
future commits:
- Expr has a bit to store the presence of an unexpanded parameter
pack, but it is never set.
- The error messages don't point out where the unexpanded parameter
packs were named in the type/expression, but they should.
- We don't check for unexpanded parameter packs in all of the places
where we should.
- Testing is sparse, pending the resolution of the above three
issues.
llvm-svn: 121724
2010-12-14 06:49:22 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
case TypeSpec:
|
|
|
|
case TypeSpecWithTemplate:
|
|
|
|
return getAsType()->containsUnexpandedParameterPack();
|
|
|
|
}
|
|
|
|
|
2012-01-21 05:50:17 +08:00
|
|
|
llvm_unreachable("Invalid NNS Kind!");
|
Variadic templates: extend Type, NestedNameSpecifier, TemplateName,
and TemplateArgument with an operation that determines whether there
are any unexpanded parameter packs within that construct. Use this
information to diagnose the appearance of the names of parameter packs
that have not been expanded (C++ [temp.variadic]p5). Since this
property is checked often (every declaration, ever expression
statement, etc.), we extend Type and Expr with a bit storing the
result of this computation, rather than walking the AST each time to
determine whether any unexpanded parameter packs occur.
This commit is deficient in several ways, which will be remedied with
future commits:
- Expr has a bit to store the presence of an unexpanded parameter
pack, but it is never set.
- The error messages don't point out where the unexpanded parameter
packs were named in the type/expression, but they should.
- We don't check for unexpanded parameter packs in all of the places
where we should.
- Testing is sparse, pending the resolution of the above three
issues.
llvm-svn: 121724
2010-12-14 06:49:22 +08:00
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Print this nested name specifier to the given output
|
2009-03-27 07:50:42 +08:00
|
|
|
/// stream.
|
2009-09-09 23:08:12 +08:00
|
|
|
void
|
2011-07-23 18:55:15 +08:00
|
|
|
NestedNameSpecifier::print(raw_ostream &OS,
|
2009-05-30 04:38:28 +08:00
|
|
|
const PrintingPolicy &Policy) const {
|
2009-04-01 08:28:59 +08:00
|
|
|
if (getPrefix())
|
2009-05-30 04:38:28 +08:00
|
|
|
getPrefix()->print(OS, Policy);
|
2009-03-27 07:50:42 +08:00
|
|
|
|
|
|
|
switch (getKind()) {
|
|
|
|
case Identifier:
|
|
|
|
OS << getAsIdentifier()->getName();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Namespace:
|
2011-11-03 08:16:13 +08:00
|
|
|
if (getAsNamespace()->isAnonymousNamespace())
|
|
|
|
return;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-02-24 10:36:08 +08:00
|
|
|
OS << getAsNamespace()->getName();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NamespaceAlias:
|
|
|
|
OS << getAsNamespaceAlias()->getName();
|
2009-03-27 07:50:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Global:
|
|
|
|
break;
|
|
|
|
|
2014-09-26 08:28:20 +08:00
|
|
|
case Super:
|
|
|
|
OS << "__super";
|
|
|
|
break;
|
|
|
|
|
2009-03-27 07:50:42 +08:00
|
|
|
case TypeSpecWithTemplate:
|
|
|
|
OS << "template ";
|
|
|
|
// Fall through to print the type.
|
2017-06-03 14:31:42 +08:00
|
|
|
LLVM_FALLTHROUGH;
|
2009-03-27 07:50:42 +08:00
|
|
|
|
|
|
|
case TypeSpec: {
|
2011-01-19 14:33:43 +08:00
|
|
|
const Type *T = getAsType();
|
2009-03-27 07:50:42 +08:00
|
|
|
|
2009-05-30 04:38:28 +08:00
|
|
|
PrintingPolicy InnerPolicy(Policy);
|
2009-09-05 14:31:47 +08:00
|
|
|
InnerPolicy.SuppressScope = true;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-26 08:04:55 +08:00
|
|
|
// Nested-name-specifiers are intended to contain minimally-qualified
|
2010-05-12 05:36:43 +08:00
|
|
|
// types. An actual ElaboratedType will not occur, since we'll store
|
2009-08-26 08:04:55 +08:00
|
|
|
// just the type that is referred to in the nested-name-specifier (e.g.,
|
|
|
|
// a TypedefType, TagType, etc.). However, when we are dealing with
|
2009-09-09 23:08:12 +08:00
|
|
|
// dependent template-id types (e.g., Outer<T>::template Inner<U>),
|
2009-08-26 08:04:55 +08:00
|
|
|
// the type requires its own nested-name-specifier for uniqueness, so we
|
|
|
|
// suppress that nested-name-specifier during printing.
|
2010-05-12 05:36:43 +08:00
|
|
|
assert(!isa<ElaboratedType>(T) &&
|
|
|
|
"Elaborated type in nested-name-specifier");
|
2009-08-26 08:04:55 +08:00
|
|
|
if (const TemplateSpecializationType *SpecType
|
|
|
|
= dyn_cast<TemplateSpecializationType>(T)) {
|
2009-09-09 23:08:12 +08:00
|
|
|
// Print the template name without its corresponding
|
2009-08-26 08:04:55 +08:00
|
|
|
// nested-name-specifier.
|
|
|
|
SpecType->getTemplateName().print(OS, InnerPolicy, true);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-26 08:04:55 +08:00
|
|
|
// Print the template argument list.
|
2017-11-29 00:14:14 +08:00
|
|
|
printTemplateArgumentList(OS, SpecType->template_arguments(),
|
|
|
|
InnerPolicy);
|
2009-08-26 08:04:55 +08:00
|
|
|
} else {
|
|
|
|
// Print the type normally
|
2013-02-22 23:46:01 +08:00
|
|
|
QualType(T, 0).print(OS, InnerPolicy);
|
2009-08-26 08:04:55 +08:00
|
|
|
}
|
2009-03-27 07:50:42 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << "::";
|
|
|
|
}
|
|
|
|
|
2018-10-05 03:22:00 +08:00
|
|
|
LLVM_DUMP_METHOD void NestedNameSpecifier::dump(const LangOptions &LO) const {
|
|
|
|
dump(llvm::errs(), LO);
|
2015-12-27 22:34:22 +08:00
|
|
|
}
|
|
|
|
|
2018-10-05 03:22:00 +08:00
|
|
|
LLVM_DUMP_METHOD void NestedNameSpecifier::dump() const { dump(llvm::errs()); }
|
|
|
|
|
|
|
|
LLVM_DUMP_METHOD void NestedNameSpecifier::dump(llvm::raw_ostream &OS) const {
|
2015-12-27 22:34:22 +08:00
|
|
|
LangOptions LO;
|
2018-10-05 03:22:00 +08:00
|
|
|
dump(OS, LO);
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVM_DUMP_METHOD void NestedNameSpecifier::dump(llvm::raw_ostream &OS,
|
|
|
|
const LangOptions &LO) const {
|
|
|
|
print(OS, PrintingPolicy(LO));
|
2009-03-28 07:10:48 +08:00
|
|
|
}
|
2011-02-25 01:54:50 +08:00
|
|
|
|
2018-07-31 03:24:48 +08:00
|
|
|
unsigned
|
2011-02-25 01:54:50 +08:00
|
|
|
NestedNameSpecifierLoc::getLocalDataLength(NestedNameSpecifier *Qualifier) {
|
|
|
|
assert(Qualifier && "Expected a non-NULL qualifier");
|
|
|
|
|
|
|
|
// Location of the trailing '::'.
|
|
|
|
unsigned Length = sizeof(unsigned);
|
|
|
|
|
|
|
|
switch (Qualifier->getKind()) {
|
|
|
|
case NestedNameSpecifier::Global:
|
|
|
|
// Nothing more to add.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NestedNameSpecifier::Identifier:
|
|
|
|
case NestedNameSpecifier::Namespace:
|
|
|
|
case NestedNameSpecifier::NamespaceAlias:
|
2014-09-26 08:28:20 +08:00
|
|
|
case NestedNameSpecifier::Super:
|
2011-02-25 01:54:50 +08:00
|
|
|
// The location of the identifier or namespace name.
|
|
|
|
Length += sizeof(unsigned);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NestedNameSpecifier::TypeSpecWithTemplate:
|
|
|
|
case NestedNameSpecifier::TypeSpec:
|
|
|
|
// The "void*" that points at the TypeLoc data.
|
|
|
|
// Note: the 'template' keyword is part of the TypeLoc.
|
|
|
|
Length += sizeof(void *);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Length;
|
|
|
|
}
|
|
|
|
|
2018-07-31 03:24:48 +08:00
|
|
|
unsigned
|
2011-02-25 01:54:50 +08:00
|
|
|
NestedNameSpecifierLoc::getDataLength(NestedNameSpecifier *Qualifier) {
|
|
|
|
unsigned Length = 0;
|
|
|
|
for (; Qualifier; Qualifier = Qualifier->getPrefix())
|
|
|
|
Length += getLocalDataLength(Qualifier);
|
|
|
|
return Length;
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Load a (possibly unaligned) source location from a given address
|
2017-11-22 07:26:08 +08:00
|
|
|
/// and offset.
|
|
|
|
static SourceLocation LoadSourceLocation(void *Data, unsigned Offset) {
|
|
|
|
unsigned Raw;
|
|
|
|
memcpy(&Raw, static_cast<char *>(Data) + Offset, sizeof(unsigned));
|
|
|
|
return SourceLocation::getFromRawEncoding(Raw);
|
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Load a (possibly unaligned) pointer from a given address and
|
2017-11-22 07:26:08 +08:00
|
|
|
/// offset.
|
|
|
|
static void *LoadPointer(void *Data, unsigned Offset) {
|
|
|
|
void *Result;
|
|
|
|
memcpy(&Result, static_cast<char *>(Data) + Offset, sizeof(void*));
|
|
|
|
return Result;
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|
2011-02-25 01:54:50 +08:00
|
|
|
|
2011-02-25 08:36:19 +08:00
|
|
|
SourceRange NestedNameSpecifierLoc::getSourceRange() const {
|
2011-02-26 00:33:46 +08:00
|
|
|
if (!Qualifier)
|
|
|
|
return SourceRange();
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-02-25 01:54:50 +08:00
|
|
|
NestedNameSpecifierLoc First = *this;
|
2011-02-26 00:33:46 +08:00
|
|
|
while (NestedNameSpecifierLoc Prefix = First.getPrefix())
|
2011-02-25 01:54:50 +08:00
|
|
|
First = Prefix;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
|
|
|
return SourceRange(First.getLocalSourceRange().getBegin(),
|
2011-02-25 01:54:50 +08:00
|
|
|
getLocalSourceRange().getEnd());
|
|
|
|
}
|
|
|
|
|
2011-02-25 08:36:19 +08:00
|
|
|
SourceRange NestedNameSpecifierLoc::getLocalSourceRange() const {
|
2011-02-26 00:33:46 +08:00
|
|
|
if (!Qualifier)
|
|
|
|
return SourceRange();
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-02-25 01:54:50 +08:00
|
|
|
unsigned Offset = getDataLength(Qualifier->getPrefix());
|
|
|
|
switch (Qualifier->getKind()) {
|
|
|
|
case NestedNameSpecifier::Global:
|
|
|
|
return LoadSourceLocation(Data, Offset);
|
|
|
|
|
|
|
|
case NestedNameSpecifier::Identifier:
|
|
|
|
case NestedNameSpecifier::Namespace:
|
|
|
|
case NestedNameSpecifier::NamespaceAlias:
|
2014-09-26 08:28:20 +08:00
|
|
|
case NestedNameSpecifier::Super:
|
2011-02-25 01:54:50 +08:00
|
|
|
return SourceRange(LoadSourceLocation(Data, Offset),
|
|
|
|
LoadSourceLocation(Data, Offset + sizeof(unsigned)));
|
|
|
|
|
|
|
|
case NestedNameSpecifier::TypeSpecWithTemplate:
|
|
|
|
case NestedNameSpecifier::TypeSpec: {
|
|
|
|
// The "void*" that points at the TypeLoc data.
|
|
|
|
// Note: the 'template' keyword is part of the TypeLoc.
|
|
|
|
void *TypeData = LoadPointer(Data, Offset);
|
|
|
|
TypeLoc TL(Qualifier->getAsType(), TypeData);
|
|
|
|
return SourceRange(TL.getBeginLoc(),
|
|
|
|
LoadSourceLocation(Data, Offset + sizeof(void*)));
|
|
|
|
}
|
|
|
|
}
|
2012-01-21 05:50:17 +08:00
|
|
|
|
|
|
|
llvm_unreachable("Invalid NNS Kind!");
|
2011-02-25 01:54:50 +08:00
|
|
|
}
|
2011-02-25 08:36:19 +08:00
|
|
|
|
|
|
|
TypeLoc NestedNameSpecifierLoc::getTypeLoc() const {
|
|
|
|
assert((Qualifier->getKind() == NestedNameSpecifier::TypeSpec ||
|
|
|
|
Qualifier->getKind() == NestedNameSpecifier::TypeSpecWithTemplate) &&
|
|
|
|
"Nested-name-specifier location is not a type");
|
|
|
|
|
|
|
|
// The "void*" that points at the TypeLoc data.
|
|
|
|
unsigned Offset = getDataLength(Qualifier->getPrefix());
|
|
|
|
void *TypeData = LoadPointer(Data, Offset);
|
|
|
|
return TypeLoc(Qualifier->getAsType(), TypeData);
|
|
|
|
}
|
2011-03-01 07:58:31 +08:00
|
|
|
|
2017-11-22 07:26:08 +08:00
|
|
|
static void Append(char *Start, char *End, char *&Buffer, unsigned &BufferSize,
|
2011-03-01 07:58:31 +08:00
|
|
|
unsigned &BufferCapacity) {
|
2017-11-22 07:26:08 +08:00
|
|
|
if (Start == End)
|
|
|
|
return;
|
2015-08-04 11:52:56 +08:00
|
|
|
|
2017-11-22 07:26:08 +08:00
|
|
|
if (BufferSize + (End - Start) > BufferCapacity) {
|
|
|
|
// Reallocate the buffer.
|
|
|
|
unsigned NewCapacity = std::max(
|
|
|
|
(unsigned)(BufferCapacity ? BufferCapacity * 2 : sizeof(void *) * 2),
|
|
|
|
(unsigned)(BufferSize + (End - Start)));
|
2018-02-21 10:02:39 +08:00
|
|
|
char *NewBuffer = static_cast<char *>(llvm::safe_malloc(NewCapacity));
|
2017-11-22 07:26:08 +08:00
|
|
|
if (BufferCapacity) {
|
|
|
|
memcpy(NewBuffer, Buffer, BufferSize);
|
|
|
|
free(Buffer);
|
2011-03-01 07:58:31 +08:00
|
|
|
}
|
2017-11-22 07:26:08 +08:00
|
|
|
Buffer = NewBuffer;
|
|
|
|
BufferCapacity = NewCapacity;
|
2011-03-01 07:58:31 +08:00
|
|
|
}
|
2017-11-22 07:26:08 +08:00
|
|
|
|
|
|
|
memcpy(Buffer + BufferSize, Start, End - Start);
|
|
|
|
BufferSize += End-Start;
|
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Save a source location to the given buffer.
|
2017-11-22 07:26:08 +08:00
|
|
|
static void SaveSourceLocation(SourceLocation Loc, char *&Buffer,
|
|
|
|
unsigned &BufferSize, unsigned &BufferCapacity) {
|
|
|
|
unsigned Raw = Loc.getRawEncoding();
|
|
|
|
Append(reinterpret_cast<char *>(&Raw),
|
|
|
|
reinterpret_cast<char *>(&Raw) + sizeof(unsigned),
|
|
|
|
Buffer, BufferSize, BufferCapacity);
|
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Save a pointer to the given buffer.
|
2017-11-22 07:26:08 +08:00
|
|
|
static void SavePointer(void *Ptr, char *&Buffer, unsigned &BufferSize,
|
|
|
|
unsigned &BufferCapacity) {
|
|
|
|
Append(reinterpret_cast<char *>(&Ptr),
|
|
|
|
reinterpret_cast<char *>(&Ptr) + sizeof(void *),
|
|
|
|
Buffer, BufferSize, BufferCapacity);
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|
2011-03-01 07:58:31 +08:00
|
|
|
|
|
|
|
NestedNameSpecifierLocBuilder::
|
2018-07-31 03:24:48 +08:00
|
|
|
NestedNameSpecifierLocBuilder(const NestedNameSpecifierLocBuilder &Other)
|
2017-11-22 07:26:08 +08:00
|
|
|
: Representation(Other.Representation) {
|
2011-03-01 07:58:31 +08:00
|
|
|
if (!Other.Buffer)
|
|
|
|
return;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-03-01 07:58:31 +08:00
|
|
|
if (Other.BufferCapacity == 0) {
|
|
|
|
// Shallow copy is okay.
|
|
|
|
Buffer = Other.Buffer;
|
|
|
|
BufferSize = Other.BufferSize;
|
|
|
|
return;
|
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-03-01 07:58:31 +08:00
|
|
|
// Deep copy
|
2014-07-17 02:18:13 +08:00
|
|
|
Append(Other.Buffer, Other.Buffer + Other.BufferSize, Buffer, BufferSize,
|
|
|
|
BufferCapacity);
|
2011-03-01 07:58:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NestedNameSpecifierLocBuilder &
|
|
|
|
NestedNameSpecifierLocBuilder::
|
|
|
|
operator=(const NestedNameSpecifierLocBuilder &Other) {
|
|
|
|
Representation = Other.Representation;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-03-01 07:58:31 +08:00
|
|
|
if (Buffer && Other.Buffer && BufferCapacity >= Other.BufferSize) {
|
|
|
|
// Re-use our storage.
|
|
|
|
BufferSize = Other.BufferSize;
|
|
|
|
memcpy(Buffer, Other.Buffer, BufferSize);
|
|
|
|
return *this;
|
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-03-01 07:58:31 +08:00
|
|
|
// Free our storage, if we have any.
|
|
|
|
if (BufferCapacity) {
|
|
|
|
free(Buffer);
|
|
|
|
BufferCapacity = 0;
|
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-03-01 07:58:31 +08:00
|
|
|
if (!Other.Buffer) {
|
|
|
|
// Empty.
|
2014-05-12 13:36:57 +08:00
|
|
|
Buffer = nullptr;
|
2011-03-01 07:58:31 +08:00
|
|
|
BufferSize = 0;
|
|
|
|
return *this;
|
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-03-01 07:58:31 +08:00
|
|
|
if (Other.BufferCapacity == 0) {
|
|
|
|
// Shallow copy is okay.
|
|
|
|
Buffer = Other.Buffer;
|
|
|
|
BufferSize = Other.BufferSize;
|
|
|
|
return *this;
|
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-03-01 07:58:31 +08:00
|
|
|
// Deep copy.
|
2018-09-11 05:54:04 +08:00
|
|
|
BufferSize = 0;
|
2014-07-17 02:18:13 +08:00
|
|
|
Append(Other.Buffer, Other.Buffer + Other.BufferSize, Buffer, BufferSize,
|
|
|
|
BufferCapacity);
|
2011-03-01 07:58:31 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-07-31 03:24:48 +08:00
|
|
|
void NestedNameSpecifierLocBuilder::Extend(ASTContext &Context,
|
|
|
|
SourceLocation TemplateKWLoc,
|
|
|
|
TypeLoc TL,
|
2011-03-01 07:58:31 +08:00
|
|
|
SourceLocation ColonColonLoc) {
|
2018-07-31 03:24:48 +08:00
|
|
|
Representation = NestedNameSpecifier::Create(Context, Representation,
|
|
|
|
TemplateKWLoc.isValid(),
|
2011-03-01 07:58:31 +08:00
|
|
|
TL.getTypePtr());
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-03-01 07:58:31 +08:00
|
|
|
// Push source-location info into the buffer.
|
|
|
|
SavePointer(TL.getOpaqueData(), Buffer, BufferSize, BufferCapacity);
|
|
|
|
SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity);
|
|
|
|
}
|
|
|
|
|
2018-07-31 03:24:48 +08:00
|
|
|
void NestedNameSpecifierLocBuilder::Extend(ASTContext &Context,
|
2011-03-01 07:58:31 +08:00
|
|
|
IdentifierInfo *Identifier,
|
2018-07-31 03:24:48 +08:00
|
|
|
SourceLocation IdentifierLoc,
|
2011-03-01 07:58:31 +08:00
|
|
|
SourceLocation ColonColonLoc) {
|
2018-07-31 03:24:48 +08:00
|
|
|
Representation = NestedNameSpecifier::Create(Context, Representation,
|
2011-03-01 07:58:31 +08:00
|
|
|
Identifier);
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-03-01 07:58:31 +08:00
|
|
|
// Push source-location info into the buffer.
|
|
|
|
SaveSourceLocation(IdentifierLoc, Buffer, BufferSize, BufferCapacity);
|
|
|
|
SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity);
|
|
|
|
}
|
|
|
|
|
2018-07-31 03:24:48 +08:00
|
|
|
void NestedNameSpecifierLocBuilder::Extend(ASTContext &Context,
|
2011-03-01 07:58:31 +08:00
|
|
|
NamespaceDecl *Namespace,
|
2018-07-31 03:24:48 +08:00
|
|
|
SourceLocation NamespaceLoc,
|
2011-03-01 07:58:31 +08:00
|
|
|
SourceLocation ColonColonLoc) {
|
2018-07-31 03:24:48 +08:00
|
|
|
Representation = NestedNameSpecifier::Create(Context, Representation,
|
2011-03-01 07:58:31 +08:00
|
|
|
Namespace);
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-03-01 07:58:31 +08:00
|
|
|
// Push source-location info into the buffer.
|
|
|
|
SaveSourceLocation(NamespaceLoc, Buffer, BufferSize, BufferCapacity);
|
|
|
|
SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NestedNameSpecifierLocBuilder::Extend(ASTContext &Context,
|
|
|
|
NamespaceAliasDecl *Alias,
|
2018-07-31 03:24:48 +08:00
|
|
|
SourceLocation AliasLoc,
|
2011-03-01 07:58:31 +08:00
|
|
|
SourceLocation ColonColonLoc) {
|
|
|
|
Representation = NestedNameSpecifier::Create(Context, Representation, Alias);
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-03-01 07:58:31 +08:00
|
|
|
// Push source-location info into the buffer.
|
|
|
|
SaveSourceLocation(AliasLoc, Buffer, BufferSize, BufferCapacity);
|
|
|
|
SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity);
|
|
|
|
}
|
|
|
|
|
2018-07-31 03:24:48 +08:00
|
|
|
void NestedNameSpecifierLocBuilder::MakeGlobal(ASTContext &Context,
|
2011-03-01 07:58:31 +08:00
|
|
|
SourceLocation ColonColonLoc) {
|
|
|
|
assert(!Representation && "Already have a nested-name-specifier!?");
|
|
|
|
Representation = NestedNameSpecifier::GlobalSpecifier(Context);
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-03-01 07:58:31 +08:00
|
|
|
// Push source-location info into the buffer.
|
|
|
|
SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity);
|
|
|
|
}
|
|
|
|
|
2014-09-26 08:28:20 +08:00
|
|
|
void NestedNameSpecifierLocBuilder::MakeSuper(ASTContext &Context,
|
|
|
|
CXXRecordDecl *RD,
|
|
|
|
SourceLocation SuperLoc,
|
|
|
|
SourceLocation ColonColonLoc) {
|
|
|
|
Representation = NestedNameSpecifier::SuperSpecifier(Context, RD);
|
|
|
|
|
|
|
|
// Push source-location info into the buffer.
|
|
|
|
SaveSourceLocation(SuperLoc, Buffer, BufferSize, BufferCapacity);
|
|
|
|
SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity);
|
|
|
|
}
|
|
|
|
|
2018-07-31 03:24:48 +08:00
|
|
|
void NestedNameSpecifierLocBuilder::MakeTrivial(ASTContext &Context,
|
|
|
|
NestedNameSpecifier *Qualifier,
|
2011-03-01 07:58:31 +08:00
|
|
|
SourceRange R) {
|
|
|
|
Representation = Qualifier;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
|
|
|
// Construct bogus (but well-formed) source information for the
|
2011-03-01 07:58:31 +08:00
|
|
|
// nested-name-specifier.
|
|
|
|
BufferSize = 0;
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<NestedNameSpecifier *, 4> Stack;
|
2011-03-01 07:58:31 +08:00
|
|
|
for (NestedNameSpecifier *NNS = Qualifier; NNS; NNS = NNS->getPrefix())
|
|
|
|
Stack.push_back(NNS);
|
|
|
|
while (!Stack.empty()) {
|
2013-08-24 00:11:15 +08:00
|
|
|
NestedNameSpecifier *NNS = Stack.pop_back_val();
|
2011-03-01 07:58:31 +08:00
|
|
|
switch (NNS->getKind()) {
|
|
|
|
case NestedNameSpecifier::Identifier:
|
|
|
|
case NestedNameSpecifier::Namespace:
|
|
|
|
case NestedNameSpecifier::NamespaceAlias:
|
|
|
|
SaveSourceLocation(R.getBegin(), Buffer, BufferSize, BufferCapacity);
|
|
|
|
break;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-03-01 07:58:31 +08:00
|
|
|
case NestedNameSpecifier::TypeSpec:
|
|
|
|
case NestedNameSpecifier::TypeSpecWithTemplate: {
|
|
|
|
TypeSourceInfo *TSInfo
|
|
|
|
= Context.getTrivialTypeSourceInfo(QualType(NNS->getAsType(), 0),
|
|
|
|
R.getBegin());
|
2018-07-31 03:24:48 +08:00
|
|
|
SavePointer(TSInfo->getTypeLoc().getOpaqueData(), Buffer, BufferSize,
|
2011-03-01 07:58:31 +08:00
|
|
|
BufferCapacity);
|
|
|
|
break;
|
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-03-01 07:58:31 +08:00
|
|
|
case NestedNameSpecifier::Global:
|
2014-09-26 08:28:20 +08:00
|
|
|
case NestedNameSpecifier::Super:
|
2011-03-01 07:58:31 +08:00
|
|
|
break;
|
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-03-01 07:58:31 +08:00
|
|
|
// Save the location of the '::'.
|
2018-07-31 03:24:48 +08:00
|
|
|
SaveSourceLocation(Stack.empty()? R.getEnd() : R.getBegin(),
|
2011-03-01 07:58:31 +08:00
|
|
|
Buffer, BufferSize, BufferCapacity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NestedNameSpecifierLocBuilder::Adopt(NestedNameSpecifierLoc Other) {
|
|
|
|
if (BufferCapacity)
|
|
|
|
free(Buffer);
|
|
|
|
|
|
|
|
if (!Other) {
|
2014-05-12 13:36:57 +08:00
|
|
|
Representation = nullptr;
|
2011-03-01 07:58:31 +08:00
|
|
|
BufferSize = 0;
|
|
|
|
return;
|
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
|
|
|
// Rather than copying the data (which is wasteful), "adopt" the
|
2011-03-01 07:58:31 +08:00
|
|
|
// pointer (which points into the ASTContext) but set the capacity to zero to
|
|
|
|
// indicate that we don't own it.
|
|
|
|
Representation = Other.getNestedNameSpecifier();
|
|
|
|
Buffer = static_cast<char *>(Other.getOpaqueData());
|
|
|
|
BufferSize = Other.getDataLength();
|
|
|
|
BufferCapacity = 0;
|
|
|
|
}
|
|
|
|
|
2018-07-31 03:24:48 +08:00
|
|
|
NestedNameSpecifierLoc
|
2011-03-01 07:58:31 +08:00
|
|
|
NestedNameSpecifierLocBuilder::getWithLocInContext(ASTContext &Context) const {
|
|
|
|
if (!Representation)
|
|
|
|
return NestedNameSpecifierLoc();
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-03-01 07:58:31 +08:00
|
|
|
// If we adopted our data pointer from elsewhere in the AST context, there's
|
|
|
|
// no need to copy the memory.
|
|
|
|
if (BufferCapacity == 0)
|
|
|
|
return NestedNameSpecifierLoc(Representation, Buffer);
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-03-01 07:58:31 +08:00
|
|
|
// FIXME: After copying the source-location information, should we free
|
|
|
|
// our (temporary) buffer and adopt the ASTContext-allocated memory?
|
|
|
|
// Doing so would optimize repeated calls to getWithLocInContext().
|
2016-10-20 22:27:22 +08:00
|
|
|
void *Mem = Context.Allocate(BufferSize, alignof(void *));
|
2011-03-01 07:58:31 +08:00
|
|
|
memcpy(Mem, Buffer, BufferSize);
|
|
|
|
return NestedNameSpecifierLoc(Representation, Mem);
|
|
|
|
}
|