Skip to content

Commit

Permalink
Typedefs don't like to be called enums
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Feb 5, 2024
1 parent 12a993e commit 7f77efa
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/context/display/displayToplevel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ let collect ctx tk with_type sort =
let tname,is_private,meta = match d with
| EClass d -> fst d.d_name,List.mem HPrivate d.d_flags,d.d_meta
| EEnum d -> fst d.d_name,List.mem EPrivate d.d_flags,d.d_meta
| ETypedef d -> fst d.d_name,List.mem EPrivate d.d_flags,d.d_meta
| ETypedef d -> fst d.d_name,List.mem TDPrivate d.d_flags,d.d_meta
| EAbstract d -> fst d.d_name,List.mem AbPrivate d.d_flags,d.d_meta
| EStatic d -> fst d.d_name,List.exists (fun (a,_) -> a = APrivate) d.d_flags,d.d_meta
| EImport _ | EUsing _ -> raise Exit
Expand Down
6 changes: 5 additions & 1 deletion src/core/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ type abstract_flag =
| AbExtern
| AbEnum

type typedef_flag =
| TDPrivate
| TDExtern

type enum_constructor = {
ec_name : placed_name;
ec_doc : documentation;
Expand Down Expand Up @@ -381,7 +385,7 @@ type import = placed_name list * import_mode
type type_def =
| EClass of (class_flag, class_field list) definition
| EEnum of (enum_flag, enum_constructor list) definition
| ETypedef of (enum_flag, type_hint) definition
| ETypedef of (typedef_flag, type_hint) definition
| EAbstract of (abstract_flag, class_field list) definition
| EStatic of (placed_access, class_field_kind) definition
| EImport of import
Expand Down
4 changes: 2 additions & 2 deletions src/core/display/completionItem.ml
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ module CompletionModuleType = struct
name = fst d.d_name;
module_name = module_name;
pos = p;
is_private = List.mem EPrivate d.d_flags;
is_private = List.mem TDPrivate d.d_flags;
params = d.d_params;
meta = d.d_meta;
doc = d.d_doc;
is_extern = List.mem EExtern d.d_flags;
is_extern = List.mem TDExtern d.d_flags;
is_final = false;
is_abstract = false;
kind = kind;
Expand Down
4 changes: 2 additions & 2 deletions src/macro/macroApi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,7 @@ let decode_type_def v =
in
EEnum (mk (if isExtern then [EExtern] else []) (List.map conv fields))
| 1, [] ->
ETypedef (mk (if isExtern then [EExtern] else []) (CTAnonymous fields,pos))
ETypedef (mk (if isExtern then [TDExtern] else []) (CTAnonymous fields,pos))
| 2, [ext;impl;interf;final;abstract] ->
let flags = if isExtern then [HExtern] else [] in
let is_interface = decode_opt_bool interf in
Expand All @@ -1636,7 +1636,7 @@ let decode_type_def v =
let flags = if is_abstract then HAbstract :: flags else flags in
EClass (mk flags fields)
| 3, [t] ->
ETypedef (mk (if isExtern then [EExtern] else []) (decode_ctype t))
ETypedef (mk (if isExtern then [TDExtern] else []) (decode_ctype t))
| 4, [tthis;tflags;tfrom;tto] ->
let flags = match opt decode_array tflags with
| None -> []
Expand Down
2 changes: 1 addition & 1 deletion src/syntax/grammar.mly
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ and parse_type_decl mode s =
d_doc = doc_from_string_opt doc;
d_meta = meta;
d_params = tl;
d_flags = ExtList.List.filter_map decl_flag_to_enum_flag c;
d_flags = ExtList.List.filter_map decl_flag_to_typedef_flag c;
d_data = t;
}, punion p1 (pos t))
| [< '(Kwd Abstract,p1) >] ->
Expand Down
6 changes: 6 additions & 0 deletions src/syntax/parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ let unsupported_decl_flag decl flag pos =
let unsupported_decl_flag_class = unsupported_decl_flag "classes"
let unsupported_decl_flag_enum = unsupported_decl_flag "enums"
let unsupported_decl_flag_abstract = unsupported_decl_flag "abstracts"
let unsupported_decl_flag_typedef = unsupported_decl_flag "typedefs"
let unsupported_decl_flag_module_field = unsupported_decl_flag "module-level fields"

let decl_flag_to_class_flag (flag,p) = match flag with
Expand All @@ -230,6 +231,11 @@ let decl_flag_to_abstract_flag (flag,p) = match flag with
| DExtern -> Some AbExtern
| DFinal | DMacro | DDynamic | DInline | DPublic | DStatic | DOverload -> unsupported_decl_flag_abstract flag p

let decl_flag_to_typedef_flag (flag,p) = match flag with
| DPrivate -> Some TDPrivate
| DExtern -> Some TDExtern
| DFinal | DMacro | DDynamic | DInline | DPublic | DStatic | DOverload -> unsupported_decl_flag_typedef flag p

let decl_flag_to_module_field_flag (flag,p) = match flag with
| DPrivate -> Some (APrivate,p)
| DMacro -> Some (AMacro,p)
Expand Down
2 changes: 1 addition & 1 deletion src/typing/typeloadModule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ module ModuleLevel = struct
let name = fst d.d_name in
check_type_name name d.d_meta;
has_declaration := true;
let priv = List.mem EPrivate d.d_flags in
let priv = List.mem TDPrivate d.d_flags in
let path = make_path name priv d.d_meta p in
let t = {(mk_typedef m path p (pos d.d_name) (mk_mono())) with
t_doc = d.d_doc;
Expand Down
4 changes: 2 additions & 2 deletions src/typing/typeloadParse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ let parse_module com m p =
d_doc = None;
d_meta = [];
d_params = d.d_params;
d_flags = if priv then [EPrivate] else [];
d_flags = if priv then [TDPrivate] else [];
d_data = begin
let tp =
if priv then
Expand All @@ -335,7 +335,7 @@ let parse_module com m p =
match t with
| EClass d -> build HPrivate d
| EEnum d -> build EPrivate d
| ETypedef d -> build EPrivate d
| ETypedef d -> build TDPrivate d
| EAbstract d -> build AbPrivate d
| EStatic d -> build (AStatic,null_pos) d
| EImport _ | EUsing _ -> acc
Expand Down

0 comments on commit 7f77efa

Please sign in to comment.