mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
57 lines
2.0 KiB
C++
57 lines
2.0 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "Utils.h"
|
|
#include "swift/AST/Expr.h"
|
|
#include "swift/AST/Stmt.h"
|
|
|
|
using namespace swift;
|
|
|
|
/// Whether or not the given statement starts a new scope. Note that most
|
|
/// statements are handled by the \c BraceStmt check. The others listed are
|
|
/// a somewhat special case since they can also declare variables in their
|
|
/// condition.
|
|
bool swift::refactoring::asyncrefactorings::startsNewScope(Stmt *S) {
|
|
switch (S->getKind()) {
|
|
case StmtKind::Brace:
|
|
case StmtKind::If:
|
|
case StmtKind::While:
|
|
case StmtKind::ForEach:
|
|
case StmtKind::Case:
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// A more aggressive variant of \c Expr::getReferencedDecl that also looks
|
|
/// through autoclosures created to pass the \c self parameter to a member funcs
|
|
ValueDecl *swift::refactoring::asyncrefactorings::
|
|
getReferencedDeclLookingThroughAutoclosures(const Expr *Fn) {
|
|
Fn = Fn->getSemanticsProvidingExpr();
|
|
if (auto *DRE = dyn_cast<DeclRefExpr>(Fn))
|
|
return DRE->getDecl();
|
|
if (auto ApplyE = dyn_cast<SelfApplyExpr>(Fn))
|
|
return getReferencedDeclLookingThroughAutoclosures(ApplyE->getFn());
|
|
if (auto *ACE = dyn_cast<AutoClosureExpr>(Fn)) {
|
|
if (auto *Unwrapped = ACE->getUnwrappedCurryThunkExpr())
|
|
return getReferencedDeclLookingThroughAutoclosures(Unwrapped);
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
FuncDecl *
|
|
swift::refactoring::asyncrefactorings::getUnderlyingFunc(const Expr *Fn) {
|
|
return dyn_cast_or_null<FuncDecl>(
|
|
getReferencedDeclLookingThroughAutoclosures(Fn));
|
|
}
|