-open Common
-
-(* Try detect some cpp idioms so can parse as-is files by adjusting or
- * commenting some tokens. Parsing hack style. Sometime use indentation info,
- * sometimes do some kind of lalr(k) by finding patterns. Often try to
+(* This module tries to detect some cpp idioms so that we can parse as-is
+ * files by adjusting or commenting some tokens. Parsing hack style.
+ * Sometime we use some indentation information,
+ * sometimes we do some kind of lalr(k) by finding patterns. Often try to
* work on better token representation, like ifdef-paren-ized, brace-ized,
* paren-ized, so can do easier pattern matching to more easily match
- * complex cpp idiom pattern. Also try to get context info such as
- * whether the token is in a initializer as some common patterns have different
+ * complex cpp idiom pattern (cf token_views_c.ml).
+ * We also try to get more contextual information such as whether the
+ * token is in a initializer as some common patterns have different
* use depending on context.
- *
- *
+ *
+ *
* Example of cpp idioms:
* - if 0 for commenting stuff (not always code, sometimes just real comments)
* - ifdef old version
* - macro no ptvirg
* - macro string, and macro function string taking param and ##
* - macro attribute
+ *
* Cf the TMacroXxx in parser_c.mly and MacroXxx in ast_c.ml
- *
- * Also try infer typedef.
- *
- * Also do other stuff involving cpp like expanding some macros,
- * or try parse well define body by finding the end of define virtual
- * end-of-line token.
+ *
+ * Also try to infer typedef.
+ *
+ * Also do other stuff involving cpp like expanding some macros,
+ * or try parse well define body by finding the end of define virtual
+ * end-of-line token. But now most of the code is actually in cpp_token_c.ml
+ * It is related to what is in the yacfe configuration file (e.g. standard.h)
*)
-(* corresponds to what is in the yacfe configuration file (e.g. standard.h) *)
-type define_def = string * define_param * define_body
- and define_param =
- | NoParam
- | Params of string list
- and define_body =
- | DefineBody of Parser_c.token list
- | DefineHint of parsinghack_hint
-
- (* strongly corresponds to the TMacroXxx in the grammar and lexer and the
- * MacroXxx in the ast.
- *)
- and parsinghack_hint =
- | HintIterator
- | HintDeclarator
- | HintMacroString
- | HintMacroStatement
- | HintAttribute
-
-val _defs : (string, define_def) Hashtbl.t ref
+val regexp_macro: Str.regexp
+val regexp_annot: Str.regexp
+val regexp_declare: Str.regexp
+val regexp_foreach: Str.regexp
+val regexp_typedef: Str.regexp
-(* can reset it *)
+(* can reset this global *)
val ifdef_paren_cnt: int ref
-val fix_tokens_define : Parser_c.token list -> Parser_c.token list
-val extract_cpp_define : Parser_c.token list -> (string, define_def) assoc
+val filter_cpp_stuff :
+ Token_views_c.token_extended list -> Token_views_c.token_extended list
+val insert_virtual_positions:
+ Parser_c.token list -> Parser_c.token list
-
-val fix_tokens_cpp : Parser_c.token list -> Parser_c.token list
+(* will among other things interally call cpp_token_c to macro
+ * expand some macros *)
+val fix_tokens_cpp :
+ macro_defs:(string, Cpp_token_c.define_def) Hashtbl.t ->
+ Parser_c.token list -> Parser_c.token list
(* next stream tokens -> passed stream tokens -> final next token *)
-val lookahead :
- pass:int ->
+val lookahead :
+ pass:int ->
Parser_c.token list -> Parser_c.token list -> Parser_c.token
+
+
+(* ------------------------------------------------------------------------ *)
+(* Parsing hack helpers related to #define or #include *)
+(* ------------------------------------------------------------------------ *)
+
+(* generate virtual end-of-line token, TDefEol, pass the antislash, etc *)
+val fix_tokens_define :
+ Parser_c.token list -> Parser_c.token list
+
+(* called when need to pass some tokens during some error recovery *)
+val drop_until_defeol: Parser_c.token list -> Parser_c.token list
+val comment_until_defeol: Parser_c.token list -> Parser_c.token list
+
+(* generates TIncludeStart and TIncludeFilename tokens *)
+val tokens_include:
+ Ast_c.info * string * string * bool ref ->
+ Parser_c.token * Parser_c.token list
+