File: get_astinfo_bts1136.ml

package info (click to toggle)
frama-c 20161101%2Bsilicon%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 42,324 kB
  • ctags: 35,695
  • sloc: ml: 200,142; ansic: 31,465; makefile: 2,334; sh: 1,643; lisp: 259; python: 85; asm: 26
file content (45 lines) | stat: -rw-r--r-- 1,414 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

let get_formal_variables name =
  let add_kf_vars kf vars =
    try 
      let v = Globals.Vars.find_from_astinfo name (Cil_types.VFormal kf) in
      Format.printf "found variable vid:%d formal in %a@."
        v.Cil_types.vid Cil_datatype.Kf.pretty kf;
      v::vars
    with Not_found -> vars
  in
  let vars = Globals.Functions.fold add_kf_vars [] in
    vars

let get_local_variables name =
  let add_kf_vars kf vars =
    try 
      let v = Globals.Vars.find_from_astinfo name (Cil_types.VLocal kf) in
      Format.printf "found variable vid:%d formal in %a@."
        v.Cil_types.vid Cil_datatype.Kf.pretty kf;
      v::vars
    with Not_found -> vars
  in
  let vars = Globals.Functions.fold add_kf_vars [] in
    vars



let main () =
  Ast.compute ();
  let vars = get_formal_variables "x" in
  let vars' = get_local_variables "y" in
  let do_v v =
    let pp_kind fmt kind = match kind with
      | Cil_types.VGlobal -> Format.fprintf fmt "global"
      | Cil_types.VFormal kf -> 
          Format.fprintf fmt "formal in %a" Cil_datatype.Kf.pretty kf
      | Cil_types.VLocal kf -> 
          Format.fprintf fmt "local in %a" Cil_datatype.Kf.pretty kf
    in
    let _, kind = Globals.Vars.get_astinfo v in
      Format.printf "[do_v] vid:%d %a@."  v.Cil_types.vid 
       (* Cil_datatype.Localisation.pretty *) pp_kind kind
  in List.iter do_v vars; List.iter do_v vars'

let () = Db.Main.extend main