You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.2 KiB
42 lines
1.2 KiB
8 years ago
|
(*
|
||
|
* Copyright (c) 2017 - present Facebook, Inc.
|
||
|
* All rights reserved.
|
||
|
*
|
||
|
* This source code is licensed under the BSD style license found in the
|
||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||
|
*)
|
||
|
|
||
|
open! IStd
|
||
|
|
||
|
module F = Format
|
||
|
module L = Logging
|
||
|
|
||
|
type t = int AccessPath.BaseMap.t
|
||
|
|
||
|
let make pdesc =
|
||
|
let pname = Procdesc.get_proc_name pdesc in
|
||
|
let attrs = Procdesc.get_attributes pdesc in
|
||
|
let formals_with_nums =
|
||
8 years ago
|
List.mapi
|
||
|
~f:(fun index (name, typ) ->
|
||
8 years ago
|
let pvar = Pvar.mk name pname in
|
||
|
AccessPath.base_of_pvar pvar typ, index)
|
||
|
attrs.ProcAttributes.formals in
|
||
8 years ago
|
List.fold
|
||
|
~f:(fun formal_map (base, index) -> AccessPath.BaseMap.add base index formal_map)
|
||
|
~init:AccessPath.BaseMap.empty
|
||
8 years ago
|
formals_with_nums
|
||
|
|
||
|
let empty = AccessPath.BaseMap.empty
|
||
|
|
||
|
let is_formal = AccessPath.BaseMap.mem
|
||
|
|
||
|
let get_formal_index base t =
|
||
|
try Some (AccessPath.BaseMap.find base t)
|
||
|
with Not_found -> None
|
||
8 years ago
|
|
||
|
let get_formal_base index t =
|
||
|
List.find ~f:(fun (_, i) -> Int.equal i index) (AccessPath.BaseMap.bindings t)
|
||
|
|> Option.map ~f:fst
|