Debian Codegraph @

gcc/cobol/genapi.h

raw
1 /*
2 * Copyright (c) 2021-2025 Symas Corporation
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above`
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of the Symas Corporation nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 #ifndef _GENAPI_H_
31 #define _GENAPI_H_
32
33 #define DISPLAY_ADVANCE true
34 #define DISPLAY_NO_ADVANCE false
35
36 typedef enum
37 {
38 refer_dest,
39 refer_source,
40 } refer_type_t;
41
42 void parser_display_internal( tree file_descriptor,
43 cbl_refer_t refer,
44 bool advance=DISPLAY_NO_ADVANCE);
45
46 void parser_first_statement( int lineno );
47
48 void parser_enter_file(const char *filename);
49 void parser_leave_file();
50 void parser_division( cbl_division_t division,
51 cbl_field_t *ret, size_t narg, cbl_ffi_arg_t args[] );
52 void parser_enter_program(const char *funcname, bool is_function, int *retval);
53 void parser_leave_program();
54
55 void parser_accept( const cbl_refer_t &refer,
56 special_name_t special_e,
57 cbl_label_t *error,
58 cbl_label_t *not_error );
59 void parser_accept_exception( cbl_label_t *name );
60 void parser_accept_exception_end( cbl_label_t *name );
61
62 void parser_accept_under_discussion(struct cbl_refer_t tgt, special_name_t special,
63 cbl_label_t *error, cbl_label_t *not_error );
64 void parser_accept_envar( const cbl_refer_t &refer,
65 const cbl_refer_t &envar,
66 cbl_label_t *error,
67 cbl_label_t *not_error );
68 void parser_set_envar( const cbl_refer_t &envar, const cbl_refer_t &refer );
69
70 void parser_accept_command_line(const cbl_refer_t &tgt,
71 const cbl_refer_t &src,
72 cbl_label_t *error,
73 cbl_label_t *not_error );
74 void parser_accept_command_line_count( const cbl_refer_t &tgt );
75
76 void parser_accept_date_yymmdd( cbl_field_t *tgt );
77 void parser_accept_date_yyyymmdd( cbl_field_t *tgt );
78 void parser_accept_date_yyddd( cbl_field_t *tgt );
79 void parser_accept_date_yyyyddd( cbl_field_t *tgt );
80 void parser_accept_date_dow( cbl_field_t *tgt );
81 void parser_accept_date_hhmmssff( cbl_field_t *tgt );
82
83 void
84 parser_alphabet( cbl_alphabet_t& alphabet );
85 void
86 parser_alphabet_use( cbl_alphabet_t& alphabet );
87
88 void
89 parser_allocate( cbl_refer_t size_or_based, cbl_refer_t returning, bool initialized );
90 void
91 parser_free( size_t n, cbl_refer_t refers[] );
92
93 void
94 parser_add( size_t nC, cbl_num_result_t *C,
95 size_t nA, cbl_refer_t *A,
96 cbl_arith_format_t format,
97 cbl_label_t *error,
98 cbl_label_t *not_error, void *compute_error = NULL); // This has to be cast to a tree pointer to int
99
100 void parser_arith_error( cbl_label_t *name );
101 void parser_arith_error_end( cbl_label_t *name );
102
103 void
104 parser_subtract(size_t nC, cbl_num_result_t *C,
105 size_t nA, cbl_refer_t *A,
106 size_t nB, cbl_refer_t *B,
107 cbl_arith_format_t format,
108 cbl_label_t *error,
109 cbl_label_t *not_error,
110 void *compute_error = NULL); // This has to be cast to a tree pointer to int
111
112 void
113 parser_multiply(size_t nC, cbl_num_result_t *C,
114 size_t nA, cbl_refer_t *A,
115 size_t nB, cbl_refer_t *B,
116 cbl_label_t *error,
117 cbl_label_t *not_error,
118 void *compute_error = NULL); // This has to be cast to a tree pointer to int
119
120 void
121 parser_divide(size_t nC, cbl_num_result_t *C,
122 size_t nA, cbl_refer_t *A,
123 size_t nB, cbl_refer_t *B,
124 cbl_refer_t remainder,
125 cbl_label_t *error,
126 cbl_label_t *not_error,
127 void *compute_error = NULL); // This has to be cast to a tree pointer to int
128
129 void
130 parser_add( const cbl_refer_t& tgt,
131 const cbl_refer_t& a, const cbl_refer_t& b,
132 enum cbl_round_t = truncation_e );
133
134 void
135 parser_subtract( const cbl_refer_t& tgt,
136 const cbl_refer_t& a, const cbl_refer_t& b,
137 enum cbl_round_t = truncation_e );
138
139 void
140 parser_multiply( const cbl_refer_t& tgt,
141 const cbl_refer_t& a, const cbl_refer_t& b,
142 enum cbl_round_t = truncation_e );
143
144 void
145 parser_divide( const cbl_refer_t& quotient,
146 const cbl_refer_t& divisor,
147 const cbl_refer_t& dividend,
148 enum cbl_round_t = truncation_e,
149 const cbl_refer_t& remainder = cbl_refer_t());
150
151 // void
152 // parser_exponentiation( cbl_refer_t cref,
153 // cbl_refer_t aref,
154 // cbl_refer_t bref,
155 // cbl_round_t rounded = truncation_e );
156
157 void
158 parser_relop( struct cbl_field_t *tgt,
159 struct cbl_refer_t a, enum relop_t, struct cbl_refer_t b );
160
161 void
162 parser_relop_long(struct cbl_field_t *tgt,
163 long a, enum relop_t, struct cbl_refer_t b );
164
165 void
166 parser_logop( struct cbl_field_t *tgt,
167 struct cbl_field_t *a, enum logop_t, struct cbl_field_t *b );
168
169 void
170 parser_setop( struct cbl_field_t *tgt,
171 struct cbl_field_t *a, enum setop_t, struct cbl_field_t *b );
172
173 void
174 parser_bitop( struct cbl_field_t *tgt,
175 struct cbl_field_t *a, enum bitop_t, size_t B );
176
177 void
178 parser_bitwise_op(struct cbl_field_t *tgt,
179 struct cbl_field_t *a,
180 enum bitop_t op,
181 size_t bitmask );
182
183 void
184 parser_classify( struct cbl_field_t *tgt,
185 const struct cbl_refer_t &srca,
186 enum classify_t type );
187
188 void
189 parser_op( struct cbl_refer_t cref,
190 struct cbl_refer_t aref, int op, struct cbl_refer_t bref,
191 struct cbl_label_t *op_error);
192
193 cbl_field_t
194 determine_intermediate_type( const cbl_refer_t& aref,
195 int op,
196 const cbl_refer_t& bref );
197
198 void
199 parser_if( struct cbl_field_t *yn ); // value is 1 or 0
200 void
201 parser_else(void);
202 void
203 parser_fi(void);
204
205
206 void
207 parser_enter_paragraph( struct cbl_label_t *label );
208 void
209 parser_leave_paragraph( cbl_label_t *label );
210
211 void
212 parser_enter_section( struct cbl_label_t *label );
213 void
214 parser_leave_section( struct cbl_label_t *label );
215
216 void
217 parser_perform( struct cbl_label_t *label, bool suppress_nexting=false );
218
219 void
220 parser_perform_times( struct cbl_label_t *label, cbl_refer_t count );
221
222 void
223 parser_perform_start( struct cbl_perform_tgt_t *tgt );
224
225 void
226 parser_perform_conditional( struct cbl_perform_tgt_t *tgt );
227
228 void
229 parser_perform_conditional_end( struct cbl_perform_tgt_t *tgt );
230
231 /*
232 * To perform once (not a loop) N is NULL because the user didn't provide a count.
233 * tgt->to is NULL if the PERFORM statement has no THRU phrase.
234 * For an in-line loop body, tgt->from.type == LblLoop, and tgt->to is NULL.
235 */
236 void
237 parser_perform( const cbl_perform_tgt_t *tgt, cbl_refer_t N );
238
239 /*
240 * A simple UNTIL loop uses 1 varys element. For VARY loops, the
241 * VARY/AFTER phrases appear in varys in the same order as in the
242 * COBOL text.
243 */
244
245 // Either parser_perform_until() or parser_perform_inline_times() must appear
246 // after a parser_perform_start()
247 void
248 parser_perform_until( struct cbl_perform_tgt_t *tgt,
249 bool test_before,
250 size_t nvary,
251 struct cbl_perform_vary_t *varys );
252
253 void
254 parser_perform_inline_times(struct cbl_perform_tgt_t *tgt,
255 struct cbl_refer_t count );
256
257 void
258 parser_see_stop_run( struct cbl_refer_t exit_status, const char name[] );
259
260 void
261 parser_program_hierarchy( const struct cbl_prog_hier_t& hier );
262 void
263 parser_end_program(const char *name=NULL);
264
265 void parser_sleep(const cbl_refer_t &seconds);
266
267 void parser_exit( const cbl_refer_t& refer, ec_type_t = ec_none_e );
268 void parser_exit_section(void);
269 void parser_exit_paragraph(void);
270 void parser_exit_perform( struct cbl_perform_tgt_t *tgt, bool cycle );
271 void parser_exit_program(void); // exits back to COBOL only, else continue
272
273 void
274 parser_exhibit( bool changed, bool named,
275 const std::vector<cbl_refer_t> &args );
276 void
277 parser_display( const struct cbl_special_name_t *upon,
278 const std::vector<cbl_refer_t> &args,
279 bool advance = DISPLAY_ADVANCE,
280 const cbl_label_t *not_error = nullptr,
281 const cbl_label_t *compute_error = nullptr );
282
283 void parser_display_field(cbl_field_t *fld);
284
285 void parser_display_literal(const char *literal,
286 bool advance = DISPLAY_ADVANCE);
287
288 void
289 parser_assign( size_t nC, cbl_num_result_t *C,
290 struct cbl_refer_t from,
291 cbl_label_t *on_error,
292 cbl_label_t *not_error,
293 cbl_label_t *compute_error );
294
295 void parser_move(struct cbl_refer_t to,
296 struct cbl_refer_t from,
297 cbl_round_t rounded=truncation_e,
298 bool skip_fill_from = false);
299
300 void parser_move( size_t ntgt, cbl_refer_t *tgts,
301 cbl_refer_t src, cbl_round_t rounded=truncation_e );
302
303 void parser_initialize_table( size_t ntgt, cbl_refer_t src,
304 size_t nspan, const cbl_bytespan_t spans[],
305 size_t table, // symbol table index
306 size_t ntbl, const cbl_subtable_t tbls[] );
307
308 void parser_set_pointers( size_t ntgt, cbl_refer_t *tgts, cbl_refer_t src );
309
310 void
311 parser_symbol_add(struct cbl_field_t *field);
312
313 void
314 parser_initialize(const cbl_refer_t& refer, bool like_parser_symbol_add=false);
315
316 void
317 parser_initialize_programs(size_t nprog, const struct cbl_refer_t *progs);
318
319 void
320 parser_label_label( struct cbl_label_t *label );
321
322 void
323 parser_label_goto( struct cbl_label_t *label );
324
325 void
326 parser_goto( cbl_refer_t value, size_t narg, cbl_label_t * const labels[] );
327
328 void
329 parser_alter( cbl_perform_tgt_t *tgt );
330
331 void
332 parser_set_conditional88( const cbl_refer_t& tgt, bool which_way );
333 void
334 parser_set_numeric(struct cbl_field_t *tgt, ssize_t value);
335
336 void
337 parser_field_attr_set( cbl_field_t *tgt, cbl_field_attr_t attr, bool on_off = true );
338
339 void
340 parser_file_add(struct cbl_file_t *file);
341
342 void
343 parser_file_open( struct cbl_file_t *file, int mode_char );
344 void
345 parser_file_open( size_t n, struct cbl_file_t *files[], int mode_char );
346
347 void
348 parser_file_close( struct cbl_file_t *file, file_close_how_t how = file_close_no_how_e);
349
350 void
351 parser_file_read( struct cbl_file_t *file,
352 struct cbl_refer_t buffer,
353 int where );
354
355 void
356 parser_file_start( struct cbl_file_t *file, relop_t op, int flk,
357 cbl_refer_t = cbl_refer_t() );
358
359 /*
360 * Write *field* to *file*. *after* is a bool where false
361 * means BEFORE. *nlines* is the number of lines, frequently
362 * FldLiteralN. To indicate PAGE, nlines is the literal "PAGE", with
363 * quoted_e off.
364 *
365 * According to the 2014 standard, the lack of an ADVANCING clause implies
366 * AFTER ADVANCING 1 LINE. *nlines* is be zero to write a line without
367 * prepending or appending newlines. See section 14.9.47.1 paragraph 22)
368 *
369 * At present, we don't have enough information to implement PAGE
370 * correctly, because we don't know the page size (in lines) of the
371 * output device. Rather than doing nothing, we issue a 0x0C form feed
372 * character.
373 */
374 void
375 parser_file_write( cbl_file_t *file,
376 cbl_field_t *source,
377 bool after,
378 cbl_refer_t& nlines,
379 bool sequentially);
380
381 void
382 parser_file_rewrite( cbl_file_t *file, cbl_field_t *field,
383 bool sequentially );
384
385 void
386 parser_file_delete( cbl_file_t *file, bool sequentially );
387
388 #if condition_lists
389 struct cbl_conditional_t {
390 cbl_field_t *tgt;
391 cbl_refer_t& lhs;
392 unsigned int op;
393 cbl_refer_t& rhs;
394 };
395 #endif
396
397 void
398 parser_lsearch_start( cbl_label_t *name,
399 cbl_field_t *table,
400 cbl_field_t *index,
401 cbl_field_t *varying );
402
403 void parser_lsearch_conditional(cbl_label_t * name);
404 void parser_bsearch_conditional(cbl_label_t * name);
405
406 void parser_lsearch_when( cbl_label_t *name, cbl_field_t *conditional );
407 void
408 parser_bsearch_when(cbl_label_t *name,
409 cbl_refer_t key,
410 cbl_refer_t sarg,
411 bool ascending);
412
413 void parser_lsearch_end( cbl_label_t *name );
414 void parser_bsearch_end( cbl_label_t *name );
415
416 void
417 parser_bsearch_start( cbl_label_t *name, cbl_field_t *tgt );
418
419 void
420 parser_sort(cbl_refer_t table,
421 bool duplicates,
422 cbl_alphabet_t *alphabet,
423 const std::vector<cbl_key_t>& keys );
424 void
425 parser_file_sort( cbl_file_t *file,
426 bool duplicates,
427 cbl_alphabet_t *alphabet,
428 const std::vector<cbl_key_t>& keys,
429 size_t ninput,
430 cbl_file_t **inputs,
431 size_t noutput,
432 cbl_file_t **outputs,
433 cbl_perform_tgt_t *in_proc,
434 cbl_perform_tgt_t *out_proc );
435 void
436 parser_file_merge( cbl_file_t *file,
437 cbl_alphabet_t *alphabet,
438 const std::vector<cbl_key_t>& keys,
439 size_t ninput,
440 cbl_file_t **inputs,
441 size_t noutput,
442 cbl_file_t **outputs,
443 cbl_perform_tgt_t *out_proc );
444
445 void
446 parser_release( cbl_field_t *record_area );
447
448 void
449 parser_exception_file( cbl_field_t *tgt, cbl_file_t* file = NULL );
450
451 void
452 parser_module_name( cbl_field_t *tgt, module_type_t type );
453
454 void
455 parser_intrinsic_numval_c( cbl_field_t *f,
456 cbl_refer_t& input,
457 bool locale,
458 cbl_refer_t& currency,
459 bool anycases,
460 bool test_numval_c = false);
461
462 void
463 parser_intrinsic_subst( cbl_field_t *f,
464 const cbl_refer_t& ref1,
465 size_t argc,
466 cbl_substitute_t * argv );
467
468 void
469 parser_intrinsic_callv( cbl_field_t *f,
470 const char name[],
471 size_t argc,
472 cbl_refer_t * argv );
473
474 void
475 parser_intrinsic_call_0( cbl_field_t *tgt,
476 const char name[] );
477 void
478 parser_intrinsic_call_1( cbl_field_t *tgt,
479 const char name[],
480 cbl_refer_t& ref1 );
481 void
482 parser_intrinsic_call_2( cbl_field_t *tgt,
483 const char name[],
484 cbl_refer_t& ref1,
485 cbl_refer_t& ref2 );
486 void
487 parser_intrinsic_call_3( cbl_field_t *tgt,
488 const char name[],
489 cbl_refer_t& ref1,
490 cbl_refer_t& ref2,
491 cbl_refer_t& ref3 );
492 void
493 parser_intrinsic_call_4( cbl_field_t *tgt,
494 const char name[],
495 cbl_refer_t& ref1,
496 cbl_refer_t& ref2,
497 cbl_refer_t& ref3,
498 cbl_refer_t& ref4 );
499
500 void
501 parser_string_overflow( cbl_label_t *name );
502 void
503 parser_string_overflow_end( cbl_label_t *name );
504
505 void
506 parser_string(const cbl_refer_t& tgt,
507 const cbl_refer_t& pointer,
508 size_t nsource,
509 cbl_string_src_t *sources,
510 cbl_label_t *overflow,
511 cbl_label_t *not_overflow );
512
513 void
514 parser_unstring( cbl_refer_t src,
515 size_t ndelimited,
516 cbl_refer_t *delimiteds,
517 // into
518 size_t noutput,
519 cbl_refer_t *outputs,
520 cbl_refer_t *delimiters,
521 cbl_refer_t *counts,
522 cbl_refer_t pointer,
523 cbl_refer_t tally,
524 cbl_label_t *overflow,
525 cbl_label_t *not_overflow );
526
527 void parser_return_start( cbl_file_t *file, cbl_refer_t into );
528 void parser_return_atend( cbl_file_t *file );
529 void parser_return_notatend( cbl_file_t *file );
530 void parser_return_finish( cbl_file_t *file );
531
532 struct cbl_exception_file;
533
534 void parser_exception_raise(ec_type_t ec);
535
536 void parser_call_exception( cbl_label_t *name );
537 void parser_call_exception_end( cbl_label_t *name );
538
539 //void parser_stash_exceptions(const cbl_enabled_exceptions_array_t *enabled);
540
541 void parser_match_exception(cbl_field_t *index);
542 void parser_check_fatal_exception();
543 void parser_clear_exception();
544 void parser_push_exception();
545 void parser_pop_exception();
546
547 void parser_call_targets_dump();
548 size_t parser_call_target_update( size_t caller,
549 const char extant[],
550 const char mangled_tgt[] );
551
552 void parser_file_stash( struct cbl_file_t *file );
553
554 void parser_call( cbl_refer_t name,
555 cbl_refer_t returning,
556 size_t narg, cbl_ffi_arg_t args[],
557 cbl_label_t *except,
558 cbl_label_t *not_except,
559 bool is_function);
560
561 void parser_entry_activate( size_t iprog, const cbl_label_t *declarative );
562
563 void parser_entry( cbl_field_t *name,
564 size_t narg = 0, cbl_ffi_arg_t args[] = NULL);
565
566 bool is_ascending_key(const cbl_refer_t& key);
567
568 void register_main_switch(const char *main_string);
569
570 tree parser_cast_long(tree N);
571 void parser_print_long(tree N);
572 void parser_print_long(const char *fmt, tree N);
573 void parser_print_long(long N);
574 void parser_print_long(const char *fmt, long N); // fmt needs to have a %ls in it
575 void parser_print_string(const char *ach);
576 void parser_print_string(const char *fmt, const char *ach); // fmt needs to have a %s in it
577 void parser_set_statement(const char *statement);
578 void parser_exception_clear();
579
580 void parser_init_list_size(int count_of_variables);
581 void parser_init_list_element(cbl_field_t *field);
582 void parser_init_list();
583
584 tree file_static_variable(tree type, const char *name);
585
586 void parser_statement_begin( const cbl_name_t name, tree ecs, tree dcls );
587
588 tree parser_compile_ecs( const std::vector<uint64_t>& ecs );
589 tree parser_compile_dcls( const std::vector<uint64_t>& dcls );
590
591 #endif