camlspotter avatar camlspotter committed af3df43

import diff from custom-3.12.0

Comments (0)

Files changed (2)

ocamlspot/spotapi.ml

     let end_ = Position.of_lexing_position l.Location.loc_end in
     match Position.compare start end_ with
     | -1 | 0 -> { start = start; end_ = end_ }
-    | _ -> 
-        let pos = { start = start; end_ = end_ } in
-        Format.eprintf "ILLFORMED LOCATION %s: ignored@." (to_string pos);
-        { start = start; end_ = start }
+    | _ -> { start = end_; end_ = start }
 
   let compare l1 l2 = 
     if Position.compare l1.start l2.start = 0 
 
   let clear () = Hashtbl.clear recorded
 
+  type location_property = Wellformed | Flipped | Over_files | Illformed
+
+  let check_location loc = 
+    if loc.Location.loc_start == Lexing.dummy_pos || loc.Location.loc_end == Lexing.dummy_pos then Illformed
+    else if loc.Location.loc_start = Lexing.dummy_pos || loc.Location.loc_end = Lexing.dummy_pos then Illformed
+    else 
+      (* If the file name is different between the start and the end, we cannot tell the wellformedness. *)
+      if loc.Location.loc_start.Lexing.pos_fname <> loc.Location.loc_end.Lexing.pos_fname then Over_files
+      else
+        (* P4 creates some flipped locations where loc_start > loc_end *)
+        match compare loc.Location.loc_start.Lexing.pos_cnum loc.Location.loc_end.Lexing.pos_cnum 
+        with
+        | -1 | 0 -> Wellformed
+        | _ -> Flipped
+
   let record loc t = 
-    let location_wellformed loc =
-      match 
-        compare 
-          loc.Location.loc_start.Lexing.pos_cnum 
-          loc.Location.loc_end.Lexing.pos_cnum 
-      with
-      | -1 | 0 -> true
-      | _ -> false
-    in
-
     if !Clflags.annotations then begin
-      if not (location_wellformed loc) then
-        Format.eprintf "%aWarning: ill-formed location. Ignored for spot.@." Location.print loc
-      else begin
+      let really_record () = 
         let num_records, records = 
           try Hashtbl.find recorded loc with Not_found -> 0, []
         in
+        (* CR jfuruse: I am not really sure the below is correct now, 
+           but I remember the huge compilation slow down... *)
         (* This caching works horribly when too many things are defined 
-           at the same locations. For example, a type definition of more than 
+           at the same location. For example, a type definition of more than 
            3000 variants, with sexp camlp4 extension, the compile time explodes
            from 10secs to 4mins! Therefore this works 
            only if [num_records <= 10] 
         *)
         if num_records <= 10 && List.exists (equal t) records then ()
         else Hashtbl.replace recorded loc (num_records + 1, t :: records)
-      end
+      in
+      match check_location loc with
+      | Wellformed -> really_record ()
+      | Flipped -> Format.eprintf "%aWarning: Flipped location.@." Location.print loc; really_record ()
+      | Illformed -> Format.eprintf "%aWarning: Ill-formed location.@." Location.print loc
+      | Over_files -> ()
     end
 
   let record_constr_type_use loc ty =
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.