本文整理汇总了C++中TemplateArgument类的典型用法代码示例。如果您正苦于以下问题:C++ TemplateArgument类的具体用法?C++ TemplateArgument怎么用?C++ TemplateArgument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TemplateArgument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: structurallyEquals
bool TemplateArgument::structurallyEquals(const TemplateArgument &Other) const {
if (getKind() != Other.getKind()) return false;
switch (getKind()) {
case Null:
case Type:
case Declaration:
case Template:
case Expression:
return TypeOrValue == Other.TypeOrValue;
case Integral:
return getIntegralType() == Other.getIntegralType() &&
*getAsIntegral() == *Other.getAsIntegral();
case Pack:
if (Args.NumArgs != Other.Args.NumArgs) return false;
for (unsigned I = 0, E = Args.NumArgs; I != E; ++I)
if (!Args.Args[I].structurallyEquals(Other.Args.Args[I]))
return false;
return true;
}
// Suppress warnings.
return false;
}
示例2: TransAssert
void ReduceClassTemplateParameter::removeOneParameterByArgExpression(
const ClassTemplatePartialSpecializationDecl *PartialD,
const TemplateArgument &Arg)
{
TransAssert((Arg.getKind() == TemplateArgument::Expression) &&
"Arg is not TemplateArgument::Expression!");
const Expr *E = Arg.getAsExpr();
TransAssert(E && "Bad Expression!");
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E->IgnoreParenCasts());
TransAssert(DRE && "Bad DeclRefExpr!");
const NonTypeTemplateParmDecl *ParmD =
dyn_cast<NonTypeTemplateParmDecl>(DRE->getDecl());
TransAssert(ParmD && "Invalid NonTypeTemplateParmDecl!");
const TemplateParameterList *TPList = PartialD->getTemplateParameters();
unsigned Idx = 0;
for (TemplateParameterList::const_iterator I = TPList->begin(),
E = TPList->end(); I != E; ++I) {
if ((*I) == ParmD)
break;
Idx++;
}
unsigned NumParams = TPList->size();
TransAssert((Idx < NumParams) && "Cannot find valid TemplateParameter!");
(void)NumParams;
SourceRange Range = ParmD->getSourceRange();
removeParameterByRange(Range, TPList, Idx);
}
示例3: switch
void ODRHash::AddTemplateArgument(TemplateArgument TA) {
const auto Kind = TA.getKind();
ID.AddInteger(Kind);
switch (Kind) {
case TemplateArgument::Null:
llvm_unreachable("Require valid TemplateArgument");
case TemplateArgument::Type:
AddQualType(TA.getAsType());
break;
case TemplateArgument::Declaration:
AddDecl(TA.getAsDecl());
break;
case TemplateArgument::NullPtr:
AddQualType(TA.getNullPtrType());
break;
case TemplateArgument::Integral:
TA.getAsIntegral().Profile(ID);
AddQualType(TA.getIntegralType());
break;
case TemplateArgument::Template:
case TemplateArgument::TemplateExpansion:
AddTemplateName(TA.getAsTemplateOrTemplatePattern());
break;
case TemplateArgument::Expression:
AddStmt(TA.getAsExpr());
break;
case TemplateArgument::Pack:
ID.AddInteger(TA.pack_size());
for (auto SubTA : TA.pack_elements())
AddTemplateArgument(SubTA);
break;
}
}
示例4: printIntegral
/// \brief Print a template integral argument value.
///
/// \param TemplArg the TemplateArgument instance to print.
///
/// \param Out the raw_ostream instance to use for printing.
///
/// \param Policy the printing policy for EnumConstantDecl printing.
static void printIntegral(const TemplateArgument &TemplArg,
raw_ostream &Out, const PrintingPolicy& Policy) {
const ::clang::Type *T = TemplArg.getIntegralType().getTypePtr();
const llvm::APSInt &Val = TemplArg.getAsIntegral();
if (const EnumType *ET = T->getAs<EnumType>()) {
for (const EnumConstantDecl* ECD : ET->getDecl()->enumerators()) {
// In Sema::CheckTemplateArugment, enum template arguments value are
// extended to the size of the integer underlying the enum type. This
// may create a size difference between the enum value and template
// argument value, requiring isSameValue here instead of operator==.
if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) {
ECD->printQualifiedName(Out, Policy);
return;
}
}
}
if (T->isBooleanType() && !Policy.MSVCFormatting) {
Out << (Val.getBoolValue() ? "true" : "false");
} else if (T->isCharType()) {
const char Ch = Val.getZExtValue();
Out << ((Ch == '\'') ? "'\\" : "'");
Out.write_escaped(StringRef(&Ch, 1), /*UseHexEscapes=*/ true);
Out << "'";
} else {
Out << Val;
}
}
示例5: switch
bool TemplateArgument::structurallyEquals(const TemplateArgument &Other) const {
if (getKind() != Other.getKind()) return false;
switch (getKind()) {
case Null:
case Type:
case Expression:
case Template:
case TemplateExpansion:
case NullPtr:
return TypeOrValue.V == Other.TypeOrValue.V;
case Declaration:
return getAsDecl() == Other.getAsDecl() &&
isDeclForReferenceParam() && Other.isDeclForReferenceParam();
case Integral:
return getIntegralType() == Other.getIntegralType() &&
getAsIntegral() == Other.getAsIntegral();
case Pack:
if (Args.NumArgs != Other.Args.NumArgs) return false;
for (unsigned I = 0, E = Args.NumArgs; I != E; ++I)
if (!Args.Args[I].structurallyEquals(Other.Args.Args[I]))
return false;
return true;
}
llvm_unreachable("Invalid TemplateArgument Kind!");
}
示例6: switch
bool TemplateNonTypeArgToInt::isValidTemplateArgument(
const TemplateArgument &Arg)
{
TemplateArgument::ArgKind K = Arg.getKind();
switch (K) {
case TemplateArgument::Declaration: {
return true;
}
case TemplateArgument::Expression: {
const Expr *E = Arg.getAsExpr()->IgnoreParenCasts();
if (dyn_cast<IntegerLiteral>(E) || dyn_cast<CXXBoolLiteralExpr>(E))
return false;
if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) {
UnaryOperator::Opcode Op = UO->getOpcode();
if((Op == UO_Minus) || (Op == UO_Plus))
return false;
}
return true;
}
default:
TransAssert(0 && "Unreachable code!");
return false;
}
TransAssert(0 && "Unreachable code!");
return false;
}
示例7: switch
void ReduceClassTemplateParameter::removeOneParameterFromPartialDecl(
const ClassTemplatePartialSpecializationDecl *PartialD,
const TemplateArgument &Arg)
{
if (!Arg.isInstantiationDependent())
return;
TemplateArgument::ArgKind K = Arg.getKind();
switch (K) {
case TemplateArgument::Expression:
removeOneParameterByArgExpression(PartialD, Arg);
return;
case TemplateArgument::Template:
removeOneParameterByArgTemplate(PartialD, Arg);
return;
case TemplateArgument::Type:
removeOneParameterByArgType(PartialD, Arg);
return;
default:
TransAssert(0 && "Uncatched ArgKind!");
}
TransAssert(0 && "Unreachable code!");
}
示例8: switch
void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
// Mostly repetitive with TemplateArgument::Profile!
ID.AddInteger(Arg.getKind());
switch (Arg.getKind()) {
case TemplateArgument::Null:
break;
case TemplateArgument::Type:
VisitType(Arg.getAsType());
break;
case TemplateArgument::Template:
VisitTemplateName(Arg.getAsTemplate());
break;
case TemplateArgument::Declaration:
VisitDecl(Arg.getAsDecl());
break;
case TemplateArgument::Integral:
Arg.getAsIntegral()->Profile(ID);
VisitType(Arg.getIntegralType());
break;
case TemplateArgument::Expression:
Visit(Arg.getAsExpr());
break;
case TemplateArgument::Pack:
const TemplateArgument *Pack = Arg.pack_begin();
for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
VisitTemplateArgument(Pack[i]);
break;
}
}
示例9: SubstNonTypeTemplateParmPackExpr
SubstNonTypeTemplateParmPackExpr::
SubstNonTypeTemplateParmPackExpr(QualType T,
NonTypeTemplateParmDecl *Param,
SourceLocation NameLoc,
const TemplateArgument &ArgPack)
: Expr(SubstNonTypeTemplateParmPackExprClass, T, VK_RValue, OK_Ordinary,
true, true, true, true),
Param(Param), Arguments(ArgPack.pack_begin()),
NumArguments(ArgPack.pack_size()), NameLoc(NameLoc) { }
示例10: describeTemplateParameter
static void describeTemplateParameter(raw_ostream &Out,
const TemplateArgument &TArg,
const LangOptions &LO) {
if (TArg.getKind() == TemplateArgument::ArgKind::Pack) {
describeTemplateParameters(Out, TArg.getPackAsArray(), LO);
} else {
TArg.print(PrintingPolicy(LO), Out);
}
}
示例11: while
Type *
TypeCheck::visit(TemplateArgumentList *ast)
{
FUNCLOG;
List<TemplateArgument*>::iterator it = ast->args.begin();
while (it != ast->args.end()) {
TemplateArgument *arg = *it;
arg->accept(this);
++it;
}
return NULL;
}
示例12: getTypeString
bool
InstantiateTemplateParam::getTemplateArgumentString(const TemplateArgument &Arg,
std::string &ArgStr,
std::string &ForwardStr)
{
ArgStr = "";
ForwardStr = "";
if (Arg.getKind() != TemplateArgument::Type)
return false;
QualType QT = Arg.getAsType();
return getTypeString(QT, ArgStr, ForwardStr);
}
示例13: clang_Cursor_getTemplateArgumentType
CXType clang_Cursor_getTemplateArgumentType(CXCursor C, unsigned I) {
TemplateArgument TA;
if (clang_Cursor_getTemplateArgument(C, I, &TA) !=
CXGetTemplateArgumentStatus_Success) {
return cxtype::MakeCXType(QualType(), getCursorTU(C));
}
if (TA.getKind() != TemplateArgument::Type) {
return cxtype::MakeCXType(QualType(), getCursorTU(C));
}
return cxtype::MakeCXType(TA.getAsType(), getCursorTU(C));
}
示例14: assert
Optional<unsigned> Sema::getFullyPackExpandedSize(TemplateArgument Arg) {
assert(Arg.containsUnexpandedParameterPack());
// If this is a substituted pack, grab that pack. If not, we don't know
// the size yet.
// FIXME: We could find a size in more cases by looking for a substituted
// pack anywhere within this argument, but that's not necessary in the common
// case for 'sizeof...(A)' handling.
TemplateArgument Pack;
switch (Arg.getKind()) {
case TemplateArgument::Type:
if (auto *Subst = Arg.getAsType()->getAs<SubstTemplateTypeParmPackType>())
Pack = Subst->getArgumentPack();
else
return None;
break;
case TemplateArgument::Expression:
if (auto *Subst =
dyn_cast<SubstNonTypeTemplateParmPackExpr>(Arg.getAsExpr()))
Pack = Subst->getArgumentPack();
else if (auto *Subst = dyn_cast<FunctionParmPackExpr>(Arg.getAsExpr())) {
for (ParmVarDecl *PD : *Subst)
if (PD->isParameterPack())
return None;
return Subst->getNumExpansions();
} else
return None;
break;
case TemplateArgument::Template:
if (SubstTemplateTemplateParmPackStorage *Subst =
Arg.getAsTemplate().getAsSubstTemplateTemplateParmPack())
Pack = Subst->getArgumentPack();
else
return None;
break;
case TemplateArgument::Declaration:
case TemplateArgument::NullPtr:
case TemplateArgument::TemplateExpansion:
case TemplateArgument::Integral:
case TemplateArgument::Pack:
case TemplateArgument::Null:
return None;
}
// Check that no argument in the pack is itself a pack expansion.
for (TemplateArgument Elem : Pack.pack_elements()) {
// There's no point recursing in this case; we would have already
// expanded this pack expansion into the enclosing pack if we could.
if (Elem.isPackExpansion())
return None;
}
return Pack.pack_size();
}
示例15: clang_Cursor_getTemplateArgumentValue
long long clang_Cursor_getTemplateArgumentValue(CXCursor C, unsigned I) {
TemplateArgument TA;
if (clang_Cursor_getTemplateArgument(C, I, &TA) !=
CXGetTemplateArgumentStatus_Success) {
assert(0 && "Unable to retrieve TemplateArgument");
return 0;
}
if (TA.getKind() != TemplateArgument::Integral) {
assert(0 && "Passed template argument is not Integral");
return 0;
}
return TA.getAsIntegral().getSExtValue();
}