-(*
-* Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
-* Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller
-* This file is part of Coccinelle.
-*
-* Coccinelle is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, according to version 2 of the License.
-*
-* Coccinelle is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
-*
-* The authors reserve the right to distribute this or future versions of
-* Coccinelle under other licenses.
-*)
-
-
open Format
module Ast = Ast_cocci
let print_around printer term = function
Ast.NOTHING -> printer term
- | Ast.BEFORE(bef) -> print_anything "<<< " bef; printer term
- | Ast.AFTER(aft) -> printer term; print_anything ">>> " aft
- | Ast.BEFOREAFTER(bef,aft) ->
+ | Ast.BEFORE(bef,_) -> print_anything "<<< " bef; printer term
+ | Ast.AFTER(aft,_) -> printer term; print_anything ">>> " aft
+ | Ast.BEFOREAFTER(bef,aft,_) ->
print_anything "<<< " bef; printer term; print_anything ">>> " aft
let print_string_befaft fn x info =
- List.iter (function s -> print_string s; force_newline())
+ List.iter (function (s,_,_) -> print_string s; force_newline())
info.Ast.strbef;
fn x;
- List.iter (function s -> force_newline(); print_string s)
+ List.iter (function (s,_,_) -> force_newline(); print_string s)
info.Ast.straft
let print_meta (r,x) = print_string r; print_string ":"; print_string x
| _ -> ()
let mcode fn = function
- (x, _, Ast.MINUS(_,plus_stream), pos) ->
+ (x, _, Ast.MINUS(_,_,adj,plus_stream), pos) ->
if !print_minus_flag
then print_string (if !Flag.sgrep_mode2 then "*" else "-");
fn x; print_pos pos;
let fn x = fn x; print_pos pos in
print_around fn x plus_streams
else (fn x; print_pos pos)
- | (x, info, Ast.PLUS, pos) ->
+ | (x, info, Ast.PLUS _, pos) ->
let fn x = fn x; print_pos pos in
print_string_befaft fn x info
let print_mcodekind = function
- Ast.MINUS(_,plus_stream) ->
+ Ast.MINUS(_,_,_,plus_stream) ->
print_string "MINUS";
print_anything ">>> " plus_stream
| Ast.CONTEXT(_,plus_streams) ->
print_around (function _ -> print_string "CONTEXT") () plus_streams
- | Ast.PLUS -> print_string "PLUS"
+ | Ast.PLUS _ -> print_string "PLUS"
(* --------------------------------------------------------------------- *)
(* --------------------------------------------------------------------- *)
print_string " inherited:"; print_bool inherited;*)
print_string " */"*)
+(* --------------------------------------------------------------------- *)
+(* Contraint on Identifier and Function *)
+(* FIXME: Not called at the moment *)
+
+let idconstraint c =
+ match c with
+ Ast.IdNoConstraint -> print_string "/* No constraint */"
+ | Ast.IdNegIdSet ids -> List.iter (fun s -> print_string (" "^s)) ids
+ | Ast.IdRegExp (re,_) -> print_string "~= \""; print_string re; print_string "\""
+ | Ast.IdNotRegExp (re,_) -> print_string "~!= \""; print_string re; print_string "\""
+
(* --------------------------------------------------------------------- *)
(* Identifier *)
let rec ident i =
match Ast.unwrap i with
- Ast.Id(name) -> mcode print_string name
- | Ast.MetaId(name,_,keep,inherited) -> mcode print_meta name
- | Ast.MetaFunc(name,_,_,_) -> mcode print_meta name
- | Ast.MetaLocalFunc(name,_,_,_) -> mcode print_meta name
- | Ast.OptIdent(id) -> print_string "?"; ident id
- | Ast.UniqueIdent(id) -> print_string "!"; ident id
+ Ast.Id(name) -> mcode print_string name
+ | Ast.MetaId(name,_,keep,inherited) -> mcode print_meta name
+ | Ast.MetaFunc(name,_,_,_) -> mcode print_meta name
+ | Ast.MetaLocalFunc(name,_,_,_) -> mcode print_meta name
+ | Ast.OptIdent(id) -> print_string "?"; ident id
+ | Ast.UniqueIdent(id) -> print_string "!"; ident id
and print_unitary = function
Type_cocci.Unitary -> print_string "unitary"
and statement arity s =
match Ast.unwrap s with
- Ast.Seq(lbrace,decls,body,rbrace) ->
+ Ast.Seq(lbrace,body,rbrace) ->
rule_elem arity lbrace;
- dots force_newline (statement arity) decls;
dots force_newline (statement arity) body;
rule_elem arity rbrace
| Ast.IfThen(header,branch,(_,_,_,aft)) ->
| Ast.Iterator(header,body,(_,_,_,aft)) ->
rule_elem arity header; statement arity body;
mcode (function _ -> ()) ((),Ast.no_info,aft,Ast.NoMetaPos)
- | Ast.Switch(header,lb,cases,rb) ->
+ | Ast.Switch(header,lb,decls,cases,rb) ->
rule_elem arity header; rule_elem arity lb;
+ dots force_newline (statement arity) decls;
List.iter (function x -> case_line arity x; force_newline()) cases;
rule_elem arity rb
| Ast.Atomic(re) -> rule_elem arity re
- | Ast.FunDecl(header,lbrace,decls,body,rbrace) ->
+ | Ast.FunDecl(header,lbrace,body,rbrace) ->
rule_elem arity header; rule_elem arity lbrace;
- dots force_newline (statement arity) decls;
dots force_newline (statement arity) body;
rule_elem arity rbrace
| Ast.Disj([stmt_dots]) ->
| Ast.ConstVolTag(x) -> const_vol x
| Ast.Token(x,Some info) -> print_string_befaft print_string x info
| Ast.Token(x,None) -> print_string x
+ | Ast.Pragma(xs) -> print_between force_newline print_string xs
| Ast.Code(x) -> let _ = top_level x in ()
| Ast.ExprDotsTag(x) -> dots (function _ -> ()) expression x
| Ast.ParamDotsTag(x) -> parameter_list x
if not in_and
then print_or ()
else (print_string "("; print_or(); print_string ")")
- | Ast.NoDep -> failwith "not possible"
+ | Ast.NoDep -> print_string "no_dep"
+ | Ast.FailDep -> print_string "fail_dep"
let unparse z =
match z with
- Ast.ScriptRule (lang,deps,bindings,code) ->
- print_string "@@";
- force_newline();
- print_string ("script:" ^ lang);
- (match deps with
- Ast.NoDep -> ()
- | _ -> print_string " depends on "; dep true deps);
- force_newline();
- print_string "@@";
- force_newline();
- print_string code;
- force_newline()
+ Ast.InitialScriptRule (lang,code) ->
+ print_string "@@";
+ force_newline();
+ print_string ("initialize:" ^ lang);
+ force_newline();
+ print_string "@@";
+ force_newline();
+ print_string code;
+ force_newline()
+ | Ast.FinalScriptRule (lang,code) ->
+ print_string "@@";
+ force_newline();
+ print_string ("finalize:" ^ lang);
+ force_newline();
+ print_string "@@";
+ force_newline();
+ print_string code;
+ force_newline()
+ | Ast.ScriptRule (lang,deps,bindings,code) ->
+ print_string "@@";
+ force_newline();
+ print_string ("script:" ^ lang);
+ (match deps with
+ Ast.NoDep -> ()
+ | _ -> print_string " depends on "; dep true deps);
+ force_newline();
+ print_string "@@";
+ force_newline();
+ print_string code;
+ force_newline()
| Ast.CocciRule (nm, (deps, drops, exists), x, _, _) ->
- print_string "@@";
- force_newline();
- print_string nm;
- (match deps with
- Ast.NoDep -> ()
- | _ -> print_string " depends on "; dep true deps);
+ print_string "@@";
+ force_newline();
+ print_string nm;
+ (match deps with
+ Ast.NoDep -> ()
+ | _ -> print_string " depends on "; dep true deps);
(*
print_string "line ";
print_int (Ast.get_line (List.hd x));
*)
- force_newline();
- print_string "@@";
- print_newlines_disj := true;
- force_newline();
- force_newline();
- rule x;
- force_newline()
+ force_newline();
+ print_string "@@";
+ print_newlines_disj := true;
+ force_newline();
+ force_newline();
+ rule x;
+ force_newline()
let rule_elem_to_string x =
print_newlines_disj := true;