From 5d41388ff3e971d47f8fb7938be49f3dca85c3d1 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 29 Oct 2008 02:00:00 -0600 Subject: Corrected the way that scopes are found so that xact_t can also be found as an item_t (which it also is). --- src/scope.h | 48 ++++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/scope.h b/src/scope.h index 49c77d1c..cd6fc15a 100644 --- a/src/scope.h +++ b/src/scope.h @@ -56,28 +56,8 @@ public: else return NULL_VALUE; } - - virtual optional find_scope(const std::type_info&, bool = true) { - return none; - } }; -template -inline T& find_scope(scope_t& scope, bool skip_this = true) { - optional found = scope.find_scope(typeid(T), skip_this); - assert(found); - return static_cast(*found); -} - -template -inline optional maybe_find_scope(scope_t& scope, bool skip_this = true) { - optional found = scope.find_scope(typeid(T), skip_this); - if (found) - return optional(static_cast(*found)); - else - return none; -} - class child_scope_t : public noncopyable, public scope_t { public: @@ -99,20 +79,24 @@ public: return parent->lookup(name); return expr_t::ptr_op_t(); } +}; - virtual optional find_scope(const std::type_info& type, - bool skip_this = true) { - for (scope_t * ptr = (skip_this ? parent : this); ptr; ) { - if (typeid(*ptr) == type) - return *ptr; - if (child_scope_t * scope = dynamic_cast(ptr)) - ptr = scope->parent; - else - ptr = NULL; - } - return none; + +template +inline T& find_scope(child_scope_t& scope, bool skip_this = true) +{ + for (scope_t * ptr = (skip_this ? scope.parent : &scope); ptr; ) { + T * sought = dynamic_cast(ptr); + if (sought) + return *sought; + if (child_scope_t * scope = dynamic_cast(ptr)) + ptr = scope->parent; + else + ptr = NULL; } -}; + throw_(std::runtime_error, "Could not find scope"); + return reinterpret_cast(scope); // never executed +} class symbol_scope_t : public child_scope_t { -- cgit v1.2.3