Release coccinelle-0.2.0
[bpt/coccinelle.git] / parsing_c / parsing_hacks.mli
1 (* This module tries to detect some cpp idioms so that we can parse as-is
2 * files by adjusting or commenting some tokens. Parsing hack style.
3 * Sometime we use some indentation information,
4 * sometimes we do some kind of lalr(k) by finding patterns. Often try to
5 * work on better token representation, like ifdef-paren-ized, brace-ized,
6 * paren-ized, so can do easier pattern matching to more easily match
7 * complex cpp idiom pattern (cf token_views_c.ml).
8 * We also try to get more contextual information such as whether the
9 * token is in a initializer as some common patterns have different
10 * use depending on context.
11 *
12 *
13 * Example of cpp idioms:
14 * - if 0 for commenting stuff (not always code, sometimes just real comments)
15 * - ifdef old version
16 * - ifdef funheader
17 * - ifdef statements, ifdef expression, ifdef-mid
18 * - macro toplevel (with or without ptvirg)
19 * - macro foreach
20 * - macro higher order
21 * - macro declare
22 * - macro debug
23 * - macro no ptvirg
24 * - macro string, and macro function string taking param and ##
25 * - macro attribute
26 *
27 * Cf the TMacroXxx in parser_c.mly and MacroXxx in ast_c.ml
28 *
29 * Also try to infer typedef.
30 *
31 * Also do other stuff involving cpp like expanding some macros,
32 * or try parse well define body by finding the end of define virtual
33 * end-of-line token. But now most of the code is actually in cpp_token_c.ml
34 * It is related to what is in the yacfe configuration file (e.g. standard.h)
35 *)
36
37 val regexp_macro: Str.regexp
38 val regexp_annot: Str.regexp
39 val regexp_declare: Str.regexp
40 val regexp_foreach: Str.regexp
41 val regexp_typedef: Str.regexp
42
43 (* can reset this global *)
44 val ifdef_paren_cnt: int ref
45
46 val filter_cpp_stuff :
47 Token_views_c.token_extended list -> Token_views_c.token_extended list
48 val insert_virtual_positions:
49 Parser_c.token list -> Parser_c.token list
50
51
52 (* will among other things interally call cpp_token_c to macro
53 * expand some macros *)
54 val fix_tokens_cpp :
55 macro_defs:(string, Cpp_token_c.define_def) Hashtbl.t ->
56 Parser_c.token list -> Parser_c.token list
57
58
59 (* next stream tokens -> passed stream tokens -> final next token *)
60 val lookahead :
61 pass:int ->
62 Parser_c.token list -> Parser_c.token list -> Parser_c.token
63
64
65
66 (* ------------------------------------------------------------------------ *)
67 (* Parsing hack helpers related to #define or #include *)
68 (* ------------------------------------------------------------------------ *)
69
70 (* generate virtual end-of-line token, TDefEol, pass the antislash, etc *)
71 val fix_tokens_define :
72 Parser_c.token list -> Parser_c.token list
73
74 (* called when need to pass some tokens during some error recovery *)
75 val drop_until_defeol: Parser_c.token list -> Parser_c.token list
76 val comment_until_defeol: Parser_c.token list -> Parser_c.token list
77
78 (* generates TIncludeStart and TIncludeFilename tokens *)
79 val tokens_include:
80 Ast_c.info * string * string * bool ref ->
81 Parser_c.token * Parser_c.token list
82