@@ -203,7 +203,7 @@ extension %s$__lldb_context {
203
203
%s
204
204
}
205
205
}
206
- %s
206
+ @LLDBDebuggerFunction %s
207
207
func $__lldb_expr(_ $__lldb_arg : UnsafeMutablePointer<Any>) {
208
208
do {
209
209
$__lldb_injected_self.$__lldb_wrapped_expr_%u(
@@ -255,63 +255,51 @@ void SwiftASTManipulatorBase::DoInitialization() {
255
255
if (m_repl)
256
256
return ;
257
257
258
- static llvm::StringRef s_func_prefix_str ( " $__lldb_expr " );
258
+ // First pass: find whether we're dealing with a wrapped function or not.
259
259
260
- // First pass: find whether we're dealing with a wrapped function or not
261
-
262
- class FuncAndExtensionFinder : public swift ::ASTWalker {
263
- public:
264
- swift::FuncDecl *m_function_decl = nullptr ; // This is the function in which
265
- // the expression code is
266
- // inserted.
267
- // It is always marked with the DebuggerFunction attribute.
268
- swift::ExtensionDecl *m_extension_decl =
269
- nullptr ; // This is an optional extension holding the function
270
- swift::FuncDecl *m_wrapper_decl = nullptr ; // This is an optional wrapper
271
- // function that calls
272
- // m_function_decl.
273
- llvm::StringRef m_wrapper_func_prefix; // This is the prefix name for the
274
- // wrapper function. One tricky bit
275
- // is that in the case where there is no wrapper, the m_function_decl
276
- // has this name. That's why we check first for the debugger attribute.
277
-
278
- FuncAndExtensionFinder (llvm::StringRef &wrapped_func_prefix)
279
- : m_wrapper_func_prefix(wrapped_func_prefix) {}
260
+ struct FuncAndExtensionFinder : public swift ::ASTWalker {
261
+ // / This is the toplevel entry function for the expression. It may
262
+ // / call into \c ext_method_decl or hold the entire expression.
263
+ swift::FuncDecl *toplevel_decl = nullptr ;
264
+ // / This is optional.
265
+ swift::FuncDecl *ext_method_decl = nullptr ;
266
+ // / This is an optional extension holding the above function.
267
+ swift::ExtensionDecl *extension_decl = nullptr ;
280
268
281
269
bool walkToDeclPre (swift::Decl *D) override {
282
270
auto *FD = llvm::dyn_cast<swift::FuncDecl>(D);
271
+ // Traverse into any non-function-decls.
283
272
if (!FD)
284
273
return true ;
285
274
286
- if (FD->getAttrs ().hasAttribute <swift::LLDBDebuggerFunctionAttr>()) {
287
- m_function_decl = FD ;
275
+ if (! FD->getAttrs ().hasAttribute <swift::LLDBDebuggerFunctionAttr>())
276
+ return false ;
288
277
289
- // Now walk back up the containing DeclContexts, and if we find an
290
- // extension Decl, that's our extension:
291
- for (swift::DeclContext *DC = m_function_decl->getDeclContext (); DC;
292
- DC = DC->getParent ()) {
293
- if (auto *extension_decl = llvm::dyn_cast<swift::ExtensionDecl>(DC)) {
294
- m_extension_decl = extension_decl;
295
- break ;
296
- }
278
+ // Walk up the DeclContext chain, searching for an extension.
279
+ for (auto *DC = FD->getDeclContext (); DC; DC = DC->getParent ()) {
280
+ if (auto *extension = llvm::dyn_cast<swift::ExtensionDecl>(DC)) {
281
+ extension_decl = extension;
282
+ ext_method_decl = FD;
283
+ return false ;
297
284
}
298
- } else if (FD->hasName () && FD->getBaseIdentifier ().str ().startswith (
299
- m_wrapper_func_prefix)) {
300
- m_wrapper_decl = FD;
301
285
}
302
-
303
- // There's nothing buried in a function that we need to find in this
304
- // search.
286
+ // Not in an extenstion,
287
+ toplevel_decl = FD;
305
288
return false ;
306
289
}
307
290
};
308
291
309
- FuncAndExtensionFinder func_finder (s_func_prefix_str) ;
292
+ FuncAndExtensionFinder func_finder;
310
293
m_source_file.walk (func_finder);
311
294
312
- m_function_decl = func_finder.m_function_decl ;
313
- m_wrapper_decl = func_finder.m_wrapper_decl ;
314
- m_extension_decl = func_finder.m_extension_decl ;
295
+ m_extension_decl = func_finder.extension_decl ;
296
+ if (m_extension_decl) {
297
+ m_function_decl = func_finder.ext_method_decl ;
298
+ m_wrapper_decl = func_finder.toplevel_decl ;
299
+ } else {
300
+ m_function_decl = func_finder.toplevel_decl ;
301
+ m_wrapper_decl = nullptr ;
302
+ }
315
303
316
304
assert (m_function_decl);
317
305
0 commit comments