Hi, I am trying to add a statement s1 outside of an if and another
statement s2 inside of the if as below
s1;
if (cond1 && cond2 && cond3){
s2;
}
CIL breaks that into multiple nested if's so it will look like
s1;
if(cond1){
if(cond2){
if (cond3){
s2;
}
}
}
I wrote the following simple code for this purpose but it's not
correct -- it enters an infinite loop and I think the reason is at the
line (**problem here**) --- because it adds the new statement s1 to
the current if stuff ... then Do the children , so again revisit the
current if stuff .
(*check if there's no more if's*)
let isInnerMostBlock b =
let isIfTheFirst stmt = match stmt.skind with If(cond,b1,b2,l) ->
true |_ -> false in
match b.bstmts with [] -> true |(fst_stmt::_) -> not (isIfTheFirst fst_stmt)
class nestedIfConds () = object
inherit nopCilVisitor
val mutable inNestedIf = false
method vstmt s = (
match s.skind with
|If(cond,b1,b2,l)-> (
if inNestedIf = false then (
debug "Entering if\n";
inNestedIf <- true;
let s1 = mkEmptyStmt () in
s.skind <- Block(mkBlock([s1;{s with labels = []}]))
(** problem here**)
);
if (isInnerMostBlock b1) then (
inNestedIf <- false;
let s2 = mkEmptyStmt () in
b1.bstmts <- s2::b1.bstmts
);
DoChildren
)
|_ -> DoChildren
)
end
I am not sure how to do this correctly ? e.g., using different
Visitor action like ChangeTo or DoChildren Post etc ? I don't think
DoChildrenPost does what I want because it travels all the ways down
to if(cond3) and returns back from there. Greatly appreciate all
the helps !
VN -
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
CIL-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cil-users