implement mutation of nested scopes
This commit is contained in:
parent
1b6a87324d
commit
fe4b46ad7c
5 changed files with 32 additions and 26 deletions
|
|
@ -155,12 +155,13 @@ namespace diff{
|
|||
Scopes scopes_;
|
||||
|
||||
|
||||
void
|
||||
TreeMutator*
|
||||
buildMutator (DiffMutable& targetBinding)
|
||||
{
|
||||
scopes_.clear();
|
||||
TreeMutator::Handle buffHandle = scopes_.openScope();
|
||||
targetBinding.buildMutator (buffHandle);
|
||||
return buffHandle.get();
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -267,7 +267,11 @@ namespace diff{
|
|||
void
|
||||
TreeDiffMutatorBinding::__expect_end_of_scope (GenNode::ID const& idi)
|
||||
{
|
||||
|
||||
if (not treeMutator_->completeScope())
|
||||
throw error::State(_Fmt("Diff application floundered in nested scope %s; "
|
||||
"unexpected extra elements found when diff "
|
||||
"should have settled everything.") % idi.getSym()
|
||||
, LUMIERA_ERROR_DIFF_CONFLICT);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -349,24 +353,22 @@ namespace diff{
|
|||
void
|
||||
TreeDiffMutatorBinding::mut (GenNode const& n)
|
||||
{
|
||||
open_subScope (n);
|
||||
TreeMutator::Handle buffHandle = scopeManger_->openScope();
|
||||
if (not treeMutator_->mutateChild(n, buffHandle))
|
||||
__failMismatch (n, "enter nested scope");
|
||||
|
||||
#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #992
|
||||
Rec const& childRecord = child.data.get<Rec>();
|
||||
TRACE (diff, "tree-diff: ENTER scope %s", cStr(childRecord));
|
||||
#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #992
|
||||
TRACE (diff, "tree-diff: ENTER scope %s", cStr(n.idi));
|
||||
treeMutator_ = buffHandle.get();
|
||||
}
|
||||
|
||||
/** finish and leave child object scope, return to parent */
|
||||
void
|
||||
TreeDiffMutatorBinding::emu (GenNode const& n)
|
||||
{
|
||||
#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #992
|
||||
TRACE (diff, "tree-diff: LEAVE scope %s", cStr(describeScope()));
|
||||
#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #992
|
||||
TRACE (diff, "tree-diff: LEAVE scope %s", cStr(n.idi));
|
||||
|
||||
__expect_end_of_scope (n.idi);
|
||||
close_subScope();
|
||||
treeMutator_ = &scopeManger_->closeScope();
|
||||
__expect_valid_parent_scope (n.idi);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -289,14 +289,6 @@ namespace diff{
|
|||
|
||||
|
||||
|
||||
/* == Forwarding: mutation primitives == */
|
||||
|
||||
bool matchSrc (GenNode const& n);
|
||||
void assignElm (GenNode const& n);
|
||||
void open_subScope (GenNode const& n);
|
||||
void close_subScope();
|
||||
|
||||
|
||||
|
||||
/* == Implementation of the list diff application primitives == */
|
||||
|
||||
|
|
|
|||
|
|
@ -154,6 +154,14 @@ namespace lib {
|
|||
{
|
||||
return sizeof(SUB) <= maxSiz_;
|
||||
}
|
||||
|
||||
BA*
|
||||
get() const
|
||||
{
|
||||
ENSURE (buffer_);
|
||||
BA& bufferContent = **static_cast<InPlaceBuffer<BA>*> (buffer_);
|
||||
return &bufferContent;
|
||||
}
|
||||
};
|
||||
/////////////////////////////TODO move over into opaque-holder.hpp
|
||||
namespace diff{
|
||||
|
|
@ -286,7 +294,7 @@ namespace diff{
|
|||
* and build a suitable sub-mutator for this element
|
||||
* into the provided target buffer
|
||||
* @throw error::Fatal when buffer is insufficient
|
||||
* @return false when unable to locate the target */
|
||||
* @return `false` when unable to locate the target */
|
||||
virtual bool
|
||||
mutateChild (GenNode const&, Handle)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ namespace test{
|
|||
*/
|
||||
class Opaque
|
||||
{
|
||||
idi::EntryID<Opaque> key_;
|
||||
idi::BareEntryID key_;
|
||||
string type_ = Rec::TYPE_NIL;
|
||||
|
||||
int alpha_ = -1;
|
||||
|
|
@ -92,11 +92,13 @@ namespace test{
|
|||
vector<string> nestedData_;
|
||||
|
||||
public:
|
||||
Opaque() { }
|
||||
Opaque()
|
||||
: key_(idi::EntryID<Opaque>())
|
||||
{ }
|
||||
|
||||
explicit
|
||||
Opaque (string keyID)
|
||||
: key_(keyID)
|
||||
: key_(idi::EntryID<Opaque>(keyID))
|
||||
{ }
|
||||
|
||||
explicit
|
||||
|
|
@ -132,14 +134,15 @@ namespace test{
|
|||
|
||||
operator string() const
|
||||
{
|
||||
return _Fmt{"%s (α:%d β:%s γ:%7.5f δ:%s\n......|nested:%s\n......|data:%s\n )"}
|
||||
return _Fmt{"%s__(α:%d β:%s γ:%7.5f δ:%s\n......|nested:%s\n......|data:%s\n )__END_%s"}
|
||||
% identity()
|
||||
% alpha_
|
||||
% beta_
|
||||
% gamma_
|
||||
% delta_
|
||||
% join (nestedObj_, "\n........|")
|
||||
% join (nestedObj_, "\n......|")
|
||||
% join (nestedData_)
|
||||
% identity()
|
||||
;
|
||||
}
|
||||
|
||||
|
|
@ -347,7 +350,7 @@ namespace test{
|
|||
// TODO verify results
|
||||
cout << "after...II"<<endl << subject<<endl;
|
||||
|
||||
// Part II : apply child mutations
|
||||
// Part III : apply child mutations
|
||||
application.consume(mutationDiff());
|
||||
//
|
||||
// TODO verify results
|
||||
|
|
|
|||
Loading…
Reference in a new issue