From b45e13e77a17103e12c5a11c31b367a55e2f8757 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 5 Jul 2024 17:38:45 +0200 Subject: [PATCH 1/3] Remove @ocaml.doc/.text and Docstrings module --- jscomp/core/bs_conditional_initial.ml | 3 - jscomp/gentype/Annotation.ml | 6 +- jscomp/ml/ast_helper.ml | 77 +++--- jscomp/ml/ast_helper.mli | 31 ++- jscomp/ml/clflags.ml | 1 - jscomp/ml/clflags.mli | 1 - jscomp/ml/docstrings.ml | 343 -------------------------- jscomp/ml/docstrings.mli | 157 ------------ jscomp/ml/subst.ml | 18 +- 9 files changed, 49 insertions(+), 588 deletions(-) delete mode 100644 jscomp/ml/docstrings.ml delete mode 100644 jscomp/ml/docstrings.mli diff --git a/jscomp/core/bs_conditional_initial.ml b/jscomp/core/bs_conditional_initial.ml index 9fa5e8d2c3..3e99275919 100644 --- a/jscomp/core/bs_conditional_initial.ml +++ b/jscomp/core/bs_conditional_initial.ml @@ -22,9 +22,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -(* Clflags.keep_docs := false; *) -(* default to false -check later*) -(* Clflags.keep_locs := false; *) let setup_env () = Env.Persistent_signature.load := Bs_cmi_load.load_cmi; Matching.make_test_sequence_variant_constant := Polyvar_pattern_match.make_test_sequence_variant_constant; diff --git a/jscomp/gentype/Annotation.ml b/jscomp/gentype/Annotation.ml index 1e7e3c583d..6f1dbd1dce 100644 --- a/jscomp/gentype/Annotation.ml +++ b/jscomp/gentype/Annotation.ml @@ -36,10 +36,8 @@ let tag_is_one_of_the_gentype_annotations s = let tag_is_gentype_ignore_interface s = s = "genType.ignoreInterface" || s = "gentype.ignoreInterface" -let tag_is_doc s = - match s with - | "ocaml.doc" | "res.doc" -> true - | _ -> false +let tag_is_doc s = s = "res.doc" + let tag_is_intern_local s = s = "internal.local" let rec get_attribute_payload check_text (attributes : Typedtree.attributes) = diff --git a/jscomp/ml/ast_helper.ml b/jscomp/ml/ast_helper.ml index 42d803ae9f..7ed32f69bf 100644 --- a/jscomp/ml/ast_helper.ml +++ b/jscomp/ml/ast_helper.ml @@ -17,7 +17,6 @@ open Asttypes open Parsetree -open Docstrings type lid = Longident.t loc type str = string loc @@ -239,11 +238,6 @@ module Sig = struct let extension ?loc ?(attrs = []) a = mk ?loc (Psig_extension (a, attrs)) let attribute ?loc a = mk ?loc (Psig_attribute a) - let text txt = - let f_txt = Ext_list.filter txt (fun ds -> docstring_body ds <> "") in - List.map - (fun ds -> attribute ~loc:(docstring_loc ds) (text_attr ds)) - f_txt end module Str = struct @@ -262,20 +256,15 @@ module Str = struct let include_ ?loc a = mk ?loc (Pstr_include a) let extension ?loc ?(attrs = []) a = mk ?loc (Pstr_extension (a, attrs)) let attribute ?loc a = mk ?loc (Pstr_attribute a) - let text txt = - let f_txt = Ext_list.filter txt (fun ds -> docstring_body ds <> "") in - List.map - (fun ds -> attribute ~loc:(docstring_loc ds) (text_attr ds)) - f_txt end module Val = struct - let mk ?(loc = !default_loc) ?(attrs = []) ?(docs = empty_docs) + let mk ?(loc = !default_loc) ?(attrs = []) ?(prim = []) name typ = { pval_name = name; pval_type = typ; - pval_attributes = add_docs_attrs docs attrs; + pval_attributes = attrs; pval_loc = loc; pval_prim = prim; } @@ -283,76 +272,71 @@ end module Md = struct let mk ?(loc = !default_loc) ?(attrs = []) - ?(docs = empty_docs) ?(text = []) name typ = + name typ = { pmd_name = name; pmd_type = typ; - pmd_attributes = - add_text_attrs text (add_docs_attrs docs attrs); + pmd_attributes = attrs; pmd_loc = loc; } end module Mtd = struct let mk ?(loc = !default_loc) ?(attrs = []) - ?(docs = empty_docs) ?(text = []) ?typ name = + ?typ name = { pmtd_name = name; pmtd_type = typ; - pmtd_attributes = - add_text_attrs text (add_docs_attrs docs attrs); + pmtd_attributes = attrs; pmtd_loc = loc; } end module Mb = struct let mk ?(loc = !default_loc) ?(attrs = []) - ?(docs = empty_docs) ?(text = []) name expr = + name expr = { pmb_name = name; pmb_expr = expr; - pmb_attributes = - add_text_attrs text (add_docs_attrs docs attrs); + pmb_attributes = attrs; pmb_loc = loc; } end module Opn = struct - let mk ?(loc = !default_loc) ?(attrs = []) ?(docs = empty_docs) + let mk ?(loc = !default_loc) ?(attrs = []) ?(override = Fresh) lid = { popen_lid = lid; popen_override = override; popen_loc = loc; - popen_attributes = add_docs_attrs docs attrs; + popen_attributes = attrs; } end module Incl = struct - let mk ?(loc = !default_loc) ?(attrs = []) ?(docs = empty_docs) mexpr = + let mk ?(loc = !default_loc) ?(attrs = []) mexpr = { pincl_mod = mexpr; pincl_loc = loc; - pincl_attributes = add_docs_attrs docs attrs; + pincl_attributes = attrs; } end module Vb = struct - let mk ?(loc = !default_loc) ?(attrs = []) ?(docs = empty_docs) - ?(text = []) pat expr = + let mk ?(loc = !default_loc) ?(attrs = []) + pat expr = { pvb_pat = pat; pvb_expr = expr; - pvb_attributes = - add_text_attrs text (add_docs_attrs docs attrs); + pvb_attributes = attrs; pvb_loc = loc; } end module Type = struct - let mk ?(loc = !default_loc) ?(attrs = []) - ?(docs = empty_docs) ?(text = []) + let mk ?(loc = !default_loc) ?(attrs = []) ?(params = []) ?(cstrs = []) ?(kind = Ptype_abstract) @@ -366,70 +350,69 @@ module Type = struct ptype_kind = kind; ptype_private = priv; ptype_manifest = manifest; - ptype_attributes = - add_text_attrs text (add_docs_attrs docs attrs); + ptype_attributes = attrs; ptype_loc = loc; } - let constructor ?(loc = !default_loc) ?(attrs = []) ?(info = empty_info) + let constructor ?(loc = !default_loc) ?(attrs = []) ?(args = Pcstr_tuple []) ?res name = { pcd_name = name; pcd_args = args; pcd_res = res; pcd_loc = loc; - pcd_attributes = add_info_attrs info attrs; + pcd_attributes = attrs; } - let field ?(loc = !default_loc) ?(attrs = []) ?(info = empty_info) + let field ?(loc = !default_loc) ?(attrs = []) ?(mut = Immutable) name typ = { pld_name = name; pld_mutable = mut; pld_type = typ; pld_loc = loc; - pld_attributes = add_info_attrs info attrs; + pld_attributes = attrs; } end (** Type extensions *) module Te = struct - let mk ?(attrs = []) ?(docs = empty_docs) + let mk ?(attrs = []) ?(params = []) ?(priv = Public) path constructors = { ptyext_path = path; ptyext_params = params; ptyext_constructors = constructors; ptyext_private = priv; - ptyext_attributes = add_docs_attrs docs attrs; + ptyext_attributes = attrs; } let constructor ?(loc = !default_loc) ?(attrs = []) - ?(docs = empty_docs) ?(info = empty_info) name kind = + name kind = { pext_name = name; pext_kind = kind; pext_loc = loc; - pext_attributes = add_docs_attrs docs (add_info_attrs info attrs); + pext_attributes = attrs; } - let decl ?(loc = !default_loc) ?(attrs = []) ?(docs = empty_docs) - ?(info = empty_info) ?(args = Pcstr_tuple []) ?res name = + let decl ?(loc = !default_loc) ?(attrs = []) + ?(args = Pcstr_tuple []) ?res name = { pext_name = name; pext_kind = Pext_decl(args, res); pext_loc = loc; - pext_attributes = add_docs_attrs docs (add_info_attrs info attrs); + pext_attributes = attrs; } let rebind ?(loc = !default_loc) ?(attrs = []) - ?(docs = empty_docs) ?(info = empty_info) name lid = + name lid = { pext_name = name; pext_kind = Pext_rebind lid; pext_loc = loc; - pext_attributes = add_docs_attrs docs (add_info_attrs info attrs); + pext_attributes = attrs; } end diff --git a/jscomp/ml/ast_helper.mli b/jscomp/ml/ast_helper.mli index 122862d0a7..3aac4ed6e8 100644 --- a/jscomp/ml/ast_helper.mli +++ b/jscomp/ml/ast_helper.mli @@ -16,7 +16,6 @@ (** Helpers to produce Parsetree fragments *) open Asttypes -open Docstrings open Parsetree type lid = Longident.t loc @@ -177,40 +176,40 @@ module Exp: (** Value declarations *) module Val: sig - val mk: ?loc:loc -> ?attrs:attrs -> ?docs:docs -> + val mk: ?loc:loc -> ?attrs:attrs -> ?prim:string list -> str -> core_type -> value_description end (** Type declarations *) module Type: sig - val mk: ?loc:loc -> ?attrs:attrs -> ?docs:docs -> ?text:text -> + val mk: ?loc:loc -> ?attrs:attrs -> ?params:(core_type * variance) list -> ?cstrs:(core_type * core_type * loc) list -> ?kind:type_kind -> ?priv:private_flag -> ?manifest:core_type -> str -> type_declaration - val constructor: ?loc:loc -> ?attrs:attrs -> ?info:info -> + val constructor: ?loc:loc -> ?attrs:attrs -> ?args:constructor_arguments -> ?res:core_type -> str -> constructor_declaration - val field: ?loc:loc -> ?attrs:attrs -> ?info:info -> + val field: ?loc:loc -> ?attrs:attrs -> ?mut:mutable_flag -> str -> core_type -> label_declaration end (** Type extensions *) module Te: sig - val mk: ?attrs:attrs -> ?docs:docs -> + val mk: ?attrs:attrs -> ?params:(core_type * variance) list -> ?priv:private_flag -> lid -> extension_constructor list -> type_extension - val constructor: ?loc:loc -> ?attrs:attrs -> ?docs:docs -> ?info:info -> + val constructor: ?loc:loc -> ?attrs:attrs -> str -> extension_constructor_kind -> extension_constructor - val decl: ?loc:loc -> ?attrs:attrs -> ?docs:docs -> ?info:info -> + val decl: ?loc:loc -> ?attrs:attrs -> ?args:constructor_arguments -> ?res:core_type -> str -> extension_constructor - val rebind: ?loc:loc -> ?attrs:attrs -> ?docs:docs -> ?info:info -> + val rebind: ?loc:loc -> ?attrs:attrs -> str -> lid -> extension_constructor end @@ -267,7 +266,6 @@ module Sig: val include_: ?loc:loc -> include_description -> signature_item val extension: ?loc:loc -> ?attrs:attrs -> extension -> signature_item val attribute: ?loc:loc -> attribute -> signature_item - val text: text -> signature_item list end (** Structure items *) @@ -288,46 +286,45 @@ module Str: val include_: ?loc:loc -> include_declaration -> structure_item val extension: ?loc:loc -> ?attrs:attrs -> extension -> structure_item val attribute: ?loc:loc -> attribute -> structure_item - val text: text -> structure_item list end (** Module declarations *) module Md: sig - val mk: ?loc:loc -> ?attrs:attrs -> ?docs:docs -> ?text:text -> + val mk: ?loc:loc -> ?attrs:attrs -> str -> module_type -> module_declaration end (** Module type declarations *) module Mtd: sig - val mk: ?loc:loc -> ?attrs:attrs -> ?docs:docs -> ?text:text -> + val mk: ?loc:loc -> ?attrs:attrs -> ?typ:module_type -> str -> module_type_declaration end (** Module bindings *) module Mb: sig - val mk: ?loc:loc -> ?attrs:attrs -> ?docs:docs -> ?text:text -> + val mk: ?loc:loc -> ?attrs:attrs -> str -> module_expr -> module_binding end (** Opens *) module Opn: sig - val mk: ?loc: loc -> ?attrs:attrs -> ?docs:docs -> + val mk: ?loc: loc -> ?attrs:attrs -> ?override:override_flag -> lid -> open_description end (** Includes *) module Incl: sig - val mk: ?loc: loc -> ?attrs:attrs -> ?docs:docs -> 'a -> 'a include_infos + val mk: ?loc: loc -> ?attrs:attrs -> 'a -> 'a include_infos end (** Value bindings *) module Vb: sig - val mk: ?loc: loc -> ?attrs:attrs -> ?docs:docs -> ?text:text -> + val mk: ?loc: loc -> ?attrs:attrs -> pattern -> expression -> value_binding end diff --git a/jscomp/ml/clflags.ml b/jscomp/ml/clflags.ml index b2b2a78db5..afabf747e0 100644 --- a/jscomp/ml/clflags.ml +++ b/jscomp/ml/clflags.ml @@ -41,7 +41,6 @@ end -let keep_docs = ref false (* -keep-docs *) let keep_locs = ref true (* -keep-locs *) diff --git a/jscomp/ml/clflags.mli b/jscomp/ml/clflags.mli index 80b170422d..0ab90ad398 100644 --- a/jscomp/ml/clflags.mli +++ b/jscomp/ml/clflags.mli @@ -22,7 +22,6 @@ val dump_typedtree : bool ref val dump_rawlambda : bool ref val dump_lambda : bool ref val dont_write_files : bool ref -val keep_docs : bool ref val keep_locs : bool ref val only_parse : bool ref val ignore_parse_errors: bool ref diff --git a/jscomp/ml/docstrings.ml b/jscomp/ml/docstrings.ml deleted file mode 100644 index 85c58ad8d5..0000000000 --- a/jscomp/ml/docstrings.ml +++ /dev/null @@ -1,343 +0,0 @@ -(**************************************************************************) -(* *) -(* OCaml *) -(* *) -(* Leo White *) -(* *) -(* Copyright 1996 Institut National de Recherche en Informatique et *) -(* en Automatique. *) -(* *) -(* All rights reserved. This file is distributed under the terms of *) -(* the GNU Lesser General Public License version 2.1, with the *) -(* special exception on linking described in the file LICENSE. *) -(* *) -(**************************************************************************) - -open Location - -(* Docstrings *) - -(* A docstring is "attached" if it has been inserted in the AST. This - is used for generating unexpected docstring warnings. *) -type ds_attached = - | Unattached (* Not yet attached anything.*) - | Info (* Attached to a field or constructor. *) - | Docs (* Attached to an item or as floating text. *) - -(* A docstring is "associated" with an item if there are no blank lines between - them. This is used for generating docstring ambiguity warnings. *) -type ds_associated = - | Zero (* Not associated with an item *) - | One (* Associated with one item *) - | Many (* Associated with multiple items (ambiguity) *) - -type docstring = - { ds_body: string; - ds_loc: Location.t; - mutable ds_attached: ds_attached; - mutable ds_associated: ds_associated; } - -(* List of docstrings *) - -let docstrings : docstring list ref = ref [] - -(* Warn for unused and ambiguous docstrings *) - -let warn_bad_docstrings () = - if Warnings.is_active (Warnings.Bad_docstring true) then begin - List.iter - (fun ds -> - match ds.ds_attached with - | Info -> () - | Unattached -> - prerr_warning ds.ds_loc (Warnings.Bad_docstring true) - | Docs -> - match ds.ds_associated with - | Zero | One -> () - | Many -> - prerr_warning ds.ds_loc (Warnings.Bad_docstring false)) - (List.rev !docstrings) -end - -(* Docstring constructors and destructors *) - -let docstring body loc = - let ds = - { ds_body = body; - ds_loc = loc; - ds_attached = Unattached; - ds_associated = Zero; } - in - ds - -let register ds = - docstrings := ds :: !docstrings - -let docstring_body ds = ds.ds_body - -let docstring_loc ds = ds.ds_loc - -(* Docstrings attached to items *) - -type docs = - { docs_pre: docstring option; - docs_post: docstring option; } - -let empty_docs = { docs_pre = None; docs_post = None } - -let doc_loc = {txt = "ocaml.doc"; loc = Location.none} - -let docs_attr ds = - let open Parsetree in - let exp = - { pexp_desc = Pexp_constant (Pconst_string(ds.ds_body, None)); - pexp_loc = ds.ds_loc; - pexp_attributes = []; } - in - let item = - { pstr_desc = Pstr_eval (exp, []); pstr_loc = exp.pexp_loc } - in - (doc_loc, PStr [item]) - -let add_docs_attrs docs attrs = - let attrs = - match docs.docs_pre with - | None | Some { ds_body=""; _ } -> attrs - | Some ds -> docs_attr ds :: attrs - in - let attrs = - match docs.docs_post with - | None | Some { ds_body=""; _ } -> attrs - | Some ds -> attrs @ [docs_attr ds] - in - attrs - -(* Docstrings attached to constructors or fields *) - -type info = docstring option - -let empty_info = None - -let info_attr = docs_attr - -let add_info_attrs info attrs = - match info with - | None | Some {ds_body=""; _} -> attrs - | Some ds -> attrs @ [info_attr ds] - -(* Docstrings not attached to a specific item *) - -type text = docstring list - -let empty_text = [] -let empty_text_lazy = lazy [] - -let text_loc = {txt = "ocaml.text"; loc = Location.none} - -let text_attr ds = - let open Parsetree in - let exp = - { pexp_desc = Pexp_constant (Pconst_string(ds.ds_body, None)); - pexp_loc = ds.ds_loc; - pexp_attributes = []; } - in - let item = - { pstr_desc = Pstr_eval (exp, []); pstr_loc = exp.pexp_loc } - in - (text_loc, PStr [item]) - -let add_text_attrs dsl attrs = - let fdsl = Ext_list.filter dsl (function {ds_body=""} -> false| _ ->true) in - (List.map text_attr fdsl) @ attrs - -(* Find the first non-info docstring in a list, attach it and return it *) -let get_docstring ~info dsl = - let rec loop = function - | [] -> None - | {ds_attached = Info; _} :: rest -> loop rest - | ds :: _ -> - ds.ds_attached <- if info then Info else Docs; - Some ds - in - loop dsl - -(* Find all the non-info docstrings in a list, attach them and return them *) -let get_docstrings dsl = - let rec loop acc = function - | [] -> List.rev acc - | {ds_attached = Info; _} :: rest -> loop acc rest - | ds :: rest -> - ds.ds_attached <- Docs; - loop (ds :: acc) rest - in - loop [] dsl - -(* "Associate" all the docstrings in a list *) -let associate_docstrings dsl = - List.iter - (fun ds -> - match ds.ds_associated with - | Zero -> ds.ds_associated <- One - | (One | Many) -> ds.ds_associated <- Many) - dsl - -(* Map from positions to pre docstrings *) - -let pre_table : (Lexing.position, docstring list) Hashtbl.t = - Hashtbl.create 50 - -let set_pre_docstrings pos dsl = - if dsl <> [] then Hashtbl.add pre_table pos dsl - -let get_pre_docs pos = - try - let dsl = Hashtbl.find pre_table pos in - associate_docstrings dsl; - get_docstring ~info:false dsl - with Not_found -> None - -let mark_pre_docs pos = - try - let dsl = Hashtbl.find pre_table pos in - associate_docstrings dsl - with Not_found -> () - -(* Map from positions to post docstrings *) - -let post_table : (Lexing.position, docstring list) Hashtbl.t = - Hashtbl.create 50 - -let set_post_docstrings pos dsl = - if dsl <> [] then Hashtbl.add post_table pos dsl - -let get_post_docs pos = - try - let dsl = Hashtbl.find post_table pos in - associate_docstrings dsl; - get_docstring ~info:false dsl - with Not_found -> None - -let mark_post_docs pos = - try - let dsl = Hashtbl.find post_table pos in - associate_docstrings dsl - with Not_found -> () - -let get_info pos = - try - let dsl = Hashtbl.find post_table pos in - get_docstring ~info:true dsl - with Not_found -> None - -(* Map from positions to floating docstrings *) - -let floating_table : (Lexing.position, docstring list) Hashtbl.t = - Hashtbl.create 50 - -let set_floating_docstrings pos dsl = - if dsl <> [] then Hashtbl.add floating_table pos dsl - -let get_text pos = - try - let dsl = Hashtbl.find floating_table pos in - get_docstrings dsl - with Not_found -> [] - -(* Maps from positions to extra docstrings *) - -let pre_extra_table : (Lexing.position, docstring list) Hashtbl.t = - Hashtbl.create 50 - -let set_pre_extra_docstrings pos dsl = - if dsl <> [] then Hashtbl.add pre_extra_table pos dsl - -let get_pre_extra_text pos = - try - let dsl = Hashtbl.find pre_extra_table pos in - get_docstrings dsl - with Not_found -> [] - -let post_extra_table : (Lexing.position, docstring list) Hashtbl.t = - Hashtbl.create 50 - -let set_post_extra_docstrings pos dsl = - if dsl <> [] then Hashtbl.add post_extra_table pos dsl - -let get_post_extra_text pos = - try - let dsl = Hashtbl.find post_extra_table pos in - get_docstrings dsl - with Not_found -> [] - -(* Docstrings from parser actions *) - -let symbol_docs () = - { docs_pre = get_pre_docs (Parsing.symbol_start_pos ()); - docs_post = get_post_docs (Parsing.symbol_end_pos ()); } - -let symbol_docs_lazy () = - let p1 = Parsing.symbol_start_pos () in - let p2 = Parsing.symbol_end_pos () in - lazy { docs_pre = get_pre_docs p1; - docs_post = get_post_docs p2; } - -let rhs_docs pos1 pos2 = - { docs_pre = get_pre_docs (Parsing.rhs_start_pos pos1); - docs_post = get_post_docs (Parsing.rhs_end_pos pos2); } - -let rhs_docs_lazy pos1 pos2 = - let p1 = Parsing.rhs_start_pos pos1 in - let p2 = Parsing.rhs_end_pos pos2 in - lazy { docs_pre = get_pre_docs p1; - docs_post = get_post_docs p2; } - -let mark_symbol_docs () = - mark_pre_docs (Parsing.symbol_start_pos ()); - mark_post_docs (Parsing.symbol_end_pos ()) - -let mark_rhs_docs pos1 pos2 = - mark_pre_docs (Parsing.rhs_start_pos pos1); - mark_post_docs (Parsing.rhs_end_pos pos2) - -let symbol_info () = - get_info (Parsing.symbol_end_pos ()) - -let rhs_info pos = - get_info (Parsing.rhs_end_pos pos) - -let symbol_text () = - get_text (Parsing.symbol_start_pos ()) - -let symbol_text_lazy () = - let pos = Parsing.symbol_start_pos () in - lazy (get_text pos) - -let rhs_text pos = - get_text (Parsing.rhs_start_pos pos) - -let rhs_text_lazy pos = - let pos = Parsing.rhs_start_pos pos in - lazy (get_text pos) - -let symbol_pre_extra_text () = - get_pre_extra_text (Parsing.symbol_start_pos ()) - -let symbol_post_extra_text () = - get_post_extra_text (Parsing.symbol_end_pos ()) - -let rhs_pre_extra_text pos = - get_pre_extra_text (Parsing.rhs_start_pos pos) - -let rhs_post_extra_text pos = - get_post_extra_text (Parsing.rhs_end_pos pos) - - -(* (Re)Initialise all comment state *) - -let init () = - docstrings := []; - Hashtbl.reset pre_table; - Hashtbl.reset post_table; - Hashtbl.reset floating_table; - Hashtbl.reset pre_extra_table; - Hashtbl.reset post_extra_table diff --git a/jscomp/ml/docstrings.mli b/jscomp/ml/docstrings.mli deleted file mode 100644 index 892a80e278..0000000000 --- a/jscomp/ml/docstrings.mli +++ /dev/null @@ -1,157 +0,0 @@ -(**************************************************************************) -(* *) -(* OCaml *) -(* *) -(* Leo White *) -(* *) -(* Copyright 1996 Institut National de Recherche en Informatique et *) -(* en Automatique. *) -(* *) -(* All rights reserved. This file is distributed under the terms of *) -(* the GNU Lesser General Public License version 2.1, with the *) -(* special exception on linking described in the file LICENSE. *) -(* *) -(**************************************************************************) - -(** Documentation comments *) - -(** (Re)Initialise all docstring state *) -val init : unit -> unit - -(** Emit warnings for unattached and ambiguous docstrings *) -val warn_bad_docstrings : unit -> unit - -(** {2 Docstrings} *) - -(** Documentation comments *) -type docstring - -(** Create a docstring *) -val docstring : string -> Location.t -> docstring - -(** Register a docstring *) -val register : docstring -> unit - -(** Get the text of a docstring *) -val docstring_body : docstring -> string - -(** Get the location of a docstring *) -val docstring_loc : docstring -> Location.t - -(** {2 Set functions} - - These functions are used by the lexer to associate docstrings to - the locations of tokens. *) - -(** Docstrings immediately preceding a token *) -val set_pre_docstrings : Lexing.position -> docstring list -> unit - -(** Docstrings immediately following a token *) -val set_post_docstrings : Lexing.position -> docstring list -> unit - -(** Docstrings not immediately adjacent to a token *) -val set_floating_docstrings : Lexing.position -> docstring list -> unit - -(** Docstrings immediately following the token which precedes this one *) -val set_pre_extra_docstrings : Lexing.position -> docstring list -> unit - -(** Docstrings immediately preceding the token which follows this one *) -val set_post_extra_docstrings : Lexing.position -> docstring list -> unit - -(** {2 Items} - - The {!docs} type represents documentation attached to an item. *) - -type docs = - { docs_pre: docstring option; - docs_post: docstring option; } - -val empty_docs : docs - -val docs_attr : docstring -> Parsetree.attribute - -(** Convert item documentation to attributes and add them to an - attribute list *) -val add_docs_attrs : docs -> Parsetree.attributes -> Parsetree.attributes - -(** Fetch the item documentation for the current symbol. This also - marks this documentation (for ambiguity warnings). *) -val symbol_docs : unit -> docs -val symbol_docs_lazy : unit -> docs Lazy.t - -(** Fetch the item documentation for the symbols between two - positions. This also marks this documentation (for ambiguity - warnings). *) -val rhs_docs : int -> int -> docs -val rhs_docs_lazy : int -> int -> docs Lazy.t - -(** Mark the item documentation for the current symbol (for ambiguity - warnings). *) -val mark_symbol_docs : unit -> unit - -(** Mark as associated the item documentation for the symbols between - two positions (for ambiguity warnings) *) -val mark_rhs_docs : int -> int -> unit - -(** {2 Fields and constructors} - - The {!info} type represents documentation attached to a field or - constructor. *) - -type info = docstring option - -val empty_info : info - -val info_attr : docstring -> Parsetree.attribute - -(** Convert field info to attributes and add them to an - attribute list *) -val add_info_attrs : info -> Parsetree.attributes -> Parsetree.attributes - -(** Fetch the field info for the current symbol. *) -val symbol_info : unit -> info - -(** Fetch the field info following the symbol at a given position. *) -val rhs_info : int -> info - -(** {2 Unattached comments} - - The {!text} type represents documentation which is not attached to - anything. *) - -type text = docstring list - -val empty_text : text -val empty_text_lazy : text Lazy.t - -val text_attr : docstring -> Parsetree.attribute - -(** Convert text to attributes and add them to an attribute list *) -val add_text_attrs : text -> Parsetree.attributes -> Parsetree.attributes - -(** Fetch the text preceding the current symbol. *) -val symbol_text : unit -> text -val symbol_text_lazy : unit -> text Lazy.t - -(** Fetch the text preceding the symbol at the given position. *) -val rhs_text : int -> text -val rhs_text_lazy : int -> text Lazy.t - -(** {2 Extra text} - - There may be additional text attached to the delimiters of a block - (e.g. [struct] and [end]). This is fetched by the following - functions, which are applied to the contents of the block rather - than the delimiters. *) - -(** Fetch additional text preceding the current symbol *) -val symbol_pre_extra_text : unit -> text - -(** Fetch additional text following the current symbol *) -val symbol_post_extra_text : unit -> text - -(** Fetch additional text preceding the symbol at the given position *) -val rhs_pre_extra_text : int -> text - -(** Fetch additional text following the symbol at the given position *) -val rhs_post_extra_text : int -> text diff --git a/jscomp/ml/subst.ml b/jscomp/ml/subst.ml index 686aac5f8e..0d6666f02f 100644 --- a/jscomp/ml/subst.ml +++ b/jscomp/ml/subst.ml @@ -60,22 +60,10 @@ let remove_loc = let open Ast_mapper in {default_mapper with location = (fun _this _loc -> Location.none)} -let is_not_doc = function - | ({Location.txt = "ocaml.doc"}, _) -> false - | ({Location.txt = "ocaml.text"}, _) -> false - | ({Location.txt = "doc"}, _) -> false - | ({Location.txt = "text"}, _) -> false - | _ -> true - let attrs s x = - let x = - if s.for_saving && not !Clflags.keep_docs then - Ext_list.filter x is_not_doc - else x - in - if s.for_saving && not !Clflags.keep_locs - then remove_loc.Ast_mapper.attributes remove_loc x - else x + if s.for_saving && not !Clflags.keep_locs + then remove_loc.Ast_mapper.attributes remove_loc x + else x let rec module_path s path = try PathMap.find path s.modules From cfd4daaea7ba914a1f4ddd57e53b6f8025408a4d Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 5 Jul 2024 20:37:30 +0200 Subject: [PATCH 2/3] Fix another remaining @ocaml.text --- jscomp/runtime/caml_format.resi | 4 ---- 1 file changed, 4 deletions(-) diff --git a/jscomp/runtime/caml_format.resi b/jscomp/runtime/caml_format.resi index 7f9362cf3a..8bb6860ad7 100644 --- a/jscomp/runtime/caml_format.resi +++ b/jscomp/runtime/caml_format.resi @@ -1,4 +1,3 @@ -@@ocaml.text( /* Copyright (C) 2015-2016 Bloomberg Finance L.P. * * This program is free software: you can redistribute it and/or modify @@ -23,9 +22,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - " " -) - let format_float: (string, float) => string let hexstring_of_float: (float, int, char) => string From ac539079d445a8c931d6e1a96457a958c3932440 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sat, 6 Jul 2024 07:27:52 +0200 Subject: [PATCH 3/3] Fix gentype test --- .../typescript-react-example/src/Docstrings.gen.tsx | 6 +++++- .../typescript-react-example/src/Docstrings.res | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/jscomp/gentype_tests/typescript-react-example/src/Docstrings.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/Docstrings.gen.tsx index d6bbe2074e..2d849d55a5 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Docstrings.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/Docstrings.gen.tsx @@ -10,7 +10,11 @@ export type t = "A" | "B"; /** hello */ export const flat: number = DocstringsJS.flat as any; -/** \n * Sign a message with a key.\n *\n * @param message - A message to be signed\n * @param key - The key with which to sign the message\n * @returns A signed message\n */ +/** * Sign a message with a key. + * + * @param message - A message to be signed + * @param key - The key with which to sign the message + * @returns A signed message */ export const signMessage: (message:string, key:number) => string = DocstringsJS.signMessage as any; export const one: (a:number) => number = DocstringsJS.one as any; diff --git a/jscomp/gentype_tests/typescript-react-example/src/Docstrings.res b/jscomp/gentype_tests/typescript-react-example/src/Docstrings.res index 962b406304..e7a59c3356 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Docstrings.res +++ b/jscomp/gentype_tests/typescript-react-example/src/Docstrings.res @@ -1,13 +1,14 @@ -@ocaml.doc(" hello ") @genType +/** hello */ +@genType let flat = 34 -@ocaml.doc(" +/** * Sign a message with a key. * * @param message - A message to be signed * @param key - The key with which to sign the message * @returns A signed message - ") + */ @genType let signMessage = (. message, key) => message ++ string_of_int(key)