mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[AST] NFC: Move shouldPreferPropertyWrapperOverMacro onto CustomAttr
This commit is contained in:
@@ -2359,6 +2359,10 @@ public:
|
||||
|
||||
ASTContext &getASTContext() const;
|
||||
|
||||
/// If \c true, we should prefer a property wrapper if one exists for the
|
||||
/// given attribute over a macro.
|
||||
bool shouldPreferPropertyWrapperOverMacro() const;
|
||||
|
||||
/// Retrieve the NominalTypeDecl the CustomAttr refers to, or \c nullptr if
|
||||
/// it doesn't refer to one (which can be the case for e.g macro attrs).
|
||||
NominalTypeDecl *getNominalDecl() const;
|
||||
|
||||
@@ -3167,6 +3167,20 @@ ASTContext &CustomAttr::getASTContext() const {
|
||||
return getOwner().getDeclContext()->getASTContext();
|
||||
}
|
||||
|
||||
bool CustomAttr::shouldPreferPropertyWrapperOverMacro() const {
|
||||
// If we have a VarDecl in a local context, prefer to use a property wrapper
|
||||
// if one exists. This is necessary since we don't properly support peer
|
||||
// declarations in local contexts, so want to use a property wrapper if one
|
||||
// exists.
|
||||
if (auto *D = owner.getAsDecl()) {
|
||||
if ((isa<VarDecl>(D) || isa<PatternBindingDecl>(D)) &&
|
||||
D->getDeclContext()->isLocalContext()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
NominalTypeDecl *CustomAttr::getNominalDecl() const {
|
||||
auto &eval = getASTContext().evaluator;
|
||||
auto *mutThis = const_cast<CustomAttr *>(this);
|
||||
|
||||
@@ -4020,20 +4020,6 @@ GenericParamListRequest::evaluate(Evaluator &evaluator, GenericContext *value) c
|
||||
parsedGenericParams->getRAngleLoc());
|
||||
}
|
||||
|
||||
static bool shouldPreferPropertyWrapperOverMacro(CustomAttrOwner owner) {
|
||||
// If we have a VarDecl in a local context, prefer to use a property wrapper
|
||||
// if one exists. This is necessary since we don't properly support peer
|
||||
// declarations in local contexts, so want to use a property wrapper if one
|
||||
// exists.
|
||||
if (auto *D = owner.getAsDecl()) {
|
||||
if ((isa<VarDecl>(D) || isa<PatternBindingDecl>(D)) &&
|
||||
D->getDeclContext()->isLocalContext()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
NominalTypeDecl *CustomAttrNominalRequest::evaluate(Evaluator &evaluator,
|
||||
CustomAttr *attr) const {
|
||||
auto owner = attr->getOwner();
|
||||
@@ -4048,7 +4034,7 @@ NominalTypeDecl *CustomAttrNominalRequest::evaluate(Evaluator &evaluator,
|
||||
auto macroName = (macro) ? macro->getNameRef() : DeclNameRef();
|
||||
auto macros = namelookup::lookupMacros(dc, moduleName, macroName,
|
||||
getAttachedMacroRoles());
|
||||
auto shouldPreferPropWrapper = shouldPreferPropertyWrapperOverMacro(owner);
|
||||
auto shouldPreferPropWrapper = attr->shouldPreferPropertyWrapperOverMacro();
|
||||
if (!macros.empty() && !shouldPreferPropWrapper)
|
||||
return nullptr;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user