|
57 | 57 | using namespace swift; |
58 | 58 | using namespace constraints; |
59 | 59 |
|
60 | | -/// Find the declaration directly referenced by this expression. |
61 | | -static std::pair<ValueDecl *, FunctionRefKind> |
62 | | -findReferencedDecl(Expr *expr, DeclNameLoc &loc) { |
63 | | - do { |
64 | | - expr = expr->getSemanticsProvidingExpr(); |
65 | | - |
66 | | - if (auto ice = dyn_cast<ImplicitConversionExpr>(expr)) { |
67 | | - expr = ice->getSubExpr(); |
68 | | - continue; |
69 | | - } |
70 | | - |
71 | | - if (auto dre = dyn_cast<DeclRefExpr>(expr)) { |
72 | | - loc = dre->getNameLoc(); |
73 | | - return { dre->getDecl(), dre->getFunctionRefKind() }; |
74 | | - } |
75 | | - |
76 | | - return { nullptr, FunctionRefKind::Unapplied }; |
77 | | - } while (true); |
78 | | -} |
79 | | - |
80 | | -// Check if \p E is a call expression to curried thunk of "KeyPath as function". |
81 | | -// i.e. '{ `$kp$` in { $0[keyPath: $kp$] } }(keypath)' |
82 | | -static bool isKeyPathCurriedThunkCallExpr(Expr *E) { |
83 | | - auto CE = dyn_cast<CallExpr>(E); |
84 | | - if (!CE) |
85 | | - return false; |
86 | | - auto thunk = dyn_cast<AutoClosureExpr>(CE->getFn()); |
87 | | - if (!thunk) |
88 | | - return false; |
89 | | - if (thunk->getParameters()->size() != 1 || |
90 | | - thunk->getParameters()->get(0)->getParameterName().str() != "$kp$") |
91 | | - return false; |
92 | | - |
93 | | - auto *unaryArg = CE->getArgs()->getUnlabeledUnaryExpr(); |
94 | | - if (!unaryArg) |
95 | | - return false; |
96 | | - return isa<KeyPathExpr>(unaryArg); |
97 | | -} |
98 | | - |
99 | | -// Extract the keypath expression from the curried thunk expression. |
100 | | -static Expr *extractKeyPathFromCurryThunkCall(Expr *E) { |
101 | | - assert(isKeyPathCurriedThunkCallExpr(E)); |
102 | | - return cast<CallExpr>(E)->getArgs()->getUnlabeledUnaryExpr(); |
103 | | -} |
104 | | - |
105 | 60 | static Type |
106 | 61 | getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc, |
107 | 62 | ConcreteDeclRef &referencedDecl, |
|
0 commit comments