X-Git-Url: http://git.hcoop.net/bpt/coccinelle.git/blobdiff_plain/faf9a90c4f9e1e85931cb6b01de660587416eb97..9f8e26f459677a621822918b7539ae94214621ac:/parsing_cocci/visitor_ast.ml diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml index 6541953..d8be92b 100644 --- a/parsing_cocci/visitor_ast.ml +++ b/parsing_cocci/visitor_ast.ml @@ -1,25 +1,26 @@ (* -* 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 . -* -* The authors reserve the right to distribute this or future versions of -* Coccinelle under other licenses. -*) - - + * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen + * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix + * 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 . + * + * The authors reserve the right to distribute this or future versions of + * Coccinelle under other licenses. + *) + + +module Ast0 = Ast0_cocci module Ast = Ast_cocci (* --------------------------------------------------------------------- *) @@ -114,13 +115,13 @@ let combiner bind option_default and ident i = let k i = match Ast.unwrap i with - Ast.Id(name) -> string_mcode name - | Ast.MetaId(name,_,_,_) -> meta_mcode name - | Ast.MetaFunc(name,_,_,_) -> meta_mcode name - | Ast.MetaLocalFunc(name,_,_,_) -> meta_mcode name - | Ast.OptIdent(id) -> ident id - | Ast.UniqueIdent(id) -> ident id in - identfn all_functions k i + Ast.Id(name) -> string_mcode name + | Ast.MetaId(name,_,_,_) -> meta_mcode name + | Ast.MetaFunc(name,_,_,_) -> meta_mcode name + | Ast.MetaLocalFunc(name,_,_,_) -> meta_mcode name + | Ast.OptIdent(id) -> ident id + | Ast.UniqueIdent(id) -> ident id in + identfn all_functions k i and expression e = let k e = @@ -268,32 +269,34 @@ let combiner bind option_default and initialiser i = let k i = match Ast.unwrap i with - Ast.InitExpr(exp) -> expression exp + Ast.MetaInit(name,_,_) -> meta_mcode name + | Ast.InitExpr(exp) -> expression exp | Ast.InitList(lb,initlist,rb,whencode) -> multibind [string_mcode lb; multibind (List.map initialiser initlist); string_mcode rb; multibind (List.map initialiser whencode)] - | Ast.InitGccDotName(dot,name,eq,ini) -> - multibind - [string_mcode dot; ident name; string_mcode eq; initialiser ini] | Ast.InitGccName(name,eq,ini) -> multibind [ident name; string_mcode eq; initialiser ini] - | Ast.InitGccIndex(lb,exp,rb,eq,ini) -> + | Ast.InitGccExt(designators,eq,ini) -> multibind - [string_mcode lb; expression exp; string_mcode rb; - string_mcode eq; initialiser ini] - | Ast.InitGccRange(lb,exp1,dots,exp2,rb,eq,ini) -> - multibind - [string_mcode lb; expression exp1; string_mcode dots; - expression exp2; string_mcode rb; string_mcode eq; - initialiser ini] + ((List.map designator designators) @ + [string_mcode eq; initialiser ini]) | Ast.IComma(cm) -> string_mcode cm | Ast.OptIni(i) -> initialiser i | Ast.UniqueIni(i) -> initialiser i in initfn all_functions k i + and designator = function + Ast.DesignatorField(dot,id) -> bind (string_mcode dot) (ident id) + | Ast.DesignatorIndex(lb,exp,rb) -> + bind (string_mcode lb) (bind (expression exp) (string_mcode rb)) + | Ast.DesignatorRange(lb,min,dots,max,rb) -> + multibind + [string_mcode lb; expression min; string_mcode dots; + expression max; string_mcode rb] + and parameterTypeDef p = let k p = match Ast.unwrap p with @@ -408,8 +411,8 @@ let combiner bind option_default process_bef_aft s; let k s = match Ast.unwrap s with - Ast.Seq(lbrace,decls,body,rbrace) -> - multibind [rule_elem lbrace; statement_dots decls; + Ast.Seq(lbrace,body,rbrace) -> + multibind [rule_elem lbrace; statement_dots body; rule_elem rbrace] | Ast.IfThen(header,branch,_) -> multibind [rule_elem header; statement branch] @@ -423,8 +426,9 @@ let combiner bind option_default | Ast.For(header,body,_) -> multibind [rule_elem header; statement body] | Ast.Iterator(header,body,_) -> multibind [rule_elem header; statement body] - | Ast.Switch(header,lb,cases,rb) -> + | Ast.Switch(header,lb,decls,cases,rb) -> multibind [rule_elem header;rule_elem lb; + statement_dots decls; multibind (List.map case_line cases); rule_elem rb] | Ast.Atomic(re) -> rule_elem re @@ -433,10 +437,9 @@ let combiner bind option_default | Ast.Nest(stmt_dots,whn,_,_,_) -> bind (statement_dots stmt_dots) (multibind (List.map (whencode statement_dots statement) whn)) - | Ast.FunDecl(header,lbrace,decls,body,rbrace) -> + | Ast.FunDecl(header,lbrace,body,rbrace) -> multibind [rule_elem header; rule_elem lbrace; - statement_dots decls; statement_dots body; - rule_elem rbrace] + statement_dots body; rule_elem rbrace] | Ast.Define(header,body) -> bind (rule_elem header) (statement_dots body) | Ast.Dots(d,whn,_,_) | Ast.Circles(d,whn,_,_) | Ast.Stars(d,whn,_,_) -> @@ -502,6 +505,7 @@ let combiner bind option_default | Ast.CaseLineTag(case) -> case_line case | Ast.ConstVolTag(cv) -> option_default | Ast.Token(tok,info) -> option_default + | Ast.Pragma(str) -> option_default | Ast.Code(cd) -> top_level cd | Ast.ExprDotsTag(ed) -> expression_dots ed | Ast.ParamDotsTag(pd) -> parameter_dots pd @@ -758,29 +762,32 @@ let rebuilder let k i = Ast.rewrap i (match Ast.unwrap i with - Ast.InitExpr(exp) -> Ast.InitExpr(expression exp) + Ast.MetaInit(name,keep,inherited) -> + Ast.MetaInit(meta_mcode name,keep,inherited) + | Ast.InitExpr(exp) -> Ast.InitExpr(expression exp) | Ast.InitList(lb,initlist,rb,whencode) -> Ast.InitList(string_mcode lb, List.map initialiser initlist, string_mcode rb, List.map initialiser whencode) - | Ast.InitGccDotName(dot,name,eq,ini) -> - Ast.InitGccDotName - (string_mcode dot, ident name, string_mcode eq, initialiser ini) | Ast.InitGccName(name,eq,ini) -> Ast.InitGccName(ident name, string_mcode eq, initialiser ini) - | Ast.InitGccIndex(lb,exp,rb,eq,ini) -> - Ast.InitGccIndex - (string_mcode lb, expression exp, string_mcode rb, - string_mcode eq, initialiser ini) - | Ast.InitGccRange(lb,exp1,dots,exp2,rb,eq,ini) -> - Ast.InitGccRange - (string_mcode lb, expression exp1, string_mcode dots, - expression exp2, string_mcode rb, string_mcode eq, + | Ast.InitGccExt(designators,eq,ini) -> + Ast.InitGccExt + (List.map designator designators, string_mcode eq, initialiser ini) | Ast.IComma(cm) -> Ast.IComma(string_mcode cm) | Ast.OptIni(i) -> Ast.OptIni(initialiser i) | Ast.UniqueIni(i) -> Ast.UniqueIni(initialiser i)) in initfn all_functions k i + and designator = function + Ast.DesignatorField(dot,id) -> + Ast.DesignatorField(string_mcode dot,ident id) + | Ast.DesignatorIndex(lb,exp,rb) -> + Ast.DesignatorIndex(string_mcode lb,expression exp,string_mcode rb) + | Ast.DesignatorRange(lb,min,dots,max,rb) -> + Ast.DesignatorRange(string_mcode lb,expression min,string_mcode dots, + expression max,string_mcode rb) + and parameterTypeDef p = let k p = Ast.rewrap p @@ -913,8 +920,8 @@ let rebuilder let k s = Ast.rewrap s (match Ast.unwrap s with - Ast.Seq(lbrace,decls,body,rbrace) -> - Ast.Seq(rule_elem lbrace, statement_dots decls, + Ast.Seq(lbrace,body,rbrace) -> + Ast.Seq(rule_elem lbrace, statement_dots body, rule_elem rbrace) | Ast.IfThen(header,branch,aft) -> Ast.IfThen(rule_elem header, statement branch,aft) @@ -929,8 +936,9 @@ let rebuilder Ast.For(rule_elem header, statement body, aft) | Ast.Iterator(header,body,aft) -> Ast.Iterator(rule_elem header, statement body, aft) - | Ast.Switch(header,lb,cases,rb) -> + | Ast.Switch(header,lb,decls,cases,rb) -> Ast.Switch(rule_elem header,rule_elem lb, + statement_dots decls, List.map case_line cases,rule_elem rb) | Ast.Atomic(re) -> Ast.Atomic(rule_elem re) | Ast.Disj(stmt_dots_list) -> @@ -939,9 +947,8 @@ let rebuilder Ast.Nest(statement_dots stmt_dots, List.map (whencode statement_dots statement) whn, multi,bef,aft) - | Ast.FunDecl(header,lbrace,decls,body,rbrace) -> + | Ast.FunDecl(header,lbrace,body,rbrace) -> Ast.FunDecl(rule_elem header,rule_elem lbrace, - statement_dots decls, statement_dots body, rule_elem rbrace) | Ast.Define(header,body) -> Ast.Define(rule_elem header,statement_dots body) @@ -1021,6 +1028,7 @@ let rebuilder | Ast.CaseLineTag(case) -> Ast.CaseLineTag(case_line case) | Ast.ConstVolTag(cv) as x -> x | Ast.Token(tok,info) as x -> x + | Ast.Pragma(str) as x -> x | Ast.Code(cd) -> Ast.Code(top_level cd) | Ast.ExprDotsTag(ed) -> Ast.ExprDotsTag(expression_dots ed) | Ast.ParamDotsTag(pd) -> Ast.ParamDotsTag(parameter_dots pd)