permit multiline comments and strings in macros
[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 (* will among other things interally call cpp_token_c to macro
52 * expand some macros *)
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
63
64 (* ------------------------------------------------------------------------ *)
65 (* Parsing hack helpers related to #define or #include *)
66 (* ------------------------------------------------------------------------ *)
67
68 (* generate virtual end-of-line token, TDefEol, pass the antislash, etc *)
69 val fix_tokens_define :
70 Parser_c.token list -> Parser_c.token list
71
72 (* called when need to pass some tokens during some error recovery *)
73 val drop_until_defeol: Parser_c.token list -> Parser_c.token list
74 val comment_until_defeol: Parser_c.token list -> Parser_c.token list
75
76 (* generates TIncludeStart and TIncludeFilename tokens *)
77 val tokens_include:
78 Ast_c.info * string * string * bool ref ->
79 Parser_c.token * Parser_c.token list
80