7b41698d02497ad9de8ad4fc424adc8d6927fccb
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
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
9 * complex cpp idiom pattern. Also try to get context info such as
10 * whether the token is in a initializer as some common patterns have different
11 * use depending on context.
14 * Example of cpp idioms:
15 * - if 0 for commenting stuff (not always code, sometimes just real comments)
18 * - ifdef statements, ifdef expression, ifdef-mid
19 * - macro toplevel (with or without ptvirg)
21 * - macro higher order
25 * - macro string, and macro function string taking param and ##
28 * Cf the TMacroXxx in parser_c.mly and MacroXxx in ast_c.ml
30 * Also try infer typedef.
32 * Also do other stuff involving cpp like expanding some macros,
33 * or try parse well define body by finding the end of define virtual
37 (* corresponds to what is in the yacfe configuration file (e.g. standard.h) *)
38 type define_def
= string * define_param
* define_body
41 | Params
of string list
43 | DefineBody
of Parser_c.token list
44 | DefineHint
of parsinghack_hint
46 (* strongly corresponds to the TMacroXxx in the grammar and lexer and the
47 * MacroXxx in the ast.
49 and parsinghack_hint
=
55 | HintMacroIdentBuilder
57 val regexp_macro
: Str.regexp
58 val regexp_annot
: Str.regexp
59 val regexp_declare
: Str.regexp
60 val regexp_foreach
: Str.regexp
61 val regexp_typedef
: Str.regexp
63 val _defs
: (string, define_def
) Hashtbl.t
ref
66 val ifdef_paren_cnt
: int ref
68 val fix_tokens_define
: Parser_c.token list
-> Parser_c.token list
69 val extract_cpp_define
: Parser_c.token list
-> (string, define_def
) assoc
72 val fix_tokens_cpp
: Parser_c.token list
-> Parser_c.token list
74 (* next stream tokens -> passed stream tokens -> final next token *)
77 Parser_c.token list
-> Parser_c.token list
-> Parser_c.token