Skip to content
This repository
tree: 77fc29d9fa
Fetching contributors…

Cannot retrieve contributors at this time

file 105 lines (80 sloc) 3.42 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
(*
Copyright © 2011 MLstate

This file is part of OPA.

OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.

OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.

You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*)
(**
Ident for AST.
*)

(**
This kind of ident is used for generating code.
It has a support for renaming, and packages separation.

This was originally Ident, but now is exported
there since we use it in ocamllang too.

So, we need probably to change some opa-specificities.
(in a next commit)
*)

type uniq
type t = private
         | Source of string
         | FakeSource of string
         | Internal of uniq

(** comparaison. equal implementation is [compare a b = 0]*)
val compare : t -> t -> int
val equal : t -> t -> bool
val hash : t -> int

(** Constructors *)
val next : ?filename:string -> ?descr:string -> string -> t (** Fixed : don't allow anonymous internal *)
  (** Fixed : don't allow anonymous internal *)
val nextf : ?filename:string -> ?descr:string -> ('a, unit, string, t) format4 -> 'a

val source : string -> t
val fake_source : string -> t

(** this is like to_string but raise an error if it is a db *)
val stident : t -> string

val is_operator : t -> bool

(** see if it is really used -- it is possibly a good idea *)
(* val active_alpha_protection : unit -> unit *)

(** beware of usability of `id with backquote` : with libconvert it becomes a nightmare
Beware: this function behaves differently whether we are testing mode
or not => it is for debug
If you want something else, then use either [stdident], [original_name]
(or [refresh] insteand of [next (to_string _)])
*)
val to_string : t -> string

(** guaranties unicity of string, fails for source ident *)
val to_uniq_string: t -> string

(** gives back the non-uniq'ed name -- for hacking only *)
val original_name : t -> string

val refresh : ?map:(string -> string) -> t -> t
  (**
equivalent to fun x -> ExprIdent.next (map (origrepr x))
except that the description and filename is kept
*)

val refreshf : map:(string -> string, unit, string) format -> t -> t
  (**
example of use: [refreshf ~map:"coucou_%s" ident]
*)

val concrete_string : t -> string

(** used for printing opa-ligth, before or after renaming
dont_protect_operator is [false] by default, it means that
the identitifier should not be protect with backquote, typically
for infix application printing *)
val opa_syntax : ?dont_protect_operator:bool -> t -> string

(** used for printing a lighter code with opatrack, we do not print the
description, just the local stamp.
Beware: do not use for generating code, just for debugging.
*)
val light_ident : t -> string

(** works only on internal identifiers *)
val get_package_name : t -> string

(** returns none when the identifier is not internal *)
val safe_get_package_name : t -> string option

val renaming_should_warn_when : t -> [`used | `unused | `never]
Something went wrong with that request. Please try again.