Commit | Line | Data |
---|---|---|
34e49164 C |
1 | open Common |
2 | ||
485bce71 | 3 | (* Try detect some cpp idioms so can parse as-is files by adjusting or |
34e49164 | 4 | * commenting some tokens. Parsing hack style. Sometime use indentation info, |
485bce71 | 5 | * sometimes do some kind of lalr(k) by finding patterns. Often try to |
34e49164 C |
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 | ||
485bce71 C |
35 | (* corresponds to what is in the yacfe configuration file (e.g. standard.h) *) |
36 | type define_def = string * define_param * define_body | |
37 | and define_param = | |
38 | | NoParam | |
39 | | Params of string list | |
40 | and define_body = | |
41 | | DefineBody of Parser_c.token list | |
42 | | DefineHint of parsinghack_hint | |
34e49164 | 43 | |
485bce71 C |
44 | (* strongly corresponds to the TMacroXxx in the grammar and lexer and the |
45 | * MacroXxx in the ast. | |
46 | *) | |
47 | and parsinghack_hint = | |
48 | | HintIterator | |
49 | | HintDeclarator | |
50 | | HintMacroString | |
51 | | HintMacroStatement | |
52 | | HintAttribute | |
34e49164 | 53 | |
485bce71 C |
54 | val _defs : (string, define_def) Hashtbl.t ref |
55 | ||
56 | (* can reset it *) | |
57 | val ifdef_paren_cnt: int ref | |
34e49164 C |
58 | |
59 | val fix_tokens_define : Parser_c.token list -> Parser_c.token list | |
485bce71 | 60 | val extract_cpp_define : Parser_c.token list -> (string, define_def) assoc |
34e49164 C |
61 | |
62 | ||
63 | val fix_tokens_cpp : Parser_c.token list -> Parser_c.token list | |
64 | ||
65 | (* next stream tokens -> passed stream tokens -> final next token *) | |
485bce71 C |
66 | val lookahead : |
67 | pass:int -> | |
68 | Parser_c.token list -> Parser_c.token list -> Parser_c.token | |
34e49164 | 69 |