Skip to content

Commit

Permalink
Revert "[clang] Implement sugared substitution changes to infrastruct…
Browse files Browse the repository at this point in the history
…ure"

This reverts commit c4c2a3c.
  • Loading branch information
mizvekov committed Oct 26, 2022
1 parent a88ebd4 commit 8383c2a
Show file tree
Hide file tree
Showing 22 changed files with 289 additions and 447 deletions.
5 changes: 2 additions & 3 deletions clang/include/clang/AST/ASTContext.h
Expand Up @@ -1621,7 +1621,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
Decl *AssociatedDecl, unsigned Index,
Optional<unsigned> PackIndex) const;
QualType getSubstTemplateTypeParmPackType(Decl *AssociatedDecl,
unsigned Index, bool Final,
unsigned Index,
const TemplateArgument &ArgPack);

QualType
Expand Down Expand Up @@ -2207,8 +2207,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
Optional<unsigned> PackIndex) const;
TemplateName getSubstTemplateTemplateParmPack(const TemplateArgument &ArgPack,
Decl *AssociatedDecl,
unsigned Index,
bool Final) const;
unsigned Index) const;

enum GetBuiltinTypeError {
/// No error
Expand Down
5 changes: 1 addition & 4 deletions clang/include/clang/AST/PropertiesBase.td
Expand Up @@ -730,11 +730,8 @@ let Class = PropertyTypeCase<TemplateName, "SubstTemplateTemplateParmPack"> in {
def : Property<"index", UInt32> {
let Read = [{ parm->getIndex() }];
}
def : Property<"final", Bool> {
let Read = [{ parm->getFinal() }];
}
def : Creator<[{
return ctx.getSubstTemplateTemplateParmPack(argumentPack, associatedDecl, index, final);
return ctx.getSubstTemplateTemplateParmPack(argumentPack, associatedDecl, index);
}]>;
}

Expand Down
17 changes: 9 additions & 8 deletions clang/include/clang/AST/TemplateName.h
Expand Up @@ -139,24 +139,25 @@ class OverloadedTemplateStorage : public UncommonTemplateNameStorage {
class SubstTemplateTemplateParmPackStorage : public UncommonTemplateNameStorage,
public llvm::FoldingSetNode {
const TemplateArgument *Arguments;
llvm::PointerIntPair<Decl *, 1, bool> AssociatedDeclAndFinal;
Decl *AssociatedDecl;

public:
SubstTemplateTemplateParmPackStorage(ArrayRef<TemplateArgument> ArgPack,
Decl *AssociatedDecl, unsigned Index,
bool Final);
Decl *AssociatedDecl, unsigned Index)
: UncommonTemplateNameStorage(SubstTemplateTemplateParmPack, Index,
ArgPack.size()),
Arguments(ArgPack.data()), AssociatedDecl(AssociatedDecl) {
assert(AssociatedDecl != nullptr);
}

/// A template-like entity which owns the whole pattern being substituted.
/// This will own a set of template parameters.
Decl *getAssociatedDecl() const;
Decl *getAssociatedDecl() const { return AssociatedDecl; }

/// Returns the index of the replaced parameter in the associated declaration.
/// This should match the result of `getParameterPack()->getIndex()`.
unsigned getIndex() const { return Bits.Index; }

// When true the substitution will be 'Final' (subst node won't be placed).
bool getFinal() const;

/// Retrieve the template template parameter pack being substituted.
TemplateTemplateParmDecl *getParameterPack() const;

Expand All @@ -168,7 +169,7 @@ class SubstTemplateTemplateParmPackStorage : public UncommonTemplateNameStorage,

static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
const TemplateArgument &ArgPack, Decl *AssociatedDecl,
unsigned Index, bool Final);
unsigned Index);
};

