Commit | Line | Data |
---|---|---|
91eba41f | 1 | (* This module tries to detect some cpp idioms so that we can parse as-is |
ae4735db | 2 | * files by adjusting or commenting some tokens. Parsing hack style. |
91eba41f C |
3 | * Sometime we use some indentation information, |
4 | * sometimes we do some kind of lalr(k) by finding patterns. Often try to | |
34e49164 C |
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 | |
ae4735db C |
7 | * complex cpp idiom pattern (cf token_views_c.ml). |
8 | * We also try to get more contextual information such as whether the | |
708f4980 | 9 | * token is in a initializer as some common patterns have different |
34e49164 | 10 | * use depending on context. |
ae4735db C |
11 | * |
12 | * | |
34e49164 C |
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 | |
ae4735db | 26 | * |
34e49164 | 27 | * Cf the TMacroXxx in parser_c.mly and MacroXxx in ast_c.ml |
ae4735db | 28 | * |
708f4980 | 29 | * Also try to infer typedef. |
ae4735db C |
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 | |
708f4980 C |
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) | |
34e49164 C |
35 | *) |
36 | ||
91eba41f C |
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 | ||
708f4980 | 43 | (* can reset this global *) |
485bce71 | 44 | val ifdef_paren_cnt: int ref |
34e49164 | 45 | |
ae4735db | 46 | val filter_cpp_stuff : |
708f4980 | 47 | Token_views_c.token_extended list -> Token_views_c.token_extended list |
ae4735db | 48 | val insert_virtual_positions: |
708f4980 | 49 | Parser_c.token list -> Parser_c.token list |
34e49164 | 50 | |
978fd7e5 C |
51 | (* will among other things interally call cpp_token_c to macro |
52 | * expand some macros *) | |
ae4735db | 53 | val fix_tokens_cpp : |
708f4980 C |
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 *) | |
ae4735db C |
58 | val lookahead : |
59 | pass:int -> | |
485bce71 | 60 | Parser_c.token list -> Parser_c.token list -> Parser_c.token |
34e49164 | 61 | |
91eba41f | 62 | |
978fd7e5 C |
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 *) | |
ae4735db | 69 | val fix_tokens_define : |
978fd7e5 C |
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 *) | |
ae4735db | 77 | val tokens_include: |
978fd7e5 C |
78 | Ast_c.info * string * string * bool ref -> |
79 | Parser_c.token * Parser_c.token list | |
80 |