On Tue, 10 Aug 2010, Lucas De Marchi wrote:

> On Tue, Aug 10, 2010 at 3:55 PM, Julia Lawall <[email protected]> wrote:
> > But if what you want is (a) && (b) && (c), then that is another problem,
> > because in that case, the aprentheses don't accumulate.
> 
> 
> Yes, all I want is to put parenthesis on outer level. If there are
> nested parenthesis, whatever coccinelle decides to do is ok, but the
> outer ones should be there. In other words, between the parenthesis
> I'm putting, there will be no && operator.
> 
> The only way I found that works is to expand my "good" rule, taking
> into consideration 3 &&, 4 &&, 5 && and so on. But I hope there's a
> better solution because after that I want to do the same for ||
> operator and mixing both.

Here is an incredibly clunky solution...  Perhaps I can find something 
better.  If you want to extend this solution to ||, replace AndLog by 
OrLog.

julia

----------------------------

@r disable paren expression@
expression E1,E2;
position p;
@@

 e...@p && ... && E2

@script:ocaml@
(_,e1) << r.E1;
p << r.p;
@@

match Ast_c.unwrap e1 with
  (Ast_c.ParenExpr _,_) -> Coccilib.include_match(false)
| (Ast_c.Binary(_,Ast_c.Logical(Ast_c.AndLog),_),_) ->
     Coccilib.include_match(false)
| _ -> ()

@@
position r.p;
expression E;
@@

+(
 e...@p
+)

@rr disable paren expression@
expression E1,E2;
position p;
@@

 E2 && ... && e...@p

@script:ocaml@
(_,e1) << rr.E1;
p << rr.p;
@@

match Ast_c.unwrap e1 with
  (Ast_c.ParenExpr _,_) -> Coccilib.include_match(false)
| (Ast_c.Binary(_,Ast_c.Logical(Ast_c.AndLog),_),_) ->
     Coccilib.include_match(false)
| _ -> ()

@@
position rr.p;
expression E;
@@

+(
 e...@p
+)

----------------------------

_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to