[typ][fieldname] further reduce and improve interface

Summary:
- Remove `to_flat_string` as there is `get_field_name` that unambiguously does the same thing.
- Make `pp` print only the field in all languages.
- Fix `to_full_string` so that it has unified behaviour across java/clang and so that it doesn't print `class Foo.x`, but rather `Foo.x`.

Reviewed By: ezgicicek

Differential Revision: D18963033

fbshipit-source-id: e2c803c7d
master
Nikos Gorogiannis 5 years ago committed by Facebook Github Bot
parent 59a95b316c
commit e42bd8cd6c

@ -33,7 +33,7 @@ module Raw = struct
let rec pp_access fmt = function let rec pp_access fmt = function
| FieldAccess field_name -> | FieldAccess field_name ->
F.pp_print_string fmt (Typ.Fieldname.to_flat_string field_name) F.pp_print_string fmt (Typ.Fieldname.get_field_name field_name)
| ArrayAccess (typ, []) -> | ArrayAccess (typ, []) ->
F.pp_print_string fmt "[_]" ; may_pp_typ fmt typ F.pp_print_string fmt "[_]" ; may_pp_typ fmt typ
| ArrayAccess (typ, index_aps) -> | ArrayAccess (typ, index_aps) ->
@ -310,7 +310,7 @@ let inner_class_normalize p =
|> Option.bind ~f:(fun outer_name -> |> Option.bind ~f:(fun outer_name ->
let outer_class = mk ~default:cls (Tstruct outer_name) in let outer_class = mk ~default:cls (Tstruct outer_name) in
let outer_ptr = mk ~default:ptr (Tptr (outer_class, pkind)) in let outer_ptr = mk ~default:ptr (Tptr (outer_class, pkind)) in
let varname = Fieldname.to_flat_string first |> Mangled.from_string in let varname = Fieldname.get_field_name first |> Mangled.from_string in
mk_pvar_as varname pvar mk_pvar_as varname pvar
|> Option.map ~f:(fun new_pvar -> |> Option.map ~f:(fun new_pvar ->
let base = base_of_pvar new_pvar outer_ptr in let base = base_of_pvar new_pvar outer_ptr in

@ -100,14 +100,14 @@ let rec pp fmt = function
F.pp_print_string fmt (Typ.Fieldname.to_simplified_string f) F.pp_print_string fmt (Typ.Fieldname.to_simplified_string f)
| Darrow (de, f) -> | Darrow (de, f) ->
if Language.curr_language_is Java then if Language.curr_language_is Java then
F.fprintf fmt "%a.%s" pp de (Typ.Fieldname.to_flat_string f) F.fprintf fmt "%a.%s" pp de (Typ.Fieldname.get_field_name f)
else F.fprintf fmt "%a->%s" pp de (Typ.Fieldname.to_string f) else F.fprintf fmt "%a->%s" pp de (Typ.Fieldname.to_string f)
| Ddot (Dpvar _, fe) when eradicate_java () -> | Ddot (Dpvar _, fe) when eradicate_java () ->
(* static field access *) (* static field access *)
F.pp_print_string fmt (Typ.Fieldname.to_simplified_string fe) F.pp_print_string fmt (Typ.Fieldname.to_simplified_string fe)
| Ddot (de, f) -> | Ddot (de, f) ->
let field_text = let field_text =
if Language.curr_language_is Java then Typ.Fieldname.to_flat_string f if Language.curr_language_is Java then Typ.Fieldname.get_field_name f
else Typ.Fieldname.to_string f else Typ.Fieldname.to_string f
in in
F.fprintf fmt "%a.%s" pp de field_text F.fprintf fmt "%a.%s" pp de field_text

@ -1460,16 +1460,10 @@ module Fieldname = struct
let to_full_string fld = let to_full_string fld =
if is_java fld then dot_join (Name.name fld.class_name) fld.field_name (if is_java fld then dot_join else cc_join) (Name.name fld.class_name) fld.field_name
else cc_join (Name.to_string fld.class_name) fld.field_name
let to_flat_string {field_name} = field_name let pp f fld = F.pp_print_string f fld.field_name
let pp f ({class_name; field_name} as field) =
F.pp_print_string f
(if is_java field then dot_join (Name.name class_name) field_name else field_name)
let is_java_captured_parameter ({field_name} as field) = let is_java_captured_parameter ({field_name} as field) =
is_java field && String.is_prefix ~prefix:"val$" field_name is_java field && String.is_prefix ~prefix:"val$" field_name

@ -669,9 +669,6 @@ module Fieldname : sig
val to_simplified_string : t -> string val to_simplified_string : t -> string
(** Convert a fieldname to a simplified string with at most one-level path. *) (** Convert a fieldname to a simplified string with at most one-level path. *)
val to_flat_string : t -> string
(** Convert a fieldname to a flat string without path. *)
val pp : Format.formatter -> t -> unit val pp : Format.formatter -> t -> unit
(** Pretty print a field name. *) (** Pretty print a field name. *)
end end

@ -32,7 +32,7 @@ let is_method_of_objc_cpp_class pname matcher =
let is_vector_method pname = is_method_of_objc_cpp_class pname vector_matcher let is_vector_method pname = is_method_of_objc_cpp_class pname vector_matcher
let is_special_field matcher field_name_opt field = let is_special_field matcher field_name_opt field =
let field_name = Typ.Fieldname.to_flat_string field in let field_name = Typ.Fieldname.get_field_name field in
let field_ok = let field_ok =
match field_name_opt with match field_name_opt with
| Some field_name' -> | Some field_name' ->

@ -790,7 +790,7 @@ let add_guarded_by_constraints tenv prop lexp pdesc =
let is_guarded_by_fld guarded_by_str fld _ = let is_guarded_by_fld guarded_by_str fld _ =
(* this comparison needs to be somewhat fuzzy, since programmers are free to write (* this comparison needs to be somewhat fuzzy, since programmers are free to write
@GuardedBy("mLock"), @GuardedBy("MyClass.mLock"), or use other conventions *) @GuardedBy("mLock"), @GuardedBy("MyClass.mLock"), or use other conventions *)
String.equal (Typ.Fieldname.to_flat_string fld) guarded_by_str String.equal (Typ.Fieldname.get_field_name fld) guarded_by_str
|| String.equal (Typ.Fieldname.to_string fld) guarded_by_str || String.equal (Typ.Fieldname.to_string fld) guarded_by_str
in in
let get_fld_strexp_and_typ typ f flds = let get_fld_strexp_and_typ typ f flds =

@ -13,7 +13,7 @@ module L = Logging
Create invisible phantom fields by giving them a name ending in '.' The name preceeding the '.' Create invisible phantom fields by giving them a name ending in '.' The name preceeding the '.'
will be used in debug mode. *) will be used in debug mode. *)
let pp ~pp_lhs ~pp_lhs_alone ~sep f lhs fn = let pp ~pp_lhs ~pp_lhs_alone ~sep f lhs fn =
let fieldname = Typ.Fieldname.to_flat_string fn in let fieldname = Typ.Fieldname.get_field_name fn in
if String.is_empty fieldname then if String.is_empty fieldname then
if Config.bo_debug > 0 then if Config.bo_debug > 0 then
let fieldname = let fieldname =

@ -41,7 +41,7 @@ let report_warning class_name fld fld_typ summary =
the back stack, a reference to this (probably dead) View will be retained. In general, it \ the back stack, a reference to this (probably dead) View will be retained. In general, it \
is a good idea to initialize View's in %a, then nullify them in %a." is a good idea to initialize View's in %a, then nullify them in %a."
pp_m (Typ.Name.name class_name) pp_m pp_m (Typ.Name.name class_name) pp_m
(Typ.Fieldname.to_flat_string fld) (Typ.Fieldname.get_field_name fld)
pp_m (format_typ fld_typ) pp_m (format_method pname) pp_m on_create_view pp_m on_destroy_view pp_m (format_typ fld_typ) pp_m (format_method pname) pp_m on_create_view pp_m on_destroy_view
in in
Reporting.log_warning summary ~loc IssueType.checkers_fragment_retain_view description Reporting.log_warning summary ~loc IssueType.checkers_fragment_retain_view description

@ -175,7 +175,7 @@ let violation_description {is_strict_mode; lhs; rhs} ~assignment_location assign
Logging.die InternalError "Invariant violation: unexpected nullability" Logging.die InternalError "Invariant violation: unexpected nullability"
in in
Format.asprintf "%a is declared non-nullable but is assigned %s%s." MF.pp_monospaced Format.asprintf "%a is declared non-nullable but is assigned %s%s." MF.pp_monospaced
(Typ.Fieldname.to_flat_string field_name) (Typ.Fieldname.get_field_name field_name)
rhs_description nullability_evidence_as_suffix rhs_description nullability_evidence_as_suffix
| ReturningFromFunction function_proc_name -> | ReturningFromFunction function_proc_name ->
let return_description = let return_description =

@ -31,7 +31,7 @@ let is_object_nullability_self_explanatory ~object_expression object_origin =
| TypeOrigin.Field {field_name} -> | TypeOrigin.Field {field_name} ->
(* Either local variable or expression like `<smth>.field_name`. Latter case is trivial: (* Either local variable or expression like `<smth>.field_name`. Latter case is trivial:
the user can quickly go to field_name definition and see if its annotation. *) the user can quickly go to field_name definition and see if its annotation. *)
let field_name_str = Typ.Fieldname.to_flat_string field_name in let field_name_str = Typ.Fieldname.get_field_name field_name in
String.is_suffix object_expression ~suffix:field_name_str String.is_suffix object_expression ~suffix:field_name_str
| TypeOrigin.MethodCall {pname; annotated_signature= {model_source}} -> | TypeOrigin.MethodCall {pname; annotated_signature= {model_source}} ->
let is_modelled = Option.is_some model_source in let is_modelled = Option.is_some model_source in

@ -125,7 +125,7 @@ let make_error_trace astate ap ud =
let name_of ap = let name_of ap =
match AccessPath.get_last_access ap with match AccessPath.get_last_access ap with
| Some (AccessPath.FieldAccess field_name) -> | Some (AccessPath.FieldAccess field_name) ->
"Field " ^ Typ.Fieldname.to_flat_string field_name "Field " ^ Typ.Fieldname.get_field_name field_name
| Some (AccessPath.ArrayAccess _) -> | Some (AccessPath.ArrayAccess _) ->
"Some array element" "Some array element"
| None -> | None ->
@ -163,7 +163,7 @@ let pretty_field_name proc_data field_name =
| Typ.Procname.Java jproc_name -> | Typ.Procname.Java jproc_name ->
let proc_class_name = Typ.Procname.Java.get_class_name jproc_name in let proc_class_name = Typ.Procname.Java.get_class_name jproc_name in
let field_class_name = Typ.Fieldname.get_class_name field_name |> Typ.Name.name in let field_class_name = Typ.Fieldname.get_class_name field_name |> Typ.Name.name in
if String.equal proc_class_name field_class_name then Typ.Fieldname.to_flat_string field_name if String.equal proc_class_name field_class_name then Typ.Fieldname.get_field_name field_name
else Typ.Fieldname.to_simplified_string field_name else Typ.Fieldname.to_simplified_string field_name
| _ -> | _ ->
(* This format is subject to change once this checker gets to run on C/Cpp/ObjC *) (* This format is subject to change once this checker gets to run on C/Cpp/ObjC *)

@ -232,7 +232,7 @@ let get_error_info err_instance =
"Field %a is declared non-nullable, so it should be initialized in the constructor or in \ "Field %a is declared non-nullable, so it should be initialized in the constructor or in \
an `@Initializer` method" an `@Initializer` method"
MF.pp_monospaced MF.pp_monospaced
(Typ.Fieldname.to_flat_string field_name) (Typ.Fieldname.get_field_name field_name)
, IssueType.eradicate_field_not_initialized , IssueType.eradicate_field_not_initialized
, None ) , None )
| Bad_assignment {rhs_origin; assignment_location; assignment_type; assignment_violation} -> | Bad_assignment {rhs_origin; assignment_location; assignment_type; assignment_violation} ->

@ -144,7 +144,7 @@ let get_description origin =
| NullConst loc -> | NullConst loc ->
Some ("null constant" ^ atline loc) Some ("null constant" ^ atline loc)
| Field {field_name; access_loc} -> | Field {field_name; access_loc} ->
Some ("field " ^ Typ.Fieldname.to_flat_string field_name ^ atline access_loc) Some ("field " ^ Typ.Fieldname.get_field_name field_name ^ atline access_loc)
| MethodParameter {mangled} -> | MethodParameter {mangled} ->
Some ("method parameter " ^ Mangled.to_string mangled) Some ("method parameter " ^ Mangled.to_string mangled)
| MethodCall {pname; call_loc; annotated_signature} -> | MethodCall {pname; call_loc; annotated_signature} ->

Loading…
Cancel
Save