本文整理汇总了C++中SILGenFunction::emitPropertyLValue方法的典型用法代码示例。如果您正苦于以下问题:C++ SILGenFunction::emitPropertyLValue方法的具体用法?C++ SILGenFunction::emitPropertyLValue怎么用?C++ SILGenFunction::emitPropertyLValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SILGenFunction
的用法示例。
在下文中一共展示了SILGenFunction::emitPropertyLValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: emitLValueForMemberInit
static LValue emitLValueForMemberInit(SILGenFunction &SGF, SILLocation loc,
VarDecl *selfDecl,
VarDecl *property) {
CanType selfFormalType = selfDecl->getType()->getCanonicalType();
auto self = emitSelfForMemberInit(SGF, loc, selfDecl);
return SGF.emitPropertyLValue(loc, self, selfFormalType, property,
LValueOptions(), SGFAccessKind::Write,
AccessSemantics::DirectToStorage);
}
示例2: emitStoreToForeignErrorSlot
/// Emit a store of a native error to the foreign-error slot.
static void emitStoreToForeignErrorSlot(SILGenFunction &gen,
SILLocation loc,
SILValue foreignErrorSlot,
const BridgedErrorSource &errorSrc) {
ASTContext &ctx = gen.getASTContext();
// The foreign error slot has type SomePointer<SomeErrorProtocol?>,
// or possibly an optional thereof.
// If the pointer itself is optional, we need to branch based on
// whether it's really there.
// FIXME: this code is written expecting pointer types to actually
// be optional, as opposed to simply having a null inhabitant.
OptionalTypeKind errorPtrOptKind;
if (SILType errorPtrObjectTy =
foreignErrorSlot->getType()
.getAnyOptionalObjectType(gen.SGM.M, errorPtrOptKind)) {
SILBasicBlock *contBB = gen.createBasicBlock();
SILBasicBlock *noSlotBB = gen.createBasicBlock();
SILBasicBlock *hasSlotBB = gen.createBasicBlock();
gen.B.createSwitchEnum(loc, foreignErrorSlot, nullptr,
{ { ctx.getOptionalSomeDecl(errorPtrOptKind), hasSlotBB },
{ ctx.getOptionalNoneDecl(errorPtrOptKind), noSlotBB } });
// If we have the slot, emit a store to it.
gen.B.emitBlock(hasSlotBB);
SILValue slot = hasSlotBB->createBBArg(errorPtrObjectTy);
emitStoreToForeignErrorSlot(gen, loc, slot, errorSrc);
gen.B.createBranch(loc, contBB);
// Otherwise, just release the error.
gen.B.emitBlock(noSlotBB);
errorSrc.emitRelease(gen, loc);
gen.B.createBranch(loc, contBB);
// Continue.
gen.B.emitBlock(contBB);
return;
}
// Okay, break down the components of SomePointer<SomeErrorProtocol?>.
// TODO: this should really be an unlowered AST type?
CanType bridgedErrorPtrType =
foreignErrorSlot->getType().getSwiftRValueType();
PointerTypeKind ptrKind;
CanType bridgedErrorProtocol =
CanType(bridgedErrorPtrType->getAnyPointerElementType(ptrKind));
FullExpr scope(gen.Cleanups, CleanupLocation::get(loc));
WritebackScope writebacks(gen);
// Convert the error to a bridged form.
SILValue bridgedError = errorSrc.emitBridged(gen, loc, bridgedErrorProtocol);
// Store to the "pointee" property.
// If we can't find it, diagnose and then just don't store anything.
VarDecl *pointeeProperty = ctx.getPointerPointeePropertyDecl(ptrKind);
if (!pointeeProperty) {
gen.SGM.diagnose(loc, diag::could_not_find_pointer_pointee_property,
bridgedErrorPtrType);
return;
}
// Otherwise, do a normal assignment.
LValue lvalue =
gen.emitPropertyLValue(loc, ManagedValue::forUnmanaged(foreignErrorSlot),
bridgedErrorPtrType, pointeeProperty,
AccessKind::Write,
AccessSemantics::Ordinary);
RValue rvalue(gen, loc, bridgedErrorProtocol,
gen.emitManagedRValueWithCleanup(bridgedError));
gen.emitAssignToLValue(loc, std::move(rvalue), std::move(lvalue));
}
示例3: emitMemberInit
/// Emit a member initialization for the members described in the
/// given pattern from the given source value.
static void emitMemberInit(SILGenFunction &SGF, VarDecl *selfDecl,
Pattern *pattern, RValue &&src) {
switch (pattern->getKind()) {
case PatternKind::Paren:
return emitMemberInit(SGF, selfDecl,
cast<ParenPattern>(pattern)->getSubPattern(),
std::move(src));
case PatternKind::Tuple: {
auto tuple = cast<TuplePattern>(pattern);
auto fields = tuple->getElements();
SmallVector<RValue, 4> elements;
std::move(src).extractElements(elements);
for (unsigned i = 0, n = fields.size(); i != n; ++i) {
emitMemberInit(SGF, selfDecl, fields[i].getPattern(),
std::move(elements[i]));
}
break;
}
case PatternKind::Named: {
auto named = cast<NamedPattern>(pattern);
// Form the lvalue referencing this member.
WritebackScope scope(SGF);
SILLocation loc = pattern;
ManagedValue self;
CanType selfFormalType = selfDecl->getType()
->getInOutObjectType()->getCanonicalType();
if (selfFormalType->hasReferenceSemantics())
self = SGF.emitRValueForDecl(loc, selfDecl, selfDecl->getType(),
AccessSemantics::DirectToStorage,
SGFContext::AllowImmediatePlusZero)
.getAsSingleValue(SGF, loc);
else
self = SGF.emitLValueForDecl(loc, selfDecl,
src.getType()->getCanonicalType(),
AccessKind::Write,
AccessSemantics::DirectToStorage);
LValue memberRef =
SGF.emitPropertyLValue(loc, self, selfFormalType, named->getDecl(),
AccessKind::Write,
AccessSemantics::DirectToStorage);
// Assign to it.
SGF.emitAssignToLValue(loc, std::move(src), std::move(memberRef));
return;
}
case PatternKind::Any:
return;
case PatternKind::Typed:
return emitMemberInit(SGF, selfDecl,
cast<TypedPattern>(pattern)->getSubPattern(),
std::move(src));
case PatternKind::Var:
return emitMemberInit(SGF, selfDecl,
cast<VarPattern>(pattern)->getSubPattern(),
std::move(src));
#define PATTERN(Name, Parent)
#define REFUTABLE_PATTERN(Name, Parent) case PatternKind::Name:
#include "swift/AST/PatternNodes.def"
llvm_unreachable("Refutable pattern in pattern binding");
}
}
示例4: emitStoreToForeignErrorSlot
/// Emit a store of a native error to the foreign-error slot.
static void emitStoreToForeignErrorSlot(SILGenFunction &SGF,
SILLocation loc,
SILValue foreignErrorSlot,
const BridgedErrorSource &errorSrc) {
ASTContext &ctx = SGF.getASTContext();
// The foreign error slot has type SomePointer<SomeError?>,
// or possibly an optional thereof.
// If the pointer itself is optional, we need to branch based on
// whether it's really there.
if (SILType errorPtrObjectTy =
foreignErrorSlot->getType().getOptionalObjectType()) {
SILBasicBlock *contBB = SGF.createBasicBlock();
SILBasicBlock *noSlotBB = SGF.createBasicBlock();
SILBasicBlock *hasSlotBB = SGF.createBasicBlock();
SGF.B.createSwitchEnum(loc, foreignErrorSlot, nullptr,
{ { ctx.getOptionalSomeDecl(), hasSlotBB },
{ ctx.getOptionalNoneDecl(), noSlotBB } });
// If we have the slot, emit a store to it.
SGF.B.emitBlock(hasSlotBB);
SILValue slot = hasSlotBB->createPHIArgument(errorPtrObjectTy,
ValueOwnershipKind::Owned);
emitStoreToForeignErrorSlot(SGF, loc, slot, errorSrc);
SGF.B.createBranch(loc, contBB);
// Otherwise, just release the error.
SGF.B.emitBlock(noSlotBB);
errorSrc.emitRelease(SGF, loc);
SGF.B.createBranch(loc, contBB);
// Continue.
SGF.B.emitBlock(contBB);
return;
}
// Okay, break down the components of SomePointer<SomeError?>.
// TODO: this should really be an unlowered AST type?
auto bridgedErrorPtrType = foreignErrorSlot->getType().getASTType();
PointerTypeKind ptrKind;
CanType bridgedErrorProto =
CanType(bridgedErrorPtrType->getAnyPointerElementType(ptrKind));
FullExpr scope(SGF.Cleanups, CleanupLocation::get(loc));
FormalEvaluationScope writebacks(SGF);
// Convert the error to a bridged form.
SILValue bridgedError = errorSrc.emitBridged(SGF, loc, bridgedErrorProto);
// Store to the "pointee" property.
// If we can't find it, diagnose and then just don't store anything.
VarDecl *pointeeProperty = ctx.getPointerPointeePropertyDecl(ptrKind);
if (!pointeeProperty) {
SGF.SGM.diagnose(loc, diag::could_not_find_pointer_pointee_property,
bridgedErrorPtrType);
return;
}
// Otherwise, do a normal assignment.
LValue lvalue =
SGF.emitPropertyLValue(loc, ManagedValue::forUnmanaged(foreignErrorSlot),
bridgedErrorPtrType, pointeeProperty,
LValueOptions(),
AccessKind::Write,
AccessSemantics::Ordinary);
RValue rvalue(SGF, loc, bridgedErrorProto,
SGF.emitManagedRValueWithCleanup(bridgedError));
SGF.emitAssignToLValue(loc, std::move(rvalue), std::move(lvalue));
}