本文整理汇总了C++中TypeChecker::checkGenericParamList方法的典型用法代码示例。如果您正苦于以下问题:C++ TypeChecker::checkGenericParamList方法的具体用法?C++ TypeChecker::checkGenericParamList怎么用?C++ TypeChecker::checkGenericParamList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeChecker
的用法示例。
在下文中一共展示了TypeChecker::checkGenericParamList方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkGenericFuncSignature
/// Check the signature of a generic function.
static bool checkGenericFuncSignature(TypeChecker &tc,
ArchetypeBuilder *builder,
AbstractFunctionDecl *func,
GenericTypeResolver &resolver) {
bool badType = false;
func->setIsBeingTypeChecked();
// Check the generic parameter list.
auto genericParams = func->getGenericParams();
tc.checkGenericParamList(builder, genericParams,
func->getDeclContext()->getGenericSignatureOfContext(),
nullptr,
&resolver);
// Check the parameter patterns.
for (auto params : func->getParameterLists()) {
// Check the pattern.
if (tc.typeCheckParameterList(params, func, TypeResolutionOptions(),
&resolver))
badType = true;
// Infer requirements from the pattern.
if (builder) {
builder->inferRequirements(params, genericParams);
}
}
// If there is a declared result type, check that as well.
if (auto fn = dyn_cast<FuncDecl>(func)) {
if (!fn->getBodyResultTypeLoc().isNull()) {
// Check the result type of the function.
TypeResolutionOptions options;
if (fn->hasDynamicSelf())
options |= TR_DynamicSelfResult;
if (tc.validateType(fn->getBodyResultTypeLoc(), fn, options, &resolver)) {
badType = true;
}
// Infer requirements from it.
if (builder && fn->getBodyResultTypeLoc().getTypeRepr()) {
builder->inferRequirements(fn->getBodyResultTypeLoc(), genericParams);
}
}
}
func->setIsBeingTypeChecked(false);
return badType;
}
示例2: checkGenericSubscriptSignature
/// Check the signature of a generic subscript.
static bool checkGenericSubscriptSignature(TypeChecker &tc,
GenericSignatureBuilder *builder,
SubscriptDecl *subscript,
GenericTypeResolver &resolver) {
bool badType = false;
// Check the generic parameter list.
auto genericParams = subscript->getGenericParams();
auto *dc = subscript->getDeclContext();
tc.checkGenericParamList(
builder, genericParams,
dc->getGenericSignatureOfContext(),
&resolver);
// Check the element type.
badType |= tc.validateType(subscript->getElementTypeLoc(), subscript,
TypeResolutionOptions(),
&resolver);
// Infer requirements from it.
if (genericParams && builder) {
auto source =
GenericSignatureBuilder::FloatingRequirementSource::forInferred(
subscript->getElementTypeLoc().getTypeRepr(),
/*quietly=*/true);
builder->inferRequirements(*subscript->getParentModule(),
subscript->getElementTypeLoc(),
source);
}
// Check the indices.
auto params = subscript->getIndices();
badType |= tc.typeCheckParameterList(params, subscript,
TR_SubscriptParameters,
resolver);
// Infer requirements from the pattern.
if (builder) {
builder->inferRequirements(*subscript->getParentModule(), params,
genericParams);
}
return badType;
}
示例3: checkGenericFuncSignature
/// Check the signature of a generic function.
static bool checkGenericFuncSignature(TypeChecker &tc,
GenericSignatureBuilder *builder,
AbstractFunctionDecl *func,
GenericTypeResolver &resolver) {
bool badType = false;
// Check the generic parameter list.
auto genericParams = func->getGenericParams();
tc.checkGenericParamList(
builder, genericParams,
func->getDeclContext()->getGenericSignatureOfContext(),
&resolver);
// Check the parameter patterns.
for (auto params : func->getParameterLists()) {
// Check the pattern.
if (tc.typeCheckParameterList(params, func, TypeResolutionOptions(),
resolver))
badType = true;
// Infer requirements from the pattern.
if (builder) {
builder->inferRequirements(*func->getParentModule(), params,
genericParams);
}
}
// If there is a declared result type, check that as well.
if (auto fn = dyn_cast<FuncDecl>(func)) {
if (!fn->getBodyResultTypeLoc().isNull()) {
// Check the result type of the function.
TypeResolutionOptions options;
if (fn->hasDynamicSelf())
options |= TR_DynamicSelfResult;
if (tc.validateType(fn->getBodyResultTypeLoc(), fn, options, &resolver)) {
badType = true;
}
// Infer requirements from it.
if (builder && genericParams &&
fn->getBodyResultTypeLoc().getTypeRepr()) {
auto source =
GenericSignatureBuilder::FloatingRequirementSource::forInferred(
fn->getBodyResultTypeLoc().getTypeRepr(),
/*quietly=*/true);
builder->inferRequirements(*func->getParentModule(),
fn->getBodyResultTypeLoc(),
source);
}
}
// If this is a materializeForSet, infer requirements from the
// storage type instead, since it's not part of the accessor's
// type signature.
if (fn->getAccessorKind() == AccessorKind::IsMaterializeForSet) {
if (builder) {
auto *storage = fn->getAccessorStorageDecl();
if (auto *subscriptDecl = dyn_cast<SubscriptDecl>(storage)) {
auto source =
GenericSignatureBuilder::FloatingRequirementSource::forInferred(
subscriptDecl->getElementTypeLoc().getTypeRepr(),
/*quietly=*/true);
TypeLoc type(nullptr, subscriptDecl->getElementInterfaceType());
assert(type.getType());
builder->inferRequirements(*func->getParentModule(),
type, source);
}
}
}
}
return badType;
}