[Prev][Next][Index]

Yet more stuff



Thanks,

Carl
------- Forwarded Message

Forwarded: Mon, 23 Oct 1995 11:43:23 -0700
Forwarded: mohr@cs.uoregon.edu
Return-Path: mei 
Received: from folding.compbio.caltech.edu by bioserv
        (5.0/DEI:4.45) id AA08262; Fri, 20 Oct 1995 18:34:27 -0700
From: Mei-Hui Su <mei>
Return-Path: <mei>
Received: by folding.compbio.caltech.edu
	(5.0/DEI:4.45) id AA05175; Fri, 20 Oct 1995 18:33:46 +0800
Date: Fri, 20 Oct 1995 18:33:46 +0800
Message-Id: <9510210133.AA05175@folding.compbio.caltech.edu>
To: carl, gannon@cs.indiana.edu, garnett, mei
Subject: if statement
Content-Length: 2796


 
Hi Dennis,
 
 I am trying to generate the sage conditional statement in a
piecewise fashion.. and insert it into the statement list.
 
 I always would be getting an extra CONTROL_END in some cases.
 
For example,
 
 If( 10 ) { then_statement } else { else_statement }
 
 could I do this ??
 
 SgIfStmt *ifstmt=new SgIfStmt(expr);
 currentStmt->insertStmtAfter(*ifstmt);
 currentStmt = curStmt->lexNext();
 
 and then
 generate the then_statement and call
 ifstmt->replaceTrue(*curStmt);
 and do the same thing for the else_statement
 
 If I were to create the complete if-stmt tree before inserting it
into the currentStmt's list, I get the following list of
statement
 
  IF_NODE
  STMT
  CONTROL_END
  STMT
  CONTROL_END
 
but, if I were to create the code piecewise, this is what
I get in some cases I tested. I did extend the libSage++.h to
get the necessary member funtion
 
  IF_NODE
  STMT
  CONTROL_END
  CONTROL_END
  STNT
  CONTROL_END
 
- ---------------- code I added -------------------------------
/*CCPP*/
/* should only be use with a replaceTrueBody and replaceFalseBody */
inline SgIfStmt::SgIfStmt(SgExpression &cond) :SgStatement(IF_NODE)
{
  BIF_LL1(thebif) = cond.thellnd;
}
 
I am not very sure about what --> addControlEndToStmt(thebif);
should do because I notice it is in the constructor call in the
other SgIfStmt and also in the replaceTrueBody and replaceFalseBody.
Wouldn't that be putting extra ControlEnds everytime the replaceX
is called? or do they get deleted somehow.
 
Another related question, what if I have an if statement with empty
then-stmt, would the piecewise method above still work?? I notice
the replaceFalseBody is an append instead of insert but they are on
different lists. So, they might not affect each other at all?
 
 
example I tried is like this..
    {
    SgExpression *texpr=fake_sgexpression(88);
    SgIfStmt *ifstmt=new SgIfStmt(*texpr);
    printSgStatement(ifstmt, "TREE");
    curStmt->insertStmtAfter((SgStatement&)*ifstmt);
    curStmt = curStmt->lexNext();
    printSgStatement(ifstmt, "TREE");
    sub=(SgStatement *)(new SgContinueStmt());
    ifstmt->replaceTrueBody(*sub);
    printSgStatement(ifstmt, "TREE");
    sub=(SgStatement *)(new SgBreakStmt());
    ifstmt->replaceFalseBody(*sub);
    printSgStatement(ifstmt, "TREE");
    }
 
and
SgExpression *fake_sgexpression(int val)
{
SgExprListExp *exprlist=new SgExprListExp(SgValueExp(val));
return (SgExpression *) exprlist;
}
 
so the resulting printout I got is like this
=>if (88)
{
      continue;
  }
 else{
      break;
 }
 
0:SgIfStmt[0,0|10|IF_NODE|-]
1:SgExecutableStmt[1,0|11|CONT_STAT|-]
1:SgExecutableStmt[1,1|12|CONTROL_END|-]
1:SgExecutableStmt[1,2|14|CONTROL_END|-]
1:SgExecutableStmt[1,0|13|BREAK_NODE|-]
1:SgExecutableStmt[1,1|15|CONTROL_END|-]
 
 
mei

------- End of Forwarded Message