From 279e7d67f08e2128c8ccdc636fd2af69ea3d53dd Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 8 Mar 2018 07:22:47 -0800 Subject: [PATCH] More inline records Summary: Names are better than comments :) Reviewed By: dulmarod Differential Revision: D7194145 fbshipit-source-id: 4a8bc3c --- infer/src/IR/Typ.ml | 31 ++++++++++++++-------------- infer/src/IR/Typ.mli | 8 +++---- infer/src/clang/CProcname.ml | 6 +++--- infer/src/clang/cType_to_sil_type.ml | 2 +- infer/src/unit/addressTakenTests.ml | 2 +- infer/src/unit/livenessTests.ml | 2 +- 6 files changed, 26 insertions(+), 25 deletions(-) diff --git a/infer/src/IR/Typ.ml b/infer/src/IR/Typ.ml index 2fe5f2b85..b730ffb05 100644 --- a/infer/src/IR/Typ.ml +++ b/infer/src/IR/Typ.ml @@ -123,7 +123,7 @@ module T = struct | Tint of ikind (** integer type *) | Tfloat of fkind (** float type *) | Tvoid (** void type *) - | Tfun of bool (** function type with noreturn attribute *) + | Tfun of {no_return: bool} (** function type with noreturn attribute *) | Tptr of t * ptr_kind (** pointer type *) | Tstruct of name (** structured value type name *) | TVar of string (** type variable (ie. C++ template variables) *) @@ -218,9 +218,9 @@ let rec pp_full pe f typ = F.fprintf f "%s" (fkind_to_string fk) | Tvoid -> F.fprintf f "void" - | Tfun false -> + | Tfun {no_return= false} -> F.fprintf f "_fn_" - | Tfun true -> + | Tfun {no_return= true} -> F.fprintf f "_fn_noreturn_" | Tptr (({desc= Tarray _ | Tfun _} as typ), pk) -> F.fprintf f "%a(%s)" (pp_full pe) typ (ptr_kind_string pk |> escape pe) @@ -700,9 +700,9 @@ module Procname = struct module ObjC_Cpp = struct type kind = - | CPPMethod of string option - | CPPConstructor of (string option * bool) - | CPPDestructor of string option + | CPPMethod of {mangled: string option} + | CPPConstructor of {mangled: string option; is_constexpr: bool} + | CPPDestructor of {mangled: string option} | ObjCClassMethod | ObjCInstanceMethod | ObjCInternalMethod @@ -752,18 +752,18 @@ module Procname = struct is_objc_dealloc name.method_name - let is_constexpr = function {kind= CPPConstructor (_, true)} -> true | _ -> false + let is_constexpr = function {kind= CPPConstructor {is_constexpr= true}} -> true | _ -> false let is_cpp_lambda {method_name} = String.is_substring ~substring:"operator()" method_name let is_operator_equal {method_name} = String.is_substring ~substring:"operator=" method_name let kind_to_verbose_string = function - | CPPMethod m | CPPDestructor m -> - "(" ^ (match m with None -> "" | Some s -> s) ^ ")" - | CPPConstructor (m, is_constexpr) -> - "{" ^ (match m with None -> "" | Some s -> s) - ^ (if is_constexpr then "|constexpr" else "") ^ "}" + | CPPMethod {mangled} | CPPDestructor {mangled} -> + "(" ^ Option.value ~default:"" mangled ^ ")" + | CPPConstructor {mangled; is_constexpr} -> + "{" ^ Option.value ~default:"" mangled ^ (if is_constexpr then "|constexpr" else "") + ^ "}" | ObjCClassMethod -> "class" | ObjCInstanceMethod -> @@ -1127,9 +1127,10 @@ module Procname = struct end module Fieldname = struct - type clang_field_info = {class_name: Name.t; field_name: string} [@@deriving compare] - - type t = Clang of clang_field_info | Java of string [@@deriving compare] + type t = + | Clang of {class_name: Name.t; field_name: string} + | Java of string + [@@deriving compare] let equal = [%compare.equal : t] diff --git a/infer/src/IR/Typ.mli b/infer/src/IR/Typ.mli index 666f609d1..aa9d590d9 100644 --- a/infer/src/IR/Typ.mli +++ b/infer/src/IR/Typ.mli @@ -74,7 +74,7 @@ and desc = | Tint of ikind (** integer type *) | Tfloat of fkind (** float type *) | Tvoid (** void type *) - | Tfun of bool (** function type with noreturn attribute *) + | Tfun of {no_return: bool} (** function type with noreturn attribute *) | Tptr of t * ptr_kind (** pointer type *) | Tstruct of name (** structured value type name *) | TVar of string (** type variable (ie. C++ template variables) *) @@ -339,9 +339,9 @@ module Procname : sig module ObjC_Cpp : sig type kind = - | CPPMethod of string option (** with mangling *) - | CPPConstructor of (string option * bool) (** with mangling + is it constexpr? *) - | CPPDestructor of string option (** with mangling *) + | CPPMethod of {mangled: string option} + | CPPConstructor of {mangled: string option; is_constexpr: bool} + | CPPDestructor of {mangled: string option} | ObjCClassMethod | ObjCInstanceMethod | ObjCInternalMethod diff --git a/infer/src/clang/CProcname.ml b/infer/src/clang/CProcname.ml index b6e544e8d..3c8113454 100644 --- a/infer/src/clang/CProcname.ml +++ b/infer/src/clang/CProcname.ml @@ -105,11 +105,11 @@ let mk_cpp_method ?tenv class_name method_name ?meth_decl mangled = let method_kind = match meth_decl with | Some Clang_ast_t.CXXConstructorDecl (_, _, _, _, {xmdi_is_constexpr}) -> - Typ.Procname.ObjC_Cpp.CPPConstructor (mangled, xmdi_is_constexpr) + Typ.Procname.ObjC_Cpp.CPPConstructor {mangled; is_constexpr= xmdi_is_constexpr} | Some Clang_ast_t.CXXDestructorDecl _ -> - Typ.Procname.ObjC_Cpp.CPPDestructor mangled + Typ.Procname.ObjC_Cpp.CPPDestructor {mangled} | _ -> - Typ.Procname.ObjC_Cpp.CPPMethod mangled + Typ.Procname.ObjC_Cpp.CPPMethod {mangled} in let template_info, is_generic_model = match meth_decl with diff --git a/infer/src/clang/cType_to_sil_type.ml b/infer/src/clang/cType_to_sil_type.ml index 4be87c331..70b90bd45 100644 --- a/infer/src/clang/cType_to_sil_type.ml +++ b/infer/src/clang/cType_to_sil_type.ml @@ -131,7 +131,7 @@ and type_desc_of_c_type translate_decl tenv c_type : Typ.desc = | ConstantArrayType (_, {arti_element_type; arti_stride}, n) -> build_array_type translate_decl tenv arti_element_type (Some n) arti_stride | FunctionProtoType _ | FunctionNoProtoType _ -> - Typ.Tfun false + Typ.Tfun {no_return= false} | ParenType (_, qual_type) -> (qual_type_to_sil_type translate_decl tenv qual_type).Typ.desc | DecayedType (_, qual_type) -> diff --git a/infer/src/unit/addressTakenTests.ml b/infer/src/unit/addressTakenTests.ml index 6d496afdb..02ae94924 100644 --- a/infer/src/unit/addressTakenTests.ml +++ b/infer/src/unit/addressTakenTests.ml @@ -17,7 +17,7 @@ let tests = let assert_empty = invariant "{ }" in let int_typ = Typ.mk (Tint IInt) in let int_ptr_typ = Typ.mk (Tptr (int_typ, Pk_pointer)) in - let fun_ptr_typ = Typ.mk (Tptr (Typ.mk (Tfun false), Pk_pointer)) in + let fun_ptr_typ = Typ.mk (Tptr (Typ.mk (Tfun {no_return= false}), Pk_pointer)) in let closure_exp captureds = let mk_captured_var str = (Exp.Var (ident_of_str str), pvar_of_str str, int_ptr_typ) in let captured_vars = List.map ~f:mk_captured_var captureds in diff --git a/infer/src/unit/livenessTests.ml b/infer/src/unit/livenessTests.ml index 05aeb7a47..ccc75a934 100644 --- a/infer/src/unit/livenessTests.ml +++ b/infer/src/unit/livenessTests.ml @@ -16,7 +16,7 @@ let tests = let open OUnit2 in let open AnalyzerTester.StructuredSil in let assert_empty = invariant "{ }" in - let fun_ptr_typ = Typ.mk (Tptr (Typ.mk (Tfun false), Pk_pointer)) in + let fun_ptr_typ = Typ.mk (Tptr (Typ.mk (Tfun {no_return= false}), Pk_pointer)) in let closure_exp captured_pvars = let mk_captured_var str = (Exp.Var (ident_of_str str), pvar_of_str str, dummy_typ) in let captured_vars = List.map ~f:mk_captured_var captured_pvars in