aboutsummaryrefslogtreecommitdiff
path: root/include/clang/AST/TemplateBase.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/clang/AST/TemplateBase.h')
-rw-r--r--include/clang/AST/TemplateBase.h116
1 files changed, 53 insertions, 63 deletions
diff --git a/include/clang/AST/TemplateBase.h b/include/clang/AST/TemplateBase.h
index 1d01753c10fe..f87171a81d1d 100644
--- a/include/clang/AST/TemplateBase.h
+++ b/include/clang/AST/TemplateBase.h
@@ -22,6 +22,7 @@
#include "llvm/ADT/iterator_range.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/TrailingObjects.h"
namespace llvm {
class FoldingSetNodeID;
@@ -198,22 +199,19 @@ public:
///
/// We assume that storage for the template arguments provided
/// outlives the TemplateArgument itself.
- TemplateArgument(const TemplateArgument *Args, unsigned NumArgs) {
+ explicit TemplateArgument(ArrayRef<TemplateArgument> Args) {
this->Args.Kind = Pack;
- this->Args.Args = Args;
- this->Args.NumArgs = NumArgs;
+ this->Args.Args = Args.data();
+ this->Args.NumArgs = Args.size();
}
- static TemplateArgument getEmptyPack() {
- return TemplateArgument((TemplateArgument*)nullptr, 0);
- }
+ static TemplateArgument getEmptyPack() { return TemplateArgument(None); }
/// \brief Create a new template argument pack by copying the given set of
/// template arguments.
static TemplateArgument CreatePackCopy(ASTContext &Context,
- const TemplateArgument *Args,
- unsigned NumArgs);
-
+ ArrayRef<TemplateArgument> Args);
+
/// \brief Return the kind of stored template argument.
ArgKind getKind() const { return (ArgKind)TypeOrValue.Kind; }
@@ -523,7 +521,7 @@ class TemplateArgumentListInfo {
// This can leak if used in an AST node, use ASTTemplateArgumentListInfo
// instead.
- void* operator new(size_t bytes, ASTContext& C);
+ void *operator new(size_t bytes, ASTContext &C) = delete;
public:
TemplateArgumentListInfo() {}
@@ -544,6 +542,10 @@ public:
return Arguments.data();
}
+ llvm::ArrayRef<TemplateArgumentLoc> arguments() const {
+ return Arguments;
+ }
+
const TemplateArgumentLoc &operator[](unsigned I) const {
return Arguments[I];
}
@@ -561,84 +563,72 @@ public:
/// the "<int>" in "sort<int>".
/// This is safe to be used inside an AST node, in contrast with
/// TemplateArgumentListInfo.
-struct ASTTemplateArgumentListInfo {
+struct ASTTemplateArgumentListInfo final
+ : private llvm::TrailingObjects<ASTTemplateArgumentListInfo,
+ TemplateArgumentLoc> {
+private:
+ friend TrailingObjects;
+
+ ASTTemplateArgumentListInfo(const TemplateArgumentListInfo &List);
+
+public:
/// \brief The source location of the left angle bracket ('<').
SourceLocation LAngleLoc;
-
+
/// \brief The source location of the right angle bracket ('>').
SourceLocation RAngleLoc;
-
- union {
- /// \brief The number of template arguments in TemplateArgs.
- /// The actual template arguments (if any) are stored after the
- /// ExplicitTemplateArgumentList structure.
- unsigned NumTemplateArgs;
-
- /// Force ASTTemplateArgumentListInfo to the right alignment
- /// for the following array of TemplateArgumentLocs.
- llvm::AlignedCharArray<
- llvm::AlignOf<TemplateArgumentLoc>::Alignment, 1> Aligner;
- };
- /// \brief Retrieve the template arguments
- TemplateArgumentLoc *getTemplateArgs() {
- return reinterpret_cast<TemplateArgumentLoc *> (this + 1);
- }
-
+ /// \brief The number of template arguments in TemplateArgs.
+ unsigned NumTemplateArgs;
+
/// \brief Retrieve the template arguments
const TemplateArgumentLoc *getTemplateArgs() const {
- return reinterpret_cast<const TemplateArgumentLoc *> (this + 1);
+ return getTrailingObjects<TemplateArgumentLoc>();
}
const TemplateArgumentLoc &operator[](unsigned I) const {
return getTemplateArgs()[I];
}
- static const ASTTemplateArgumentListInfo *Create(ASTContext &C,
- const TemplateArgumentListInfo &List);
-
- void initializeFrom(const TemplateArgumentListInfo &List);
- void initializeFrom(const TemplateArgumentListInfo &List,
- bool &Dependent, bool &InstantiationDependent,
- bool &ContainsUnexpandedParameterPack);
- void copyInto(TemplateArgumentListInfo &List) const;
- static std::size_t sizeFor(unsigned NumTemplateArgs);
+ static const ASTTemplateArgumentListInfo *
+ Create(ASTContext &C, const TemplateArgumentListInfo &List);
};
-/// \brief Extends ASTTemplateArgumentListInfo with the source location
-/// information for the template keyword; this is used as part of the
-/// representation of qualified identifiers, such as S<T>::template apply<T>.
-struct ASTTemplateKWAndArgsInfo : public ASTTemplateArgumentListInfo {
- typedef ASTTemplateArgumentListInfo Base;
-
- // NOTE: the source location of the (optional) template keyword is
- // stored after all template arguments.
+/// \brief Represents an explicit template argument list in C++, e.g.,
+/// the "<int>" in "sort<int>".
+///
+/// It is intended to be used as a trailing object on AST nodes, and
+/// as such, doesn't contain the array of TemplateArgumentLoc itself,
+/// but expects the containing object to also provide storage for
+/// that.
+struct LLVM_ALIGNAS(LLVM_PTR_SIZE) ASTTemplateKWAndArgsInfo {
+ /// \brief The source location of the left angle bracket ('<').
+ SourceLocation LAngleLoc;
- /// \brief Get the source location of the template keyword.
- SourceLocation getTemplateKeywordLoc() const {
- return *reinterpret_cast<const SourceLocation*>
- (getTemplateArgs() + NumTemplateArgs);
- }
+ /// \brief The source location of the right angle bracket ('>').
+ SourceLocation RAngleLoc;
- /// \brief Sets the source location of the template keyword.
- void setTemplateKeywordLoc(SourceLocation TemplateKWLoc) {
- *reinterpret_cast<SourceLocation*>
- (getTemplateArgs() + NumTemplateArgs) = TemplateKWLoc;
- }
+ /// \brief The source location of the template keyword; this is used
+ /// as part of the representation of qualified identifiers, such as
+ /// S<T>::template apply<T>. Will be empty if this expression does
+ /// not have a template keyword.
+ SourceLocation TemplateKWLoc;
- static const ASTTemplateKWAndArgsInfo*
- Create(ASTContext &C, SourceLocation TemplateKWLoc,
- const TemplateArgumentListInfo &List);
+ /// \brief The number of template arguments in TemplateArgs.
+ unsigned NumTemplateArgs;
void initializeFrom(SourceLocation TemplateKWLoc,
- const TemplateArgumentListInfo &List);
+ const TemplateArgumentListInfo &List,
+ TemplateArgumentLoc *OutArgArray);
void initializeFrom(SourceLocation TemplateKWLoc,
const TemplateArgumentListInfo &List,
- bool &Dependent, bool &InstantiationDependent,
+ TemplateArgumentLoc *OutArgArray, bool &Dependent,
+ bool &InstantiationDependent,
bool &ContainsUnexpandedParameterPack);
void initializeFrom(SourceLocation TemplateKWLoc);
- static std::size_t sizeFor(unsigned NumTemplateArgs);
+ void copyInto(const TemplateArgumentLoc *ArgArray,
+ TemplateArgumentListInfo &List) const;
};
const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,