Skip to content

Commit 710a13d

Browse files
committed
Add some more wide-ranging source locations in the AST
1 parent 1e4a0fa commit 710a13d

File tree

10 files changed

+416
-348
lines changed

10 files changed

+416
-348
lines changed

src/lsp/cobol_ast/misc_descr.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ type informational_paragraphs =
2929
(* ------------------------- ENVIRONMENT DIVISION -------------------------- *)
3030
type environment_division =
3131
{
32-
env_configuration: configuration_section option;
33-
env_input_output: input_output_section option;
32+
env_configuration: configuration_section with_loc option;
33+
env_input_output: input_output_section with_loc option;
3434
}
3535
[@@deriving show, ord]
3636

3737
(* ------------- ENVIRONMENT DIVISION / CONFIGURATION SECTION -------------- *)
3838
and configuration_section =
3939
{
40-
source_computer_paragraph: source_computer_paragraph option;
41-
object_computer_paragraph: object_computer_paragraph option;
42-
special_names_paragraph: special_names_paragraph option;
43-
repository_paragraph: repository_paragraph option; (* +COB2002 *)
40+
source_computer_paragraph: source_computer_paragraph with_loc option;
41+
object_computer_paragraph: object_computer_paragraph with_loc option;
42+
special_names_paragraph: special_names_paragraph with_loc option;
43+
repository_paragraph: repository_paragraph with_loc option; (* +COB2002 *)
4444
}
4545
[@@deriving show]
4646

@@ -249,8 +249,8 @@ and expands =
249249
(* -------------- ENVIRONMENT DIVISION / INPUT-OUTPUT SECTION -------------- *)
250250
and input_output_section =
251251
{
252-
file_control_paragraph: file_control_paragraph option; (* COB85: mandatory *)
253-
io_control_paragraph: io_control_paragraph option;
252+
file_control_paragraph: file_control_paragraph with_loc option; (* COB85: mandatory *)
253+
io_control_paragraph: io_control_paragraph with_loc option;
254254
}
255255
[@@deriving show]
256256

src/lsp/cobol_ast/raw.ml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,13 @@ module Data_division (Data_sections: Abstract.DATA_SECTIONS) = struct
271271

272272
type data_division =
273273
{
274-
file_section: file_section option;
275-
working_storage_section: working_storage_section option;
276-
linkage_section: linkage_section option;
277-
communication_section: communication_section option;
278-
local_storage_section: local_storage_section option;
279-
report_section: report_section option;
280-
screen_section: screen_section option;
274+
file_section: file_section with_loc option;
275+
working_storage_section: working_storage_section with_loc option;
276+
linkage_section: linkage_section with_loc option;
277+
communication_section: communication_section with_loc option;
278+
local_storage_section: local_storage_section with_loc option;
279+
report_section: report_section with_loc option;
280+
screen_section: screen_section with_loc option;
281281
}
282282
[@@deriving show]
283283

