Commits

camlspotter  committed 06537df

prdefined type constructors

  • Participants
  • Parent commits 643267d
  • Branches dev

Comments (0)

Files changed (6)

File ocamlspot.el

 	  ;; (if type (ocamlspot-message-add (format "Type: %s" type)))
 	  ))
     ;; failed to get the normal result
-    ;; CR jfuruse: this is an error message. Should be decolated?
+    ;; This can be: Spot: %a: predefined %s
     (ocamlspot-message-add path-range)))
 
 ;; Show the type information

File ocamlspot.ml

     eprintf "@[<2>top =@ @[%a@]@]@." 
       Abstraction.format_structure file.Unit.top;
     let str = 
-      Eval.structure (File.empty_env file) file.Unit.top
+      Eval.structure (File.initial_env file) file.Unit.top
     in
     if C.eager_dump then begin
       let module Enforcer = Value.Enforcer(struct end) in
   module Binding = struct
     type t = binding
     let error () = failwith "Binding: premature"
-    let with_check f t = 
-      match !t with
+    let with_check f t = match !t with
       | None -> error ()
       | Some str -> f str
     let domain = with_check (List.map fst) 
           :: !items
       in
       Predef.build_initial_env 
-        (fun id _ _ -> add_predefined Kind.Type id)
+        (fun id decl _ -> 
+          add_predefined Kind.Type id;
+          match decl.Types.type_kind with
+          | Types.Type_abstract -> ()
+          | Types.Type_record (l, _) -> List.iter (fun (id, _, _) -> add_predefined Kind.Type id) l
+          | Types.Type_variant l     -> List.iter (fun (id, _, _) -> add_predefined Kind.Type id) l
+        )
         (fun id _ _ -> add_predefined Kind.Exception id) 
         ();
       List.iter (fun (_, id) -> add_predefined Kind.Value id) Predef.builtin_values;
 
 include Load
 
-let empty_env file =
+let initial_env file =
   { Env.path = file.Unit.path;
     cwd = file.Unit.builddir;
     load_paths = file.Unit.loadpath;
-    binding = Binding.empty }
+    binding = Binding.predef }
 
 let invalid_env file =
   { Env.path = file.Unit.path;
   assert (Ident.global id);
   let file = Load.load_module ~spit:Spotconfig.print_interface ~cwd ~load_paths (Ident0.name id) in
   file.Unit.path,
-  Eval.structure (empty_env file) file.Unit.top
+  Eval.structure (initial_env file) file.Unit.top
 
 let _ = Eval.str_of_global_ident := str_of_global_ident
 
 let eval_packed env file =
   let f = Load.load ~load_paths:[""] (Cmt.of_path (env.Env.cwd ^/ file)) in
   Value.Structure ({ PIdent.path = f.Unit.path; ident = None },
-                  Eval.structure (empty_env f) f.Unit.top,
+                  Eval.structure (initial_env f) f.Unit.top,
                   None (* packed has no .mli *))
 
 let _ = Eval.packed := eval_packed

File spotfile.mli

 val load : load_paths:string list -> string -> Unit.t
 val load_module : ?spit:bool -> cwd:string -> load_paths:string list -> string -> Unit.t (* CR jfuruse: spit *)
 
-val empty_env   : Unit.t -> Env.t
+val initial_env   : Unit.t -> Env.t
 val invalid_env : Unit.t -> Env.t
 
 type result = File_itself | Found_at of Region.t | Predefined

File tests/Makefile.targets

 packed_alias.cmo \
 pathname.cmo \
 perv.cmo \
+predef.cmo \
 primitive.cmo \
 recmodule.cmo \
 record.cmo \