/// Represents a C++ template name within the type system.
Expand Down
12 changes: 4 additions & 8 deletions clang/include/clang/AST/Type.h
Expand Up @@ -5158,10 +5158,10 @@ class SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {
/// parameter pack is instantiated with.
const TemplateArgument *Arguments;

llvm::PointerIntPair<Decl *, 1, bool> AssociatedDeclAndFinal;
Decl *AssociatedDecl;

SubstTemplateTypeParmPackType(QualType Canon, Decl *AssociatedDecl,
unsigned Index, bool Final,
unsigned Index,
const TemplateArgument &ArgPack);

public:
Expand All @@ -5170,7 +5170,7 @@ class SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {
/// A template-like entity which owns the whole pattern being substituted.
/// This will usually own a set of template parameters, or in some
/// cases might even be a template parameter itself.
Decl *getAssociatedDecl() const;
Decl *getAssociatedDecl() const { return AssociatedDecl; }

/// Gets the template parameter declaration that was substituted for.
const TemplateTypeParmDecl *getReplacedParameter() const;
Expand All @@ -5179,9 +5179,6 @@ class SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {
/// This should match the result of `getReplacedParameter()->getIndex()`.
unsigned getIndex() const { return SubstTemplateTypeParmPackTypeBits.Index; }

// When true the substitution will be 'Final' (subst node won't be placed).
bool getFinal() const;

unsigned getNumArgs() const {
return SubstTemplateTypeParmPackTypeBits.NumArgs;
}
Expand All @@ -5193,8 +5190,7 @@ class SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {

void Profile(llvm::FoldingSetNodeID &ID);
static void Profile(llvm::FoldingSetNodeID &ID, const Decl *AssociatedDecl,
unsigned Index, bool Final,
const TemplateArgument &ArgPack);
unsigned Index, const TemplateArgument &ArgPack);

static bool classof(const Type *T) {
return T->getTypeClass() == SubstTemplateTypeParmPack;
Expand Down
5 changes: 1 addition & 4 deletions clang/include/clang/AST/TypeProperties.td
Expand Up @@ -773,16 +773,13 @@ let Class = SubstTemplateTypeParmPackType in {
def : Property<"Index", UInt32> {
let Read = [{ node->getIndex() }];
}
def : Property<"Final", Bool> {
let Read = [{ node->getFinal() }];
}
def : Property<"replacementPack", TemplateArgument> {
let Read = [{ node->getArgumentPack() }];
}

def : Creator<[{
return ctx.getSubstTemplateTypeParmPackType(
associatedDecl, Index, Final, replacementPack);
associatedDecl, Index, replacementPack);
}]>;
}

Expand Down
26 changes: 14 additions & 12 deletions clang/include/clang/Sema/Sema.h
Expand Up @@ -9074,12 +9074,10 @@ class Sema final {
// C++ Template Instantiation
//

MultiLevelTemplateArgumentList
getTemplateInstantiationArgs(const NamedDecl *D, bool Final = false,
const TemplateArgumentList *Innermost = nullptr,
bool RelativeToPrimary = false,
const FunctionDecl *Pattern = nullptr,
bool ForConstraintInstantiation = false);
MultiLevelTemplateArgumentList getTemplateInstantiationArgs(
const NamedDecl *D, const TemplateArgumentList *Innermost = nullptr,
bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr,
bool ForConstraintInstantiation = false);

/// A context in which code is being synthesized (where a source location
/// alone is not sufficient to identify the context). This covers template
Expand Down Expand Up @@ -10173,12 +10171,16 @@ class Sema final {
bool FailOnError = false);

/// Build an Objective-C object pointer type.
QualType BuildObjCObjectType(
QualType BaseType, SourceLocation Loc, SourceLocation TypeArgsLAngleLoc,
ArrayRef<TypeSourceInfo *> TypeArgs, SourceLocation TypeArgsRAngleLoc,
SourceLocation ProtocolLAngleLoc, ArrayRef<ObjCProtocolDecl *> Protocols,
ArrayRef<SourceLocation> ProtocolLocs, SourceLocation ProtocolRAngleLoc,
bool FailOnError, bool Rebuilding);
QualType BuildObjCObjectType(QualType BaseType,
SourceLocation Loc,
SourceLocation TypeArgsLAngleLoc,
ArrayRef<TypeSourceInfo *> TypeArgs,
SourceLocation TypeArgsRAngleLoc,
SourceLocation ProtocolLAngleLoc,
ArrayRef<ObjCProtocolDecl *> Protocols,
ArrayRef<SourceLocation> ProtocolLocs,
SourceLocation ProtocolRAngleLoc,
bool FailOnError = false);

/// Ensure attributes are consistent with type.
/// \param [in, out] Attributes The attributes to check; they will
Expand Down
23 changes: 10 additions & 13 deletions clang/include/clang/Sema/Template.h
Expand Up @@ -77,7 +77,7 @@ enum class TemplateSubstitutionKind : char {

using ArgList = ArrayRef<TemplateArgument>;
struct ArgumentListLevel {
llvm::PointerIntPair<Decl *, 1, bool> AssociatedDeclAndFinal;
Decl *AssociatedDecl;
ArgList Args;
};
using ContainerType = SmallVector<ArgumentListLevel, 4>;
Expand All @@ -101,8 +101,8 @@ enum class TemplateSubstitutionKind : char {
MultiLevelTemplateArgumentList() = default;

/// Construct a single-level template argument list.
MultiLevelTemplateArgumentList(Decl *D, ArgList Args, bool Final) {
addOuterTemplateArguments(D, Args, Final);
MultiLevelTemplateArgumentList(Decl *D, ArgList Args) {
addOuterTemplateArguments(D, Args);
}

void setKind(TemplateSubstitutionKind K) { Kind = K; }
Expand Down Expand Up @@ -160,11 +160,9 @@ enum class TemplateSubstitutionKind : char {
/// A template-like entity which owns the whole pattern being substituted.
/// This will usually own a set of template parameters, or in some
/// cases might even be a template parameter itself.
std::pair<Decl *, bool> getAssociatedDecl(unsigned Depth) const {
Decl *getAssociatedDecl(unsigned Depth) const {
assert(NumRetainedOuterLevels <= Depth && Depth < getNumLevels());
auto AD = TemplateArgumentLists[getNumLevels() - Depth - 1]
.AssociatedDeclAndFinal;
return {AD.getPointer(), AD.getInt()};
return TemplateArgumentLists[getNumLevels() - Depth - 1].AssociatedDecl;
}

/// Determine whether there is a non-NULL template argument at the
Expand Down Expand Up @@ -204,22 +202,21 @@ enum class TemplateSubstitutionKind : char {

/// Add a new outmost level to the multi-level template argument
/// list.
/// A 'Final' substitution means that Subst* nodes won't be built
/// for the replacements.
void addOuterTemplateArguments(Decl *AssociatedDecl, ArgList Args,
bool Final) {
void addOuterTemplateArguments(Decl *AssociatedDecl, ArgList Args) {
assert(!NumRetainedOuterLevels &&
"substituted args outside retained args?");
assert(getKind() == TemplateSubstitutionKind::Specialization);
assert(AssociatedDecl != nullptr || Args.size() == 0);
TemplateArgumentLists.push_back(
{{AssociatedDecl->getCanonicalDecl(), Final}, Args});
{AssociatedDecl ? AssociatedDecl->getCanonicalDecl() : nullptr,
Args});
}

void addOuterTemplateArguments(ArgList Args) {
assert(!NumRetainedOuterLevels &&
"substituted args outside retained args?");
assert(getKind() == TemplateSubstitutionKind::Rewrite);
TemplateArgumentLists.push_back({{}, Args});
TemplateArgumentLists.push_back({nullptr, Args});
}

void addOuterTemplateArguments(llvm::NoneType) {
Expand Down

0 comments on commit 8383c2a

Please sign in to comment.