3897a4794e16ee6bb44cf362c76ded3aa9a8ee20
[bpt/coccinelle.git] / parsing_c / parsing_hacks.mli
1 open Common
2
3 (* Try detect some cpp idioms so can parse as is files by adjusting or
4 * commenting some tokens. Parsing hack style. Sometime use indentation info,
5 * Sometimes do some kind of lalr(k) by finding patterns. Often try to
6 * work on better token representation, like ifdef-paren-ized, brace-ized,
7 * paren-ized, so can do easier pattern matching to more easily match
8 * complex cpp idiom pattern. Also try to get context info such as
9 * whether the 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 * Cf the TMacroXxx in parser_c.mly and MacroXxx in ast_c.ml
27 *
28 * Also try infer typedef.
29 *
30 * Also do other stuff involving cpp like expanding some macros,
31 * or try parse well define body by finding the end of define virtual
32 * end-of-line token.
33 *)
34
35 (* the either is to differentialte macro-variables from macro-functions *)
36 type define_body = (unit,string list) either * Parser_c.token list
37
38 val _defs : (string, define_body) Hashtbl.t ref
39
40
41 val fix_tokens_define : Parser_c.token list -> Parser_c.token list
42 val extract_cpp_define : Parser_c.token list -> (string, define_body) assoc
43
44
45 val fix_tokens_cpp : Parser_c.token list -> Parser_c.token list
46
47 (* next stream tokens -> passed stream tokens -> final next token *)
48 val lookahead : Parser_c.token list -> Parser_c.token list -> Parser_c.token
49