X-Git-Url: https://git.hcoop.net/bpt/coccinelle.git/blobdiff_plain/ae4735db5e7e9386036cf7b496ebdc994514dc53..3a31414346dd7d7e8baa4cb8b804a2d5e1797962:/parsing_c/parsing_hacks.ml diff --git a/parsing_c/parsing_hacks.ml b/parsing_c/parsing_hacks.ml index 490783d..c1f32c6 100644 --- a/parsing_c/parsing_hacks.ml +++ b/parsing_c/parsing_hacks.ml @@ -395,6 +395,7 @@ let rec set_ifdef_parenthize_info xs = * [TCommentSpace "\n"; TDefEOL] but if TDefEOL is a fakeinfo then we will * not synchronize on it and so we will not print the "\n". * A solution would be to put the TDefEOL before the "\n". + * (jll: tried to do this, see the comment "Put end of line..." below) * * todo?: could put a ExpandedTok for that ? *) @@ -418,6 +419,10 @@ let rec define_line_1 acc xs = let line = Ast_c.line_of_info ii in let acc = (TDefine ii) :: acc in define_line_2 acc line ii xs + | TUndef ii::xs -> + let line = Ast_c.line_of_info ii in + let acc = (TUndef ii) :: acc in + define_line_2 acc line ii xs | TCppEscapedNewline ii::xs -> pr2 ("SUSPICIOUS: a \\ character appears outside of a #define at"); pr2 (Ast_c.strloc_of_info ii); @@ -447,12 +452,29 @@ and define_line_2 acc line lastinfo xs = | x -> if line' =|= line then define_line_2 (x::acc) line info xs - else define_line_1 (mark_end_define lastinfo::acc) (x::xs) + else + (* Put end of line token before the newline. A newline at least + must be there because the line changed and because we saw a + #define previously to get to this function at all *) + define_line_1 + ((List.hd acc)::(mark_end_define lastinfo::(List.tl acc))) + (x::xs) ) let rec define_ident acc xs = match xs with | [] -> List.rev acc + | TUndef ii::xs -> + let acc = TUndef ii :: acc in + (match xs with + TCommentSpace i1::TIdent (s,i2)::xs -> + let acc = (TCommentSpace i1) :: acc in + let acc = (TIdentDefine (s,i2)) :: acc in + define_ident acc xs + | _ -> + pr2 "WEIRD: weird #define body"; + define_ident acc xs + ) | TDefine ii::xs -> let acc = TDefine ii :: acc in (match xs with @@ -2020,7 +2042,7 @@ let lookahead2 ~pass next before = end else x - | (TUndef (id, ii) as x)::_, _ + | (TUndef (ii) as x)::_, _ -> if (pass >= 2) then begin @@ -2050,7 +2072,6 @@ let lookahead2 ~pass next before = *) -> - if s ==~ regexp_foreach && is_really_foreach (Common.take_safe forLOOKAHEAD rest)