123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164(**************************************************************************)(* *)(* This file is part of Frama-C. *)(* *)(* Copyright (C) 2007-2023 *)(* CEA (Commissariat à l'énergie atomique et aux énergies *)(* alternatives) *)(* *)(* you can redistribute it and/or modify it under the terms of the GNU *)(* Lesser General Public License as published by the Free Software *)(* Foundation, version 2.1. *)(* *)(* It is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU Lesser General Public License for more details. *)(* *)(* See the GNU Lesser General Public License version 2.1 *)(* for more details (enclosed in the file licenses/LGPLv2.1). *)(* *)(**************************************************************************)openFormat_typesletstring_of_flag=function|FMinus->"-"|FPlus->"+"|FSpace->"' '"|FSharp->"#"|FZero->"0"letstring_of_flagsfl=letrecauxaccufl=matchflwith|f::fl->aux(accu^string_of_flagf)fl|[]->accuinaux""flletpp_flagfff=Format.fprintfff"%s"(string_of_flagf)letpp_flagsfffl=Pretty_utils.pp_list~sep:", "pp_flagffflletstring_of_fw=function|`FWStar->"*"|`FWInti->string_of_intiletpp_fwfffw=Format.fprintfff"%s"(string_of_fwfw)letstring_of_precision=function|PStar->"*"|PInti->string_of_intiletpp_precisionffp=Format.fprintfff".%s"(string_of_precisionp)letstring_of_lm=function|`hh->"hh"|`h->"h"|`l->"l"|`ll->"ll"|`j->"j"|`z->"z"|`t->"t"|`L->"L"letpp_lmfflm=Format.fprintfff"%s"(string_of_lmlm)letstring_of_cs=function|`d->"d"|`i->"i"|`o->"o"|`u->"u"|`x->"x"|`f->"f"|`e->"e"|`g->"g"|`a->"a"|`c->"c"|`s->"s"|`p->"p"|`n->"n"|`Bracketsb->"["^b^"]"letpp_csff(cs,capitalize)=lets=string_of_cscsinlets=ifcapitalizethenString.capitalize_asciiselsesinFormat.fprintfff"%s"sletstring_of_option?pre:(pre="")?suf:(suf="")f=function|Someo->pre^(fo)^suf|None->""letpp_f_specificationffspec=letsuf="; "inFormat.fprintfff"<";ifList.lengthspec.f_flags<>0then(Format.fprintfff"Flags: ";pp_flagsffspec.f_flags;Format.fprintfff"%s"suf);Format.fprintfff"%s%s%s"(string_of_option~pre:"Field width: "~suf:sufstring_of_fwspec.f_field_width)(string_of_option~pre:"Precision: "~suf:sufstring_of_precisionspec.f_precision)(string_of_option~pre:"Length modifier: "~suf:sufstring_of_lmspec.f_length_modifier);Format.fprintfff"Conversion specifier: %s>"(string_of_csspec.f_conversion_specifier)letpp_s_specificationff(spec:s_conversion_specification)=letsuf="; "inFormat.fprintfff"<%s; %s%s"("Assignment: "^(string_of_bool(notspec.s_assignment_suppression)))(string_of_option~pre:"Field width: "~suf:sufstring_of_fwspec.s_field_width)(string_of_option~pre:"Length modifier: "~suf:sufstring_of_lmspec.s_length_modifier);Format.fprintfff"Conversion specifier: %s>"(string_of_csspec.s_conversion_specifier)letpp_f_formatfffl=letfl=List.filter_map(functionSpecifications->Somes|_->None)flinPretty_utils.pp_list~sep:"@."(funffs->pp_f_specificationffs)ffflletpp_s_formatff(fl:s_format)=letfl=List.filter_map(function|Specifications->Somes|_->None)flinPretty_utils.pp_list~sep:"@."(funffs->pp_s_specificationffs)ffflletpp_formatff=function|FFormats->pp_f_formatffs|SFormats->pp_s_formatffsletrecf_format_to_cstringfl=letauxspec="%"^(string_of_flagsspec.f_flags)^(string_of_optionstring_of_fwspec.f_field_width)^(string_of_option~pre:"."string_of_precisionspec.f_precision)^(string_of_optionstring_of_lmspec.f_length_modifier)^(string_of_csspec.f_conversion_specifier)inmatchflwith|[]->""|Char'%'::fl->"%%"^f_format_to_cstringfl|Charc::fl->(String.make1c)^f_format_to_cstringfl|Specifications::fl->(auxs)^f_format_to_cstringflletrecs_format_to_cstringfl=letauxspec="%"^(ifspec.s_assignment_suppressionthen"*"else"")^(string_of_optionstring_of_fwspec.s_field_width)^(string_of_optionstring_of_lmspec.s_length_modifier)^(string_of_csspec.s_conversion_specifier)inmatchflwith|[]->""|Char'%'::fl->"%%"^s_format_to_cstringfl|Charc::fl->(String.make1c)^s_format_to_cstringfl|Specifications::fl->(auxs)^s_format_to_cstringflletformat_to_cstring=function|FFormats->f_format_to_cstrings|SFormats->s_format_to_cstrings