123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116(************************************************************************)(* * The Coq Proof Assistant / The Coq Development Team *)(* v * Copyright INRIA, CNRS and contributors *)(* <O___,, * (see version control and CREDITS file for authors & dates) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)(* Locations management *)typesource=(* OCaml won't allow using DirPath.t in InFile *)|InFileof{dirpath:stringoption;file:string}|ToplevelInputtypet={fname:source;(** filename or toplevel input *)line_nb:int;(** start line number *)bol_pos:int;(** position of the beginning of start line *)line_nb_last:int;(** end line number *)bol_pos_last:int;(** position of the beginning of end line *)bp:int;(** start position *)ep:int;(** end position *)}letcreatefnameline_nbbol_posbpep={fname=fname;line_nb=line_nb;bol_pos=bol_pos;line_nb_last=line_nb;bol_pos_last=bol_pos;bp=bp;ep=ep;}letinitialsource=createsource1000letmake_loc(bp,ep)={fname=ToplevelInput;line_nb=-1;bol_pos=0;line_nb_last=-1;bol_pos_last=0;bp=bp;ep=ep;}letmergeableloc1loc2=loc1.fname=loc2.fnameletmergeloc1loc2=ifnot(mergeableloc1loc2)thenfailwith"Trying to merge unmergeable locations.";ifloc1.bp<loc2.bpthenifloc1.ep<loc2.epthen{fname=loc1.fname;line_nb=loc1.line_nb;bol_pos=loc1.bol_pos;line_nb_last=loc2.line_nb_last;bol_pos_last=loc2.bol_pos_last;bp=loc1.bp;ep=loc2.ep;}elseloc1elseifloc2.ep<loc1.epthen{fname=loc2.fname;line_nb=loc2.line_nb;bol_pos=loc2.bol_pos;line_nb_last=loc1.line_nb_last;bol_pos_last=loc1.bol_pos_last;bp=loc2.bp;ep=loc1.ep;}elseloc2letmerge_optl1l2=matchl1,l2with|None,None->None|Somel,None->Somel|None,Somel->Somel|Somel1,Somel2->Some(mergel1l2)letsublocshlen={locwithbp=loc.bp+sh;ep=loc.bp+sh+len}letafterlocshlen={locwithbp=loc.ep+sh;ep=loc.ep+sh+len}letfinerl1l2=matchl1,l2with|None,_->false|Somel,None->true|Somel1,Somel2->l1.fname=l2.fname&&mergel1l2=l2letunlocloc=(loc.bp,loc.ep)letshift_lockbkploc={locwithbp=loc.bp+kb;ep=loc.ep+kp}(** Located type *)type'alocated=toption*'alettag?locx=loc,xletmapf(l,x)=(l,fx)(** Exceptions *)letlocation:tExninfo.t=Exninfo.make"location"letadd_loceloc=Exninfo.addelocationlocletget_loce=Exninfo.getelocationletraise?loce=matchlocwith|None->raisee|Someloc->letinfo=Exninfo.addExninfo.nulllocationlocinExninfo.iraise(e,info)letprloc=letopenPpinletfname=loc.fnameinmatchfnamewith|ToplevelInput->(str"Toplevel input, characters "++intloc.bp++str"-"++intloc.ep)|InFile{file}->(str"File "++str"\""++strfile++str"\""++str", line "++intloc.line_nb++str", characters "++int(loc.bp-loc.bol_pos)++str"-"++int(loc.ep-loc.bol_pos))