本文整理汇总了C++中ValueDecl::getAttrs方法的典型用法代码示例。如果您正苦于以下问题:C++ ValueDecl::getAttrs方法的具体用法?C++ ValueDecl::getAttrs怎么用?C++ ValueDecl::getAttrs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ValueDecl
的用法示例。
在下文中一共展示了ValueDecl::getAttrs方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: walkRelatedDecls
void walkRelatedDecls(const ValueDecl *VD, const FnTy &Fn) {
llvm::SmallDenseMap<DeclName, unsigned, 16> NamesSeen;
++NamesSeen[VD->getFullName()];
SmallVector<ValueDecl *, 8> RelatedDecls;
// FIXME: Extract useful related declarations, overloaded functions,
// if VD is an initializer, we should extract other initializers etc.
// For now we use UnqualifiedLookup to fetch other declarations with the same
// base name.
auto TypeResolver = VD->getASTContext().getLazyResolver();
UnqualifiedLookup Lookup(VD->getName(), VD->getDeclContext(), TypeResolver);
for (auto result : Lookup.Results) {
ValueDecl *RelatedVD = result.getValueDecl();
if (RelatedVD->getAttrs().isUnavailable(VD->getASTContext()))
continue;
if (RelatedVD != VD) {
++NamesSeen[RelatedVD->getFullName()];
RelatedDecls.push_back(RelatedVD);
}
}
// Now provide the results along with whether the name is duplicate or not.
for (auto RelatedVD : RelatedDecls) {
Fn(RelatedVD, NamesSeen[RelatedVD->getFullName()] > 1);
}
}
示例2: getLinkage
SILLinkage SILDeclRef::getLinkage(ForDefinition_t forDefinition) const {
// Anonymous functions have shared linkage.
// FIXME: This should really be the linkage of the parent function.
if (getAbstractClosureExpr())
return SILLinkage::Shared;
// Native function-local declarations have shared linkage.
// FIXME: @objc declarations should be too, but we currently have no way
// of marking them "used" other than making them external.
ValueDecl *d = getDecl();
DeclContext *moduleContext = d->getDeclContext();
while (!moduleContext->isModuleScopeContext()) {
if (!isForeign && moduleContext->isLocalContext())
return SILLinkage::Shared;
moduleContext = moduleContext->getParent();
}
// Currying and calling convention thunks have shared linkage.
if (isThunk())
// If a function declares a @_cdecl name, its native-to-foreign thunk
// is exported with the visibility of the function.
if (!isNativeToForeignThunk() || !d->getAttrs().hasAttribute<CDeclAttr>())
return SILLinkage::Shared;
// Enum constructors are essentially the same as thunks, they are
// emitted by need and have shared linkage.
if (kind == Kind::EnumElement)
return SILLinkage::Shared;
// Declarations imported from Clang modules have shared linkage.
const SILLinkage ClangLinkage = SILLinkage::Shared;
if (isClangImported())
return ClangLinkage;
// Declarations that were derived on behalf of types in Clang modules get
// shared linkage.
if (auto *FD = dyn_cast<FuncDecl>(d)) {
if (auto derivedFor = FD->getDerivedForTypeDecl())
if (isa<ClangModuleUnit>(derivedFor->getModuleScopeContext()))
return ClangLinkage;
}
// Otherwise, we have external linkage.
switch (d->getEffectiveAccess()) {
case Accessibility::Private:
return (forDefinition ? SILLinkage::Private : SILLinkage::PrivateExternal);
case Accessibility::Internal:
return (forDefinition ? SILLinkage::Hidden : SILLinkage::HiddenExternal);
default:
return (forDefinition ? SILLinkage::Public : SILLinkage::PublicExternal);
}
}
示例3: getLinkage
SILLinkage SILDeclRef::getLinkage(ForDefinition_t forDefinition) const {
// Anonymous functions have shared linkage.
// FIXME: This should really be the linkage of the parent function.
if (getAbstractClosureExpr())
return SILLinkage::Shared;
// Native function-local declarations have shared linkage.
// FIXME: @objc declarations should be too, but we currently have no way
// of marking them "used" other than making them external.
ValueDecl *d = getDecl();
DeclContext *moduleContext = d->getDeclContext();
while (!moduleContext->isModuleScopeContext()) {
if (!isForeign && moduleContext->isLocalContext())
return SILLinkage::Shared;
moduleContext = moduleContext->getParent();
}
// Currying and calling convention thunks have shared linkage.
if (isThunk())
// If a function declares a @_cdecl name, its native-to-foreign thunk
// is exported with the visibility of the function.
if (!isNativeToForeignThunk() || !d->getAttrs().hasAttribute<CDeclAttr>())
return SILLinkage::Shared;
// Enum constructors are essentially the same as thunks, they are
// emitted by need and have shared linkage.
if (isEnumElement())
return SILLinkage::Shared;
// Stored property initializers have hidden linkage, since they are
// not meant to be used from outside of their module.
if (isStoredPropertyInitializer())
return SILLinkage::Hidden;
// Declarations imported from Clang modules have shared linkage.
const SILLinkage ClangLinkage = SILLinkage::Shared;
if (isClangImported())
return ClangLinkage;
// Otherwise, we have external linkage.
switch (d->getEffectiveAccess()) {
case Accessibility::Private:
case Accessibility::FilePrivate:
return (forDefinition ? SILLinkage::Private : SILLinkage::PrivateExternal);
case Accessibility::Internal:
return (forDefinition ? SILLinkage::Hidden : SILLinkage::HiddenExternal);
default:
return (forDefinition ? SILLinkage::Public : SILLinkage::PublicExternal);
}
}
示例4: getLinkage
SILLinkage SILDeclRef::getLinkage(ForDefinition_t forDefinition) const {
if (getAbstractClosureExpr()) {
return isSerialized() ? SILLinkage::Shared : SILLinkage::Private;
}
// Add External to the linkage (e.g. Public -> PublicExternal) if this is a
// declaration not a definition.
auto maybeAddExternal = [&](SILLinkage linkage) {
return forDefinition ? linkage : addExternalToLinkage(linkage);
};
// Native function-local declarations have shared linkage.
// FIXME: @objc declarations should be too, but we currently have no way
// of marking them "used" other than making them external.
ValueDecl *d = getDecl();
DeclContext *moduleContext = d->getDeclContext();
while (!moduleContext->isModuleScopeContext()) {
if (!isForeign && moduleContext->isLocalContext()) {
return isSerialized() ? SILLinkage::Shared : SILLinkage::Private;
}
moduleContext = moduleContext->getParent();
}
// Enum constructors and curry thunks either have private or shared
// linkage, dependings are essentially the same as thunks, they are
// emitted by need and have shared linkage.
if (isEnumElement() || isCurried) {
switch (d->getEffectiveAccess()) {
case AccessLevel::Private:
case AccessLevel::FilePrivate:
return maybeAddExternal(SILLinkage::Private);
case AccessLevel::Internal:
case AccessLevel::Public:
case AccessLevel::Open:
return SILLinkage::Shared;
}
}
// Calling convention thunks have shared linkage.
if (isForeignToNativeThunk())
return SILLinkage::Shared;
// If a function declares a @_cdecl name, its native-to-foreign thunk
// is exported with the visibility of the function.
if (isNativeToForeignThunk() && !d->getAttrs().hasAttribute<CDeclAttr>())
return SILLinkage::Shared;
// Declarations imported from Clang modules have shared linkage.
if (isClangImported())
return SILLinkage::Shared;
// Default argument generators of Public functions have PublicNonABI linkage
// if the function was type-checked in Swift 4 mode.
if (kind == SILDeclRef::Kind::DefaultArgGenerator) {
if (isSerialized())
return maybeAddExternal(SILLinkage::PublicNonABI);
}
enum class Limit {
/// No limit.
None,
/// The declaration is emitted on-demand; it should end up with internal
/// or shared linkage.
OnDemand,
/// The declaration should never be made public.
NeverPublic
};
auto limit = Limit::None;
// ivar initializers and destroyers are completely contained within the class
// from which they come, and never get seen externally.
if (isIVarInitializerOrDestroyer()) {
limit = Limit::NeverPublic;
}
// Stored property initializers get the linkage of their containing type.
if (isStoredPropertyInitializer()) {
// Three cases:
//
// 1) Type is formally @_fixed_layout. Root initializers can be declared
// @inlinable. The property initializer must only reference
// public symbols, and is serialized, so we give it PublicNonABI linkage.
//
// 2) Type is not formally @_fixed_layout and the module is not resilient.
// Root initializers can be declared @inlinable. This is the annoying
// case. We give the initializer public linkage if the type is public.
//
// 3) Type is resilient. The property initializer is never public because
// root initializers cannot be @inlinable.
//
// FIXME: Get rid of case 2 somehow.
if (isSerialized())
return maybeAddExternal(SILLinkage::PublicNonABI);
d = cast<NominalTypeDecl>(d->getDeclContext());
// FIXME: This should always be true.
if (d->getDeclContext()->getParentModule()->getResilienceStrategy() ==
ResilienceStrategy::Resilient)
//.........这里部分代码省略.........