Skip to content

Commit

Permalink
Temporarily revert universal template params
Browse files Browse the repository at this point in the history
  • Loading branch information
cor3ntin committed Oct 4, 2024
1 parent d658277 commit ffb33f1
Show file tree
Hide file tree
Showing 39 changed files with 14 additions and 1,268 deletions.
5 changes: 0 additions & 5 deletions clang/include/clang/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "clang/AST/PrettyPrinter.h"
#include "clang/AST/RawCommentList.h"
#include "clang/AST/TemplateName.h"
#include "clang/AST/UniversalTemplateParameterName.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/PartialDiagnostic.h"
#include "clang/Basic/SourceLocation.h"
Expand Down Expand Up @@ -2336,10 +2335,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
unsigned Index,
bool Final) const;

UniversalTemplateParameterName *
getUniversalTemplateParameterName(SourceLocation Loc,
DeclarationNameInfo Name,
UniversalTemplateParmDecl *Decl) const;
/// Represents a TemplateName which had some of its default arguments
/// deduced. This both represents this default argument deduction as sugar,
/// and provides the support for it's equivalences through canonicalization.
Expand Down
2 changes: 0 additions & 2 deletions clang/include/clang/AST/ASTNodeTraverser.h
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,6 @@ class ASTNodeTraverser
D->defaultArgumentWasInherited() ? "inherited from" : "previous");
}

void VisitUniversalTemplateParmDecl(const UniversalTemplateParmDecl *D) {}

void VisitConceptDecl(const ConceptDecl *D) {
dumpTemplateParameters(D->getTemplateParameters());
Visit(D->getConstraintExpr());
Expand Down
74 changes: 1 addition & 73 deletions clang/include/clang/AST/DeclTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class IdentifierInfo;
class NonTypeTemplateParmDecl;
class TemplateDecl;
class TemplateTemplateParmDecl;
class UniversalTemplateParmDecl;
class TemplateTypeParmDecl;
class ConceptDecl;
class UnresolvedSetImpl;
Expand All @@ -64,7 +63,7 @@ class VarTemplatePartialSpecializationDecl;
/// Stores a template parameter of any kind.
using TemplateParameter =
llvm::PointerUnion<TemplateTypeParmDecl *, NonTypeTemplateParmDecl *,
TemplateTemplateParmDecl *, UniversalTemplateParmDecl *>;
TemplateTemplateParmDecl *>;

NamedDecl *getAsNamedDecl(TemplateParameter P);

Expand Down Expand Up @@ -1768,75 +1767,6 @@ class TemplateTemplateParmDecl final
static bool classofKind(Kind K) { return K == TemplateTemplateParm; }
};

class UniversalTemplateParmDecl final : public NamedDecl,
protected TemplateParmPosition {

/// Whether this universal template parameter is a parameter pack.
bool ParameterPack;

UniversalTemplateParmDecl(DeclContext *DC, SourceLocation L, unsigned D,
unsigned P, bool ParameterPack, IdentifierInfo *Id)
: NamedDecl(UniversalTemplateParm, DC, L, Id), TemplateParmPosition(D, P),
ParameterPack(ParameterPack) {}

// UniversalTemplateParmDecl(DeclContext *DC, SourceLocation L, unsigned D,
// unsigned P, IdentifierInfo *Id,
// TemplateNameKind ParameterKind,
// TemplateParameterList *Params,
// ArrayRef<TemplateParameterList *> Expansions);

void anchor() override {}

public:
friend class ASTDeclReader;
friend class ASTDeclWriter;

static UniversalTemplateParmDecl *Create(const ASTContext &C, DeclContext *DC,
SourceLocation L, unsigned D,
unsigned P, bool ParameterPack,
IdentifierInfo *Id);

// static TemplateTemplateParmDecl *
// Create(const ASTContext &C, DeclContext *DC, SourceLocation L, unsigned D,
/// unsigned P, IdentifierInfo *Id, TemplateNameKind ParameterKind,
// TemplateParameterList *Params,
// ArrayRef<TemplateParameterList *> Expansions);

static TemplateTemplateParmDecl *CreateDeserialized(ASTContext &C,
unsigned ID);
// static TemplateTemplateParmDecl *CreateDeserialized(ASTContext &C,
// unsigned ID,
// unsigned
// NumExpansions);

using TemplateParmPosition::getDepth;
using TemplateParmPosition::getIndex;
using TemplateParmPosition::getPosition;
using TemplateParmPosition::setDepth;
using TemplateParmPosition::setPosition;

/// Whether this template template parameter is a template
/// parameter pack.
///
/// \code
/// template<template <class T> ...MetaFunctions> struct Apply;
/// \endcode
bool isParameterPack() const { return ParameterPack; }

// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classofKind(Kind K) { return K == UniversalTemplateParm; }

void Profile(llvm::FoldingSetNodeID &ID) const {
Profile(ID, ParameterPack, getASTContext());
}

static void Profile(llvm::FoldingSetNodeID &ID, bool ParameterPack,
const ASTContext &Context) {
ID.AddBoolean(ParameterPack);
}
};

