本文整理汇总了C++中TemplateParameterList类的典型用法代码示例。如果您正苦于以下问题:C++ TemplateParameterList类的具体用法?C++ TemplateParameterList怎么用?C++ TemplateParameterList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TemplateParameterList类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: getCommonPtr
QualType
ClassTemplateDecl::getInjectedClassNameSpecialization() {
Common *CommonPtr = getCommonPtr();
if (!CommonPtr->InjectedClassNameType.isNull())
return CommonPtr->InjectedClassNameType;
// C++0x [temp.dep.type]p2:
// The template argument list of a primary template is a template argument
// list in which the nth template argument has the value of the nth template
// parameter of the class template. If the nth template parameter is a
// template parameter pack (14.5.3), the nth template argument is a pack
// expansion (14.5.3) whose pattern is the name of the template parameter
// pack.
ASTContext &Context = getASTContext();
TemplateParameterList *Params = getTemplateParameters();
llvm::SmallVector<TemplateArgument, 16> TemplateArgs;
TemplateArgs.reserve(Params->size());
for (TemplateParameterList::iterator Param = Params->begin(),
ParamEnd = Params->end();
Param != ParamEnd; ++Param) {
TemplateArgument Arg;
if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*Param)) {
QualType ArgType = Context.getTypeDeclType(TTP);
if (TTP->isParameterPack())
ArgType = Context.getPackExpansionType(ArgType,
llvm::Optional<unsigned>());
Arg = TemplateArgument(ArgType);
} else if (NonTypeTemplateParmDecl *NTTP =
dyn_cast<NonTypeTemplateParmDecl>(*Param)) {
Expr *E = new (Context) DeclRefExpr(NTTP,
NTTP->getType().getNonLValueExprType(Context),
Expr::getValueKindForType(NTTP->getType()),
NTTP->getLocation());
if (NTTP->isParameterPack())
E = new (Context) PackExpansionExpr(Context.DependentTy, E,
NTTP->getLocation(),
llvm::Optional<unsigned>());
Arg = TemplateArgument(E);
} else {
TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*Param);
if (TTP->isParameterPack())
Arg = TemplateArgument(TemplateName(TTP), llvm::Optional<unsigned>());
else
Arg = TemplateArgument(TemplateName(TTP));
}
if ((*Param)->isTemplateParameterPack())
Arg = TemplateArgument::CreatePackCopy(Context, &Arg, 1);
TemplateArgs.push_back(Arg);
}
CommonPtr->InjectedClassNameType
= Context.getTemplateSpecializationType(TemplateName(this),
&TemplateArgs[0],
TemplateArgs.size());
return CommonPtr->InjectedClassNameType;
}
开发者ID:colgur,项目名称:clang,代码行数:60,代码来源:DeclTemplate.cpp
示例2: getTemplateParameters
QualType ClassTemplateDecl::getInjectedClassNameType(ASTContext &Context) {
if (!CommonPtr->InjectedClassNameType.isNull())
return CommonPtr->InjectedClassNameType;
// FIXME: n2800 14.6.1p1 should say how the template arguments
// corresponding to template parameter packs should be pack
// expansions. We already say that in 14.6.2.1p2, so it would be
// better to fix that redundancy.
TemplateParameterList *Params = getTemplateParameters();
llvm::SmallVector<TemplateArgument, 16> TemplateArgs;
TemplateArgs.reserve(Params->size());
for (TemplateParameterList::iterator Param = Params->begin(),
ParamEnd = Params->end();
Param != ParamEnd; ++Param) {
if (isa<TemplateTypeParmDecl>(*Param)) {
QualType ParamType = Context.getTypeDeclType(cast<TypeDecl>(*Param));
TemplateArgs.push_back(TemplateArgument(ParamType));
} else if (NonTypeTemplateParmDecl *NTTP =
dyn_cast<NonTypeTemplateParmDecl>(*Param)) {
Expr *E = new (Context) DeclRefExpr(NTTP, NTTP->getType(),
NTTP->getLocation());
TemplateArgs.push_back(TemplateArgument(E));
} else {
TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*Param);
TemplateArgs.push_back(TemplateArgument(TemplateName(TTP)));
}
}
CommonPtr->InjectedClassNameType
= Context.getTemplateSpecializationType(TemplateName(this),
&TemplateArgs[0],
TemplateArgs.size());
return CommonPtr->InjectedClassNameType;
}
开发者ID:silviubaranga,项目名称:SHP,代码行数:35,代码来源:DeclTemplate.cpp
示例3: isValidClassTemplateDecl
bool ClassTemplateToClass::isValidClassTemplateDecl(ClassTemplateDecl *TmplD)
{
TemplateParameterList *TPList = TmplD->getTemplateParameters();
if (TPList->size() != 1)
return false;
CXXRecordDecl *CXXRD = TmplD->getTemplatedDecl();
CXXRecordDecl *Def = CXXRD->getDefinition();
if (!Def)
return true;
NamedDecl *ND = TPList->getParam(0);
if (dyn_cast<NonTypeTemplateParmDecl>(ND))
return true;
if (isUsedNamedDecl(ND, Def))
return false;
SmallVector<ClassTemplatePartialSpecializationDecl *, 10> PartialDecls;
TmplD->getPartialSpecializations(PartialDecls);
for (SmallVector<ClassTemplatePartialSpecializationDecl *, 10>::iterator
I = PartialDecls.begin(), E = PartialDecls.end(); I != E; ++I) {
if (hasUsedNameDecl(*I))
return false;
}
return true;
}
开发者ID:annulen,项目名称:creduce,代码行数:28,代码来源:ClassTemplateToClass.cpp
示例4: removeTemplateKeyword
void InstantiateTemplateParam::removeTemplateKeyword()
{
if (dyn_cast<ClassTemplateDecl>(TheTemplateDecl))
return;
TemplateParameterList *TPList = TheTemplateDecl->getTemplateParameters();
if (TPList->size() != 1)
return;
const NamedDecl *ND = TPList->getParam(0); (void)ND;
TransAssert((ND == TheParameter) && "Invalid template parameter!");
TheRewriter.RemoveText(SourceRange(TPList->getTemplateLoc(),
TPList->getRAngleLoc()));
}
开发者ID:csmith-project,项目名称:creduce,代码行数:12,代码来源:InstantiateTemplateParam.cpp
示例5: getTemplateParameters
std::pair<const TemplateArgument *, unsigned>
FunctionTemplateDecl::getInjectedTemplateArgs() {
TemplateParameterList *Params = getTemplateParameters();
Common *CommonPtr = getCommonPtr();
if (!CommonPtr->InjectedArgs) {
CommonPtr->InjectedArgs
= new (getASTContext()) TemplateArgument [Params->size()];
GenerateInjectedTemplateArgs(getASTContext(), Params,
CommonPtr->InjectedArgs);
}
return std::make_pair(CommonPtr->InjectedArgs, Params->size());
}
开发者ID:Tarrasch,项目名称:clang,代码行数:13,代码来源:DeclTemplate.cpp
示例6: ParameterVisitor
void InstantiateTemplateParam::handleOneTemplateSpecialization(
const TemplateDecl *D, const TemplateArgumentList & ArgList)
{
if (isInIncludedFile(D))
return;
NamedDecl *ND = D->getTemplatedDecl();
TemplateParameterSet ParamsSet;
TemplateParameterVisitor ParameterVisitor(ParamsSet);
ParameterVisitor.TraverseDecl(ND);
if (ParamsSet.size() == 0)
return;
unsigned NumArgs = ArgList.size(); (void)NumArgs;
unsigned Idx = 0;
TemplateParameterList *TPList = D->getTemplateParameters();
for (TemplateParameterList::const_iterator I = TPList->begin(),
E = TPList->end(); I != E; ++I) {
const NamedDecl *ND = (*I);
// make it simple, skip NonTypeTemplateParmDecl and
// TemplateTemplateParmDecl for now
const TemplateTypeParmDecl *TyParmDecl =
dyn_cast<TemplateTypeParmDecl>(ND);
if (!TyParmDecl || TyParmDecl->isParameterPack() || !ParamsSet.count(ND)) {
Idx++;
continue;
}
TransAssert((Idx < NumArgs) && "Invalid Idx!");
const TemplateArgument &Arg = ArgList.get(Idx);
std::string ArgStr;
std::string ForwardStr;
if (!getTemplateArgumentString(Arg, ArgStr, ForwardStr))
continue;
ValidInstanceNum++;
if (ValidInstanceNum == TransformationCounter) {
TheInstantiationString = ArgStr;
TheParameter = ND;
TheTemplateDecl = D;
TheForwardDeclString = ForwardStr;
}
}
}
开发者ID:csmith-project,项目名称:creduce,代码行数:44,代码来源:InstantiateTemplateParam.cpp
示例7: ParameterVisitor
void TemplateArgToInt::collectInvalidParamIdx(
const TemplateDecl *D,
TemplateParameterIdxSet &InvalidParamIdx)
{
TemplateParameterSet InvalidParams;
NamedDecl *ND = D->getTemplatedDecl();
TemplateInvalidParameterVisitor ParameterVisitor(InvalidParams, this);
ParameterVisitor.TraverseDecl(ND);
TemplateParameterList *TPList = D->getTemplateParameters();
unsigned Idx = 0;
for (TemplateParameterList::const_iterator I = TPList->begin(),
E = TPList->end(); I != E; ++I) {
const NamedDecl *ParamND = (*I);
ParamToTemplateDecl[ParamND] = D;
if (InvalidParams.count(ParamND)) {
TransAssert(!InvalidParamIdx.count(Idx) && "Duplicate Index!");
InvalidParamIdx.insert(Idx);
}
Idx++;
}
}
开发者ID:vgvassilev,项目名称:creduce,代码行数:22,代码来源:TemplateArgToInt.cpp
示例8: hasUsedNameDecl
bool ClassTemplateToClass::hasUsedNameDecl(
ClassTemplatePartialSpecializationDecl *PartialD)
{
if (!PartialD->isCompleteDefinition())
return false;
SmallPtrSet<NamedDecl *, 8> Params;
TemplateParameterList *PartialTPList = PartialD->getTemplateParameters();
for (unsigned PI = 0; PI < PartialTPList->size(); ++PI) {
NamedDecl *ND = PartialTPList->getParam(PI);
if (dyn_cast<NonTypeTemplateParmDecl>(ND))
continue;
Params.insert(ND);
}
TemplateParameterTypeVisitor ParamVisitor(Context);
// Skip visiting parameters and arguments
for (CXXRecordDecl::base_class_iterator I = PartialD->bases_begin(),
E = PartialD->bases_end(); I != E; ++I) {
ParamVisitor.TraverseType(I->getType());
}
DeclContext *Ctx = dyn_cast<DeclContext>(PartialD);
for (DeclContext::decl_iterator DI = Ctx->decls_begin(),
DE = Ctx->decls_end(); DI != DE; ++DI) {
ParamVisitor.TraverseDecl(*DI);
}
for (SmallPtrSet<NamedDecl *, 8>::iterator I = Params.begin(),
E = Params.end(); I != E; ++I) {
if (ParamVisitor.isAUsedParameter(*I))
return true;
}
return false;
}
开发者ID:annulen,项目名称:creduce,代码行数:36,代码来源:ClassTemplateToClass.cpp
示例9: TemplateParameterIdxSet
void TemplateNonTypeArgToInt::handleOneTemplateDecl(const TemplateDecl *D)
{
if (isInIncludedFile(D))
return;
TemplateParameterIdxSet *ValidParamIdx = new TemplateParameterIdxSet();
TemplateParameterList *TPList = D->getTemplateParameters();
unsigned Idx = 0;
for (TemplateParameterList::const_iterator I = TPList->begin(),
E = TPList->end(); I != E; ++I) {
const NamedDecl *ParamND = (*I);
if (isValidParameter(ParamND)) {
ValidParamIdx->insert(Idx);
if (const ValueDecl* ValD = dyn_cast<ValueDecl>(ParamND)) {
++ValidInstanceNum;
if (ValidInstanceNum == TransformationCounter)
TheValueDecl = ValD;
}
}
Idx++;
}
TransAssert(!DeclToParamIdx[D] && "Duplicate TemplateDecl!");
DeclToParamIdx[dyn_cast<TemplateDecl>(D->getCanonicalDecl())] = ValidParamIdx;
}
开发者ID:JIghtuse,项目名称:creduce,代码行数:24,代码来源:TemplateNonTypeArgToInt.cpp
示例10: ParameterVisitor
bool ReduceClassTemplateParameterASTVisitor::VisitClassTemplateDecl(
ClassTemplateDecl *D)
{
if (ConsumerInstance->isInIncludedFile(D))
return true;
ClassTemplateDecl *CanonicalD = D->getCanonicalDecl();
if (ConsumerInstance->VisitedDecls.count(CanonicalD))
return true;
ConsumerInstance->VisitedDecls.insert(CanonicalD);
if (!ConsumerInstance->isValidClassTemplateDecl(D))
return true;
TemplateParameterSet ParamsSet;
TemplateParameterVisitor ParameterVisitor(ParamsSet);
CXXRecordDecl *CXXRD = D->getTemplatedDecl();
CXXRecordDecl *Def = CXXRD->getDefinition();
if (Def)
ParameterVisitor.TraverseDecl(Def);
// ISSUE: we should also check the parameter usage for partial template
// specializations. For example:
// template<typename T1, typename T2> struct S{};
// template<typename T1, typename T2> struct<T1 *, T2 *> S{...};
// T1 or T2 could be used in "..."
// Also, we could have another bad transformation, for example,
// template<bool, typename T> struct S{};
// template<typename T> struct<true, T> S{};
// if we remove bool and true, we will have two definitions for S
TemplateParameterList *TPList;
if (Def) {
// make sure we use the params as in ParameterVisitor
const ClassTemplateDecl *CT = Def->getDescribedClassTemplate();
TransAssert(CT && "NULL DescribedClassTemplate!");
TPList = CT->getTemplateParameters();
}
else {
TPList = CanonicalD->getTemplateParameters();
}
unsigned Index = 0;
for (TemplateParameterList::const_iterator I = TPList->begin(),
E = TPList->end(); I != E; ++I) {
const NamedDecl *ND = (*I);
if (ParamsSet.count(ND)) {
Index++;
continue;
}
ConsumerInstance->ValidInstanceNum++;
if (ConsumerInstance->ValidInstanceNum ==
ConsumerInstance->TransformationCounter) {
ConsumerInstance->TheClassTemplateDecl = CanonicalD;
ConsumerInstance->TheParameterIndex = Index;
ConsumerInstance->TheTemplateName = new TemplateName(CanonicalD);
ConsumerInstance->setDefaultArgFlag(ND);
}
Index++;
}
return true;
}
开发者ID:oriceemple,项目名称:creduce,代码行数:63,代码来源:ReduceClassTemplateParameter.cpp
注:本文中的TemplateParameterList类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论