-(*
- * Copyright 2010, INRIA, University of Copenhagen
- * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
- * 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 <http://www.gnu.org/licenses/>.
- *
- * The authors reserve the right to distribute this or future versions of
- * Coccinelle under other licenses.
- *)
-
-
open Common
module CCI = Ctlcocci_integration
(* --------------------------------------------------------------------- *)
(* C related *)
(* --------------------------------------------------------------------- *)
-let cprogram_of_file file =
- let (program2, _stat) = Parse_c.parse_c_and_cpp file in
+let cprogram_of_file saved_typedefs saved_macros file =
+ let (program2, _stat) =
+ Parse_c.parse_c_and_cpp_keep_typedefs
+ (Some saved_typedefs) (Some saved_macros) file in
program2
let cprogram_of_file_cached file =
- let (program2, _stat) = Parse_c.parse_cache file in
+ let ((program2,typedefs,macros), _stat) = Parse_c.parse_cache file in
if !Flag_cocci.ifdef_to_if
then
- program2 +> Parse_c.with_program2 (fun asts ->
- Cpp_ast_c.cpp_ifdef_statementize asts
- )
- else program2
+ let p2 =
+ program2 +> Parse_c.with_program2 (fun asts ->
+ Cpp_ast_c.cpp_ifdef_statementize asts
+ ) in
+ (p2,typedefs,macros)
+ else (program2,typedefs,macros)
let cfile_of_program program2_with_ppmethod outf =
Unparse_c.pp_program program2_with_ppmethod outf
search_path native_file_exists searchlist relpath
let (includes_to_parse:
- (Common.filename * Parse_c.program2) list ->
+ (Common.filename * Parse_c.extended_program2) list ->
Flag_cocci.include_options -> 'a) = fun xs choose_includes ->
match choose_includes with
Flag_cocci.I_UNSPECIFIED -> failwith "not possible"
let all_includes =
List.mem x
[Flag_cocci.I_ALL_INCLUDES; Flag_cocci.I_REALLY_ALL_INCLUDES] in
+ let xs = List.map (function (file,(cs,_,_)) -> (file,cs)) xs in
xs +> List.map (fun (file, cs) ->
let dir = Common.dirname file in
was_modified: bool ref;
+ all_typedefs: (string, Lexer_parser.identkind) Common.scoped_h_env;
+ all_macros: (string, Cpp_token_c.define_def) Hashtbl.t;
+
(* id: int *)
}
(* --------------------------------------------------------------------- *)
-let build_info_program cprogram env =
+let build_info_program (cprogram,typedefs,macros) env =
let (cs, parseinfos) =
Common.unzip cprogram in
env_typing_after = envb;
was_modified = ref false;
+
+ all_typedefs = typedefs;
+ all_macros = macros;
}
)
file;
(* Common.command2 ("cat " ^ file); *)
- let cprogram = cprogram_of_file file in
+ let cprogram = cprogram_of_file c.all_typedefs c.all_macros file in
let xs = build_info_program cprogram c.env_typing_before in
(* TODO: assert env has not changed,