Commit | Line | Data |
---|---|---|
34e49164 C |
1 | open Common |
2 | ||
91eba41f C |
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 | |
34e49164 C |
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 | |
708f4980 C |
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 | |
34e49164 C |
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 | |
91eba41f | 28 | * |
34e49164 C |
29 | * Cf the TMacroXxx in parser_c.mly and MacroXxx in ast_c.ml |
30 | * | |
708f4980 | 31 | * Also try to infer typedef. |
34e49164 C |
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 | |
708f4980 C |
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) | |
34e49164 C |
37 | *) |
38 | ||
91eba41f C |
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 | ||
708f4980 | 45 | (* can reset this global *) |
485bce71 | 46 | val ifdef_paren_cnt: int ref |
34e49164 | 47 | |
708f4980 C |
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 | |
34e49164 | 52 | |
708f4980 C |
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 | |
34e49164 C |
56 | |
57 | (* next stream tokens -> passed stream tokens -> final next token *) | |
485bce71 C |
58 | val lookahead : |
59 | pass:int -> | |
60 | Parser_c.token list -> Parser_c.token list -> Parser_c.token | |
34e49164 | 61 | |
91eba41f | 62 |