@@ -392,7 +392,7 @@ struct
392392
program_name: name with_loc;
393393
program_as: strlit option;
394394
program_level: program_level;
395-
program_options: options_paragraph option;
395+
program_options: options_paragraph with_loc option;
396396
program_env: environment_division with_loc option;
397397
program_data: data_division with_loc option;
398398
program_proc: procedure_division with_loc option;
@@ -422,7 +422,7 @@ struct
422422
function_name: name with_loc;
423423
function_as: strlit option;
424424
function_is_proto: bool;
425-
function_options: options_paragraph option;
425+
function_options: options_paragraph with_loc option;
426426
function_env: environment_division with_loc option;
427427
function_data: data_division with_loc option;
428428
function_proc: procedure_division option;
@@ -436,7 +436,7 @@ struct
436436
method_kind: method_kind;
437437
method_override: bool;
438438
method_final: bool;
439-
method_options: options_paragraph option;
439+
method_options: options_paragraph with_loc option;
440440
method_env: environment_division with_loc option;
441441
method_data: data_division with_loc option;
442442
method_proc: procedure_division option;
@@ -451,7 +451,7 @@ struct
451451
type factory_definition = (* Note: could be merged with instance_definition *)
452452
{
453453
factory_implements: name with_loc list;
454-
factory_options: options_paragraph option;
454+
factory_options: options_paragraph with_loc option;
455455
factory_env: environment_division with_loc option;
456456
factory_data: data_division with_loc option;
457457
factory_methods: method_definition with_loc list option;
@@ -461,7 +461,7 @@ struct
461461
type instance_definition =
462462
{
463463
instance_implements: name with_loc list;
464-
instance_options: options_paragraph option;
464+
instance_options: options_paragraph with_loc option;
465465
instance_env: environment_division with_loc option;
466466
instance_data: data_division with_loc option;
467467
instance_methods: method_definition with_loc list option;
@@ -475,7 +475,7 @@ struct
475475
class_final: bool;
476476
class_inherits: name with_loc list;
477477
class_usings: name with_loc list;
478-
class_options: options_paragraph option;
478+
class_options: options_paragraph with_loc option;
479479
class_env: environment_division with_loc option;
480480
class_factory: factory_definition option;
481481
class_instance: instance_definition option;
@@ -489,7 +489,7 @@ struct
489489
interface_as: strlit option;
490490
interface_inherits: name with_loc list;
491491
interface_usings: name with_loc list;
492-
interface_options: options_paragraph option;
492+
interface_options: options_paragraph with_loc option;
493493
interface_env: environment_division with_loc option;
494494
interface_methods: method_definition with_loc list option;
495495
interface_end_name: name with_loc;

src/lsp/cobol_ast/raw_compilation_group_visitor.ml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ struct
4646
inherit ['a] Terms_visitor.folder
4747
inherit ['a] Misc_sections_visitor.folder
4848
inherit ['a] Data_division_visitor.folder
49+
method fold_options_paragraph' : (options_paragraph with_loc , 'a) fold = default
50+
method fold_environment_division' : (environment_division with_loc, 'a) fold = default
4951
method fold_data_division' : (data_division with_loc , 'a) fold = default
5052
inherit ['a] Proc_division_visitor.folder
5153
method fold_procedure_division' : (procedure_division with_loc , 'a) fold = default
@@ -67,11 +69,16 @@ struct
6769
let todo x = todo __MODULE__ x
6870
let partial x = partial __MODULE__ x
6971

70-
let fold_options_paragraph_opt (v: _ #folder) =
71-
fold_option ~fold:(fun v -> v#continue_with_options_paragraph) v
72+
let fold_options_paragraph' (v: _ #folder) =
73+
handle' v#fold_options_paragraph' v
74+
~fold:(fun v -> v#continue_with_options_paragraph)
75+
76+
let fold_options_paragraph'_opt (v: _ #folder) =
77+
fold_option ~fold:fold_options_paragraph' v
7278

7379
let fold_environment_division' (v: _ #folder) =
74-
fold' ~fold:(fun v -> v#continue_with_environment_division) v
80+
handle' v#fold_environment_division' v
81+
~fold:(fun v -> v#continue_with_environment_division)
7582

7683
let fold_environment_division'_opt (v: _ #folder) =
7784
fold_option ~fold:fold_environment_division' v
@@ -99,7 +106,7 @@ struct
99106
program_proc; program_end_name } x -> x
100107
>> fold_name' v program_name
101108
>> fold_strlit_opt v program_as
102-
>> fold_options_paragraph_opt v program_options
109+
>> fold_options_paragraph'_opt v program_options
103110
>> fold_environment_division'_opt v program_env
104111
>> fold_data_division'_opt v program_data
105112
>> (fun x -> match program_level with
@@ -126,7 +133,7 @@ struct
126133
>> fold_name' v function_name
127134
>> fold_strlit_opt v function_as
128135
>> fold_bool v function_is_proto (* XXX: useful? *)
129-
>> fold_options_paragraph_opt v function_options
136+
>> fold_options_paragraph'_opt v function_options
130137
>> fold_environment_division'_opt v function_env
131138
>> fold_data_division'_opt v function_data
132139
>> fold_procedure_division_opt v function_proc
@@ -153,7 +160,7 @@ struct
153160
>> fold_method_kind v method_kind
154161
>> fold_bool v method_override
155162
>> fold_bool v method_final
156-
>> fold_options_paragraph_opt v method_options
163+
>> fold_options_paragraph'_opt v method_options
157164
>> fold_environment_division'_opt v method_env
158165
>> fold_data_division'_opt v method_data
159166
>> fold_procedure_division_opt v method_proc
@@ -165,7 +172,7 @@ struct
165172
~continue:begin fun { factory_implements; factory_options; factory_env;
166173
factory_data; factory_methods } x -> x
167174
>> fold_name'_list v factory_implements
168-
>> fold_options_paragraph_opt v factory_options
175+
>> fold_options_paragraph'_opt v factory_options
169176
>> fold_environment_division'_opt v factory_env
170177
>> fold_data_division'_opt v factory_data
171178
>> fold_option v factory_methods
@@ -180,7 +187,7 @@ struct
180187
partial __LINE__ "fold_instance_definition" ();
181188
x
182189
>> fold_name'_list v instance_implements
183-
>> fold_options_paragraph_opt v instance_options
190+
>> fold_options_paragraph'_opt v instance_options
184191
>> fold_data_division'_opt v instance_data
185192
>> fold_option v instance_methods
186193
~fold:(fold_with_loc_list ~fold:fold_method_definition)

src/lsp/cobol_ast/raw_data_division_visitor.ml

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
(* *)
1212
(**************************************************************************)
1313

14+
open Cobol_common.Srcloc.TYPES
1415
open Cobol_common.Visitor
1516
open Cobol_common.Visitor.INFIX (* for `>>` (== `|>`) *)
1617

@@ -31,32 +32,69 @@ struct
3132
module Data_division_visitor =
3233
Abstract_visitor.For_data_division (Data_division)
3334

35+
open Data_sections
36+
3437
class virtual ['a] folder = object
3538
inherit ['a] Terms_visitor.folder
3639
inherit ['a] Data_sections_visitor.folder
3740
inherit ['a] Data_division_visitor.folder
41+
method fold_file_section': (file_section with_loc, 'a) fold = default
42+
method fold_working_storage_section': (working_storage_section with_loc, 'a) fold = default
43+
method fold_linkage_section': (linkage_section with_loc, 'a) fold = default
44+
method fold_communication_section': (communication_section with_loc, 'a) fold = default
45+
method fold_local_storage_section': (local_storage_section with_loc, 'a) fold = default
46+
method fold_report_section': (report_section with_loc, 'a) fold = default
47+
method fold_screen_section': (screen_section with_loc, 'a) fold = default
3848
end
3949

50+
let fold_file_section' (v: _ #folder) =
51+
handle' v#fold_file_section' v
52+
~fold:(fun v -> v#continue_with_file_section)
53+
54+
let fold_working_storage_section' (v: _ #folder) =
55+
handle' v#fold_working_storage_section' v
56+
~fold:(fun v -> v#continue_with_working_storage_section)
57+
58+
let fold_linkage_section' (v: _ #folder) =
59+
handle' v#fold_linkage_section' v
60+
~fold:(fun v -> v#continue_with_linkage_section)
61+
62+
let fold_communication_section' (v: _ #folder) =
63+
handle' v#fold_communication_section' v
64+
~fold:(fun v -> v#continue_with_communication_section)
65+
66+
let fold_local_storage_section' (v: _ #folder) =
67+
handle' v#fold_local_storage_section' v
68+
~fold:(fun v -> v#continue_with_local_storage_section)
69+
70+
let fold_report_section' (v: _ #folder) =
71+
handle' v#fold_report_section' v
72+
~fold:(fun v -> v#continue_with_report_section)
73+
74+
let fold_screen_section' (v: _ #folder) =
75+
handle' v#fold_screen_section' v
76+
~fold:(fun v -> v#continue_with_screen_section)
77+
4078
let fold_data_division (v: _#folder) =
4179
handle v#fold_data_division
4280
~continue:begin fun { file_section; working_storage_section;
4381
linkage_section; communication_section;
4482
local_storage_section; report_section;
4583
screen_section } x -> x
4684
>> fold_option v file_section
47-
~fold:(fun v -> v#continue_with_file_section)
85+
~fold:fold_file_section'
4886
>> fold_option v working_storage_section
49-
~fold:(fun v -> v#continue_with_working_storage_section)
87+
~fold:fold_working_storage_section'
5088
>> fold_option v linkage_section
51-
~fold:(fun v -> v#continue_with_linkage_section)
89+
~fold:fold_linkage_section'
5290
>> fold_option v communication_section
53-
~fold:(fun v -> v#continue_with_communication_section)
91+
~fold:fold_communication_section'
5492
>> fold_option v local_storage_section
55-
~fold:(fun v -> v#continue_with_local_storage_section)
93+
~fold:fold_local_storage_section'
5694
>> fold_option v report_section
57-
~fold:(fun v -> v#continue_with_report_section)
95+
~fold:fold_report_section'
5896
>> fold_option v screen_section
59-
~fold:(fun v -> v#continue_with_screen_section)
97+
~fold:fold_screen_section'
6098
end
6199

62100
end

src/lsp/cobol_ast/raw_misc_sections_visitor.ml

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,20 @@ module Make = struct
3333
inherit ['a] Misc_sections_visitor.folder
3434
method fold_options_clause: (options_clause, 'a) fold = default
3535
method fold_configuration_section: (configuration_section, 'a) fold = default
36+
method fold_configuration_section': (configuration_section with_loc, 'a) fold = default
3637
method fold_special_names_paragraph: (special_names_paragraph, 'a) fold = default
3738
method fold_special_names_clause: (special_names_clause, 'a) fold = default
3839
method fold_special_names_clause': (special_names_clause with_loc, 'a) fold = default
3940
method fold_repository_paragraph: (repository_paragraph, 'a) fold = default
41+
method fold_repository_paragraph': (repository_paragraph with_loc, 'a) fold = default
4042
method fold_specifier: (specifier, 'a) fold = default
4143
method fold_expands: (expands, 'a) fold = default
4244
method fold_select: (select, 'a) fold = default
4345
method fold_select_clause: (select_clause, 'a) fold = default
4446
method fold_file_control_paragraph: (file_control_paragraph, 'a) fold = default
47+
method fold_file_control_paragraph': (file_control_paragraph with_loc, 'a) fold = default
4548
method fold_io_control_paragraph: (io_control_paragraph, 'a) fold = default
49+
method fold_io_control_paragraph': (io_control_paragraph with_loc, 'a) fold = default
4650
method fold_io_control_entry: (io_control_entry, 'a) fold = default
4751
method fold_rerun_clause: (rerun_clause, 'a) fold = default
4852
method fold_rerun_frequency: (rerun_frequency, 'a) fold = default
@@ -51,6 +55,7 @@ module Make = struct
5155
method fold_multiple_file_clause: (multiple_file_clause, 'a) fold = default
5256
method fold_file_portion: (file_portion, 'a) fold = default
5357
method fold_input_output_section: (input_output_section, 'a) fold = default
58+
method fold_input_output_section': (input_output_section with_loc, 'a) fold = default
5459
method fold_alphabet_specification: (alphabet_specification, 'a) fold = default
5560
end
5661

@@ -77,6 +82,10 @@ module Make = struct
7782
handle v#fold_file_control_paragraph
7883
~continue:(fold_list ~fold:fold_select v)
7984

85+
let fold_file_control_paragraph' (v: _ #folder) =
86+
handle' v#fold_file_control_paragraph' v
87+
~fold:fold_file_control_paragraph
88+
8089
let fold_rerun_frequency (v: _ #folder) =
8190
handle v#fold_rerun_frequency
8291
~continue:begin function
@@ -133,15 +142,23 @@ module Make = struct
133142
handle v#fold_io_control_paragraph
134143
~continue:(fold_option ~fold:fold_io_control_entry v)
135144

145+
let fold_io_control_paragraph' (v: _ #folder) =
146+
handle' v#fold_io_control_paragraph' v
147+
~fold:fold_io_control_paragraph
148+
136149
let fold_input_output_section (v: _ #folder) =
137150
handle v#fold_input_output_section
138151
~continue:begin fun { file_control_paragraph; io_control_paragraph } x -> x
139152
>> fold_option v file_control_paragraph
140-
~fold:fold_file_control_paragraph
153+
~fold:fold_file_control_paragraph'
141154
>> fold_option v io_control_paragraph
142-
~fold:fold_io_control_paragraph
155+
~fold:fold_io_control_paragraph'
143156
end
144157

158+
let fold_input_output_section' (v: _ #folder) =
159+
handle' v#fold_input_output_section' v
160+
~fold:fold_input_output_section
161+
145162
(* --- *)
146163

147164
let fold_informational_paragraphs (v: _ #folder) =
@@ -189,6 +206,10 @@ module Make = struct
189206
handle v#fold_repository_paragraph
190207
~continue:(fold_list ~fold:fold_specifier v)
191208

209+
let fold_repository_paragraph' (v: _ #folder) =
210+
handle' v#fold_repository_paragraph' v
211+
~fold:fold_repository_paragraph
212+
192213
let fold_special_names_clause (v: _ #folder) =
193214
handle v#fold_special_names_clause
194215
~continue:begin fun c x -> match c with
@@ -217,14 +238,18 @@ module Make = struct
217238
ignore special_names_paragraph;
218239
x
219240
>> partial __LINE__ "fold_configuration_section"
220-
>> fold_option ~fold:fold_repository_paragraph v repository_paragraph
241+
>> fold_option ~fold:fold_repository_paragraph' v repository_paragraph
221242
end
222243

244+
let fold_configuration_section' (v: _ #folder) =
245+
handle' v#fold_configuration_section' v
246+
~fold:fold_configuration_section
247+
223248
let fold_environment_division (v: _ #folder) =
224249
handle v#fold_environment_division
225250
~continue:begin fun { env_configuration; env_input_output } x -> x
226-
>> fold_option ~fold:fold_configuration_section v env_configuration
227-
>> fold_option ~fold:fold_input_output_section v env_input_output
251+
>> fold_option ~fold:fold_configuration_section' v env_configuration
252+
>> fold_option ~fold:fold_input_output_section' v env_input_output
228253
end
229254

230255
let fold_alphabet_specification (v: _ #folder) =

0 commit comments

Comments
 (0)