On 9/30/10 5:53 PM, Jean-Marc Lasgouttes wrote:
Le 30/09/2010 23:03, Richard Heck a écrit :
It's not so much detecting the recursion. It's what to do about it once
you detect it. So, say, we have: A -> B -> A. What should
B.masterBuffer() return? What should A.masterBuffer() return? How do you
safely write recursions?
I would say the second A is invalid (and the inset should output a
nice ERROR in red text or something), and thus everything should as if
we had A->B (start from master document, and prune documents that are
repeats).
Except if you do this from B, then it's B->A. We want something stable.
Maybe the place to do this is in Buffer::setParent(). I.e., every time
we are asked to set a parent, we check for recursive includes and refuse
to set it if doing saw causes recursion.
Of course, we'd like to accept:
A----->B
\---->C----->B
where B is inserted twice with different parent, but I do not think
our current system allows it now.
This kind of works and kind of doesn't. There will be complaints about
the double-parent thing, but if you are doing the recursion "from the
top", then it will be OK. Of course, labels in B will cause a problem,
e.g., as they'll be detected as dupes, and I'm not sure what happens
then, possibly a nightmare. But you could certainly include some
boilerplate lots of times, and that would be OK, I think, except for
"bottom up" recursion.
I wonder if it would be possible to do entirely without
Buffer::parent(). That is the root of all our problems. We'd have to
find the structural relationships top-down, but the children_positions
thing makes that fairly easy....if you know where the master is. So
maybe what we need is Buffer::master(), and then Buffer::setMaster()
could do the check for recursive includes?
It occurs to me that there are cases here, e.g., where B contains
macros, say, where we would want to search B twice, when collecting
macro positions. One of my patches yesterday broke that, so I'd better
fix it. ;-)
Richard