diff options
Diffstat (limited to 'clang/lib/AST/TemplateBase.cpp')
-rw-r--r-- | clang/lib/AST/TemplateBase.cpp | 113 |
1 files changed, 3 insertions, 110 deletions
diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp index 2bdbeb0..2ec0b2cc 100644 --- a/clang/lib/AST/TemplateBase.cpp +++ b/clang/lib/AST/TemplateBase.cpp @@ -161,25 +161,8 @@ static bool needsAmpersandOnTemplateArg(QualType paramType, QualType argType) { // TemplateArgument Implementation //===----------------------------------------------------------------------===// -void TemplateArgument::initFromType(QualType T, bool IsNullPtr, - bool IsDefaulted) { - TypeOrValue.Kind = IsNullPtr ? NullPtr : Type; - TypeOrValue.IsDefaulted = IsDefaulted; - TypeOrValue.V = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr()); -} - -void TemplateArgument::initFromDeclaration(ValueDecl *D, QualType QT, - bool IsDefaulted) { - assert(D && "Expected decl"); - DeclArg.Kind = Declaration; - DeclArg.IsDefaulted = IsDefaulted; - DeclArg.QT = QT.getAsOpaquePtr(); - DeclArg.D = D; -} - -void TemplateArgument::initFromIntegral(const ASTContext &Ctx, - const llvm::APSInt &Value, - QualType Type, bool IsDefaulted) { +TemplateArgument::TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value, + QualType Type, bool IsDefaulted) { Integer.Kind = Integral; Integer.IsDefaulted = IsDefaulted; // Copy the APSInt value into our decomposed form. @@ -198,56 +181,6 @@ void TemplateArgument::initFromIntegral(const ASTContext &Ctx, Integer.Type = Type.getAsOpaquePtr(); } -void TemplateArgument::initFromStructural(const ASTContext &Ctx, QualType Type, - const APValue &V, bool IsDefaulted) { - Value.Kind = StructuralValue; - Value.IsDefaulted = IsDefaulted; - Value.Value = new (Ctx) APValue(V); - Ctx.addDestruction(Value.Value); - Value.Type = Type.getAsOpaquePtr(); -} - -TemplateArgument::TemplateArgument(const ASTContext &Ctx, - const llvm::APSInt &Value, QualType Type, - bool IsDefaulted) { - initFromIntegral(Ctx, Value, Type, IsDefaulted); -} - -static const ValueDecl *getAsSimpleValueDeclRef(const ASTContext &Ctx, - QualType T, const APValue &V) { - // Pointers to members are relatively easy. - if (V.isMemberPointer() && V.getMemberPointerPath().empty()) - return V.getMemberPointerDecl(); - - // We model class non-type template parameters as their template parameter - // object declaration. - if (V.isStruct() || V.isUnion()) - return Ctx.getTemplateParamObjectDecl(T, V); - - // Pointers and references with an empty path use the special 'Declaration' - // representation. - if (V.isLValue() && V.hasLValuePath() && V.getLValuePath().empty() && - !V.isLValueOnePastTheEnd()) - return V.getLValueBase().dyn_cast<const ValueDecl *>(); - - // Everything else uses the 'structural' representation. - return nullptr; -} - -TemplateArgument::TemplateArgument(const ASTContext &Ctx, QualType Type, - const APValue &V, bool IsDefaulted) { - if (Type->isIntegralOrEnumerationType() && V.isInt()) - initFromIntegral(Ctx, V.getInt(), Type, IsDefaulted); - else if ((V.isLValue() && V.isNullPointer()) || - (V.isMemberPointer() && !V.getMemberPointerDecl())) - initFromType(Type, /*isNullPtr=*/true, IsDefaulted); - else if (const ValueDecl *VD = getAsSimpleValueDeclRef(Ctx, Type, V)) - // FIXME: The Declaration form should expose a const ValueDecl*. - initFromDeclaration(const_cast<ValueDecl *>(VD), Type, IsDefaulted); - else - initFromStructural(Ctx, Type, V, IsDefaulted); -} - TemplateArgument TemplateArgument::CreatePackCopy(ASTContext &Context, ArrayRef<TemplateArgument> Args) { @@ -288,7 +221,6 @@ TemplateArgumentDependence TemplateArgument::getDependence() const { case NullPtr: case Integral: - case StructuralValue: return TemplateArgumentDependence::None; case Expression: @@ -319,7 +251,6 @@ bool TemplateArgument::isPackExpansion() const { case Null: case Declaration: case Integral: - case StructuralValue: case Pack: case Template: case NullPtr: @@ -370,9 +301,6 @@ QualType TemplateArgument::getNonTypeTemplateArgumentType() const { case TemplateArgument::NullPtr: return getNullPtrType(); - - case TemplateArgument::StructuralValue: - return getStructuralValueType(); } llvm_unreachable("Invalid TemplateArgument Kind!"); @@ -406,13 +334,8 @@ void TemplateArgument::Profile(llvm::FoldingSetNodeID &ID, break; case Integral: - getIntegralType().Profile(ID); getAsIntegral().Profile(ID); - break; - - case StructuralValue: - getStructuralValueType().Profile(ID); - getAsStructuralValue().Profile(ID); + getIntegralType().Profile(ID); break; case Expression: @@ -449,16 +372,6 @@ bool TemplateArgument::structurallyEquals(const TemplateArgument &Other) const { return getIntegralType() == Other.getIntegralType() && getAsIntegral() == Other.getAsIntegral(); - case StructuralValue: { - if (getStructuralValueType() != Other.getStructuralValueType()) - return false; - - llvm::FoldingSetNodeID A, B; - getAsStructuralValue().Profile(A); - Other.getAsStructuralValue().Profile(B); - return A == B; - } - case Pack: if (Args.NumArgs != Other.Args.NumArgs) return false; for (unsigned I = 0, E = Args.NumArgs; I != E; ++I) @@ -485,7 +398,6 @@ TemplateArgument TemplateArgument::getPackExpansionPattern() const { case Declaration: case Integral: - case StructuralValue: case Pack: case Null: case Template: @@ -528,10 +440,6 @@ void TemplateArgument::print(const PrintingPolicy &Policy, raw_ostream &Out, break; } - case StructuralValue: - getAsStructuralValue().printPretty(Out, Policy, getStructuralValueType()); - break; - case NullPtr: // FIXME: Include the type if it's not obvious from the context. Out << "nullptr"; @@ -615,9 +523,6 @@ SourceRange TemplateArgumentLoc::getSourceRange() const { case TemplateArgument::Integral: return getSourceIntegralExpression()->getSourceRange(); - case TemplateArgument::StructuralValue: - return getSourceStructuralValueExpression()->getSourceRange(); - case TemplateArgument::Pack: case TemplateArgument::Null: return SourceRange(); @@ -646,18 +551,6 @@ static const T &DiagTemplateArg(const T &DB, const TemplateArgument &Arg) { case TemplateArgument::Integral: return DB << toString(Arg.getAsIntegral(), 10); - case TemplateArgument::StructuralValue: { - // FIXME: We're guessing at LangOptions! - SmallString<32> Str; - llvm::raw_svector_ostream OS(Str); - LangOptions LangOpts; - LangOpts.CPlusPlus = true; - PrintingPolicy Policy(LangOpts); - Arg.getAsStructuralValue().printPretty(OS, Policy, - Arg.getStructuralValueType()); - return DB << OS.str(); - } - case TemplateArgument::Template: return DB << Arg.getAsTemplate(); |