From: BT Templeton Date: Thu, 18 Jul 2013 00:53:27 +0000 (-0400) Subject: permit multiline comments and strings in macros X-Git-Url: https://git.hcoop.net/bpt/coccinelle.git/commitdiff_plain/00bac93c9f784d62c7921f6e191d38ff15b34612 permit multiline comments and strings in macros --- diff --git a/parsing_c/parsing_hacks.ml b/parsing_c/parsing_hacks.ml index e1b3893..0e96e67 100644 --- a/parsing_c/parsing_hacks.ml +++ b/parsing_c/parsing_hacks.ml @@ -425,11 +425,11 @@ let rec define_line_1 acc xs = | TDefine ii::xs -> let line = Ast_c.line_of_info ii in let acc = (TDefine ii) :: acc in - define_line_2 acc line ii xs + 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 + 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); @@ -437,14 +437,14 @@ let rec define_line_1 acc xs = define_line_1 acc xs | x::xs -> define_line_1 (x::acc) xs -and define_line_2 acc line lastinfo xs = +and define_line_2 acc lineOk lastinfo xs = match xs with | [] -> (* should not happened, should meet EOF before *) pr2 "PB: WEIRD"; List.rev (mark_end_define lastinfo::acc) | x::xs -> - let line' = TH.line_of_tok x in + let line = TH.line_of_tok x in let info = TH.info_of_tok x in (match x with @@ -453,12 +453,16 @@ and define_line_2 acc line lastinfo xs = let acc = (EOF ii) :: acc in define_line_1 acc xs | TCppEscapedNewline ii -> - if (line' <> line) then pr2 "PB: WEIRD: not same line number"; + if not (lineOk line) then pr2 "PB: WEIRD: not same line number"; let acc = (TCommentSpace ii) :: acc in - define_line_2 acc (line+1) info xs + define_line_2 acc ((=|=) (line + 1)) info xs + | TComment _ when lineOk line -> + define_line_2 (x::acc) (function x -> true) info xs + | TString _ when lineOk line -> + define_line_2 (x::acc) (function x -> true) info xs | x -> - if line' =|= line - then define_line_2 (x::acc) line info xs + if lineOk line + then define_line_2 (x::acc) ((=|=) line) info 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