[Suif-talk] new walker status code: Walker::TruncateReplaced
Karl Eisenhofer
karl@stage2i.com
Thu, 24 Aug 2000 17:46:58 -0700
This is a multi-part message in MIME format.
--------------6314B2A82B82B7A08AF99F6D
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
I had a need for this fucntionality so I just added it since I couldn't
wait for a new release:
Occasionally when you replace a object during a walk
you do NOT want to walk the fields of the replaced in object.
You may know something about the new object such that it
never requires walking. However, a walker does not permit
this when the replaced object is the top walked node.
Note: It is possible to use the set_address(..) call and then
return Walker::Truncate, but it is not possible to find out what that
node is from the calling walker. Only be returning Walker::Replaced,
which in turn walks the fields of the replaced object, can you determine
if the top node of a walk has been
replaced.
The new status code of Walker::TruncateReplace solves this problem by
allowing a user to specify whether to walk the fields of
a replacement or not. The TruncateReplace status code has the same
requirements as the Replace status code (i.e. set_address(..) must be
called or it asserts).
The attachment is context diff of the code that enables this feature.
Note that files labeled <suif_souce_file>.[cpp,h].sav indicate the
new code, and the file sans the .sav extension are the original suif
source.
Have fun!
Karl
--------------6314B2A82B82B7A08AF99F6D
Content-Type: text/plain; charset=us-ascii;
name="suifdiffs"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="suifdiffs"
*** aggregate_meta_class.cpp Thu Aug 24 17:30:25 2000
--- aggregate_meta_class.cpp.sav Thu Aug 24 15:46:53 2000
***************
*** 683,688 ****
--- 683,691 ----
return status;
case Walker::Truncate:
return Walker::Continue;
+ case Walker::TruncateReplaced:
+ assert(w.get_address());
+ return Walker::Replaced;
case Walker::Replaced:
instance = w.get_address();
assert(instance);
***************
*** 701,706 ****
--- 704,710 ----
case Walker::Truncate:
return Walker::Continue;
case Walker::Replaced:
+ case Walker::TruncateReplaced:
assert(false);
break;
}
***************
*** 769,774 ****
--- 773,781 ----
return status;
case Walker::Truncate:
return Walker::Continue;
+ case Walker::TruncateReplaced:
+ assert(w.get_address());
+ return Walker::Replaced;
case Walker::Replaced:
instance = w.get_address();
assert(instance);
***************
*** 788,793 ****
--- 795,801 ----
case Walker::Truncate:
return Walker::Continue;
case Walker::Replaced:
+ case Walker::TruncateReplaced:
assert(false);
break;
}
*** list_meta_class.cpp Thu Aug 24 17:30:25 2000
--- list_meta_class.cpp.sav Thu Aug 24 16:15:28 2000
***************
*** 233,238 ****
--- 233,239 ----
case Walker::Continue:
case Walker::Truncate:
case Walker::Replaced:
+ case Walker::TruncateReplaced:
break;
case Walker::Stop:
case Walker::Abort:
*** walker.h Thu Aug 24 17:30:25 2000
--- walker.h.sav Thu Aug 24 15:46:53 2000
***************
*** 27,35 ****
Stop, // stop iteration
Abort, // stop with error condition
Truncate, // do not walk subobjects of this object (pre-order only)
! Replaced};// Object has been replaced with a new object.
// You must set the address of the new object by calling set_address before
! // returning
Walker(SuifEnv *the_env);
--- 27,36 ----
Stop, // stop iteration
Abort, // stop with error condition
Truncate, // do not walk subobjects of this object (pre-order only)
! Replaced, // Object has been replaced with a new object.
! TruncateReplaced }; // Object has been replaced, but do not walk the fields of the new object (pre-order only)
// You must set the address of the new object by calling set_address before
! // returning with status Replaced or TruncateReplaced
Walker(SuifEnv *the_env);
*** group_walker.cpp Thu Aug 24 17:34:10 2000
--- group_walker.cpp.sav Thu Aug 24 16:13:12 2000
***************
*** 78,84 ****
if (!w)
return Walker::Continue;
Walker::ApplyStatus status = (*w)(x);
! if (status == Replaced)
set_address(w->get_address());
return status;
}
--- 78,84 ----
if (!w)
return Walker::Continue;
Walker::ApplyStatus status = (*w)(x);
! if (status == Replaced || status == TruncateReplaced)
set_address(w->get_address());
return status;
}
***************
*** 88,94 ****
Walker::ApplyStatus ReplacingWalker::operator () (SuifObject *x) {
Walker::ApplyStatus status = GroupWalker::operator()(x);
! if (status == Replaced) {
SuifObject *y = (SuifObject *)get_address();
_map.enter_value(x,y);
SuifObject *parent = (SuifObject *)get_parent();
--- 88,94 ----
Walker::ApplyStatus ReplacingWalker::operator () (SuifObject *x) {
Walker::ApplyStatus status = GroupWalker::operator()(x);
! if (status == Replaced || status == TruncateReplaced) {
SuifObject *y = (SuifObject *)get_address();
_map.enter_value(x,y);
SuifObject *parent = (SuifObject *)get_parent();
--------------6314B2A82B82B7A08AF99F6D--