Permalink
Browse files

[cleanup] AST: Merged Abstract and Extern tags of TypeIdent into 1 un…

…ique Extern.

In fact, one implied the other, making ton of useless and confusing code. The
aim in fine is to remove these tags from TypeIdents.
  • Loading branch information...
1 parent 9506f59 commit 3e6b0ccfeb5656fff9eeb7cb504317320dfd478b @fpessaux fpessaux committed Jun 29, 2011
View
@@ -486,20 +486,10 @@ let of_ty ~gamma ty =
~visibility_applies: false typeident gamma with
| Some (typeident, typ) ->
let ident = Q.TypeIdent.to_string typeident in
- if Q.TypeIdent.is_abstract typeident
- then
- (* warning : an abstract type can point to another type which can be different;
- extern types point to themselves, so we have to avoid looping *)
- if Q.TypeIdent.is_extern typeident
- then
- let varmap, maped_ty = List.fold_left_map aux varmap ty_list in
- let maped = External (pos, ident, maped_ty) in
- varmap, maped
- else (
- (* abstract, but we found its definition: apparently we do as if it was concrete *)
- List.iter (ignore @* aux varmap) ty_list; (* side-effect *)
- aux varmap (QmlTypes.Scheme.specialize ~typeident:typeident ~ty:ty_list typ)
- )
+ if Q.TypeIdent.is_external_ty typeident then
+ let varmap, maped_ty = List.fold_left_map aux varmap ty_list in
+ let maped = External (pos, ident, maped_ty) in
+ varmap, maped
else (
(* Standard extended types in LibBSL : bool, option *)
match ident with
View
@@ -316,7 +316,7 @@ type ident = Ident.t
module TypeIdent :
sig
- type tag = Concrete | Abstract | Extern
+ type tag = Concrete | Extern
type uniq
type t = private
| Raw of Ident.t
@@ -333,15 +333,11 @@ sig
val new_ident : ?prefix:string -> tag -> t -> t
val new_concrete : t -> t
- val new_abstract : ?prefix:string -> ?extern:bool -> t -> t
- val new_local : ?prefix:string -> t -> t * t
- (* creates a concrete and an abstract (and prefixed) version of the same ident
- /!\ can be dangerous *)
+ val new_external_ty : ?prefix:string -> t -> t
val is_already_processed : t -> bool
val is_already_known : t -> bool
- val is_abstract : t -> bool
- val is_extern : t -> bool
+ val is_external_ty : t -> bool
val compare_names : t -> t -> int
val equal_names : t -> t -> bool
@@ -354,7 +350,7 @@ struct
to do the right cast with the data in qmltoplevel.
For others application, there is no distinction *)
- type tag = Concrete | Abstract | Extern
+ type tag = Concrete | Extern
type uniq = tag * Ident.t
type t = Raw of Ident.t | Processed of uniq
@@ -369,7 +365,6 @@ struct
let to_debug_string id =
let tag_to_string = function
| Concrete -> ""
- | Abstract -> "(abs)"
| Extern -> "(ext)"
in
match id with
@@ -418,21 +413,9 @@ struct
let new_concrete id =
new_ident Concrete id
- let new_abstract ?(prefix="") ?(extern=false) id =
- new_ident ~prefix (if extern then Extern else Abstract) id
+ let new_external_ty ?(prefix="") id = new_ident ~prefix Extern id
- let new_local ?(prefix="") id =
- let concrete = new_ident Concrete id in
- let abstract = new_ident ~prefix Abstract concrete in
- (concrete, abstract)
-
- let is_abstract = function
- | Raw _ ->
- (* The identifier should have already been please processed. *)
- assert false
- | Processed (t, _) -> t = Abstract || t = Extern
-
- let is_extern = function
+ let is_external_ty = function
| Raw _ ->
(* The identifier should have already been please processed. *)
assert false
@@ -208,7 +208,7 @@ struct
match te with
| _ when TypeIdent.is_already_known ti -> add_ti ti visibility
| Q.TypeAbstract ->
- add_ti (TypeIdent.new_abstract ~extern: true ti) visibility
+ add_ti (TypeIdent.new_external_ty ti) visibility
| _ ->
(* [TODO] Attention, here the body of the definition is
allowed to use only type constructors that are visible
View
@@ -621,21 +621,25 @@ struct
let add id (s, visibility) g =
assert (TypeIdent.is_already_processed id);
let field_map =
- if TypeIdent.is_abstract id
- then g.field_map (** abstract: don't update the field map *)
+ if TypeIdent.is_external_ty id then (
+ (** Abstract (i.e external) : don't update the field map. *)
+ g.field_map
+ )
else
- (** update field map : only in the case of type sum and type record *)
+ (** Update field map : only in the case of type sum and type record *)
let fields =
let _, ty = Scheme.export s in
records_field_names ty
in
List.fold_left (fun map f -> ImplFieldMap.add f id map) g.field_map fields
in
let field_map_quick =
- if TypeIdent.is_abstract id
- then g.field_map_quick (** abstract: don't update the field map *)
+ if TypeIdent.is_external_ty id then (
+ (** Abstract(i.e external) : don't update the field map. *)
+ g.field_map_quick
+ )
else
- (** update field map : only in the case of type sum and type record *)
+ (** Update field map : only in the case of type sum and type record *)
let fields =
let _, ty = Scheme.export s in
records_field_names_quick ty
@@ -765,7 +769,7 @@ let unsugar_type gamma ty =
| Q.TypeName (params, ti) ->
let (ti, tsc) =
Env.TypeIdent.findi ~visibility_applies: true ti gamma in
- if TypeIdent.is_abstract ti ||
+ if TypeIdent.is_external_ty ti ||
Scheme.instantiate tsc = Q.TypeAbstract then (
(* The type name is bound to a definition that is said "abstract" or
"extern", so return a type that is a named type with the same
@@ -47,7 +47,7 @@ module TyPairSet : (BaseSetSig.S with type elt = QmlAst.ty * QmlAst.ty) =
-let typeident_is_abstract ti = QmlAst.TypeIdent.is_abstract ti
+let typeident_is_abstract ti = QmlAst.TypeIdent.is_external_ty ti
View
@@ -75,7 +75,7 @@ let merge_pos = LangAst.merge_pos
let pp_value ?ty ?(force=false) fmt value =
match ty with
- | Some (Q.TypeName (_, ident)) when (QmlAst.TypeIdent.is_abstract ident) ->
+ | Some (Q.TypeName (_, ident)) when (QmlAst.TypeIdent.is_external_ty ident) ->
Format.pp_print_string fmt "<abstr>"
| Some (Q.TypeVar _) ->

0 comments on commit 3e6b0cc

Please sign in to comment.