dbf050fd82888ced90723685e90e404f9b01de96
3 (* Try detect some cpp idioms so can parse as-is files by adjusting or
4 * commenting some tokens. Parsing hack style. Sometime use indentation info,
5 * sometimes do some kind of lalr(k) by finding patterns. Often try to
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.
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 ##
26 * Cf the TMacroXxx in parser_c.mly and MacroXxx in ast_c.ml
28 * Also try infer typedef.
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
35 (* corresponds to what is in the yacfe configuration file (e.g. standard.h) *)
36 type define_def
= string * define_param
* define_body
39 | Params
of string list
41 | DefineBody
of Parser_c.token list
42 | DefineHint
of parsinghack_hint
44 (* strongly corresponds to the TMacroXxx in the grammar and lexer and the
45 * MacroXxx in the ast.
47 and parsinghack_hint
=
54 val _defs
: (string, define_def
) Hashtbl.t
ref
57 val ifdef_paren_cnt
: int ref
59 val fix_tokens_define
: Parser_c.token list
-> Parser_c.token list
60 val extract_cpp_define
: Parser_c.token list
-> (string, define_def
) assoc
63 val fix_tokens_cpp
: Parser_c.token list
-> Parser_c.token list
65 (* next stream tokens -> passed stream tokens -> final next token *)
68 Parser_c.token list
-> Parser_c.token list
-> Parser_c.token