Skip to content
Snippets Groups Projects
Commit 0f45c55f authored by David Bühler's avatar David Bühler
Browse files

Merge branch 'fix/virgile/gcc-10' into 'master'

Parses UCN encoded characters in ACSL

Closes #849

See merge request frama-c/frama-c!2637
parents 92419510 96f9cdb7
No related branches found
No related tags found
No related merge requests found
...@@ -71,6 +71,37 @@ ...@@ -71,6 +71,37 @@
fun s -> try Hashtbl.find h s fun s -> try Hashtbl.find h s
with Not_found -> IDENTIFIER s with Not_found -> IDENTIFIER s
let all_digits s =
let is_digit =
function
| '0'..'9' | 'a'..'f' | 'A'..'F' -> ()
| _ -> raise Exit
in
try String.iter is_digit s; true with Exit -> false
let is_ucn s =
if String.length s <= 2 || s.[0] <> '\\' then false else begin
match s.[1] with
| 'U' -> String.length s = 10 && all_digits (String.sub s 2 8)
| 'u' -> String.length s = 6 && all_digits (String.sub s 2 4)
| _ -> false
end
let int_of_digit chr =
match chr with
| '0'..'9' -> (Char.code chr) - (Char.code '0')
| 'a'..'f' -> (Char.code chr) - (Char.code 'a') + 10
| 'A'..'F' -> (Char.code chr) - (Char.code 'A') + 10
| _ -> assert false
(* assumes is_ucn s *)
let unicode_char s =
let code = ref 0 in
let add_digit c = code := 16 * !code + int_of_digit c in
String.iter add_digit (String.sub s 2 (String.length s - 2));
let c = Utf8_logic.from_unichar !code in
find_utf8 c
let identifier, is_acsl_keyword = let identifier, is_acsl_keyword =
let all_kw = Hashtbl.create 37 in let all_kw = Hashtbl.create 37 in
let c_kw = Hashtbl.create 37 in let c_kw = Hashtbl.create 37 in
...@@ -242,18 +273,11 @@ ...@@ -242,18 +273,11 @@
]; ];
fun lexbuf -> fun lexbuf ->
let s = lexeme lexbuf in let s = lexeme lexbuf in
try Hashtbl.find h s with Not_found -> if is_ucn s then unicode_char s else begin
if Logic_env.typename_status s then TYPENAME s try Hashtbl.find h s with Not_found ->
else if Logic_env.typename_status s then TYPENAME s
IDENTIFIER s else IDENTIFIER s
end
let int_of_digit chr =
match chr with
'0'..'9' -> (Char.code chr) - (Char.code '0')
| 'a'..'f' -> (Char.code chr) - (Char.code 'a') + 10
| 'A'..'F' -> (Char.code chr) - (Char.code 'A') + 10
| _ -> assert false
(* Update lexer buffer. *) (* Update lexer buffer. *)
let update_line_loc lexbuf line = let update_line_loc lexbuf line =
......
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
(** UTF-8 string for logic symbols. *) (** UTF-8 string for logic symbols. *)
(** given an unicode code point, returns the corresponding utf-8 encoding. *)
val from_unichar: int -> string
val forall : string val forall : string
val exists : string val exists : string
val eq : string val eq : string
......
[kernel] Parsing tests/spec/ucn.c (with preprocessing)
/* Generated by Frama-C */
/*@ lemma test_ucn: ∀ 𝔹 b; b ≡ \true ⇔ b ≡ \true;
*/
/*@ lemma test_ucn: \U00002200 \U0001D539 b; b \u21D4 \u00AC \U000000AC b; */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment