permit multiline comments and strings in macros
[bpt/coccinelle.git] / parsing_c / parse_c.mli
1 (* The main function is parse_c_and_cpp. It uses globals in Lexer_Parser and
2 * and also _defs below which often comes from a standard.h macro file.
3 * cf also init_defs_xxx below.
4 *)
5
6 type program2 = toplevel2 list
7 and extended_program2 = toplevel2 list *
8 (string, Lexer_parser.identkind) Common.scoped_h_env (* type defs *) *
9 (string, Cpp_token_c.define_def) Hashtbl.t (* macro defs *)
10 and toplevel2 =
11 Ast_c.toplevel * info_item
12 (* the token list contains now also the comment-tokens *)
13 and info_item = (string * Parser_c.token list)
14
15 (* usually correspond to what is inside your macros.h *)
16 val _defs : (string, Cpp_token_c.define_def) Hashtbl.t ref
17 (* usually correspond to what is inside your standard.h *)
18 val _defs_builtins : (string, Cpp_token_c.define_def) Hashtbl.t ref
19
20 val init_defs_macros : Common.filename -> unit
21 val init_defs_builtins : Common.filename -> unit
22
23
24 (* This is the main function *)
25 val parse_c_and_cpp :
26 Common.filename (*cfile*) -> (program2 * Parsing_stat.parsing_stat)
27 val parse_c_and_cpp_keep_typedefs :
28 (string, Lexer_parser.identkind) Common.scoped_h_env option (*typedefs*) ->
29 (string, Cpp_token_c.define_def) Hashtbl.t option (* macro defs *) ->
30 Common.filename (*cfile*) ->
31 (extended_program2 * Parsing_stat.parsing_stat)
32
33 (* use some .ast_raw memoized version, and take care if obsolete *)
34 val parse_cache:
35 Common.filename (*cfile*) -> (extended_program2 * Parsing_stat.parsing_stat)
36
37
38 (* ---------------------------------------------------------------------- *)
39 (* used to extract macros from standard.h, but also now from regular C files
40 * in -extract_macros to later feed an automatically build standard.h *)
41 val extract_macros :
42 Common.filename -> (string, Cpp_token_c.define_def) Common.assoc
43
44
45
46
47
48 (* ---------------------------------------------------------------------- *)
49 (* used also for the standard.h file *)
50 val tokens: ?profile:bool -> Common.filename -> Parser_c.token list
51 val tokens_of_string: string -> Parser_c.token list
52
53 val parse: Common.filename -> Ast_c.program
54 val parse_print_error: Common.filename -> Ast_c.program
55 val parse_gen:
56 ((Lexing.lexbuf -> Parser_c.token) -> Lexing.lexbuf -> 'a) -> string -> 'a
57
58 (* ---------------------------------------------------------------------- *)
59 (* Easy way to build complex Ast elements from simple strings.
60 * Can also be useful when called from the ocaml toplevel to test.
61 *)
62 val type_of_string : string -> Ast_c.fullType
63 val statement_of_string : string -> Ast_c.statement
64
65 (* similar but use parse_c_and_cpp and a /tmp/__cocci.c and extract the part *)
66 val cstatement_of_string : string -> Ast_c.statement
67 val cexpression_of_string : string -> Ast_c.expression
68
69
70 (* ---------------------------------------------------------------------- *)
71 (* a few helpers *)
72 val print_commentized : Parser_c.token list -> unit
73
74 val program_of_program2 : program2 -> Ast_c.program
75 val with_program2: (Ast_c.program -> Ast_c.program) -> program2 -> program2