Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 11 additions & 41 deletions clang/include/clang/AST/PropertiesBase.td
Original file line number Diff line number Diff line change
Expand Up @@ -785,14 +785,9 @@ let Class = PropertyTypeCase<TemplateArgument, "Null"> in {
}]>;
}
let Class = PropertyTypeCase<TemplateArgument, "Type"> in {
def : Property<"type", QualType> {
let Read = [{ node.getAsType() }];
}
def : Property<"isDefaulted", Bool> {
let Read = [{ node.getIsDefaulted() }];
}
def : Property<"type", QualType> { let Read = [{ node.getAsType() }]; }
def : Creator<[{
return TemplateArgument(type, /* isNullPtr */ false, isDefaulted);
return TemplateArgument(type, /* isNullPtr=*/false);
}]>;
}
let Class = PropertyTypeCase<TemplateArgument, "Declaration"> in {
Expand All @@ -802,36 +797,23 @@ let Class = PropertyTypeCase<TemplateArgument, "Declaration"> in {
def : Property<"parameterType", QualType> {
let Read = [{ node.getParamTypeForDecl() }];
}
def : Property<"isDefaulted", Bool> {
let Read = [{ node.getIsDefaulted() }];
}
def : Creator<[{
return TemplateArgument(declaration, parameterType, isDefaulted);
return TemplateArgument(declaration, parameterType);
}]>;
}
let Class = PropertyTypeCase<TemplateArgument, "NullPtr"> in {
def : Property<"type", QualType> {
let Read = [{ node.getNullPtrType() }];
}
def : Property<"isDefaulted", Bool> {
let Read = [{ node.getIsDefaulted() }];
}
def : Property<"type", QualType> { let Read = [{ node.getNullPtrType() }]; }
def : Creator<[{
return TemplateArgument(type, /*nullptr*/ true, isDefaulted);
return TemplateArgument(type, /*IsNullPtr=*/true);
}]>;
}
let Class = PropertyTypeCase<TemplateArgument, "Integral"> in {
def : Property<"value", APSInt> {
let Read = [{ node.getAsIntegral() }];
}
def : Property<"type", QualType> {
let Read = [{ node.getIntegralType() }];
}
def : Property<"isDefaulted", Bool> {
let Read = [{ node.getIsDefaulted() }];
}
def : Property<"type", QualType> { let Read = [{ node.getIntegralType() }]; }
def : Creator<[{
return TemplateArgument(ctx, value, type, isDefaulted);
return TemplateArgument(ctx, value, type);
}]>;
}
let Class = PropertyTypeCase<TemplateArgument, "StructuralValue"> in {
Expand All @@ -841,22 +823,16 @@ let Class = PropertyTypeCase<TemplateArgument, "StructuralValue"> in {
def : Property<"type", QualType> {
let Read = [{ node.getStructuralValueType() }];
}
def : Property<"isDefaulted", Bool> {
let Read = [{ node.getIsDefaulted() }];
}
def : Creator<[{
return TemplateArgument(ctx, type, value, isDefaulted);
return TemplateArgument(ctx, type, value);
}]>;
}
let Class = PropertyTypeCase<TemplateArgument, "Template"> in {
def : Property<"name", TemplateName> {
let Read = [{ node.getAsTemplateOrTemplatePattern() }];
}
def : Property<"isDefaulted", Bool> {
let Read = [{ node.getIsDefaulted() }];
}
def : Creator<[{
return TemplateArgument(name, isDefaulted);
return TemplateArgument(name);
}]>;
}
let Class = PropertyTypeCase<TemplateArgument, "TemplateExpansion"> in {
Expand All @@ -868,11 +844,8 @@ let Class = PropertyTypeCase<TemplateArgument, "TemplateExpansion"> in {
node.getNumTemplateExpansions()
}];
}
def : Property<"isDefaulted", Bool> {
let Read = [{ node.getIsDefaulted() }];
}
def : Creator<[{
return TemplateArgument(name, numExpansions, isDefaulted);
return TemplateArgument(name, numExpansions);
}]>;
}
let Class = PropertyTypeCase<TemplateArgument, "Expression"> in {
Expand All @@ -882,11 +855,8 @@ let Class = PropertyTypeCase<TemplateArgument, "Expression"> in {
def : Property<"IsCanonical", Bool> {
let Read = [{ node.isCanonicalExpr() }];
}
def : Property<"isDefaulted", Bool> {
let Read = [{ node.getIsDefaulted() }];
}
def : Creator<[{
return TemplateArgument(expression, IsCanonical, isDefaulted);
return TemplateArgument(expression, IsCanonical);
}]>;
}
let Class = PropertyTypeCase<TemplateArgument, "Pack"> in {
Expand Down
75 changes: 26 additions & 49 deletions clang/include/clang/AST/TemplateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,18 @@ class TemplateArgument {
struct DA {
LLVM_PREFERRED_TYPE(ArgKind)
unsigned Kind : 31;
LLVM_PREFERRED_TYPE(bool)
unsigned IsDefaulted : 1;
void *QT;
ValueDecl *D;
};
struct I {
LLVM_PREFERRED_TYPE(ArgKind)
unsigned Kind : 31;
LLVM_PREFERRED_TYPE(bool)
unsigned IsDefaulted : 1;
unsigned IsUnsigned : 1;
// We store a decomposed APSInt with the data allocated by ASTContext if
// BitWidth > 64. The memory may be shared between multiple
// TemplateArgument instances.
unsigned BitWidth : 31;
LLVM_PREFERRED_TYPE(bool)
unsigned IsUnsigned : 1;
union {
/// Used to store the <= 64 bits integer value.
uint64_t VAL;
Expand All @@ -141,33 +137,25 @@ class TemplateArgument {
struct V {
LLVM_PREFERRED_TYPE(ArgKind)
unsigned Kind : 31;
LLVM_PREFERRED_TYPE(bool)
unsigned IsDefaulted : 1;
APValue *Value;
void *Type;
};
struct A {
LLVM_PREFERRED_TYPE(ArgKind)
unsigned Kind : 31;
LLVM_PREFERRED_TYPE(bool)
unsigned IsDefaulted : 1;
unsigned NumArgs;
const TemplateArgument *Args;
};
struct TA {
LLVM_PREFERRED_TYPE(ArgKind)
unsigned Kind : 31;
LLVM_PREFERRED_TYPE(bool)
unsigned IsDefaulted : 1;
UnsignedOrNone NumExpansions;
void *Name;
};
struct TV {
LLVM_PREFERRED_TYPE(ArgKind)
unsigned Kind : 31;
LLVM_PREFERRED_TYPE(bool)
unsigned IsDefaulted : 1;
LLVM_PREFERRED_TYPE(bool)
unsigned IsCanonicalExpr : 1;
uintptr_t V;
};
Expand All @@ -180,38 +168,46 @@ class TemplateArgument {
struct TV TypeOrValue;
};

void initFromType(QualType T, bool IsNullPtr, bool IsDefaulted);
void initFromDeclaration(ValueDecl *D, QualType QT, bool IsDefaulted);
void initFromType(QualType T, bool IsNullPtr) {
TypeOrValue.Kind = IsNullPtr ? NullPtr : Type;
TypeOrValue.V = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr());
}

void initFromDeclaration(ValueDecl *D, QualType QT) {
assert(D && "Expected decl");
DeclArg.Kind = Declaration;
DeclArg.QT = QT.getAsOpaquePtr();
DeclArg.D = D;
}

void initFromIntegral(const ASTContext &Ctx, const llvm::APSInt &Value,
QualType Type, bool IsDefaulted);
QualType Type);
void initFromStructural(const ASTContext &Ctx, QualType Type,
const APValue &V, bool IsDefaulted);
const APValue &V);

public:
/// Construct an empty, invalid template argument.
constexpr TemplateArgument()
: TypeOrValue{Null, /*IsDefaulted=*/0, /*IsCanonicalExpr=*/0, /*V=*/0} {}
: TypeOrValue{Null, /*IsCanonicalExpr=*/false, /*V=*/0} {}

/// Construct a template type argument.
TemplateArgument(QualType T, bool isNullPtr = false,
bool IsDefaulted = false) {
initFromType(T, isNullPtr, IsDefaulted);
TemplateArgument(QualType T, bool isNullPtr = false) {
initFromType(T, isNullPtr);
}

/// Construct a template argument that refers to a (non-dependent)
/// declaration.
TemplateArgument(ValueDecl *D, QualType QT, bool IsDefaulted = false) {
initFromDeclaration(D, QT, IsDefaulted);
}
TemplateArgument(ValueDecl *D, QualType QT) { initFromDeclaration(D, QT); }

/// Construct an integral constant template argument. The memory to
/// store the value is allocated with Ctx.
TemplateArgument(const ASTContext &Ctx, const llvm::APSInt &Value,
QualType Type, bool IsDefaulted = false);
QualType Type) {
initFromIntegral(Ctx, Value, Type);
}

/// Construct a template argument from an arbitrary constant value.
TemplateArgument(const ASTContext &Ctx, QualType Type, const APValue &Value,
bool IsDefaulted = false);
TemplateArgument(const ASTContext &Ctx, QualType Type, const APValue &Value);

/// Construct an integral constant template argument with the same
/// value as Other but a different type.
Expand All @@ -228,12 +224,8 @@ class TemplateArgument {
/// is taken.
///
/// \param Name The template name.
///
/// \param IsDefaulted If 'true', implies that this TemplateArgument
/// corresponds to a default template parameter
TemplateArgument(TemplateName Name, bool IsDefaulted = false) {
TemplateArgument(TemplateName Name) {
TemplateArg.Kind = Template;
TemplateArg.IsDefaulted = IsDefaulted;
TemplateArg.Name = Name.getAsVoidPointer();
TemplateArg.NumExpansions = std::nullopt;
}
Expand All @@ -249,13 +241,8 @@ class TemplateArgument {
///
/// \param NumExpansions The number of expansions that will be generated by
/// instantiating
///
/// \param IsDefaulted If 'true', implies that this TemplateArgument
/// corresponds to a default template parameter
TemplateArgument(TemplateName Name, UnsignedOrNone NumExpansions,
bool IsDefaulted = false) {
TemplateArgument(TemplateName Name, UnsignedOrNone NumExpansions) {
TemplateArg.Kind = TemplateExpansion;
TemplateArg.IsDefaulted = IsDefaulted;
TemplateArg.Name = Name.getAsVoidPointer();
TemplateArg.NumExpansions = NumExpansions;
}
Expand All @@ -265,9 +252,8 @@ class TemplateArgument {
/// This form of template argument only occurs in template argument
/// lists used for dependent types and for expression; it will not
/// occur in a non-dependent, canonical template argument list.
TemplateArgument(Expr *E, bool IsCanonical, bool IsDefaulted = false) {
TemplateArgument(Expr *E, bool IsCanonical) {
TypeOrValue.Kind = Expression;
TypeOrValue.IsDefaulted = IsDefaulted;
TypeOrValue.IsCanonicalExpr = IsCanonical;
TypeOrValue.V = reinterpret_cast<uintptr_t>(E);
}
Expand All @@ -278,7 +264,6 @@ class TemplateArgument {
/// outlives the TemplateArgument itself.
explicit TemplateArgument(ArrayRef<TemplateArgument> Args) {
this->Args.Kind = Pack;
this->Args.IsDefaulted = false;
this->Args.Args = Args.data();
this->Args.NumArgs = Args.size();
}
Expand Down Expand Up @@ -387,14 +372,6 @@ class TemplateArgument {
Integer.Type = T.getAsOpaquePtr();
}

/// Set to 'true' if this TemplateArgument corresponds to a
/// default template parameter.
void setIsDefaulted(bool v) { TypeOrValue.IsDefaulted = v; }

/// If returns 'true', this TemplateArgument corresponds to a
/// default template parameter.
bool getIsDefaulted() const { return (bool)TypeOrValue.IsDefaulted; }

/// Get the value of a StructuralValue.
const APValue &getAsStructuralValue() const { return *Value.Value; }

Expand Down
18 changes: 7 additions & 11 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7945,39 +7945,36 @@ ASTContext::getCanonicalTemplateArgument(const TemplateArgument &Arg) const {
return Arg;

case TemplateArgument::Expression:
return TemplateArgument(Arg.getAsExpr(), /*IsCanonical=*/true,
Arg.getIsDefaulted());
return TemplateArgument(Arg.getAsExpr(), /*IsCanonical=*/true);

case TemplateArgument::Declaration: {
auto *D = cast<ValueDecl>(Arg.getAsDecl()->getCanonicalDecl());
return TemplateArgument(D, getCanonicalType(Arg.getParamTypeForDecl()),
Arg.getIsDefaulted());
return TemplateArgument(D, getCanonicalType(Arg.getParamTypeForDecl()));
}

case TemplateArgument::NullPtr:
return TemplateArgument(getCanonicalType(Arg.getNullPtrType()),
/*isNullPtr*/ true, Arg.getIsDefaulted());
/*isNullPtr=*/true);

case TemplateArgument::Template:
return TemplateArgument(getCanonicalTemplateName(Arg.getAsTemplate()),
Arg.getIsDefaulted());
return TemplateArgument(getCanonicalTemplateName(Arg.getAsTemplate()));

case TemplateArgument::TemplateExpansion:
return TemplateArgument(
getCanonicalTemplateName(Arg.getAsTemplateOrTemplatePattern()),
Arg.getNumTemplateExpansions(), Arg.getIsDefaulted());
Arg.getNumTemplateExpansions());

case TemplateArgument::Integral:
return TemplateArgument(Arg, getCanonicalType(Arg.getIntegralType()));

case TemplateArgument::StructuralValue:
return TemplateArgument(*this,
getCanonicalType(Arg.getStructuralValueType()),
Arg.getAsStructuralValue(), Arg.getIsDefaulted());
Arg.getAsStructuralValue());

case TemplateArgument::Type:
return TemplateArgument(getCanonicalType(Arg.getAsType()),
/*isNullPtr*/ false, Arg.getIsDefaulted());
/*isNullPtr=*/false);

case TemplateArgument::Pack: {
bool AnyNonCanonArgs = false;
Expand All @@ -7987,7 +7984,6 @@ ASTContext::getCanonicalTemplateArgument(const TemplateArgument &Arg) const {
return Arg;
auto NewArg = TemplateArgument::CreatePackCopy(
const_cast<ASTContext &>(*this), CanonArgs);
NewArg.setIsDefaulted(Arg.getIsDefaulted());
return NewArg;
}
}
Expand Down
Loading
Loading