|
|
|
@ -98,29 +98,6 @@ let type_get_annotation tenv (typ: Typ.t): Annot.Item.t option =
|
|
|
|
|
)
|
|
|
|
|
| _ -> None
|
|
|
|
|
|
|
|
|
|
let type_has_direct_supertype tenv (typ : Typ.t) (class_name : Typ.Name.t) =
|
|
|
|
|
List.exists ~f:(fun cn -> Typ.Name.equal cn class_name) (type_get_direct_supertypes tenv typ)
|
|
|
|
|
|
|
|
|
|
let type_has_supertype
|
|
|
|
|
(tenv: Tenv.t)
|
|
|
|
|
(typ: Typ.t)
|
|
|
|
|
(class_name: Typ.Name.t): bool =
|
|
|
|
|
let rec has_supertype typ visited =
|
|
|
|
|
if Typ.Set.mem typ visited then
|
|
|
|
|
false
|
|
|
|
|
else
|
|
|
|
|
let supers = type_get_direct_supertypes tenv typ in
|
|
|
|
|
let match_supertype cn =
|
|
|
|
|
let match_name () = Typ.Name.equal cn class_name in
|
|
|
|
|
let has_indirect_supertype () = has_supertype (Typ.mk (Tstruct cn)) (Typ.Set.add typ visited) in
|
|
|
|
|
(match_name () || has_indirect_supertype ()) in
|
|
|
|
|
List.exists ~f:match_supertype supers in
|
|
|
|
|
has_supertype typ Typ.Set.empty
|
|
|
|
|
|
|
|
|
|
let type_is_nested_in_direct_supertype tenv t n =
|
|
|
|
|
let is_nested_in cn1 cn2 = String.is_prefix ~prefix:(Typ.Name.name cn1 ^ "$") (Typ.Name.name cn2) in
|
|
|
|
|
List.exists ~f:(is_nested_in n) (type_get_direct_supertypes tenv t)
|
|
|
|
|
|
|
|
|
|
let rec get_type_name {Typ.desc} =
|
|
|
|
|
match desc with
|
|
|
|
|
| Typ.Tstruct name ->
|
|
|
|
@ -272,11 +249,14 @@ let initializer_methods = [
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
(** Check if the type has in its supertypes from the initializer_classes list. *)
|
|
|
|
|
let type_has_initializer
|
|
|
|
|
(tenv: Tenv.t)
|
|
|
|
|
(t: Typ.t): bool =
|
|
|
|
|
let check_candidate class_name = type_has_supertype tenv t class_name in
|
|
|
|
|
List.exists ~f:check_candidate initializer_classes
|
|
|
|
|
let type_has_initializer (tenv: Tenv.t) (t: Typ.t): bool =
|
|
|
|
|
let is_initializer_class typename _ =
|
|
|
|
|
List.mem ~equal:Typ.Name.equal initializer_classes typename in
|
|
|
|
|
match t.desc with
|
|
|
|
|
| Typ.Tstruct name | Tptr ({ desc=Tstruct name}, _) ->
|
|
|
|
|
supertype_exists tenv is_initializer_class name
|
|
|
|
|
| _ ->
|
|
|
|
|
false
|
|
|
|
|
|
|
|
|
|
(** Check if the method is one of the known initializer methods. *)
|
|
|
|
|
let method_is_initializer
|
|
|
|
|