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.
13 * Example of cpp idioms:
14 * - if 0 for commenting stuff (not always code, sometimes just real comments)
17 * - ifdef statements, ifdef expression, ifdef-mid
18 * - macro toplevel (with or without ptvirg)
20 * - macro higher order
24 * - macro string, and macro function string taking param and ##
27 * Cf the TMacroXxx in parser_c.mly and MacroXxx in ast_c.ml
29 * Also try to infer typedef.
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)
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
43 (* can reset this global *)
44 val ifdef_paren_cnt
: int ref
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
52 (* will among other things interally call cpp_token_c to macro
53 * expand some macros *)
55 macro_defs
:(string, Cpp_token_c.define_def
) Hashtbl.t
->
56 Parser_c.token list
-> Parser_c.token list
59 (* next stream tokens -> passed stream tokens -> final next token *)
62 Parser_c.token list
-> Parser_c.token list
-> Parser_c.token
66 (* ------------------------------------------------------------------------ *)
67 (* Parsing hack helpers related to #define or #include *)
68 (* ------------------------------------------------------------------------ *)
70 (* generate virtual end-of-line token, TDefEol, pass the antislash, etc *)
71 val fix_tokens_define
:
72 Parser_c.token list
-> Parser_c.token list
74 (* called when need to pass some tokens during some error recovery *)
75 val drop_until_defeol
: Parser_c.token list
-> Parser_c.token list
76 val comment_until_defeol
: Parser_c.token list
-> Parser_c.token list
78 (* generates TIncludeStart and TIncludeFilename tokens *)
80 Ast_c.info
* string * string * bool ref ->
81 Parser_c.token
* Parser_c.token list