diff --git a/mps/code/cbs.c b/mps/code/cbs.c index 383ac47c472..c7b4478ce4c 100644 --- a/mps/code/cbs.c +++ b/mps/code/cbs.c @@ -748,7 +748,7 @@ static Bool cbsIterateVisit(Tree tree, void *closureP, Size closureS) return TRUE; } -static void cbsIterate(Land land, LandVisitor visitor, +static Bool cbsIterate(Land land, LandVisitor visitor, void *closureP, Size closureS) { CBS cbs; @@ -769,8 +769,8 @@ static void cbsIterate(Land land, LandVisitor visitor, closure.visitor = visitor; closure.closureP = closureP; closure.closureS = closureS; - (void)TreeTraverse(SplayTreeRoot(splay), splay->compare, splay->nodeKey, - cbsIterateVisit, &closure, 0); + return TreeTraverse(SplayTreeRoot(splay), splay->compare, splay->nodeKey, + cbsIterateVisit, &closure, 0); } diff --git a/mps/code/failover.c b/mps/code/failover.c index e8a0dbc7dae..80ecb0a6210 100644 --- a/mps/code/failover.c +++ b/mps/code/failover.c @@ -164,7 +164,7 @@ static Res failoverDelete(Range rangeReturn, Land land, Range range) } -static void failoverIterate(Land land, LandVisitor visitor, void *closureP, Size closureS) +static Bool failoverIterate(Land land, LandVisitor visitor, void *closureP, Size closureS) { Failover fo; @@ -173,8 +173,8 @@ static void failoverIterate(Land land, LandVisitor visitor, void *closureP, Size AVERT(Failover, fo); AVER(visitor != NULL); - LandIterate(fo->primary, visitor, closureP, closureS); - LandIterate(fo->secondary, visitor, closureP, closureS); + return LandIterate(fo->primary, visitor, closureP, closureS) + && LandIterate(fo->secondary, visitor, closureP, closureS); } diff --git a/mps/code/freelist.c b/mps/code/freelist.c index 1e071e06763..241f08ff190 100644 --- a/mps/code/freelist.c +++ b/mps/code/freelist.c @@ -438,7 +438,7 @@ static Res freelistDelete(Range rangeReturn, Land land, Range range) } -static void freelistIterate(Land land, LandVisitor visitor, +static Bool freelistIterate(Land land, LandVisitor visitor, void *closureP, Size closureS) { Freelist fl; @@ -468,8 +468,9 @@ static void freelistIterate(Land land, LandVisitor visitor, } cur = next; if (!cont) - break; + return FALSE; } + return TRUE; } diff --git a/mps/code/land.c b/mps/code/land.c index 9ff8257151c..7221514fff3 100644 --- a/mps/code/land.c +++ b/mps/code/land.c @@ -233,15 +233,17 @@ Res LandDelete(Range rangeReturn, Land land, Range range) * See */ -void LandIterate(Land land, LandVisitor visitor, void *closureP, Size closureS) +Bool LandIterate(Land land, LandVisitor visitor, void *closureP, Size closureS) { + Bool res; AVERT(Land, land); AVER(FUNCHECK(visitor)); landEnter(land); - (*land->class->iterate)(land, visitor, closureP, closureS); + res = (*land->class->iterate)(land, visitor, closureP, closureS); landLeave(land); + return res; } @@ -503,13 +505,13 @@ static Res landNoDelete(Range rangeReturn, Land land, Range range) return ResUNIMPL; } -static void landNoIterate(Land land, LandVisitor visitor, void *closureP, Size closureS) +static Bool landNoIterate(Land land, LandVisitor visitor, void *closureP, Size closureS) { AVERT(Land, land); AVER(visitor != NULL); UNUSED(closureP); UNUSED(closureS); - NOOP; + return FALSE; } static Bool landNoFind(Range rangeReturn, Range oldRangeReturn, Land land, Size size, FindDelete findDelete) diff --git a/mps/code/mpm.h b/mps/code/mpm.h index 9d5854b8cf6..0a87b8fc81d 100644 --- a/mps/code/mpm.h +++ b/mps/code/mpm.h @@ -1014,7 +1014,7 @@ extern void LandDestroy(Land land); extern void LandFinish(Land land); extern Res LandInsert(Range rangeReturn, Land land, Range range); extern Res LandDelete(Range rangeReturn, Land land, Range range); -extern void LandIterate(Land land, LandVisitor visitor, void *closureP, Size closureS); +extern Bool LandIterate(Land land, LandVisitor visitor, void *closureP, Size closureS); extern Bool LandFindFirst(Range rangeReturn, Range oldRangeReturn, Land land, Size size, FindDelete findDelete); extern Bool LandFindLast(Range rangeReturn, Range oldRangeReturn, Land land, Size size, FindDelete findDelete); extern Bool LandFindLargest(Range rangeReturn, Range oldRangeReturn, Land land, Size size, FindDelete findDelete); diff --git a/mps/code/mpmtypes.h b/mps/code/mpmtypes.h index 04f73a7e42d..d81255c974d 100644 --- a/mps/code/mpmtypes.h +++ b/mps/code/mpmtypes.h @@ -272,7 +272,7 @@ typedef Size (*LandSizeMethod)(Land land); typedef Res (*LandInsertMethod)(Range rangeReturn, Land land, Range range); typedef Res (*LandDeleteMethod)(Range rangeReturn, Land land, Range range); typedef Bool (*LandVisitor)(Bool *deleteReturn, Land land, Range range, void *closureP, Size closureS); -typedef void (*LandIterateMethod)(Land land, LandVisitor visitor, void *closureP, Size closureS); +typedef Bool (*LandIterateMethod)(Land land, LandVisitor visitor, void *closureP, Size closureS); typedef Bool (*LandFindMethod)(Range rangeReturn, Range oldRangeReturn, Land land, Size size, FindDelete findDelete); typedef Res (*LandFindInZonesMethod)(Range rangeReturn, Range oldRangeReturn, Land land, Size size, ZoneSet zoneSet, Bool high); typedef Res (*LandDescribeMethod)(Land land, mps_lib_FILE *stream); diff --git a/mps/design/land.txt b/mps/design/land.txt index 11f192fa6ff..3ed8b466b0d 100644 --- a/mps/design/land.txt +++ b/mps/design/land.txt @@ -164,13 +164,15 @@ strategy. _`.function.delete.alias`: It is acceptable for ``rangeReturn`` and ``range`` to share storage. -``void LandIterate(Land land, LandIterateMethod iterate, void *closureP, Size closureS)`` +``Bool LandIterate(Land land, LandIterateMethod iterate, void *closureP, Size closureS)`` _`.function.iterate`: ``LandIterate()`` is the function used to iterate all isolated contiguous ranges in a land. It receives a pointer, ``Size`` closure pair to pass on to the iterator method, and an iterator method to invoke on every range. If the iterator method -returns ``FALSE``, then the iteration is terminated. +returns ``FALSE``, then the iteration is terminated and +``LandIterate()`` returns ``FALSE``. If all iterator method calls +return ``TRUE``, then ``LandIterate()`` returns ``TRUE`` ``Bool LandFindFirst(Range rangeReturn, Range oldRangeReturn, Land land, Size size, FindDelete findDelete)``