Commit a2ec42f4 authored by Michele Alberti's avatar Michele Alberti
Browse files

Merge branch 'feature/allow-demangling-c-files' into 'stable/chromium'

Support for editing the translated C file and keeping demangling options afterwards

See merge request frama-c/frama-clang!166
parents c0dd6c74 c3fd6db0
\documentclass[web]{frama-c-book}
\documentclass{frama-c-book}
\usepackage{graphicx}
\usepackage{calc}
\usepackage{datetime}
\newdateformat{ddMyyyydate}{\THEDAY~\monthname[\THEMONTH]~\THEYEAR}
\include{macros}
\include{fclangversion}
\input{macros.tex}
\input{fclangversion.tex}
\makeindex
......
......@@ -2,7 +2,7 @@
(* *)
(* This file is part of Frama-Clang *)
(* *)
(* Copyright (C) 2012-2021 *)
(* Copyright (C) 2012-2022 *)
(* CEA (Commissariat à l'énergie atomique et aux énergies *)
(* alternatives) *)
(* *)
......
......@@ -2,7 +2,7 @@
(* *)
(* This file is part of Frama-Clang *)
(* *)
(* Copyright (C) 2012-2021 *)
(* Copyright (C) 2012-2022 *)
(* CEA (Commissariat à l'énergie atomique et aux énergies *)
(* alternatives) *)
(* *)
......
......@@ -2,7 +2,7 @@
(* *)
(* This file is part of Frama-Clang *)
(* *)
(* Copyright (C) 2012-2021 *)
(* Copyright (C) 2012-2022 *)
(* CEA (Commissariat à l'énergie atomique et aux énergies *)
(* alternatives) *)
(* *)
......@@ -42,46 +42,69 @@ module Clang_command =
let () = Parameter_customize.no_category ()
module Clang_extra_args =
String_list(
struct
let option_name = "-fclang-cpp-extra-args"
let help =
"pass additional options to clang. If not set, the content of \
-cpp-extra-args (if any) is used instead"
let arg_name = "opt"
end)
module Unmangling:
sig
val set: string -> unit
val get: unit -> string
val clear: unit -> unit
val get_val: unit -> (string -> string)
val register_mangling_func: string -> (string->string) -> unit
end
=
struct
module Rep =
State_builder.Ref(Datatype.String)
(struct let dependencies = []
let name = "Unmangling"
let default () = "short"
end)
let available_opt = Hashtbl.create 7
let set s = if Hashtbl.mem available_opt s then Rep.set s
let clear () = Rep.clear ()
let get () = Rep.get ()
let get_val () = Hashtbl.find available_opt (Rep.get ())
let register_mangling_func s f = Hashtbl.add available_opt s f
let () =
register_mangling_func "id" (fun s -> s);
set "short"
let option_name = "-fclang-cpp-extra-args"
let help =
"pass additional options to clang. If not set, the content of \
-cpp-extra-args (if any) is used instead"
let arg_name = "opt"
end)
let unmangling_functions: (string*(string->string)) Datatype.String.Hashtbl.t =
Datatype.String.Hashtbl.create 7
let pp_unmangling_functions fmt =
Datatype.String.Hashtbl.iter
(fun key (help, _) -> Format.fprintf fmt "%s: %s@\n" key help)
unmangling_functions
let () =
Datatype.String.Hashtbl.add
unmangling_functions "none" ("keep mangled names", Fun.id)
module Unmangling =
String(
struct
let option_name = "-cxx-unmangling"
let help =
"how to pretty-print mangled symbols. Use `-cxx-unmangling help' to list \
available options"
let arg_name = "s"
let default = "none"
end
)
let unmangling_help () =
feedback "Possible unmangling functions are:@\n%t" pp_unmangling_functions;
Cmdline.nop
let unmangling_hook _ v =
if Datatype.String.equal v "help" then
Cmdline.run_after_exiting_stage unmangling_help
let () = Unmangling.add_set_hook unmangling_hook
let () = Unmangling.set_possible_values [ "none"; "help" ]
let add_unmangling_function key descr f =
let l = Unmangling.get_possible_values () in
Unmangling.set_possible_values (key :: l);
Datatype.String.Hashtbl.add unmangling_functions key (descr,f)
let get_unmangling_function () =
let v = Unmangling.get () in
if v <> "help" then
snd (Datatype.String.Hashtbl.find unmangling_functions v)
else
fatal
"cannot get current unmangling function: \
Frama-C is not supposed to run analyses if `-cxx-unmangling help' is set "
module UnmanglingFull =
Bool(struct
let default = false
let option_name = "-cxx-demangling-full"
let help= "displays identifiers with their full C++ name"
let help= "displays identifiers with their full C++ name. \
DEPRECATED: use -cxx-unmangling fully-qualified instead)"
end)
let () = Parameter_customize.set_negative_option_name ""
......@@ -92,7 +115,8 @@ module UnmanglingShort =
let option_name = "-cxx-demangling-short"
let help=
"displays identifiers with their C++ short name \
(without qualifiers)"
(without qualifiers). \
DEPRECATED: use -cxx-unmangling without-qualifier instead"
end)
let () = Parameter_customize.set_negative_option_name ""
......@@ -101,17 +125,33 @@ module UnmanglingNo =
Bool(struct
let default = false
let option_name= "-cxx-keep-mangling"
let help= "displays identifiers with their mangled name"
let help= "displays identifiers with their mangled name \
DEPRECATED: use -cxx-unmangling none instead"
end)
let add_unmangling_option s _ new_flag =
if new_flag then Unmangling.set s
else if Unmangling.get () = s then Unmangling.clear ()
let () =
UnmanglingFull.add_set_hook (add_unmangling_option "full");
UnmanglingShort.add_set_hook (add_unmangling_option "short");
UnmanglingNo.add_set_hook (add_unmangling_option "id");
UnmanglingFull.add_set_hook (add_unmangling_option "fully-qualified");
UnmanglingShort.add_set_hook (add_unmangling_option "without-qualifier");
UnmanglingNo.add_set_hook (add_unmangling_option "none")
module ParseableOutput =
False(struct
let option_name = "-cxx-parseable-output"
let help = "set up Frama-C pretty-printer to output C code that can be reparsed by Frama-C"
end)
let parseable_output_hook _ f =
let k = Kernel.dkey_print_attrs in
if f then begin
Kernel.add_debug_keys k;
Unmangling.set "none"
end
else Kernel.del_debug_keys k
let () = ParseableOutput.add_set_hook parseable_output_hook
module C_std_headers =
String(
......
......@@ -2,7 +2,7 @@
(* *)
(* This file is part of Frama-Clang *)
(* *)
(* Copyright (C) 2012-2021 *)
(* Copyright (C) 2012-2022 *)
(* CEA (Commissariat à l'énergie atomique et aux énergies *)
(* alternatives) *)
(* *)
......@@ -27,13 +27,21 @@ module Clang_command: Parameter_sig.String
module Clang_extra_args: Parameter_sig.String_list
(** state of the demangling options. *)
module Unmangling:
sig
val set: string -> unit
val get_val: unit -> (string -> string)
val register_mangling_func: string -> (string->string) -> unit
end
(** state of the -cxx-unmangling option. *)
module Unmangling: Parameter_sig.String
(** [add_unmangling_function key descr f] registers [f] as an unmangling
function, activated by [-cxx-unmangling key]. [descr] will be displayed
along with [key] in the [-cxx-unmangling help] output.
*)
val add_unmangling_function: string -> string -> (string -> string) -> unit
(** gets the unmangling function corresponding
to the current value of [Unmangling] *)
val get_unmangling_function: unit -> (string -> string)
(** -cxx-parseable-output *)
module ParseableOutput: Parameter_sig.Bool
(** -cxx-cstdlib-path option *)
module C_std_headers: Parameter_sig.String
......
......@@ -2,7 +2,7 @@
(* *)
(* This file is part of Frama-Clang *)
(* *)
(* Copyright (C) 2012-2021 *)
(* Copyright (C) 2012-2022 *)
(* CEA (Commissariat à l'énergie atomique et aux énergies *)
(* alternatives) *)
(* *)
......@@ -121,21 +121,36 @@ struct
class printer = object
inherit M.printer
method! varname fmt name =
Format.pp_print_string fmt (Frama_Clang_option.Unmangling.get_val() name)
Format.pp_print_string fmt
(Frama_Clang_option.get_unmangling_function () name)
end
end
(* we avoid any side effect on the kernel unless we are parsing explicitly
a C++ file. *)
let is_cxx_printer_initialized = ref false
let init_cxx_printer _ v =
if v <> "help" && not !is_cxx_printer_initialized then
begin
is_cxx_printer_initialized := true;
Cil_printer.register_shallow_attribute Convert.fc_implicit_attr;
Cil_printer.register_shallow_attribute Convert.fc_pure_template_decl_attr;
Printer.update_printer (module Cxx_printer);
end
let () =
Frama_Clang_option.Unmangling.add_set_hook init_cxx_printer
let is_initialized = ref false
let init_cxx_normalization () =
if not !is_initialized then begin
is_initialized:=true;
Cil_printer.register_shallow_attribute Convert.fc_implicit_attr;
Cil_printer.register_shallow_attribute Convert.fc_pure_template_decl_attr;
Printer.update_printer (module Cxx_printer);
(* If unmangling has not been set, default to short. *)
if not (Frama_Clang_option.Unmangling.is_set ()) then
Frama_Clang_option.Unmangling.set "without-qualifier";
(* enable exception removal unless it has explicitely been set to false
on the command line.
*)
......@@ -146,7 +161,7 @@ let init_cxx_normalization () =
(* C++ allows this *)
Cil.set_acceptEmptyCompinfo ()
end
let parse_cxx file =
init_cxx_normalization ();
Frama_Clang_option.feedback
......
......@@ -2,7 +2,7 @@
(* *)
(* This file is part of Frama-Clang *)
(* *)
(* Copyright (C) 2012-2021 *)
(* Copyright (C) 2012-2022 *)
(* CEA (Commissariat à l'énergie atomique et aux énergies *)
(* alternatives) *)
(* *)
......
......@@ -2,7 +2,7 @@
(* *)
(* This file is part of Frama-Clang *)
(* *)
(* Copyright (C) 2012-2021 *)
(* Copyright (C) 2012-2022 *)
(* CEA (Commissariat à l'énergie atomique et aux énergies *)
(* alternatives) *)
(* *)
......
......@@ -2,7 +2,7 @@
(* *)
(* This file is part of Frama-Clang *)
(* *)
(* Copyright (C) 2012-2021 *)
(* Copyright (C) 2012-2022 *)
(* CEA (Commissariat à l'énergie atomique et aux énergies *)
(* alternatives) *)
(* *)
......
......@@ -2,7 +2,7 @@
(* *)
(* This file is part of Frama-Clang *)
(* *)
(* Copyright (C) 2012-2021 *)
(* Copyright (C) 2012-2022 *)
(* CEA (Commissariat à l'énergie atomique et aux énergies *)
(* alternatives) *)
(* *)
......
......@@ -2,7 +2,7 @@
(* *)
(* This file is part of Frama-Clang *)
(* *)
(* Copyright (C) 2012-2021 *)
(* Copyright (C) 2012-2022 *)
(* CEA (Commissariat à l'énergie atomique et aux énergies *)
(* alternatives) *)
(* *)
......
......@@ -2,7 +2,7 @@
/* */
/* This file is part of Frama-Clang */
/* */
/* Copyright (C) 2012-2021 */
/* Copyright (C) 2012-2022 */
/* CEA (Commissariat à l'énergie atomique et aux énergies */
/* alternatives) */
/* */
......
......@@ -2,7 +2,7 @@
(* *)
(* This file is part of Frama-Clang *)
(* *)
(* Copyright (C) 2012-2021 *)
(* Copyright (C) 2012-2022 *)
(* CEA (Commissariat à l'énergie atomique et aux énergies *)
(* alternatives) *)
(* *)
......@@ -801,6 +801,7 @@ let short_name name =
let is_constructor_name name = basename name = "Ctor"
let () =
Frama_Clang_option.Unmangling.register_mangling_func "short" short_name;
Frama_Clang_option.Unmangling.register_mangling_func "full" unmangle;
Frama_Clang_option.Unmangling.set "short"
Frama_Clang_option.add_unmangling_function
"without-qualifier" "short version of the symbol" short_name;
Frama_Clang_option.add_unmangling_function
"fully-qualified" "fully qualified symbol" unmangle
......@@ -2,7 +2,7 @@
(* *)
(* This file is part of Frama-Clang *)
(* *)
(* Copyright (C) 2012-2021 *)
(* Copyright (C) 2012-2022 *)
(* CEA (Commissariat à l'énergie atomique et aux énergies *)
(* alternatives) *)
(* *)
......
......@@ -2,7 +2,7 @@
(* *)
(* This file is part of Frama-Clang *)
(* *)
(* Copyright (C) 2012-2021 *)
(* Copyright (C) 2012-2022 *)
(* CEA (Commissariat à l'énergie atomique et aux énergies *)
(* alternatives) *)
(* *)
......
......@@ -2,7 +2,7 @@
/* */
/* This file is part of Frama-Clang */
/* */
/* Copyright (C) 2012-2021 */
/* Copyright (C) 2012-2022 */
/* CEA (Commissariat à l'énergie atomique et aux énergies */
/* alternatives) */
/* */
......
......@@ -2,7 +2,7 @@
/* */
/* This file is part of Frama-Clang */
/* */
/* Copyright (C) 2012-2021 */
/* Copyright (C) 2012-2022 */
/* CEA (Commissariat à l'énergie atomique et aux énergies */
/* alternatives) */
/* */
......
......@@ -2,7 +2,7 @@
/* */
/* This file is part of Frama-Clang */
/* */
/* Copyright (C) 2012-2021 */
/* Copyright (C) 2012-2022 */
/* CEA (Commissariat à l'énergie atomique et aux énergies */
/* alternatives) */
/* */
......
......@@ -2,7 +2,7 @@
/* */
/* This file is part of Frama-Clang */
/* */
/* Copyright (C) 2012-2021 */
/* Copyright (C) 2012-2022 */
/* CEA (Commissariat à l'énergie atomique et aux énergies */
/* alternatives) */
/* */
......
......@@ -2,7 +2,7 @@
/* */
/* This file is part of Frama-Clang */
/* */
/* Copyright (C) 2012-2021 */
/* Copyright (C) 2012-2022 */
/* CEA (Commissariat à l'énergie atomique et aux énergies */
/* alternatives) */
/* */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment