diff options
| author | Xavier Clerc <xavier.clerc@inria.fr> | 2010-05-31 13:18:11 +0000 |
|---|---|---|
| committer | Xavier Clerc <xavier.clerc@inria.fr> | 2010-05-31 13:18:11 +0000 |
| commit | ffa66ded92cdad98a2b38ccf8f5befed9cbf5bc5 (patch) | |
| tree | dc6c2d71e2c33004810e6b93cbc9b5f04c29dfbd | |
| parent | 2146210d4eb16ae75eef903a756580d912809b86 (diff) | |
| download | ocaml-ffa66ded92cdad98a2b38ccf8f5befed9cbf5bc5.tar.gz | |
PR#4964: parenthesized names for infix functions in annot files
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10486 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
| -rw-r--r-- | Changes | 1 | ||||
| -rw-r--r-- | typing/oprint.ml | 16 | ||||
| -rw-r--r-- | typing/oprint.mli | 2 | ||||
| -rw-r--r-- | typing/typecore.ml | 10 |
4 files changed, 22 insertions, 7 deletions
@@ -107,6 +107,7 @@ Bug Fixes: - PR#4478: better error messages for type definition mismatches - PR#4742: finalisation function raising an exception blocks other finalisations - PR#4775: compiler crash on crazy types (temporary fix) +- PR#4964: parenthesized names for infix functions in annot files - PR#4970: better error message for instance variables - PR#4975: spelling mistakes - PR#4988: contravariance lost with ocamlc -i diff --git a/typing/oprint.ml b/typing/oprint.ml index 2344436b91..ca5db71a63 100644 --- a/typing/oprint.ml +++ b/typing/oprint.ml @@ -28,15 +28,19 @@ let rec print_ident ppf = | Oide_apply (id1, id2) -> fprintf ppf "%a(%a)" print_ident id1 print_ident id2 +let parenthesized_ident name = + (List.mem name ["or"; "mod"; "land"; "lor"; "lxor"; "lsl"; "lsr"; "asr"]) + || + (match name.[0] with + 'a'..'z' | '\223'..'\246' | '\248'..'\255' | '_' -> + false + | _ -> true) + let value_ident ppf name = - if List.mem name - ["or"; "mod"; "land"; "lor"; "lxor"; "lsl"; "lsr"; "asr"] then + if parenthesized_ident name then fprintf ppf "( %s )" name else - match name.[0] with - 'a'..'z' | '\223'..'\246' | '\248'..'\255' | '_' -> - fprintf ppf "%s" name - | _ -> fprintf ppf "( %s )" name + fprintf ppf "%s" name (* Values *) diff --git a/typing/oprint.mli b/typing/oprint.mli index 902d3cf26b..7a5121ae19 100644 --- a/typing/oprint.mli +++ b/typing/oprint.mli @@ -22,3 +22,5 @@ val out_module_type : (formatter -> out_module_type -> unit) ref val out_sig_item : (formatter -> out_sig_item -> unit) ref val out_signature : (formatter -> out_sig_item list -> unit) ref val out_phrase : (formatter -> out_phrase -> unit) ref + +val parenthesized_ident : string -> bool diff --git a/typing/typecore.ml b/typing/typecore.ml index d9213c232b..5aff9c07eb 100644 --- a/typing/typecore.ml +++ b/typing/typecore.ml @@ -1005,8 +1005,16 @@ let rec type_exp env sexp = begin if !Clflags.annotations then begin try let (path, annot) = Env.lookup_annot lid env in + let rec name_of_path = function + | Path.Pident id -> Ident.name id + | Path.Pdot(p, s, pos) -> + if Oprint.parenthesized_ident s then + name_of_path p ^ ".( " ^ s ^ " )" + else + name_of_path p ^ "." ^ s + | Path.Papply(p1, p2) -> name_of_path p1 ^ "(" ^ name_of_path p2 ^ ")" in Stypes.record - (Stypes.An_ident (loc, Path.name path, annot)) + (Stypes.An_ident (loc, name_of_path path, annot)) with _ -> () end; let (path, desc) = Typetexp.find_value env loc lid in |