/// Represents the builtin template declaration which is used to
/// implement __make_integer_seq and other builtin templates. It serves
/// no real purpose beyond existing as a place to hold template parameters.
Expand Down Expand Up @@ -3387,8 +3317,6 @@ inline NamedDecl *getAsNamedDecl(TemplateParameter P) {
return PD;
if (auto *PD = P.dyn_cast<NonTypeTemplateParmDecl *>())
return PD;
if (auto *PD = P.dyn_cast<UniversalTemplateParmDecl *>())
return PD;
return P.get<TemplateTemplateParmDecl *>();
}

Expand Down
24 changes: 0 additions & 24 deletions clang/include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include "clang/AST/TemplateName.h"
#include "clang/AST/Type.h"
#include "clang/AST/TypeLoc.h"
#include "clang/AST/UniversalTemplateParameterName.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/OpenMPKinds.h"
#include "clang/Basic/Specifiers.h"
Expand Down Expand Up @@ -260,9 +259,6 @@ template <typename Derived> class RecursiveASTVisitor {
/// \returns false if the visitation was terminated early, true otherwise.
bool TraverseTemplateName(TemplateName Template);

bool
TraverseUniversalTemplateParameterName(UniversalTemplateParameterName *UTPN);

/// Recursively visit a template argument and dispatch to the
/// appropriate method for the argument type.
///
Expand Down Expand Up @@ -873,12 +869,6 @@ bool RecursiveASTVisitor<Derived>::TraverseTemplateName(TemplateName Template) {
return true;
}

template <typename Derived>
bool RecursiveASTVisitor<Derived>::TraverseUniversalTemplateParameterName(
UniversalTemplateParameterName *UTPN) {
return true;
}

template <typename Derived>
bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(
const TemplateArgument &Arg) {
Expand All @@ -903,13 +893,6 @@ bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(

case TemplateArgument::Pack:
return getDerived().TraverseTemplateArguments(Arg.pack_elements());

case TemplateArgument::Universal:
case TemplateArgument::UniversalExpansion: {
UniversalTemplateParameterName *UTPN =
Arg.getAsUniversalTemplateParameterOrPattern();
return getDerived().TraverseUniversalTemplateParameterName(UTPN);
}
}

return true;
Expand Down Expand Up @@ -946,11 +929,6 @@ bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc(
return getDerived().TraverseTemplateName(
Arg.getAsTemplateOrTemplatePattern());

case TemplateArgument::Universal:
case TemplateArgument::UniversalExpansion:
return getDerived().TraverseUniversalTemplateParameterName(
Arg.getAsUniversalTemplateParameterOrPattern());

case TemplateArgument::Expression:
return getDerived().TraverseStmt(ArgLoc.getSourceExpression());

Expand Down Expand Up @@ -1979,8 +1957,6 @@ DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, {
TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
})

DEF_TRAVERSE_DECL(UniversalTemplateParmDecl, {})

DEF_TRAVERSE_DECL(BuiltinTemplateDecl, {
TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
})
Expand Down
2 changes: 0 additions & 2 deletions clang/include/clang/AST/TemplateArgumentVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ class Base {
DISPATCH(TemplateExpansion);
DISPATCH(Expression);
DISPATCH(Pack);
DISPATCH(Universal);
DISPATCH(UniversalExpansion);
}
llvm_unreachable("TemplateArgument is not covered in switch!");
}
Expand Down
78 changes: 1 addition & 77 deletions clang/include/clang/AST/TemplateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/TemplateName.h"
#include "clang/AST/Type.h"
#include "clang/AST/UniversalTemplateParameterName.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
#include "llvm/ADT/APInt.h"
Expand Down Expand Up @@ -107,13 +106,6 @@ class TemplateArgument {
/// The template argument is actually a parameter pack. Arguments are stored
/// in the Args struct.
Pack,

/// The template argument refers to a universal template parameter
Universal,

/// The template argument refers to a universal template parameter pack
/// expansion
UniversalExpansion,
};

private:
Expand Down Expand Up @@ -179,21 +171,13 @@ class TemplateArgument {
uintptr_t V;
};

struct UniversalTpl {
unsigned Kind : 31;
unsigned IsDefaulted : 1;
unsigned NumExpansions;
UniversalTemplateParameterName *D;
};

union {
struct DA DeclArg;
struct I Integer;
struct V Value;
struct A Args;
struct TA TemplateArg;
struct TV TypeOrValue;
struct UniversalTpl UniversalArg;
};

void initFromType(QualType T, bool IsNullPtr, bool IsDefaulted);
Expand Down Expand Up @@ -300,25 +284,6 @@ class TemplateArgument {
this->Args.NumArgs = Args.size();
}

explicit TemplateArgument(UniversalTemplateParameterName *U,
bool IsDefaulted = false) {
UniversalArg.Kind = Universal;
UniversalArg.IsDefaulted = IsDefaulted;
UniversalArg.NumExpansions = 0;
UniversalArg.D = U;
}

explicit TemplateArgument(UniversalTemplateParameterName *U,
std::optional<unsigned> NumExpansions) {
UniversalArg.Kind = UniversalExpansion;
UniversalArg.IsDefaulted = false;
if (NumExpansions)
UniversalArg.NumExpansions = *NumExpansions + 1;
else
UniversalArg.NumExpansions = 0;
UniversalArg.D = U;
}

static TemplateArgument getEmptyPack() {
return TemplateArgument(std::nullopt);
}
Expand Down Expand Up @@ -393,18 +358,6 @@ class TemplateArgument {
return TemplateName::getFromVoidPointer(TemplateArg.Name);
}

UniversalTemplateParameterName *getAsUniversalTemplateParameterName() const {
assert((getKind() == Universal) && "Unexpected kind");
return UniversalArg.D;
}

UniversalTemplateParameterName *
getAsUniversalTemplateParameterOrPattern() const {
assert((getKind() == Universal || getKind() == UniversalExpansion) &&
"Unexpected kind");
return UniversalArg.D;
}

/// Retrieve the number of expansions that a template template argument
/// expansion will produce, if known.
std::optional<unsigned> getNumTemplateExpansions() const;
Expand Down Expand Up @@ -531,23 +484,14 @@ struct TemplateArgumentLocInfo {
SourceLocation EllipsisLoc;
};

struct UniversalTemplateArgLocInfo {
UniversalTemplateParameterName *Name;
SourceLocation EllipsisLoc;
};

llvm::PointerUnion<TemplateTemplateArgLocInfo *, Expr *, TypeSourceInfo *,
UniversalTemplateArgLocInfo *>
llvm::PointerUnion<TemplateTemplateArgLocInfo *, Expr *, TypeSourceInfo *>
Pointer;

TemplateTemplateArgLocInfo *getTemplate() const {
return Pointer.get<TemplateTemplateArgLocInfo *>();
}

UniversalTemplateArgLocInfo *getUniversal() const {
return Pointer.get<UniversalTemplateArgLocInfo *>();
}

public:
TemplateArgumentLocInfo() {}
TemplateArgumentLocInfo(TypeSourceInfo *Declarator) { Pointer = Declarator; }
Expand All @@ -559,9 +503,6 @@ struct TemplateArgumentLocInfo {
SourceLocation TemplateNameLoc,
SourceLocation EllipsisLoc);

TemplateArgumentLocInfo(ASTContext &Ctx, UniversalTemplateParameterName *,
SourceLocation EllipsisLoc);

TypeSourceInfo *getAsTypeSourceInfo() const {
return Pointer.get<TypeSourceInfo *>();
}
Expand All @@ -581,10 +522,6 @@ struct TemplateArgumentLocInfo {
SourceLocation getTemplateEllipsisLoc() const {
return getTemplate()->EllipsisLoc;
}

SourceLocation getUniversalEllipsisLoc() const {
return getUniversal()->EllipsisLoc;
}
};

/// Location wrapper for a TemplateArgument. TemplateArgument is to
Expand Down Expand Up @@ -627,14 +564,6 @@ class TemplateArgumentLoc {
Argument.getKind() == TemplateArgument::TemplateExpansion);
}

