[Prev][Next][Index]

Re: SgForStmt->setbody() and SgStatement->insertAfterStmt()




>>The call graph manager was
>>examining the "old" body which had no legitimate place, scope,
>>or lexical order, and so the manager would die.
>
>I think that the call graph manager should be modified so that,  
>instead of seg faulting on things it does not like, it would simply  
>leave them alone. 

The call graph manager steps through the sequence of statements using
the lexNext() method of an sgStatement(). It makes the following
assumptions about the ordering of the statements found by lexNext()
and their structure:

 - The first statement in a file is a GLOBAL statement; it has no
   control parent (or at least, no interesting one).

 - For every statement S which is not the GLOBAL statement, it is the
   case that following a chain of controlParent() from S we will get to
   the GLOBAL statement. ["S has the GLOBAL statement as a control parent."]

 - For every statement S which is logically 'nested inside' another statement T
   (e.g. S is the consequent or alternate statements of an 'if' statement T),
   it is the case that:
    - S comes after T in the lexNext ordering; and
    - T is the immediate control parent of S; and
    - If there exists a statement U following T which shares a control parent
      with T and which does not have T as a control parent, then there exist
      no control-children of T (siblings of S) anywhere following U in the
      lexNext ordering.

Note, no assumptions are being made about what these statements are,
only about the hierarchy imposed by controlParent() in relation to the
ordering being imposed by lexNext().

For example. If you have

   STMT1; IF (E) THEN STMT2; ELSE STMT3; STMT4

then the lexNext ordering of these statements is _always_

    STMT1; IF-STMT; STMT2; STMT3; STMT4

where STMT2 and STMT3 can be compound statements consisting of multiple
statements of any type. Essentially, this assumption says that
'statements appear in the order in which they will be unparsed, when
following lexNext()'.

Are these assumptions not true? Various versions of Darryl's program
(or, the Sage libraries as invoked by Darryl's program, I don't know)
violated the third assumption, first by grouping statements as

	IF1 IF2 IF3 BODY1 CTRLEND1 BODY2 CTRLEND2 BODY3 CTRLEND3

and then as 

        IF1 BODY1 IF2 BODY2 IF3 BODY3 CTRLEND3 CTRLEND2 CTRLEND1

If the assumptions stated above are not true (which, by implication, I
will take to mean as 'lexNext() does not mean what I think it means')
then I suppose one fix would be to use the child lists in the statements
rather than using lexNext(); this was not done initially because it did
not fit in very well with the existing code, and I knew of no reason why
lexNext() should not do what I expected it to do.

--lars