camlspotter avatar camlspotter committed 2c7e1b1

failwithf and comments

Comments (0)

Files changed (6)

   let build_dir = ref None in
   let set name ref v =
     match !ref with
-    | Some _ -> failwith (Printf.sprintf "key %s is defined twice" name)
+    | Some _ -> failwithf "key %s is defined twice" name
     | None -> ref := Some v
   in
   let ic = open_in s in
     | "build_dir", Some s -> 
         set "build_dir" build_dir s;
         load ()
-    | "build_dir", None -> failwith (Printf.sprintf "key %S must have a value" key)
-    | key, _ -> failwith (Printf.sprintf "unknown key %S" key)
+    | "build_dir", None -> failwithf "key %S must have a value" key
+    | key, _ -> failwithf "unknown key %S" key
   in
   try load () with End_of_file ->
     close_in ic;
 
 module File = Spotfile
 module C = Spotconfig
-
 module SAbs = Spot.Abstraction
 
 module Dump = struct
   let query_by_pos file pos = 
     let probe = Region.point pos in
     let treepath = 
-      (* subtree is not used *)
       List.map fst (Tree.find_path_contains probe !!(file.Unit.tree))
     in
     match treepath with
-    | [] -> failwith (Printf.sprintf "nothing at %s" (Position.to_string pos))
-    | { Regioned.region = r; _ } :: _ ->
+    | [] -> failwithf "nothing at %s" (Position.to_string pos)
+    | { Regioned.region = r; _ } :: _ -> (* [r] is innermost region *)
 	
-	(* find annots bound to the region *)
+	(* Find annots bound to the region.
+           CR jfuruse: do we need to scan all the paths?
+        *)
         let annots = 
 	  List.concat_map (fun rannot ->
 	    if Region.compare r rannot.Regioned.region = `Same then 
 	    treepath
         in
 
-	(* annots and region improvement by path *)
+	(* annots and region improvement by subpath *)
 	let annots, r = 
 	  match 
 	    (* only the first Use *)
 	    List.find_map_opt (function
 	      | Annot.Use (_, path) -> 
 		  (* Find subpath *)
+                  (* CR jfuruse: subpath does not work for now *)
 		  begin match Pathreparse.get file.Unit.path r pos path with    
 		  | None -> None
 		  | Some (path', r) -> 
           (String.concat "." (List.map Ident0.name (List.rev (find_module_path treepath))));
 
         (* print "Val: val name : type" if it is a Str: val *)
+        (* CR jfuruse: only the first entry is used *)
         let print_sig_entry annots =
           let rec find_type = function
             | Annot.Type (typ, _, _) :: _ -> Some typ
         print_sig_entry annots;
 
         (* print_type_decl: if one Type is found *)
+        (* CR jfuruse: only the first one is used *)
         if C.type_expand then begin
           match List.filter (function Annot.Type _ -> true | _ -> false) annots with
           (* CR jfuruse: Sometimes more than one Annot.Type are found at the same place... *)
 
 (* Spot info for each compilation unit *)
 module Unit = struct
+
+  module F = File
+
   type t = {
     modname        : string;
     builddir       : string; 
     tree           : Tree.t lazy_t
   }
 
-  (* same as File.dump, ignoring new additions in Unit *)
+  (* same as F.dump, ignoring new additions in Unit *)
   let dump file =
     eprintf "@[<v2>{ module= %S;@ path= %S;@ builddir= %S;@ loadpath= [ @[%a@] ];@ argv= [| @[%a@] |];@ ... }@]@."
       file.modname
       (Format.list ";@ " (fun ppf s -> fprintf ppf "%S" s)) (Array.to_list file.args)
 
   let to_file { modname; builddir; loadpath; args; path; top ; loc_annots } = 
-    { File.modname;
+    { F.modname;
       builddir;
       loadpath;
       args;
       loc_annots;
     }
 
-  let of_file ({ File.loc_annots; } as f) = 
+  let of_file ({ F.loc_annots; } as f) = 
     let rannots = lazy (Hashtbl.fold (fun loc annots st -> 
       { Regioned.region = Region.of_parsing loc;  value = annots } :: st) 
                           loc_annots [])
         | Annot.Str sitem -> Some sitem
         | _ -> None) annots @ st) loc_annots [])
     in
-    { modname    = f.File.modname;
-      builddir   = f.File.builddir;
-      loadpath   = f.File.loadpath;
-      args       = f.File.args;
-      path       = f.File.path;
-      top        = f.File.top;
-      loc_annots = f.File.loc_annots;
+    { modname    = f.F.modname;
+      builddir   = f.F.builddir;
+      loadpath   = f.F.loadpath;
+      args       = f.F.args;
+      path       = f.F.path;
+      top        = f.F.top;
+      loc_annots = f.F.loc_annots;
       
       flat; id_def_regions; rannots; tree; 
     }
           (Kind.from_string (String.sub s (at2+1) (at-at2-1)),
            let s = String.sub s (at+1) (String.length s - at - 1) in 
            try Path.parse s with
-           | _ -> failwith ("illegal path in <file>:<kind>:<path> : " ^ s))
+           | _ -> failwithf "illegal path in <file>:<kind>:<path> : %s" s)
       with
       | Invalid_argument _ | Not_found -> 
           String.sub s 0 at,
                      (String.sub s (at+1) (String.length s - at - 1)))
     with
     | Failure s -> failwith s
-    | Position.Parse_failure s -> failwith ("illegal <file>:<pos> : " ^ s)
-    | Not_found -> failwith ("strange search : " ^ s)
+    | Position.Parse_failure s -> failwithf "illegal <file>:<pos> : %s" s
+    | Not_found -> failwithf "strange search : %s" s
 
   let to_string = function
     | Pos pos -> ":" ^ Position.to_string pos
     match load_cmt_file path with
     | Some cmt -> 
         Spot.Unit.of_file (Spot.File.of_cmt path cmt)
-    | None -> failwith (sprintf "load_directly failed: %s" path)
+    | None -> failwithf "load_directly failed: %s" path
 
   exception Old_cmt of string (* cmt *) * string (* source *)
 
             file
           with
           | Not_found ->
-              failwith (Printf.sprintf "failed to find cmt file %s" path)
+              failwithf "failed to find cmt file %s" path
 
   let find_in_path load_paths body ext =
     let body_ext = body ^ ext in
         if Sys.file_exists cmtpath then begin
           Debug.format "Found an alternative %s: %s@." ext cmtpath;
             cmtpath 
-          end else failwith (Printf.sprintf "cmt file not found: %s, neither in %s" body_ext cmtpath)
+          end else failwithf "cmt file not found: %s, neither in %s" body_ext cmtpath
         end else raise Not_found
       with
       | (Failure _ as e) -> raise e
-      | _ -> failwith (Printf.sprintf "cmt file not found: %s" body_ext)
+      | _ -> failwithf "cmt file not found: %s" body_ext
     
 
   let load ~load_paths cmtname : Unit.t =
   val add_elem : elem -> t -> t
 
   val find_path_contains : elem -> t -> (elem * t) list
+    (** Returns the path which contains [elem].
+        The result is the elems which contains [elem].
+        Deeper (smaller) elem comes first. *)
 
   val iter_elem : (parent:elem option -> elem -> 'a) -> t -> unit
 end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.