From 823b4fd322e40800313903aee79993998200db7a Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 11 Sep 2015 19:23:40 +0200 Subject: [PATCH] WIP: implement the recursive scope expansion Only a Record payload constitutes a nested scope. For all other (primitive) values, we return an empty iterator. When used within ScopeExplorer, this implementation will just lead to exposing any simple value once, while delving into iteration of nested scopes --- src/lib/diff/gen-node.hpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/lib/diff/gen-node.hpp b/src/lib/diff/gen-node.hpp index fd9e788d7..edb3a912a 100644 --- a/src/lib/diff/gen-node.hpp +++ b/src/lib/diff/gen-node.hpp @@ -257,7 +257,7 @@ namespace diff{ - /** @internal diagnostics helper. Need to include format-helper.cpp */ + /** @internal diagnostics helper. Include format-helper.cpp on use */ operator string() const { return "GenNode-"+string(idi)+"-"+string(data); @@ -406,6 +406,8 @@ namespace diff{ /** * Building block for monad-like depth-first expansion of a GenNode. + * When used within lib::IterStateWrapper, the result is an Iterator + * to visit the contents of a GenNodet tree recursively depth-fist. */ class GenNode::ScopeExplorer { @@ -439,7 +441,7 @@ namespace diff{ iterNext (ScopeExplorer & explorer) { ScopeIter& current = explorer.scopes_.back(); - explorer.scopes_.emplace_back(current->data.expand()); + explorer.scopes_.emplace_back (current->data.expand()); ++current; while (!explorer.scopes_.empty() && !explorer.scopes_.back()) explorer.scopes_.pop_back(); @@ -447,6 +449,20 @@ namespace diff{ }; + /** @internal Core operation to expand nested scopes recursively */ + DataCap::Locator + DataCap::expand() const + { + Rec* val = unConst(this)->maybeGet(); + if (!val) + return Locator(); + else + return Locator(*val); + } + + + + /** * Constructor for a specially crafted 'ref GenNode'. * The identity record of the generated object will be prepared