From c8c2a17e282c2cbf3c0edb1b756e16be58328331 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 3 Mar 2012 01:17:21 -0600 Subject: Fixed invocation of lambda expressions foo = x, y, z -> print(x, y, z) foo(1, 2, 3) However, this still does not work: (x, y, z -> print(x, y, z))(1, 2, 3) --- src/scope.h | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src/scope.h') diff --git a/src/scope.h b/src/scope.h index 90f9c37a..785ce284 100644 --- a/src/scope.h +++ b/src/scope.h @@ -227,15 +227,17 @@ private: }; template -T * search_scope(scope_t * ptr) +T * search_scope(scope_t * ptr, bool prefer_direct_parents = false) { if (T * sought = dynamic_cast(ptr)) return sought; if (bind_scope_t * scope = dynamic_cast(ptr)) { - if (T * sought = search_scope(&scope->grandchild)) + if (T * sought = search_scope(prefer_direct_parents ? + scope->parent : &scope->grandchild)) return sought; - return search_scope(scope->parent); + return search_scope(prefer_direct_parents ? + &scope->grandchild : scope->parent); } else if (child_scope_t * child_scope = dynamic_cast(ptr)) { return search_scope(child_scope->parent); @@ -244,9 +246,21 @@ T * search_scope(scope_t * ptr) } template -inline T& find_scope(child_scope_t& scope, bool skip_this = true) +inline T& find_scope(child_scope_t& scope, bool skip_this = true, + bool prefer_direct_parents = false) { - if (T * sought = search_scope(skip_this ? scope.parent : &scope)) + if (T * sought = search_scope(skip_this ? scope.parent : &scope, + prefer_direct_parents)) + return *sought; + + throw_(std::runtime_error, _("Could not find scope")); + return reinterpret_cast(scope); // never executed +} + +template +inline T& find_scope(scope_t& scope, bool prefer_direct_parents = false) +{ + if (T * sought = search_scope(&scope, prefer_direct_parents)) return *sought; throw_(std::runtime_error, _("Could not find scope")); -- cgit v1.2.3