@p maximum_input_line_length = infinity @$@@{@- SYMBOL Stmt: count: int; SYMBOL Stmt COMPUTE SYNT.count = 1; END; CLASS SYMBOL CountStmts: count: int; CLASS SYMBOL CountStmts COMPUTE SYNT.count = CONSTITUENTS Stmt.count WITH (int, ADD, IDENTICAL, ZERO); END; SYMBOL IfTrue INHERITS CountStmts END; SYMBOL IfFalse INHERITS CountStmts END; SYMBOL IfStmt: iftowhileok, iftowhilebranch: int; SYMBOL IfStmt COMPUTE SYNT.iftowhileok = OR(EQ(CONSTITUENT IfTrue.count, 0), EQ(CONSTITUENT IfFalse.count, 0)); SYNT.iftowhilebranch = IF (EQ(CONSTITUENT IfTrue.count, 0), 2, 1); IF (THIS.iftowhileok, VLContextedit(_currn, "If -> While", VLLIST3("::Change", "pWhileStmt", THIS.iftowhilebranch)), VLContextedit(_currn, "If -> While", VLLIST2("::CDlg::Information", "Cannot do that,\nYou would lose data!"))); END; SYMBOL WhileStmt COMPUTE VLContextedit(_currn, "While -> If", VLLIST3("::Change","pIfStmt", 1)); END; @} @O@@{@- @ @} @O@@{@- proc ::Change {prod index whilestmt} { # Get Pointers to the interesting data set whileexpr [lindex [::vl::getDesc $whilestmt] 0] set expr [::vl::getDesc $whileexpr] set whilebody [lindex [::vl::getDesc $whilestmt] $index] set stmts [::vl::getDesc $whilebody] # Create a new pIfStmt set stmt [::vl::create $::vl::prod($prod)] set ifstmt [::vl::getDesc $stmt] set ifexpr [lindex [::vl::getDesc $ifstmt] 0] set iftrue [lindex [::vl::getDesc $ifstmt] 1] # Move the Expression and the Statement ::vl::extract $stmts ::vl::insert $iftrue 0 $stmts 1 ::vl::extract $expr ::vl::insert $ifexpr 0 $expr 1 # Search replacement position set stmt_while [::vl::getFather $whilestmt] set stmts_while [::vl::getFather $stmt_while] set pos [lsearch -exact [::vl::getDesc $stmts_while] $stmt_while] # Replace it. ::vl::insert $stmts_while $pos $stmt 1 } @}