dune/src/loc.ml

74 lines
1.5 KiB
OCaml
Raw Normal View History

2016-11-13 17:05:55 +00:00
open Import
2017-12-12 10:16:17 +00:00
type t = Usexp.Loc.t =
2016-11-03 16:44:09 +00:00
{ start : Lexing.position
; stop : Lexing.position
}
2016-11-13 11:13:47 +00:00
let of_lexbuf lb =
2016-11-13 11:27:31 +00:00
{ start = Lexing.lexeme_start_p lb
; stop = Lexing.lexeme_end_p lb
2016-11-13 11:13:47 +00:00
}
exception Error of t * string
let exnf t fmt =
Format.pp_print_as err_ppf 7 ""; (* "Error: " *)
kerrf fmt ~f:(fun s -> Error (t, s))
2016-11-13 11:13:47 +00:00
let fail t fmt =
Format.pp_print_as err_ppf 7 ""; (* "Error: " *)
kerrf fmt ~f:(fun s ->
raise (Error (t, s)))
2016-11-13 11:13:47 +00:00
let fail_lex lb fmt =
fail (of_lexbuf lb) fmt
2016-12-02 13:54:32 +00:00
let fail_opt t fmt =
match t with
| None -> die fmt
| Some t -> fail t fmt
2016-12-02 13:54:32 +00:00
let in_file fn =
let pos : Lexing.position =
{ pos_fname = fn
; pos_lnum = 1
; pos_cnum = 0
; pos_bol = 0
}
in
{ start = pos
; stop = pos
}
let of_pos (fname, lnum, cnum, enum) =
let pos : Lexing.position =
{ pos_fname = fname
; pos_lnum = lnum
; pos_cnum = cnum
; pos_bol = 0
}
in
{ start = pos
; stop = { pos with pos_cnum = enum }
}
2017-02-25 17:53:39 +00:00
let none = in_file "<none>"
let print ppf { start; stop } =
let start_c = start.pos_cnum - start.pos_bol in
let stop_c = stop.pos_cnum - start.pos_bol in
Format.fprintf ppf
"@{<loc>File \"%s\", line %d, characters %d-%d:@}@\n"
start.pos_fname start.pos_lnum start_c stop_c
let warn t fmt =
Errors.kerrf ~f:print_to_console
("%a@{<warning>Warning@}: " ^^ fmt ^^ "@.") print t
Refactor library management (#516) Lib module ---------- We have a new module Lib that replaces Lib, parts of Lib_db and parts of Findlib. It is used to manage all libraries (internal and extrernal). Lib.t represent a completely resolved library, i.e. where all the dependencies have been resolved. Lib.Compile is used to provide what is necessary to build the library itself. Lib.Meta provides what is necessary to generate the META file for the library. We also have library databases represented as Lib.DB.t. A library database is simply a mapping from names to Lib.t values and and created from a resolve function that looks up a name and return a Lib.Info.t. A Lib.Info.t is the same as a Lib.t except that dependencies are not resolved. A library database can have a parent database that is used to lookup names that are not found in the current database. In practice we have the following hierarchy: 1. For every scope, we have a library database that holds all the libraries of this scope. In this DB, a library can be referred by either it's name or public name 2. the parent of each of these databases is a database that holds all the public libraries of the workspace. In this DB libraries must be referred by their public name 3. the parent of this DB is for installed libraries (1) databases are accessible via Scope.libs (Super_context.find_scope_by_{name,dir} sctx xxx) (2) is accessible via Super_context.public_libs sctx (3) is accessible via Super_context.installed_libs sctx The dependencies of a library are always resolved inside the DB it is part of. When we compute a transitive closure, we check that we don't have two libraries from two different DB with the same name. So for instance linting Base should now supported. Jbuild.Scope_info ----------------- Jbuild.Scope was renamed Jbuild.Scope_info Scope module ------------ This replaces Lib_db. A Scope.t is now just a pair of a Jbuild.Scope_info.t and a Lib.DB.t. Scope.DB.t is an object used to lookup scopes by either name or directory. We no longer have an external scope or special anonymous scope. Instead one should use Super_context.installed_libs or Super_context.public_libs depending on the context.
2018-02-20 11:46:10 +00:00
let to_file_colon_line t =
sprintf "%s:%d" t.start.pos_fname t.start.pos_lnum
let pp_file_colon_line ppf t =
Format.pp_print_string ppf (to_file_colon_line t)