Now I have PdgTypes.Node.stmt, I just can use:
Format.printf "%a"
Printer.pp_location (Cil_datatype.Stmt.loc PdgTypes.Node.stmt)
to print the result like this:
mkdir.c:500
But I want the result that like this:
mkdir.c:500:23
It means that the output should contain the location of starting character. What should I do?
Thanks in advance for your help!
A
Locationin Frama-C (defined in moduleCil_datatype, in filesrc/kernel_services/ast_queries/cil_datatype.ml) is a pair ofPositions (defined in the same file), the start and end position of an AST element.A
Positionis very similar to an OCaml'sLexing.position. The only difference is that Lexing's position has a string fieldpos_fname, while Frama-C's position has aDatatype.Filepath(defined by Frama-C) fieldpos_fpath.Both
LocationandPositionhave functionspretty_debug, which includes the character number.Positionalso haspp_with_col, which prints the column number but in format%a char %d, which is different from what you want.In any case, these functions can serve as inspiration to the one you want.
Important note:
pos_cnumstands for character offset (from the start of the file) and not column offset, so you need to subtractpos_bol, the offset of the beginning of the current line, to get the actual column number of a character:pos_cnum - pos_bol.Here's an example of some code that should be close to what you want (you may need an
open Cil_typesoropen Cil_datatypesfor these to work):