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