Summary: This will be useful in upcoming changes to the thread-safety analysis as well. Reviewed By: dkgi Differential Revision: D4402146 fbshipit-source-id: c750127master
parent
e5ef592f11
commit
2add2954da
@ -0,0 +1,37 @@
|
|||||||
|
(*
|
||||||
|
* 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 =
|
||||||
|
IList.mapi
|
||||||
|
(fun index (name, typ) ->
|
||||||
|
let pvar = Pvar.mk name pname in
|
||||||
|
AccessPath.base_of_pvar pvar typ, index)
|
||||||
|
attrs.ProcAttributes.formals in
|
||||||
|
IList.fold_left
|
||||||
|
(fun formal_map (base, index) -> AccessPath.BaseMap.add base index formal_map)
|
||||||
|
AccessPath.BaseMap.empty
|
||||||
|
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
|
@ -0,0 +1,28 @@
|
|||||||
|
(*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
(** a map from a formal to its positional index *)
|
||||||
|
type t
|
||||||
|
|
||||||
|
(** create a formal map for the given procdesc *)
|
||||||
|
val make : Procdesc.t -> t
|
||||||
|
|
||||||
|
(** the empty formal map *)
|
||||||
|
val empty : t
|
||||||
|
|
||||||
|
(** return true if the given base var is a formal according to the given formal map *)
|
||||||
|
val is_formal : AccessPath.base -> t -> bool
|
||||||
|
|
||||||
|
(** return the index for the given base var if it is a formal, or None if it is not *)
|
||||||
|
val get_formal_index : AccessPath.base -> t -> int option
|
Loading…
Reference in new issue