本文整理汇总了C++中Pattern::setImplicit方法的典型用法代码示例。如果您正苦于以下问题:C++ Pattern::setImplicit方法的具体用法?C++ Pattern::setImplicit怎么用?C++ Pattern::setImplicit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pattern
的用法示例。
在下文中一共展示了Pattern::setImplicit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: name
static ConstructorDecl *deriveRawRepresentable_init(TypeChecker &tc,
Decl *parentDecl,
EnumDecl *enumDecl) {
ASTContext &C = tc.Context;
auto parentDC = cast<DeclContext>(parentDecl);
auto rawInterfaceType = enumDecl->getRawType();
auto rawType = ArchetypeBuilder::mapTypeIntoContext(parentDC,
rawInterfaceType);
// Make sure that the raw type is Equatable. We need it to ensure that we have
// a suitable ~= for the switch.
auto equatableProto = tc.getProtocol(enumDecl->getLoc(),
KnownProtocolKind::Equatable);
if (!equatableProto)
return nullptr;
if (!tc.conformsToProtocol(rawType, equatableProto, enumDecl, None)) {
SourceLoc loc = enumDecl->getInherited()[0].getSourceRange().Start;
tc.diagnose(loc, diag::enum_raw_type_not_equatable, rawType);
return nullptr;
}
Type enumType = parentDC->getDeclaredTypeInContext();
VarDecl *selfDecl = new (C) ParamDecl(/*IsLet*/false,
SourceLoc(),
Identifier(),
SourceLoc(),
C.Id_self,
enumType,
parentDC);
selfDecl->setImplicit();
Pattern *selfParam = new (C) NamedPattern(selfDecl, /*implicit*/ true);
selfParam->setType(enumType);
selfParam = new (C) TypedPattern(selfParam,
TypeLoc::withoutLoc(enumType));
selfParam->setType(enumType);
selfParam->setImplicit();
VarDecl *rawDecl = new (C) ParamDecl(/*IsVal*/true,
SourceLoc(),
C.Id_rawValue,
SourceLoc(),
C.Id_rawValue,
rawType,
parentDC);
rawDecl->setImplicit();
Pattern *rawParam = new (C) NamedPattern(rawDecl, /*implicit*/ true);
rawParam->setType(rawType);
rawParam = new (C) TypedPattern(rawParam, TypeLoc::withoutLoc(rawType));
rawParam->setType(rawType);
rawParam->setImplicit();
rawParam = new (C) ParenPattern(SourceLoc(), rawParam, SourceLoc());
rawParam->setType(rawType);
rawParam->setImplicit();
auto retTy = OptionalType::get(enumType);
DeclName name(C, C.Id_init, { C.Id_rawValue });
auto initDecl = new (C) ConstructorDecl(name, SourceLoc(),
/*failability*/ OTK_Optional,
SourceLoc(),
selfParam,
rawParam,
nullptr,
SourceLoc(),
parentDC);
initDecl->setImplicit();
initDecl->setBodySynthesizer(&deriveBodyRawRepresentable_init);
// Compute the type of the initializer.
GenericParamList *genericParams = initDecl->getGenericParamsOfContext();
TupleTypeElt element(rawType, C.Id_rawValue);
auto argType = TupleType::get(element, C);
TupleTypeElt interfaceElement(rawInterfaceType, C.Id_rawValue);
auto interfaceArgType = TupleType::get(interfaceElement, C);
Type type = FunctionType::get(argType, retTy);
Type selfType = initDecl->computeSelfType();
Type selfMetatype = MetatypeType::get(selfType->getInOutObjectType());
Type allocType;
Type initType;
if (genericParams) {
allocType = PolymorphicFunctionType::get(selfMetatype, type, genericParams);
initType = PolymorphicFunctionType::get(selfType, type, genericParams);
} else {
allocType = FunctionType::get(selfMetatype, type);
initType = FunctionType::get(selfType, type);
}
initDecl->setType(allocType);
initDecl->setInitializerType(initType);
// Compute the interface type of the initializer.
Type retInterfaceType
= OptionalType::get(parentDC->getDeclaredInterfaceType());
Type interfaceType = FunctionType::get(interfaceArgType, retInterfaceType);
//.........这里部分代码省略.........