Skip to content

Commit a39fb92

Browse files
committed
Mark return expressions in parsed and typed ASTs
Signed-off-by: Cristiano Calcagno <[email protected]>
1 parent 394ddaa commit a39fb92

File tree

15 files changed

+341
-4
lines changed

15 files changed

+341
-4
lines changed

analysis/src/CompletionFrontEnd.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ let rec exprToContextPathInner ~(inJsxContext : bool) (e : Parsetree.expression)
277277
{funct = d; args = (Nolabel, lhs) :: args; partial; transformed_jsx};
278278
pexp_loc;
279279
pexp_attributes;
280+
pexp_is_return = false;
280281
}
281282
| Pexp_apply
282283
({
@@ -294,11 +295,18 @@ let rec exprToContextPathInner ~(inJsxContext : bool) (e : Parsetree.expression)
294295
Pexp_apply
295296
{
296297
app with
297-
funct = {pexp_desc = Pexp_ident id; pexp_loc; pexp_attributes};
298+
funct =
299+
{
300+
pexp_desc = Pexp_ident id;
301+
pexp_loc;
302+
pexp_attributes;
303+
pexp_is_return = false;
304+
};
298305
args = [(Nolabel, lhs)];
299306
};
300307
pexp_loc;
301308
pexp_attributes;
309+
pexp_is_return = false;
302310
}
303311
| Pexp_apply {funct = e1; args} -> (
304312
match exprToContextPath ~inJsxContext e1 with

compiler/frontend/ast_compatible.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ let apply_simple ?(loc = default_loc) ?(attrs = []) (fn : expression)
3535
{
3636
pexp_loc = loc;
3737
pexp_attributes = attrs;
38+
pexp_is_return = false;
3839
pexp_desc =
3940
Pexp_apply
4041
{
@@ -49,6 +50,7 @@ let app1 ?(loc = default_loc) ?(attrs = []) fn arg1 : expression =
4950
{
5051
pexp_loc = loc;
5152
pexp_attributes = attrs;
53+
pexp_is_return = false;
5254
pexp_desc =
5355
Pexp_apply
5456
{
@@ -63,6 +65,7 @@ let app2 ?(loc = default_loc) ?(attrs = []) fn arg1 arg2 : expression =
6365
{
6466
pexp_loc = loc;
6567
pexp_attributes = attrs;
68+
pexp_is_return = false;
6669
pexp_desc =
6770
Pexp_apply
6871
{
@@ -77,6 +80,7 @@ let app3 ?(loc = default_loc) ?(attrs = []) fn arg1 arg2 arg3 : expression =
7780
{
7881
pexp_loc = loc;
7982
pexp_attributes = attrs;
83+
pexp_is_return = false;
8084
pexp_desc =
8185
Pexp_apply
8286
{
@@ -91,6 +95,7 @@ let fun_ ?(loc = default_loc) ?(attrs = []) ?(async = false) ~arity pat exp =
9195
{
9296
pexp_loc = loc;
9397
pexp_attributes = attrs;
98+
pexp_is_return = false;
9499
pexp_desc =
95100
Pexp_fun
96101
{
@@ -108,13 +113,15 @@ let const_exp_string ?(loc = default_loc) ?(attrs = []) ?delimiter (s : string)
108113
{
109114
pexp_loc = loc;
110115
pexp_attributes = attrs;
116+
pexp_is_return = false;
111117
pexp_desc = Pexp_constant (Pconst_string (s, delimiter));
112118
}
113119

114120
let const_exp_int ?(loc = default_loc) ?(attrs = []) (s : int) : expression =
115121
{
116122
pexp_loc = loc;
117123
pexp_attributes = attrs;
124+
pexp_is_return = false;
118125
pexp_desc = Pexp_constant (Pconst_integer (string_of_int s, None));
119126
}
120127

@@ -123,6 +130,7 @@ let apply_labels ?(loc = default_loc) ?(attrs = []) fn
123130
{
124131
pexp_loc = loc;
125132
pexp_attributes = attrs;
133+
pexp_is_return = false;
126134
pexp_desc =
127135
Pexp_apply
128136
{

compiler/frontend/ast_exp_apply.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) : exp =
9696
{funct = fn1; args = (Nolabel, a) :: args; partial; transformed_jsx};
9797
pexp_loc = e.pexp_loc;
9898
pexp_attributes = e.pexp_attributes @ f.pexp_attributes;
99+
pexp_is_return = false;
99100
}
100101
| Pexp_tuple xs ->
101102
bound a (fun bounded_obj_arg ->
@@ -122,11 +123,13 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) : exp =
122123
transformed_jsx;
123124
};
124125
pexp_attributes = [];
126+
pexp_is_return = false;
125127
pexp_loc = fn.pexp_loc;
126128
}
127129
| _ ->
128130
Ast_compatible.app1 ~loc:fn.pexp_loc fn bounded_obj_arg));
129131
pexp_attributes = f.pexp_attributes;
132+
pexp_is_return = false;
130133
pexp_loc = f.pexp_loc;
131134
})
132135
| _ -> Ast_compatible.app1 ~loc ~attrs:e.pexp_attributes f a)

compiler/frontend/ast_external_mk.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ let local_external_apply loc ?(pval_attributes = []) ~(pval_prim : string list)
5454
Pexp_ident
5555
{txt = Ldot (Lident local_module_name, local_fun_name); loc};
5656
pexp_attributes = [];
57+
pexp_is_return = false;
5758
pexp_loc = loc;
5859
}
5960
: Parsetree.expression)
@@ -90,6 +91,7 @@ let local_external_obj loc ?(pval_attributes = []) ~pval_prim ~pval_type
9091
Pexp_ident
9192
{txt = Ldot (Lident local_module_name, local_fun_name); loc};
9293
pexp_attributes = [];
94+
pexp_is_return = false;
9395
pexp_loc = loc;
9496
}
9597
: Parsetree.expression)
@@ -126,5 +128,6 @@ let local_extern_cont_to_obj loc ?(pval_attributes = []) ~pval_prim ~pval_type
126128
Pexp_ident
127129
{txt = Ldot (Lident local_module_name, local_fun_name); loc};
128130
pexp_attributes = [];
131+
pexp_is_return = false;
129132
pexp_loc = loc;
130133
} )

compiler/frontend/ast_open_cxt.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ let restore_exp (xs : Parsetree.expression) (qualifiers : t) :
5656
({
5757
pexp_desc = Pexp_open (flag, lid, x);
5858
pexp_attributes = attrs;
59+
pexp_is_return = false;
5960
pexp_loc = loc;
6061
}
6162
: Parsetree.expression))

compiler/ml/ast_helper.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,12 @@ end
154154

155155
module Exp = struct
156156
let mk ?(loc = !default_loc) ?(attrs = []) d =
157-
{pexp_desc = d; pexp_loc = loc; pexp_attributes = attrs}
157+
{
158+
pexp_desc = d;
159+
pexp_loc = loc;
160+
pexp_attributes = attrs;
161+
pexp_is_return = false;
162+
}
158163
let attr d a = {d with pexp_attributes = d.pexp_attributes @ [a]}
159164

160165
let ident ?loc ?attrs a = mk ?loc ?attrs (Pexp_ident a)

compiler/ml/parsetree.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ and expression = {
212212
pexp_loc: Location.t;
213213
(* Hack: made pexp_attributes mutable for use in analysis exe. Please do not use elsewhere! *)
214214
mutable pexp_attributes: attributes; (* ... [@id1] [@id2] *)
215+
mutable pexp_is_return: bool;
215216
}
216217

217218
and expression_desc =

0 commit comments

Comments
 (0)