TemplateArgumentLoc(ASTContext &Ctx, const TemplateArgument &Argument,
UniversalTemplateParameterName *Param,
SourceLocation EllipsisLoc = SourceLocation())
: Argument(Argument), LocInfo(Ctx, Param, EllipsisLoc) {
assert(Argument.getKind() == TemplateArgument::Universal ||
Argument.getKind() == TemplateArgument::UniversalExpansion);
}

/// - Fetches the primary location of the argument.
SourceLocation getLocation() const {
if (Argument.getKind() == TemplateArgument::Template ||
Expand Down Expand Up @@ -702,11 +631,6 @@ class TemplateArgumentLoc {
return LocInfo.getTemplateEllipsisLoc();
}

SourceLocation getUniversalEllipsisLoc() const {
if (Argument.getKind() != TemplateArgument::UniversalExpansion)
return SourceLocation();
return LocInfo.getUniversalEllipsisLoc();
}
};

/// A convenient class for passing around template argument
Expand Down
2 changes: 0 additions & 2 deletions clang/include/clang/AST/TextNodeDumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,6 @@ class TextNodeDumper
void VisitTemplateExpansionTemplateArgument(const TemplateArgument &TA);
void VisitExpressionTemplateArgument(const TemplateArgument &TA);
void VisitConceptTemplateArgument(const TemplateArgument &TA);
void VisitUniversalTemplateArgument(const TemplateArgument &TA);
void VisitUniversalExpansionTemplateArgument(const TemplateArgument &TA);

void VisitPackTemplateArgument(const TemplateArgument &TA);

Expand Down
1 change: 0 additions & 1 deletion clang/include/clang/Basic/DeclNodes.td
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def Named : DeclNode<Decl, "named declarations", 1>;
def VarTemplate : DeclNode<RedeclarableTemplate>;
def TypeAliasTemplate : DeclNode<RedeclarableTemplate>;
def TemplateTemplateParm : DeclNode<Template>;
def UniversalTemplateParm : DeclNode<Named>;
def BuiltinTemplate : DeclNode<Template>;
def Concept : DeclNode<Template>;
def BaseUsing : DeclNode<Named, "", 1>;
Expand Down
Loading

0 comments on commit ffb33f1

Please sign in to comment.