1 /* 2 Copyright (C) 2001-2012, 2014-2020 Free Software Foundation, Inc. 3 Written by Keisuke Nishida, Roger While, Simon Sobisch, Ron Norman 4 5 This file is part of GnuCOBOL. 6 7 The GnuCOBOL compiler is free software: you can redistribute it 8 and/or modify it under the terms of the GNU General Public License 9 as published by the Free Software Foundation, either version 3 of the 10 License, or (at your option) any later version. 11 12 GnuCOBOL is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with GnuCOBOL. If not, see <https://www.gnu.org/licenses/>. 19 */ 20 21 22 #ifndef CB_TREE_H 23 #define CB_TREE_H 24 25 #define CB_BEFORE cb_int0 26 #define CB_AFTER cb_int1 27 28 #define CB_PREFIX_ATTR "a_" /* Field attribute (cob_field_attr) */ 29 #define CB_PREFIX_BASE "b_" /* Base address (unsigned char *) */ 30 #define CB_PREFIX_CONST "c_" /* Constant or literal (cob_field) */ 31 #define CB_PREFIX_DECIMAL "d_" /* Decimal number (cob_decimal) */ 32 #define CB_PREFIX_DEC_FIELD "kc_" /* Decimal Constant for literal (cob_field) */ 33 #define CB_PREFIX_DEC_CONST "dc_" /* Decimal Constant (cob_decimal) */ 34 #define CB_PREFIX_FIELD "f_" /* Field (cob_field) */ 35 #define CB_PREFIX_SCR_FIELD "fs_" /* Screen field (cob_field) */ 36 #define CB_PREFIX_FILE "h_" /* File (cob_file) */ 37 #define CB_PREFIX_KEYS "k_" /* File keys (cob_file_key []) */ 38 #define CB_PREFIX_LABEL "l_" /* Label */ 39 #define CB_PREFIX_ML_ATTR "ma_" /* JSON/XML GENERATE attribute */ 40 #define CB_PREFIX_ML_TREE "mt_" /* JSON/XML GENERATE tree */ 41 #define CB_PREFIX_PIC "p_" /* PICTURE string */ 42 #define CB_PREFIX_SEQUENCE "s_" /* Collating sequence */ 43 #define CB_PREFIX_STRING "st_" /* String */ 44 #define CB_PREFIX_REPORT "r_" /* Report (cob_report) */ 45 #define CB_PREFIX_REPORT_LINE "rl_" /* Report line (cob_report_line) */ 46 #define CB_PREFIX_REPORT_FIELD "rf_" /* Report field (cob_report_field) */ 47 #define CB_PREFIX_REPORT_SUM "rs_" /* Report SUM (cob_report_sum) */ 48 #define CB_PREFIX_REPORT_CONTROL "rc_" /* Report CONTROL (cob_report_control) */ 49 #define CB_PREFIX_REPORT_REF "rr_" /* Report CONTROL reference (cob_report_control_ref) */ 50 #define CB_PREFIX_REPORT_SUM_CTR "rsc_" /* Report SUM COUNTER */ 51 52 #define CB_CALL_BY_REFERENCE 1 53 #define CB_CALL_BY_CONTENT 2 54 #define CB_CALL_BY_VALUE 3 55 56 #define CB_SIZE_AUTO 0 57 #define CB_SIZE_1 1 58 #define CB_SIZE_2 2 59 #define CB_SIZE_4 3 60 #define CB_SIZE_8 4 61 #define CB_SIZE_UNSIGNED 8 62 63 /* Hash values */ 64 /* Power of 2 - see hash function in tree.c */ 65 #define CB_WORD_HASH_SIZE (1U << 11) 66 #define CB_WORD_HASH_MASK (CB_WORD_HASH_SIZE - 1U) 67 68 /* Basic tree tag */ 69 enum cb_tag { 70 /* Primitives */ 71 CB_TAG_CONST = 0, /* 0 Constant value */ 72 CB_TAG_INTEGER, /* 1 Integer constant */ 73 CB_TAG_STRING, /* 2 String constant */ 74 CB_TAG_ALPHABET_NAME, /* 3 Alphabet-name */ 75 CB_TAG_CLASS_NAME, /* 4 Class-name */ 76 CB_TAG_LOCALE_NAME, /* 5 Locale-name */ 77 CB_TAG_SYSTEM_NAME, /* 6 System-name */ 78 CB_TAG_LITERAL, /* 7 Numeric/alphanumeric literal */ 79 CB_TAG_DECIMAL, /* 8 Decimal number */ 80 CB_TAG_FIELD, /* 9 User-defined variable */ 81 CB_TAG_FILE, /* 10 File description */ 82 CB_TAG_REPORT, /* 11 Report description */ 83 CB_TAG_CD, /* 12 Communication description */ 84 /* Expressions */ 85 CB_TAG_REFERENCE, /* 13 Reference to a field, file, or label */ 86 CB_TAG_BINARY_OP, /* 14 Binary operation */ 87 CB_TAG_FUNCALL, /* 15 Run-time function call */ 88 CB_TAG_CAST, /* 16 Type cast */ 89 CB_TAG_INTRINSIC, /* 17 Intrinsic function */ 90 /* Statements */ 91 CB_TAG_LABEL, /* 18 Label statement */ 92 CB_TAG_ASSIGN, /* 19 Assignment statement */ 93 CB_TAG_INITIALIZE, /* 20 INITIALIZE statement */ 94 CB_TAG_SEARCH, /* 21 SEARCH statement */ 95 CB_TAG_CALL, /* 22 CALL statement */ 96 CB_TAG_GOTO, /* 23 GO TO statement */ 97 CB_TAG_IF, /* 24 IF statement / WHEN clause / PRESENT WHEN clause */ 98 CB_TAG_PERFORM, /* 25 PERFORM statement */ 99 CB_TAG_STATEMENT, /* 26 General statement */ 100 CB_TAG_CONTINUE, /* 27 CONTINUE statement */ 101 CB_TAG_CANCEL, /* 28 CANCEL statement */ 102 CB_TAG_ALTER, /* 29 ALTER statement */ 103 CB_TAG_SET_ATTR, /* 30 SET ATTRIBUTE statement */ 104 /* Miscellaneous */ 105 CB_TAG_PERFORM_VARYING, /* 31 PERFORM VARYING parameter */ 106 CB_TAG_PICTURE, /* 32 PICTURE clause */ 107 CB_TAG_LIST, /* 33 List */ 108 CB_TAG_DIRECT, /* 34 Code output or comment */ 109 CB_TAG_DEBUG, /* 35 Debug item set */ 110 CB_TAG_DEBUG_CALL, /* 36 Debug callback */ 111 CB_TAG_PROGRAM, /* 37 Program */ 112 CB_TAG_PROTOTYPE, /* 38 Prototype */ 113 CB_TAG_DECIMAL_LITERAL, /* 39 Decimal Literal */ 114 CB_TAG_REPORT_LINE, /* 40 Report line description */ 115 CB_TAG_ML_SUPPRESS, /* 41 JSON/XML GENERATE SUPPRESS clause */ 116 CB_TAG_ML_TREE, /* 42 JSON/XML GENERATE output tree */ 117 CB_TAG_ML_SUPPRESS_CHECKS /* 43 JSON/XML GENERATE SUPPRESS checks */ 118 /* When adding a new entry, please remember to add it to 119 cobc_enum_explain as well. */ 120 }; 121 122 /* Alphabet target */ 123 #define CB_ALPHABET_ALPHANUMERIC 0 124 #define CB_ALPHABET_NATIONAL 1 125 126 /* Alphabet type */ 127 #define CB_ALPHABET_NATIVE 0 128 #define CB_ALPHABET_ASCII 1 129 #define CB_ALPHABET_EBCDIC 2 130 #define CB_ALPHABET_CUSTOM 3 131 #define CB_ALPHABET_LOCALE 4 132 #define CB_ALPHABET_UTF_8 5 133 #define CB_ALPHABET_UTF_16 6 134 #define CB_ALPHABET_UCS_4 7 135 136 /* Call convention bits */ 137 /* Bit number Meaning Value */ 138 /* 0 currently ignored by GC */ 139 /* Parameter order 0 - Right to left */ 140 /* 1 - Left to right */ 141 /* 1 currently ignored by GC */ 142 /* Stack manipulation 0 - Caller removes params */ 143 /* 1 - Callee removes params */ 144 /* 2 RETURN-CODE update 0 - Updated */ 145 /* 1 - Not updated */ 146 /* 3 Linking behaviour 0 - Normal linking */ 147 /* 1 - Static CALL linking */ 148 /* 4 currently ignored by GC + MF */ 149 /* OS/2 Optlink 0 - ?? */ 150 /* 1 - ?? */ 151 /* 5 currently ignored by GC + MF */ 152 /* Thunked to 16 bit 0 - No thunk */ 153 /* 1 - Thunk */ 154 /* 6 GC: works both with static/dynamic calls */ 155 /* MF: this has his has no effect on dynamic calls */ 156 /* STDCALL convention 0 - CDECL */ 157 /* 1 - STDCALL */ 158 /* 7 currently ignored by GC + MF */ 159 /* 8 currently ignored by GC */ 160 /* parameter-count for individual entry points 0 - checked */ 161 /* 1 - not checked */ 162 /* 9 currently ignored by GC */ 163 /* case of call + program names 0 - disregarded (depending on compile time flags) */ 164 /* 1 - regarded */ 165 /* 10 currently ignored by GC */ 166 /* RETURN-CODE storage 0 - passed as return value */ 167 /* 1 - passed in the first parameter */ 168 /* 11-14 currently ignored by GC+MF */ 169 /* 15 GC: enabling COBOL parameter handling for external callers */ 170 /* currently ignored by MF */ 171 /* 0 - external callers don't set cob_call_params */ 172 /* 1 - external callers set cob_call_params - standard (!)*/ 173 174 #define CB_CONV_L_TO_R (1 << 0) 175 #define CB_CONV_CALLEE_STACK (1 << 1) 176 #define CB_CONV_NO_RET_UPD (1 << 2) 177 #define CB_CONV_STATIC_LINK (1 << 3) 178 #define CB_CONV_OPT_LINK (1 << 4) 179 #define CB_CONV_THUNK_16 (1 << 5) 180 #define CB_CONV_STDCALL (1 << 6) 181 #define CB_CONV_COBOL (1 << 15) 182 #define CB_CONV_C (0) 183 #define CB_CONV_PASCAL (CB_CONV_L_TO_R | CB_CONV_CALLEE_STACK) 184 185 /* System category */ 186 enum cb_system_name_category { 187 CB_DEVICE_NAME = 0, 188 CB_SWITCH_NAME, 189 CB_FEATURE_NAME, 190 CB_CALL_CONVENTION_NAME, 191 CB_CODE_NAME, 192 CB_COMPUTER_NAME, 193 CB_EXTERNAL_LOCALE_NAME, 194 CB_LIBRARY_NAME, 195 CB_TEXT_NAME 196 }; 197 198 /* Mnemonic defines */ 199 /* Devices */ 200 #define CB_DEVICE_SYSIN 0 201 #define CB_DEVICE_SYSOUT 1 202 #define CB_DEVICE_SYSERR 2 203 #define CB_DEVICE_CONSOLE 3 204 #define CB_DEVICE_PRINTER 4 205 #define CB_DEVICE_SYSPCH 5 206 /* Switches (max. must match COB_SWITCH_MAX) */ 207 #define CB_SWITCH_0 0 208 #define CB_SWITCH_1 1 209 #define CB_SWITCH_2 2 210 #define CB_SWITCH_3 3 211 #define CB_SWITCH_4 4 212 #define CB_SWITCH_5 5 213 #define CB_SWITCH_6 6 214 #define CB_SWITCH_7 7 215 #define CB_SWITCH_8 8 216 #define CB_SWITCH_9 9 217 #define CB_SWITCH_10 10 218 #define CB_SWITCH_11 11 219 #define CB_SWITCH_12 12 220 #define CB_SWITCH_13 13 221 #define CB_SWITCH_14 14 222 #define CB_SWITCH_15 15 223 #define CB_SWITCH_16 16 224 #define CB_SWITCH_17 17 225 #define CB_SWITCH_18 18 226 #define CB_SWITCH_19 19 227 #define CB_SWITCH_20 20 228 #define CB_SWITCH_21 21 229 #define CB_SWITCH_22 22 230 #define CB_SWITCH_23 23 231 #define CB_SWITCH_24 24 232 #define CB_SWITCH_25 25 233 #define CB_SWITCH_26 26 234 #define CB_SWITCH_27 27 235 #define CB_SWITCH_28 28 236 #define CB_SWITCH_29 29 237 #define CB_SWITCH_30 30 238 #define CB_SWITCH_31 31 239 #define CB_SWITCH_32 32 240 #define CB_SWITCH_33 33 241 #define CB_SWITCH_34 34 242 #define CB_SWITCH_35 35 243 #define CB_SWITCH_36 36 244 /* Features */ 245 #define CB_FEATURE_FORMFEED 0 246 #define CB_FEATURE_CONVENTION 1 247 #define CB_FEATURE_C01 2 248 #define CB_FEATURE_C02 3 249 #define CB_FEATURE_C03 4 250 #define CB_FEATURE_C04 5 251 #define CB_FEATURE_C05 6 252 #define CB_FEATURE_C06 7 253 #define CB_FEATURE_C07 8 254 #define CB_FEATURE_C08 9 255 #define CB_FEATURE_C09 10 256 #define CB_FEATURE_C10 11 257 #define CB_FEATURE_C11 12 258 #define CB_FEATURE_C12 13 259 260 261 /* Class category */ 262 enum cb_class { 263 CB_CLASS_UNKNOWN = 0, /* 0 */ 264 CB_CLASS_ALPHABETIC, /* 1 */ 265 CB_CLASS_ALPHANUMERIC, /* 2 */ 266 CB_CLASS_BOOLEAN, /* 3 */ 267 CB_CLASS_INDEX, /* 4 */ 268 CB_CLASS_NATIONAL, /* 5 */ 269 CB_CLASS_NUMERIC, /* 6 */ 270 CB_CLASS_OBJECT, /* 7 */ 271 CB_CLASS_POINTER /* 8 */ 272 }; 273 274 /* Category */ 275 enum cb_category { 276 CB_CATEGORY_UNKNOWN = 0, /* 0 */ 277 CB_CATEGORY_ALPHABETIC, /* 1 */ 278 CB_CATEGORY_ALPHANUMERIC, /* 2 */ 279 CB_CATEGORY_ALPHANUMERIC_EDITED, /* 3 */ 280 CB_CATEGORY_BOOLEAN, /* 4 */ 281 CB_CATEGORY_INDEX, /* 5 */ 282 CB_CATEGORY_NATIONAL, /* 6 */ 283 CB_CATEGORY_NATIONAL_EDITED, /* 7 */ 284 CB_CATEGORY_NUMERIC, /* 8 */ 285 CB_CATEGORY_NUMERIC_EDITED, /* 9 */ 286 CB_CATEGORY_OBJECT_REFERENCE, /* 10 */ 287 CB_CATEGORY_DATA_POINTER, /* 11 */ 288 CB_CATEGORY_PROGRAM_POINTER, /* 12 */ 289 CB_CATEGORY_FLOATING_EDITED, /* 13 */ 290 CB_CATEGORY_ERROR /* 14, always last */ 291 }; 292 293 /* Storage sections */ 294 enum cb_storage { 295 CB_STORAGE_CONSTANT = 0, /* Constants */ 296 CB_STORAGE_FILE, /* FILE SECTION */ 297 CB_STORAGE_WORKING, /* WORKING-STORAGE SECTION */ 298 CB_STORAGE_LOCAL, /* LOCAL-STORAGE SECTION */ 299 CB_STORAGE_LINKAGE, /* LINKAGE SECTION */ 300 CB_STORAGE_SCREEN, /* SCREEN SECTION */ 301 CB_STORAGE_REPORT, /* REPORT SECTION */ 302 CB_STORAGE_COMMUNICATION /* COMMUNICATION SECTION */ 303 }; 304 305 /* Field types */ 306 enum cb_usage { 307 CB_USAGE_BINARY = 0, /* 0 */ 308 CB_USAGE_BIT, /* 1 */ 309 CB_USAGE_COMP_5, /* 2 */ 310 CB_USAGE_COMP_X, /* 3 */ 311 CB_USAGE_DISPLAY, /* 4 */ 312 CB_USAGE_FLOAT, /* 5 */ 313 CB_USAGE_DOUBLE, /* 6 */ 314 CB_USAGE_INDEX, /* 7 */ 315 CB_USAGE_NATIONAL, /* 8 */ 316 CB_USAGE_OBJECT, /* 9 */ 317 CB_USAGE_PACKED, /* 10 */ 318 CB_USAGE_POINTER, /* 11 */ 319 CB_USAGE_LENGTH, /* 12 */ 320 CB_USAGE_PROGRAM_POINTER, /* 13 */ 321 CB_USAGE_UNSIGNED_CHAR, /* 14 */ 322 CB_USAGE_SIGNED_CHAR, /* 15 */ 323 CB_USAGE_UNSIGNED_SHORT, /* 16 */ 324 CB_USAGE_SIGNED_SHORT, /* 17 */ 325 CB_USAGE_UNSIGNED_INT, /* 18 */ 326 CB_USAGE_SIGNED_INT, /* 19 */ 327 CB_USAGE_UNSIGNED_LONG, /* 20 */ 328 CB_USAGE_SIGNED_LONG, /* 21 */ 329 CB_USAGE_COMP_6, /* 22 */ 330 CB_USAGE_FP_DEC64, /* 23 */ 331 CB_USAGE_FP_DEC128, /* 24 */ 332 CB_USAGE_FP_BIN32, /* 25 */ 333 CB_USAGE_FP_BIN64, /* 26 */ 334 CB_USAGE_FP_BIN128, /* 27 */ 335 CB_USAGE_LONG_DOUBLE, /* 28 */ 336 CB_USAGE_HNDL, /* 29 */ 337 CB_USAGE_HNDL_WINDOW, /* 30 */ 338 CB_USAGE_HNDL_SUBWINDOW, /* 31 */ 339 CB_USAGE_HNDL_FONT, /* 32 */ 340 CB_USAGE_HNDL_THREAD, /* 33 */ 341 CB_USAGE_HNDL_MENU, /* 34 */ 342 CB_USAGE_HNDL_VARIANT, /* 35 */ 343 CB_USAGE_HNDL_LM, /* 36 */ 344 CB_USAGE_COMP_N, /* 37 */ 345 CB_USAGE_ERROR /* 38, always last */ 346 }; 347 348 349 /* Cast type */ 350 enum cb_cast_type { 351 CB_CAST_INTEGER = 0, /* 0 */ 352 CB_CAST_LONG_INT, /* 1 */ 353 CB_CAST_ADDRESS, /* 2 */ 354 CB_CAST_ADDR_OF_ADDR, /* 3 */ 355 CB_CAST_LENGTH, /* 4 */ 356 CB_CAST_PROGRAM_POINTER /* 5 */ 357 }; 358 359 /* Intrinsic functions */ 360 enum cb_intr_enum { 361 CB_INTR_ABS = 1, 362 CB_INTR_ACOS, 363 CB_INTR_ANNUITY, 364 CB_INTR_ASIN, 365 CB_INTR_ATAN, 366 CB_INTR_BOOLEAN_OF_INTEGER, 367 CB_INTR_BYTE_LENGTH, 368 CB_INTR_CHAR, 369 CB_INTR_CHAR_NATIONAL, 370 CB_INTR_COMBINED_DATETIME, 371 CB_INTR_CONCATENATE, 372 CB_INTR_CONTENT_LENGTH, 373 CB_INTR_CONTENT_OF, 374 CB_INTR_COS, 375 CB_INTR_CURRENCY_SYMBOL, 376 CB_INTR_CURRENT_DATE, 377 CB_INTR_DATE_OF_INTEGER, 378 CB_INTR_DATE_TO_YYYYMMDD, 379 CB_INTR_DAY_OF_INTEGER, 380 CB_INTR_DAY_TO_YYYYDDD, 381 CB_INTR_DISPLAY_OF, 382 CB_INTR_E, 383 CB_INTR_EXCEPTION_FILE, 384 CB_INTR_EXCEPTION_FILE_N, 385 CB_INTR_EXCEPTION_LOCATION, 386 CB_INTR_EXCEPTION_LOCATION_N, 387 CB_INTR_EXCEPTION_STATEMENT, 388 CB_INTR_EXCEPTION_STATUS, 389 CB_INTR_EXP, 390 CB_INTR_EXP10, 391 CB_INTR_FACTORIAL, 392 CB_INTR_FORMATTED_CURRENT_DATE, 393 CB_INTR_FORMATTED_DATE, 394 CB_INTR_FORMATTED_DATETIME, 395 CB_INTR_FORMATTED_TIME, 396 CB_INTR_FRACTION_PART, 397 CB_INTR_HIGHEST_ALGEBRAIC, 398 CB_INTR_INTEGER, 399 CB_INTR_INTEGER_OF_BOOLEAN, 400 CB_INTR_INTEGER_OF_DATE, 401 CB_INTR_INTEGER_OF_DAY, 402 CB_INTR_INTEGER_OF_FORMATTED_DATE, 403 CB_INTR_INTEGER_PART, 404 CB_INTR_LENGTH, 405 CB_INTR_LOCALE_COMPARE, 406 CB_INTR_LOCALE_DATE, 407 CB_INTR_LOCALE_TIME, 408 CB_INTR_LOCALE_TIME_FROM_SECS, 409 CB_INTR_LOG, 410 CB_INTR_LOG10, 411 CB_INTR_LOWER_CASE, 412 CB_INTR_LOWEST_ALGEBRAIC, 413 CB_INTR_MAX, 414 CB_INTR_MEAN, 415 CB_INTR_MEDIAN, 416 CB_INTR_MIDRANGE, 417 CB_INTR_MIN, 418 CB_INTR_MOD, 419 CB_INTR_MODULE_CALLER_ID, 420 CB_INTR_MODULE_DATE, 421 CB_INTR_MODULE_FORMATTED_DATE, 422 CB_INTR_MODULE_ID, 423 CB_INTR_MODULE_PATH, 424 CB_INTR_MODULE_SOURCE, 425 CB_INTR_MODULE_TIME, 426 CB_INTR_MON_DECIMAL_POINT, 427 CB_INTR_MON_THOUSANDS_SEP, 428 CB_INTR_NATIONAL_OF, 429 CB_INTR_NUM_DECIMAL_POINT, 430 CB_INTR_NUM_THOUSANDS_SEP, 431 CB_INTR_NUMVAL, 432 CB_INTR_NUMVAL_C, 433 CB_INTR_NUMVAL_F, 434 CB_INTR_ORD, 435 CB_INTR_ORD_MAX, 436 CB_INTR_ORD_MIN, 437 CB_INTR_PI, 438 CB_INTR_PRESENT_VALUE, 439 CB_INTR_RANDOM, 440 CB_INTR_RANGE, 441 CB_INTR_REM, 442 CB_INTR_REVERSE, 443 CB_INTR_SECONDS_FROM_FORMATTED_TIME, 444 CB_INTR_SECONDS_PAST_MIDNIGHT, 445 CB_INTR_SIGN, 446 CB_INTR_SIN, 447 CB_INTR_SQRT, 448 CB_INTR_STANDARD_COMPARE, 449 CB_INTR_STANDARD_DEVIATION, 450 CB_INTR_STORED_CHAR_LENGTH, 451 CB_INTR_SUBSTITUTE, 452 CB_INTR_SUBSTITUTE_CASE, 453 CB_INTR_SUM, 454 CB_INTR_TAN, 455 CB_INTR_TEST_DATE_YYYYMMDD, 456 CB_INTR_TEST_DAY_YYYYDDD, 457 CB_INTR_TEST_FORMATTED_DATETIME, 458 CB_INTR_TEST_NUMVAL, 459 CB_INTR_TEST_NUMVAL_C, 460 CB_INTR_TEST_NUMVAL_F, 461 CB_INTR_TRIM, 462 CB_INTR_UPPER_CASE, 463 CB_INTR_USER_FUNCTION, 464 CB_INTR_VARIANCE, 465 CB_INTR_WHEN_COMPILED, 466 CB_INTR_YEAR_TO_YYYY 467 }; 468 469 /* Perform type */ 470 enum cb_perform_type { 471 CB_PERFORM_EXIT = 0, 472 CB_PERFORM_ONCE, 473 CB_PERFORM_TIMES, 474 CB_PERFORM_UNTIL, 475 CB_PERFORM_FOREVER 476 }; 477 478 /* Index type */ 479 enum cb_index_type { 480 CB_NORMAL_INDEX = 0, 481 CB_INT_INDEX, 482 CB_STATIC_INT_INDEX 483 }; 484 485 /* Reserved word list structure */ 486 struct cobc_reserved { 487 const char *name; /* Word */ 488 unsigned short nodegen; /* Statement with END-xxx */ 489 unsigned short context_sens; /* Context sensitive */ 490 int token; /* Token */ 491 unsigned int context_set; /* Set context sensitive */ 492 unsigned int context_test; /* Test context sensitive */ 493 }; 494 495 /* Basic common tree structure */ 496 497 struct cb_tree_common { 498 enum cb_tag tag; /* TAG - see below */ 499 enum cb_category category; /* Category */ 500 const char *source_file; /* Source file */ 501 int source_line; /* Line */ 502 int source_column; /* Column */ 503 }; 504 505 /* Define common cb_tree/CB_TREE for following defines */ 506 507 typedef struct cb_tree_common *cb_tree; 508 509 #define CB_TREE(x) ((struct cb_tree_common *) (x)) 510 #define CB_TREE_TAG(x) (CB_TREE (x)->tag) 511 #define CB_TREE_CLASS(x) cb_tree_class (CB_TREE (x)) 512 #define CB_TREE_CATEGORY(x) cb_tree_category (CB_TREE (x)) 513 514 #define CB_VALID_TREE(x) (x && CB_TREE (x) != cb_error_node) 515 #define CB_INVALID_TREE(x) (!(x) || CB_TREE (x) == cb_error_node) 516 517 #ifdef COB_TREE_DEBUG 518 #define CB_TREE_CAST(tg,ty,x) \ 519 ((ty *)cobc_tree_cast_check (x, __FILE__, __LINE__, tg)) 520 #else 521 #define CB_TREE_CAST(tg,ty,x) ((ty *) (x)) 522 #endif 523 524 /* any next */ 525 struct cb_next_elem { 526 struct cb_next_elem *next; 527 }; 528 529 /* FIXME: HAVE_FUNC should be checked via configure and the others be a fallback (note: currently only used in trunk [debug.c]) */ 530 #if defined(NO_HAVE_FUNC) 531 #define CURRENT_FUNCTION "unknown" 532 #elif defined(_MSC_VER) 533 #define CURRENT_FUNCTION __FUNCTION__ 534 #elif defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600)) || defined(__ghs__) 535 #define CURRENT_FUNCTION __PRETTY_FUNCTION__ 536 #elif defined(__DMC__) && (__DMC__ >= 0x810) 537 #define CURRENT_FUNCTION __PRETTY_FUNCTION__ 538 #elif defined(__FUNCSIG__) 539 #define CURRENT_FUNCTION __FUNCSIG__ 540 #elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) || (defined(__IBMCPP__) && (__IBMCPP__ >= 500)) 541 #define CURRENT_FUNCTION __FUNCTION__ 542 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550) 543 #define CURRENT_FUNCTION __FUNC__ 544 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901) 545 #define CURRENT_FUNCTION __func__ 546 #elif defined(__cplusplus) && (__cplusplus >= 201103) 547 #define CURRENT_FUNCTION __func__ 548 #else 549 #define CURRENT_FUNCTION __FILE__ 550 #endif 551 552 /* xref entries */ 553 struct cb_xref_elem { 554 struct cb_xref_elem *next; 555 struct cb_xref_elem *prev; 556 int line; 557 int receive; 558 }; 559 560 struct cb_xref { 561 struct cb_xref_elem *head; 562 struct cb_xref_elem *tail; 563 int amount; 564 int skip; 565 }; 566 567 struct cb_call_elem { 568 struct cb_call_elem *next; 569 char *name; 570 struct cb_xref xref; 571 int is_identifier; 572 int is_system; 573 }; 574 575 struct cb_call_xref { 576 struct cb_call_elem *head; 577 struct cb_call_elem *tail; 578 }; 579 580 /* Constant */ 581 582 struct cb_const { 583 struct cb_tree_common common; /* Common values */ 584 const char *val; /* Constant value */ 585 }; 586 587 #define CB_CONST(x) (CB_TREE_CAST (CB_TAG_CONST, struct cb_const, x)) 588 #define CB_CONST_P(x) (CB_TREE_TAG (x) == CB_TAG_CONST) 589 590 /* Code output or comment */ 591 592 struct cb_direct { 593 struct cb_tree_common common; /* Common values */ 594 const char *line; /* Line redirect */ 595 cob_u32_t flag_is_direct; /* Is directed */ 596 cob_u32_t flag_new_line; /* Need new line */ 597 }; 598 599 #define CB_DIRECT(x) (CB_TREE_CAST (CB_TAG_DIRECT, struct cb_direct, x)) 600 #define CB_DIRECT_P(x) (CB_TREE_TAG (x) == CB_TAG_DIRECT) 601 602 /* DEBUG */ 603 604 struct cb_debug { 605 struct cb_tree_common common; /* Common values */ 606 cb_tree target; /* Target for debug */ 607 const char *value; /* Value for debug */ 608 cb_tree fld; /* Reference */ 609 size_t size; /* Size if relevant */ 610 }; 611 612 #define CB_DEBUG(x) (CB_TREE_CAST (CB_TAG_DEBUG, struct cb_debug, x)) 613 #define CB_DEBUG_P(x) (CB_TREE_TAG (x) == CB_TAG_DEBUG) 614 615 /* DEBUG Callback */ 616 617 struct cb_debug_call { 618 struct cb_tree_common common; /* Common values */ 619 struct cb_label *target; /* Target label */ 620 }; 621 622 #define CB_DEBUG_CALL(x) (CB_TREE_CAST (CB_TAG_DEBUG_CALL, struct cb_debug_call, x)) 623 #define CB_DEBUG_CALL_P(x) (CB_TREE_TAG (x) == CB_TAG_DEBUG_CALL) 624 625 /* Integer */ 626 627 struct cb_integer { 628 struct cb_tree_common common; /* Common values */ 629 int val; /* Integer value */ 630 #ifdef USE_INT_HEX /* Simon: using this increases the struct and we 631 *should* pass the flags as constants in any case... */ 632 unsigned int hexval; /* Output hex value */ 633 #endif 634 }; 635 636 #define CB_INTEGER(x) (CB_TREE_CAST (CB_TAG_INTEGER, struct cb_integer, x)) 637 #define CB_INTEGER_P(x) (CB_TREE_TAG (x) == CB_TAG_INTEGER) 638 639 /* String */ 640 641 struct cb_string { 642 struct cb_tree_common common; /* Common values */ 643 const unsigned char *data; /* Data */ 644 size_t size; /* Data size */ 645 }; 646 647 #define CB_STRING(x) (CB_TREE_CAST (CB_TAG_STRING, struct cb_string, x)) 648 #define CB_STRING_P(x) (CB_TREE_TAG (x) == CB_TAG_STRING) 649 650 /* Alphabet-name */ 651 652 struct cb_alphabet_name { 653 struct cb_tree_common common; /* Common values */ 654 const char *name; /* Original name */ 655 char *cname; /* Name used in C */ 656 cb_tree custom_list; /* Custom ALPHABET / LOCALE reference */ 657 unsigned int alphabet_target; /* ALPHANUMERIC or NATIONAL */ 658 unsigned int alphabet_type; /* ALPHABET type */ 659 int low_val_char; /* LOW-VALUE */ 660 int high_val_char; /* HIGH-VALUE */ 661 int values[256]; /* Collating values */ 662 int alphachr[256]; /* Actual values */ 663 }; 664 665 #define CB_ALPHABET_NAME(x) (CB_TREE_CAST (CB_TAG_ALPHABET_NAME, struct cb_alphabet_name, x)) 666 #define CB_ALPHABET_NAME_P(x) (CB_TREE_TAG (x) == CB_TAG_ALPHABET_NAME) 667 668 /* Class-name */ 669 670 struct cb_class_name { 671 struct cb_tree_common common; /* Common values */ 672 const char *name; /* Original name */ 673 char *cname; /* Name used in C */ 674 cb_tree list; /* List of CLASS definitions */ 675 }; 676 677 #define CB_CLASS_NAME(x) (CB_TREE_CAST (CB_TAG_CLASS_NAME, struct cb_class_name, x)) 678 #define CB_CLASS_NAME_P(x) (CB_TREE_TAG (x) == CB_TAG_CLASS_NAME) 679 680 /* Locale name */ 681 682 struct cb_locale_name { 683 struct cb_tree_common common; /* Common values */ 684 const char *name; /* Original name */ 685 char *cname; /* Name used in C */ 686 cb_tree list; /* List of locale definitions */ 687 }; 688 689 #define CB_LOCALE_NAME(x) (CB_TREE_CAST (CB_TAG_LOCALE_NAME, struct cb_locale_name, x)) 690 #define CB_LOCALE_NAME_P(x) (CB_TREE_TAG (x) == CB_TAG_LOCALE_NAME) 691 692 /* System-name */ 693 694 struct cb_system_name { 695 struct cb_tree_common common; /* Common values */ 696 cb_tree value; /* System value */ 697 enum cb_system_name_category category; /* System category */ 698 int token; /* Device attributes */ 699 }; 700 701 #define CB_SYSTEM_NAME(x) (CB_TREE_CAST (CB_TAG_SYSTEM_NAME, struct cb_system_name, x)) 702 #define CB_SYSTEM_NAME_P(x) (CB_TREE_TAG (x) == CB_TAG_SYSTEM_NAME) 703 704 /* Literal */ 705 706 struct cb_literal { 707 struct cb_tree_common common; /* Common values */ 708 unsigned char *data; /* Literal data */ 709 cob_u32_t size; /* Literal size */ 710 int scale; /* Numeric scale */ 711 cob_u32_t llit; /* 'L' literal */ 712 short sign; /* unsigned: 0 negative: -1 positive: 1 */ 713 short all; /* ALL */ 714 }; 715 716 #define CB_LITERAL(x) (CB_TREE_CAST (CB_TAG_LITERAL, struct cb_literal, x)) 717 #define CB_LITERAL_P(x) (CB_TREE_TAG (x) == CB_TAG_LITERAL) 718 #define CB_NUMERIC_LITERAL_P(x) \ 719 (CB_LITERAL_P (x) && CB_TREE_CATEGORY (x) == CB_CATEGORY_NUMERIC) 720 721 #define CB_ERR_LITMAX 38 722 extern char *literal_for_diagnostic (char *buff, const char *literal_data); 723 724 /* Decimal */ 725 726 struct cb_decimal { 727 struct cb_tree_common common; /* Common values */ 728 unsigned int id; /* ID for this decimal */ 729 }; 730 731 #define CB_DECIMAL(x) (CB_TREE_CAST (CB_TAG_DECIMAL, struct cb_decimal, x)) 732 #define CB_DECIMAL_P(x) (CB_TREE_TAG (x) == CB_TAG_DECIMAL) 733 734 #define CB_DECIMAL_LITERAL(x) (CB_TREE_CAST (CB_TAG_DECIMAL_LITERAL, struct cb_decimal, x)) 735 #define CB_DECIMAL_LITERAL_P(x) (CB_TREE_TAG (x) == CB_TAG_DECIMAL_LITERAL) 736 737 /* Picture */ 738 739 struct cb_picture { 740 struct cb_tree_common common; /* Common values */ 741 char *orig; /* Original picture string */ 742 cob_pic_symbol *str; /* Picture string */ 743 int size; /* Byte size */ 744 int lenstr; /* Length of picture string */ 745 enum cb_category category; /* Field category */ 746 cob_u32_t digits; /* Number of digit places */ 747 int scale; /* 1/10^scale */ 748 #if 0 /* currently unused */ 749 cob_u32_t real_digits; /* Real number of digits */ 750 #endif 751 cob_u32_t have_sign; /* Have 'S' */ 752 unsigned int flag_is_calculated : 1; /* is calculated */ 753 }; 754 755 #define CB_PICTURE(x) (CB_TREE_CAST (CB_TAG_PICTURE, struct cb_picture, x)) 756 #define CB_PICTURE_P(x) (CB_TREE_TAG (x) == CB_TAG_PICTURE) 757 758 /* Key */ 759 760 struct cb_key { 761 cb_tree key; /* KEY */ 762 cb_tree ref; /* Reference used in SEARCH ALL */ 763 cb_tree val; /* Value to be compared in SEARCH ALL */ 764 int dir; /* ASCENDING or DESCENDING */ 765 }; 766 767 /* Field */ 768 769 struct cb_field { 770 struct cb_tree_common common; /* Common values */ 771 const char *name; /* Original name */ 772 const char *ename; /* Externalized name */ 773 cb_tree depending; /* OCCURS ... DEPENDING ON */ 774 cb_tree values; /* VALUE */ 775 cb_tree false_88; /* 88 FALSE clause */ 776 cb_tree index_list; /* INDEXED BY */ 777 cb_tree external_form_identifier; /* target of IDENTIFIED BY 778 (CGI template) */ 779 780 struct cb_field *parent; /* Upper level field (if any) */ 781 struct cb_field *children; /* Top of lower level fields */ 782 struct cb_field *validation; /* First level 88 field (if any) */ 783 struct cb_field *sister; /* Fields at the same level */ 784 struct cb_field *redefines; /* REDEFINES or RENAMES */ 785 struct cb_field *rename_thru; /* RENAMES THRU */ 786 struct cb_field *index_qual; /* INDEXED BY qualifier */ 787 struct cb_file *file; /* FD section file name */ 788 struct cb_cd *cd; /* CD name */ 789 struct cb_key *keys; /* SEARCH key */ 790 struct cb_picture *pic; /* PICTURE */ 791 struct cb_field *vsize; /* Variable size cache */ 792 struct cb_label *debug_section; /* DEBUG section */ 793 struct cb_report *report; /* RD section report name */ 794 795 struct cb_xref xref; /* xref elements */ 796 797 cb_tree screen_line; /* LINE */ 798 cb_tree screen_column; /* COLUMN */ 799 cb_tree screen_from; /* TO and USING */ 800 cb_tree screen_to; /* FROM and USING */ 801 cb_tree screen_foreg; /* FOREGROUND */ 802 cb_tree screen_backg; /* BACKGROUND */ 803 cb_tree screen_prompt; /* PROMPT */ 804 cb_tree report_source; /* SOURCE field */ 805 cb_tree report_from; /* SOURCE field subscripted; so MOVE to report_source */ 806 cb_tree report_sum_counter;/* SUM counter */ 807 cb_tree report_sum_list;/* SUM field(s) */ 808 cb_tree report_sum_upon;/* SUM ... UPON detailname */ 809 cb_tree report_reset; /* RESET ON field */ 810 cb_tree report_control; /* CONTROL identifier */ 811 cb_tree report_when; /* PRESENT WHEN condition */ 812 cb_tree report_column_list;/* List of Column Numbers */ 813 cb_tree external_definition; /* by SAME AS / LIKE data-name or 814 by type-name (points to field) */ 815 cb_tree like_modifier; /* set for LIKE, may contain a length modifier */ 816 817 int id; /* Field id */ 818 int size; /* Field size */ 819 int level; /* Level number */ 820 int memory_size; /* Memory size */ 821 int offset; /* Byte offset from 01 level */ 822 int occurs_min; /* OCCURS <min> */ 823 int occurs_max; /* OCCURS [... TO] <max> */ 824 int indexes; /* Indices count (OCCURS) */ 825 826 int count; /* Reference count */ 827 int mem_offset; /* Memory offset */ 828 int nkeys; /* Number of keys */ 829 int param_num; /* CHAINING param number */ 830 cob_flags_t screen_flag; /* Flags used in SCREEN SECTION */ 831 int report_flag; /* Flags used in REPORT SECTION */ 832 int report_line; /* LINE */ 833 int report_column; /* COLUMN (first value) */ 834 int report_num_col; /* Number of COLUMNs defined */ 835 int report_decl_id; /* Label id of USE FOR REPORTING */ 836 int step_count; /* STEP in REPORT */ 837 int next_group_line;/* NEXT GROUP [PLUS] line */ 838 unsigned int vaddr; /* Variable address cache */ 839 unsigned int odo_level; /* ODO level (0 = no ODO item) 840 could be direct ODO (check via depending) 841 or via subordinate) */ 842 enum cb_index_type index_type; /* Type of generated index */ 843 844 enum cb_storage storage; /* Storage section */ 845 enum cb_usage usage; /* USAGE */ 846 847 /* Flags */ 848 unsigned char flag_base; /* Has memory allocation */ 849 unsigned char flag_external; /* EXTERNAL */ 850 unsigned char flag_local_storage; /* LOCAL storage */ 851 unsigned char flag_is_global; /* Is GLOBAL */ 852 853 unsigned int flag_local : 1; /* Has local scope */ 854 unsigned int flag_occurs : 1; /* OCCURS */ 855 unsigned int flag_sign_clause : 1; /* Any SIGN clause */ 856 unsigned int flag_sign_separate : 1; /* SIGN IS SEPARATE */ 857 unsigned int flag_sign_leading : 1; /* SIGN IS LEADING */ 858 unsigned int flag_blank_zero : 1; /* BLANK WHEN ZERO */ 859 unsigned int flag_justified : 1; /* JUSTIFIED RIGHT */ 860 unsigned int flag_binary_swap : 1; /* Binary byteswap */ 861 862 unsigned int flag_real_binary : 1; /* BINARY-CHAR/SHORT/LONG/DOUBLE */ 863 unsigned int flag_is_pointer : 1; /* Is POINTER */ 864 unsigned int flag_item_78 : 1; /* Is a constant by 78 level, 865 01 CONSTANT or SYMBOLIC CONSTANT */ 866 unsigned int flag_any_length : 1; /* Is ANY LENGTH */ 867 unsigned int flag_item_based : 1; /* Is BASED */ 868 unsigned int flag_is_external_form : 1; /* Is EXTERNAL-FORM */ 869 unsigned int flag_filler : 1; /* Implicit/explicit filler */ 870 unsigned int flag_synchronized : 1; /* SYNCHRONIZED */ 871 872 unsigned int flag_invalid : 1; /* Is broken */ 873 unsigned int flag_field : 1; /* Has been internally cached */ 874 unsigned int flag_chained : 1; /* CHAINING item */ 875 unsigned int flag_anylen_done : 1; /* ANY LENGTH is set up */ 876 unsigned int flag_is_verified : 1; /* Has been verified */ 877 unsigned int flag_is_c_long : 1; /* Is BINARY-C-LONG */ 878 unsigned int flag_is_pdiv_parm : 1; /* Is PROC DIV USING */ 879 unsigned int flag_is_pdiv_opt : 1; /* Is PROC DIV USING OPTIONAL */ 880 881 unsigned int flag_indexed_by : 1; /* INDEXED BY item */ 882 unsigned int flag_local_alloced : 1; /* LOCAL storage is allocated */ 883 unsigned int flag_no_init : 1; /* No initialize unless used */ 884 unsigned int flag_vsize_done : 1; /* Variable size cached */ 885 unsigned int flag_vaddr_done : 1; /* Variable address cached */ 886 unsigned int flag_odo_relative : 1; /* complex-odo: item address depends 887 on size of a different (ODO) item */ 888 unsigned int flag_field_debug : 1; /* DEBUGGING */ 889 unsigned int flag_all_debug : 1; /* DEBUGGING */ 890 891 unsigned int flag_no_field : 1; /* SCREEN/REPORT dummy field */ 892 unsigned int flag_any_numeric : 1; /* Is ANY NUMERIC */ 893 unsigned int flag_is_returning : 1; /* Is RETURNING item */ 894 unsigned int flag_unbounded : 1; /* OCCURS UNBOUNDED */ 895 unsigned int flag_comp_1 : 1; /* Is USAGE COMP-1 */ 896 unsigned int flag_volatile : 1; /* VOLATILE */ 897 unsigned int flag_constant : 1; /* Is 01 AS CONSTANT */ 898 unsigned int flag_internal_constant : 1; /* Is an internally generated CONSTANT */ 899 900 unsigned int flag_internal_register : 1; /* Is an internally generated register */ 901 unsigned int flag_is_typedef : 1; /* TYPEDEF */ 902 }; 903 904 #define CB_FIELD(x) (CB_TREE_CAST (CB_TAG_FIELD, struct cb_field, x)) 905 #define CB_FIELD_P(x) (CB_TREE_TAG (x) == CB_TAG_FIELD) 906 907 #define CB_REF_OR_FIELD_P(x) (CB_REFERENCE_P (x) || CB_FIELD_P (x)) 908 909 #define CB_FIELD_PTR(x) \ 910 (CB_REFERENCE_P (x) ? CB_FIELD (cb_ref (x)) : CB_FIELD (x)) 911 912 /* Index */ 913 914 #define CB_INDEX_OR_HANDLE_P(x) cb_check_index_or_handle_p (x) 915 916 /* Label */ 917 918 struct cb_para_label { 919 struct cb_para_label *next; 920 struct cb_label *para; 921 }; 922 923 struct cb_alter_id { 924 struct cb_alter_id *next; 925 int goto_id; 926 }; 927 928 struct cb_label { 929 struct cb_tree_common common; /* Common values */ 930 const char *name; /* Name */ 931 const char *orig_name; /* Original name */ 932 struct cb_label *section; /* Parent SECTION */ 933 struct cb_label *debug_section; /* DEBUG SECTION */ 934 struct cb_para_label *para_label; /* SECTION Paragraphs */ 935 struct cb_xref xref; /* xref elements */ 936 cb_tree exit_label; /* EXIT label */ 937 struct cb_alter_id *alter_gotos; /* ALTER ids */ 938 int id; /* Unique id */ 939 int section_id; /* SECTION id */ 940 int segment; /* Segment number */ 941 942 unsigned int flag_section : 1; /* Section */ 943 unsigned int flag_entry : 1; /* Entry */ 944 unsigned int flag_begin : 1; /* Begin label */ 945 unsigned int flag_return : 1; /* End label */ 946 unsigned int flag_real_label : 1; /* Is real label */ 947 unsigned int flag_global : 1; /* GLOBAL */ 948 unsigned int flag_declarative_exit : 1; /* Final EXIT */ 949 unsigned int flag_declaratives : 1; /* DECLARATIVES */ 950 951 unsigned int flag_fatal_check : 1; /* Fatal check */ 952 unsigned int flag_dummy_section : 1; /* Dummy MAIN */ 953 unsigned int flag_dummy_paragraph : 1; /* Dummy MAIN */ 954 unsigned int flag_dummy_exit : 1; /* Dummy EXIT */ 955 unsigned int flag_next_sentence : 1; /* NEXT SENTENCE */ 956 unsigned int flag_default_handler : 1; /* Error handler */ 957 unsigned int flag_statement : 1; /* Has statement */ 958 unsigned int flag_first_is_goto : 1; /* 1st is GO TO */ 959 960 unsigned int flag_alter : 1; /* ALTER code */ 961 unsigned int flag_debugging_mode : 1; /* DEBUGGING MODE */ 962 unsigned int flag_is_debug_sect : 1; /* DEBUGGING sect */ 963 unsigned int flag_skip_label : 1; /* Skip label gen */ 964 unsigned int flag_entry_for_goto : 1; /* is ENTRY FOR GO TO */ 965 }; 966 967 #define CB_LABEL(x) (CB_TREE_CAST (CB_TAG_LABEL, struct cb_label, x)) 968 #define CB_LABEL_P(x) (CB_TREE_TAG (x) == CB_TAG_LABEL) 969 970 struct handler_struct { 971 struct cb_label *handler_label; /* Handler label */ 972 struct cb_program *handler_prog; /* Handler program */ 973 }; 974 975 /* File */ 976 977 struct cb_key_component { 978 struct cb_key_component *next; 979 cb_tree component; /* Field which is part of index */ 980 }; 981 982 struct cb_alt_key { 983 struct cb_alt_key *next; /* Pointer to next */ 984 cb_tree key; /* Key item */ 985 cb_tree password; /* Password item */ 986 cb_tree collating_sequence_key; /* COLLATING */ 987 int duplicates; /* DUPLICATES */ 988 int offset; /* Offset from start */ 989 int tf_suppress; /* !0 for SUPPRESS */ 990 int char_suppress; /* character to test for suppress */ 991 struct cb_key_component *component_list; /* List of fields making up key */ 992 }; 993 994 /* How to interpret identifiers in a file's ASSIGN clause */ 995 enum cb_assign_type { 996 CB_ASSIGN_VARIABLE_DEFAULT, /* default to ASSIGN variable, where allowed by implicit-assign-dynamic-var */ 997 CB_ASSIGN_VARIABLE_REQUIRED, /* require ASSIGN variable */ 998 CB_ASSIGN_EXT_FILE_NAME_REQUIRED /* require ASSIGN external-file-name */ 999 }; 1000 1001 struct cb_file { 1002 struct cb_tree_common common; /* Common values */ 1003 const char *name; /* Original name */ 1004 char *cname; /* Name used in C */ 1005 /* SELECT */ 1006 cb_tree assign; /* ASSIGN */ 1007 cb_tree file_status; /* FILE STATUS */ 1008 cb_tree sharing; /* SHARING */ 1009 cb_tree key; /* Primary RECORD KEY */ 1010 cb_tree password; /* Password item for file or primary key */ 1011 struct cb_key_component *component_list; /* List of fields making up primary key */ 1012 struct cb_alt_key *alt_key_list; /* ALTERNATE RECORD KEY */ 1013 cb_tree collating_sequence_key; /* COLLATING */ 1014 cb_tree collating_sequence; /* COLLATING */ 1015 cb_tree collating_sequence_n; /* COLLATING FOR NATIONAL*/ 1016 cb_tree collating_sequence_keys; /* list of postponed COLLATING OF */ 1017 /* FD/SD */ 1018 cb_tree description_entry; /* FD / SD entry rerference for warnings + errors */ 1019 struct cb_field *record; /* Record descriptions */ 1020 cb_tree record_depending; /* RECORD DEPENDING */ 1021 cb_tree reports; /* REPORTS */ 1022 cb_tree linage; /* LINAGE */ 1023 cb_tree linage_ctr; /* LINAGE COUNTER */ 1024 cb_tree latfoot; /* LINAGE FOOTING */ 1025 cb_tree lattop; /* LINAGE TOP */ 1026 cb_tree latbot; /* LINAGE BOTTOM */ 1027 cb_tree extfh; /* EXTFH module to call for I/O */ 1028 struct cb_label *handler; /* Error handler */ 1029 struct cb_program *handler_prog; /* Prog where defined */ 1030 struct cb_label *debug_section; /* DEBUG SECTION */ 1031 struct cb_alphabet_name *code_set; /* CODE-SET */ 1032 struct cb_list *code_set_items; /* CODE-SET FOR items */ 1033 struct cb_xref xref; /* xref elements */ 1034 int record_min; /* RECORD CONTAINS */ 1035 int record_max; /* RECORD CONTAINS */ 1036 int optional; /* OPTIONAL */ 1037 int organization; /* ORGANIZATION - FIXME: use enum */ 1038 int access_mode; /* ACCESS MODE - FIXME: use enum */ 1039 int lock_mode; /* LOCK MODE */ 1040 int special; /* Special file */ 1041 int same_clause; /* SAME clause */ 1042 enum cb_assign_type assign_type; /* How to interpret ASSIGN clause */ 1043 unsigned int flag_finalized : 1; /* Is finalized */ 1044 unsigned int flag_external : 1; /* Is EXTERNAL */ 1045 unsigned int flag_ext_assign : 1; /* ASSIGN EXTERNAL */ 1046 unsigned int flag_fileid : 1; /* ASSIGN DISK */ 1047 unsigned int flag_global : 1; /* Is GLOBAL */ 1048 unsigned int flag_fl_debug : 1; /* DEBUGGING */ 1049 unsigned int flag_line_adv : 1; /* LINE ADVANCING */ 1050 unsigned int flag_delimiter : 1; /* RECORD DELIMITER */ 1051 unsigned int flag_report : 1; /* Used by REPORT */ 1052 /* Implied RECORD VARYING limits need checking */ 1053 unsigned int flag_check_record_varying_limits : 1; 1054 /* Whether the file's ASSIGN is like "ASSIGN word", not "ASSIGN 1055 EXTERNAL/DYNAMIC/USING/... word" */ 1056 unsigned int flag_assign_no_keyword : 1; 1057 /* Exceptions enabled for file */ 1058 struct cb_exception *exception_table; 1059 }; 1060 1061 #define CB_FILE(x) (CB_TREE_CAST (CB_TAG_FILE, struct cb_file, x)) 1062 #define CB_FILE_P(x) (CB_TREE_TAG (x) == CB_TAG_FILE) 1063 1064 /* Communication description */ 1065 1066 struct cb_cd { 1067 struct cb_tree_common common; /* Common values */ 1068 const char *name; /* Name */ 1069 struct cb_field *record; /* Record descriptions */ 1070 struct cb_label *debug_section; /* DEBUG section */ 1071 int flag_field_debug; /* DEBUGGING */ 1072 }; 1073 1074 #define CB_CD(x) (CB_TREE_CAST (CB_TAG_CD, struct cb_cd, x)) 1075 #define CB_CD_P(x) (CB_TREE_TAG (x) == CB_TAG_CD) 1076 1077 /* Reference */ 1078 1079 struct cb_word { 1080 struct cb_word *next; /* Next word with the same hash value */ 1081 const char *name; /* Word name */ 1082 cb_tree items; /* Objects associated with this word */ 1083 int count; /* Number of words with the same name */ 1084 int error; /* Set to -1 if warning raised for that, -1 if error detected */ 1085 }; 1086 1087 #define CB_WORD_TABLE_SIZE (CB_WORD_HASH_SIZE * sizeof (struct cb_word)) 1088 1089 struct cb_reference { 1090 struct cb_tree_common common; /* Common values */ 1091 cb_tree chain; /* Next qualified name */ 1092 cb_tree value; /* Item referred to */ 1093 cb_tree subs; /* List of subscripts */ 1094 cb_tree offset; /* Reference mod offset */ 1095 cb_tree length; /* Reference mod length */ 1096 cb_tree check; /* Runtime checks */ 1097 struct cb_word *word; /* Pointer to word list */ 1098 struct cb_label *section; /* Current section */ 1099 struct cb_label *paragraph; /* Current paragraph */ 1100 struct cb_label *debug_section; /* Debug section */ 1101 size_t hashval; /* Hash value of name */ 1102 1103 unsigned int flag_receiving : 1; /* Reference target */ 1104 unsigned int flag_all : 1; /* ALL */ 1105 unsigned int flag_in_decl : 1; /* In DECLARATIVE */ 1106 unsigned int flag_decl_ok : 1; /* DECLARATIVE ref OK */ 1107 unsigned int flag_alter_code : 1; /* Needs ALTER code */ 1108 unsigned int flag_debug_code : 1; /* Needs DEBUG code */ 1109 unsigned int flag_all_debug : 1; /* Needs ALL DEBUG code */ 1110 unsigned int flag_target : 1; /* DEBUG item is target */ 1111 1112 unsigned int flag_optional : 1; /* Definition optional */ 1113 unsigned int flag_ignored : 1; /* Part of ignored code */ 1114 unsigned int flag_filler_ref : 1; /* Ref to FILLER */ 1115 unsigned int flag_duped : 1; /* Duplicate name */ 1116 }; 1117 1118 #define CB_REFERENCE(x) (CB_TREE_CAST (CB_TAG_REFERENCE, struct cb_reference, x)) 1119 #define CB_REFERENCE_P(x) (CB_TREE_TAG (x) == CB_TAG_REFERENCE) 1120 1121 #define CB_WORD(x) (CB_REFERENCE (x)->word) 1122 #define CB_NAME(x) (CB_REFERENCE (x)->word->name) 1123 #define CB_WORD_COUNT(x) (CB_REFERENCE (x)->word->count) 1124 #define CB_WORD_ITEMS(x) (CB_REFERENCE (x)->word->items) 1125 1126 /* Binary operation */ 1127 1128 /* 1129 '+' x + y 1130 '-' x - y 1131 '*' x * y 1132 '/' x / y 1133 '^' x ** y 1134 '=' x = y 1135 '>' x > y 1136 '<' x < y 1137 '[' x <= y 1138 ']' x >= y 1139 '~' x != y 1140 '!' not x 1141 '&' x and y 1142 '|' x or y 1143 '@' ( x ) 1144 */ 1145 1146 struct cb_binary_op { 1147 struct cb_tree_common common; /* Common values */ 1148 cb_tree x; /* LHS */ 1149 cb_tree y; /* RHS */ 1150 int op; /* Operation */ 1151 unsigned int flag; /* Special usage */ 1152 }; 1153 1154 #define CB_BINARY_OP(x) (CB_TREE_CAST (CB_TAG_BINARY_OP, struct cb_binary_op, x)) 1155 #define CB_BINARY_OP_P(x) (CB_TREE_TAG (x) == CB_TAG_BINARY_OP) 1156 1157 /* Function call */ 1158 1159 struct cb_funcall { 1160 struct cb_tree_common common; /* Common values */ 1161 const char *name; /* Function name */ 1162 cb_tree argv[11]; /* Function arguments */ 1163 int argc; /* Number of arguments */ 1164 int varcnt; /* Variable argument count */ 1165 unsigned int screenptr; /* SCREEN usage */ 1166 unsigned int nolitcast; /* No cast for literals */ 1167 }; 1168 1169 #define CB_FUNCALL(x) (CB_TREE_CAST (CB_TAG_FUNCALL, struct cb_funcall, x)) 1170 #define CB_FUNCALL_P(x) (CB_TREE_TAG (x) == CB_TAG_FUNCALL) 1171 1172 /* Type cast */ 1173 1174 struct cb_cast { 1175 struct cb_tree_common common; /* Common values */ 1176 cb_tree val; 1177 enum cb_cast_type cast_type; 1178 }; 1179 1180 #define CB_CAST(x) (CB_TREE_CAST (CB_TAG_CAST, struct cb_cast, x)) 1181 #define CB_CAST_P(x) (CB_TREE_TAG (x) == CB_TAG_CAST) 1182 1183 /* Assign */ 1184 1185 struct cb_assign { 1186 struct cb_tree_common common; /* Common values */ 1187 cb_tree var; 1188 cb_tree val; 1189 }; 1190 1191 #define CB_ASSIGN(x) (CB_TREE_CAST (CB_TAG_ASSIGN, struct cb_assign, x)) 1192 #define CB_ASSIGN_P(x) (CB_TREE_TAG (x) == CB_TAG_ASSIGN) 1193 1194 /* Compiler features like directives, functions, mnemonics and registers */ 1195 1196 enum cb_feature_mode { 1197 CB_FEATURE_ACTIVE = 0, /* 0 Feature is implemented and not disabled */ 1198 CB_FEATURE_DISABLED, /* 1 Feature disabled */ 1199 CB_FEATURE_MUST_BE_ENABLED, /* 2 Feature disabled, if not explicit enabled */ 1200 CB_FEATURE_NOT_IMPLEMENTED /* 3 Feature known but not yet implemented */ 1201 }; 1202 1203 /* Intrinsic FUNCTION */ 1204 1205 struct cb_intrinsic_table { 1206 const char *name; /* FUNCTION NAME */ 1207 const char *intr_routine; /* Routine name */ 1208 const enum cb_intr_enum intr_enum; /* Enum intrinsic */ 1209 const int token; /* Token value */ 1210 enum cb_feature_mode active; /* Have we implemented it? Is it active? */ 1211 const int args; /* Maximum number of arguments, -1 = unlimited */ 1212 const int min_args; /* Minimum number of arguments */ 1213 const enum cb_category category; /* Category */ 1214 const unsigned int refmod; /* Can be refmodded */ 1215 }; 1216 1217 struct cb_intrinsic { 1218 struct cb_tree_common common; /* Common values */ 1219 cb_tree name; /* INTRINSIC name */ 1220 cb_tree args; /* Arguments */ 1221 cb_tree intr_field; /* Field to use */ 1222 const struct cb_intrinsic_table *intr_tab; /* Table pointer */ 1223 cb_tree offset; /* Reference mod */ 1224 cb_tree length; /* Reference mod */ 1225 int isuser; /* User function */ 1226 }; 1227 1228 #define CB_INTRINSIC(x) (CB_TREE_CAST (CB_TAG_INTRINSIC, struct cb_intrinsic, x)) 1229 #define CB_INTRINSIC_P(x) (CB_TREE_TAG (x) == CB_TAG_INTRINSIC) 1230 1231 /* INITIALIZE */ 1232 1233 struct cb_initialize { 1234 struct cb_tree_common common; /* Common values */ 1235 cb_tree var; /* Field */ 1236 cb_tree val; /* Value */ 1237 cb_tree rep; /* Replacing */ 1238 unsigned char flag_default; /* Default */ 1239 unsigned char flag_init_statement; /* INITIALIZE statement */ 1240 unsigned char flag_no_filler_init; /* No FILLER initialize */ 1241 unsigned char padding; /* Padding */ 1242 }; 1243 1244 #define CB_INITIALIZE(x) (CB_TREE_CAST (CB_TAG_INITIALIZE, struct cb_initialize, x)) 1245 #define CB_INITIALIZE_P(x) (CB_TREE_TAG (x) == CB_TAG_INITIALIZE) 1246 1247 /* SEARCH */ 1248 1249 struct cb_search { 1250 struct cb_tree_common common; /* Common values */ 1251 cb_tree table; /* Table name */ 1252 cb_tree var; /* Varying */ 1253 cb_tree end_stmt; /* AT END */ 1254 cb_tree whens; /* WHEN */ 1255 int flag_all; /* SEARCH ALL */ 1256 }; 1257 1258 #define CB_SEARCH(x) (CB_TREE_CAST (CB_TAG_SEARCH, struct cb_search, x)) 1259 #define CB_SEARCH_P(x) (CB_TREE_TAG (x) == CB_TAG_SEARCH) 1260 1261 /* CALL */ 1262 1263 struct cb_call { 1264 struct cb_tree_common common; /* Common values */ 1265 cb_tree name; /* CALL name */ 1266 cb_tree args; /* Arguments */ 1267 cb_tree stmt1; /* ON EXCEPTION */ 1268 cb_tree stmt2; /* NOT ON EXCEPTION */ 1269 cb_tree call_returning; /* RETURNING */ 1270 cob_u32_t is_system; /* System call */ 1271 int convention; /* CALL convention */ 1272 }; 1273 1274 #define CB_CALL(x) (CB_TREE_CAST (CB_TAG_CALL, struct cb_call, x)) 1275 #define CB_CALL_P(x) (CB_TREE_TAG (x) == CB_TAG_CALL) 1276 1277 /* CANCEL */ 1278 1279 struct cb_cancel { 1280 struct cb_tree_common common; /* Common values */ 1281 cb_tree target; /* CANCEL target(s) */ 1282 }; 1283 1284 #define CB_CANCEL(x) (CB_TREE_CAST (CB_TAG_CANCEL, struct cb_cancel, x)) 1285 #define CB_CANCEL_P(x) (CB_TREE_TAG (x) == CB_TAG_CANCEL) 1286 1287 /* ALTER */ 1288 1289 struct cb_alter { 1290 struct cb_tree_common common; /* Common values */ 1291 cb_tree source; /* ALTER source paragraph */ 1292 cb_tree target; /* ALTER target GO TO paragraph */ 1293 }; 1294 1295 #define CB_ALTER(x) (CB_TREE_CAST (CB_TAG_ALTER, struct cb_alter, x)) 1296 #define CB_ALTER_P(x) (CB_TREE_TAG (x) == CB_TAG_ALTER) 1297 1298 /* GO TO */ 1299 1300 struct cb_goto { 1301 struct cb_tree_common common; /* Common values */ 1302 cb_tree target; /* Procedure name(s) */ 1303 cb_tree depending; /* DEPENDING */ 1304 }; 1305 1306 #define CB_GOTO(x) (CB_TREE_CAST (CB_TAG_GOTO, struct cb_goto, x)) 1307 #define CB_GOTO_P(x) (CB_TREE_TAG (x) == CB_TAG_GOTO) 1308 1309 /* IF and WHEN and PRESENT WHEN */ 1310 1311 struct cb_if { 1312 struct cb_tree_common common; /* Common values */ 1313 cb_tree test; /* Condition */ 1314 cb_tree stmt1; /* Statement list */ 1315 cb_tree stmt2; /* ELSE/WHEN statement list */ 1316 unsigned int is_if; /* From IF (1), WHEN (0), PRESENT WHEN (3+4) */ 1317 }; 1318 1319 #define CB_IF(x) (CB_TREE_CAST (CB_TAG_IF, struct cb_if, x)) 1320 #define CB_IF_P(x) (CB_TREE_TAG (x) == CB_TAG_IF) 1321 1322 /* PERFORM */ 1323 1324 struct cb_perform_varying { 1325 struct cb_tree_common common; /* Common values */ 1326 cb_tree name; /* VARYING item */ 1327 cb_tree from; /* FROM */ 1328 cb_tree step; /* Increment */ 1329 cb_tree until; /* UNTIL */ 1330 }; 1331 1332 struct cb_perform { 1333 struct cb_tree_common common; /* Common values */ 1334 cb_tree test; /* Condition */ 1335 cb_tree body; /* Statements */ 1336 cb_tree data; /* TIMES or procedure */ 1337 cb_tree varying; /* VARYING */ 1338 cb_tree exit_label; /* Implicit exit label */ 1339 cb_tree cycle_label; /* EXIT PERFORM CYCLE */ 1340 enum cb_perform_type perform_type; /* Perform type */ 1341 }; 1342 1343 #define CB_PERFORM_VARYING(x) (CB_TREE_CAST (CB_TAG_PERFORM_VARYING, struct cb_perform_varying, x)) 1344 1345 #define CB_PERFORM(x) (CB_TREE_CAST (CB_TAG_PERFORM, struct cb_perform, x)) 1346 #define CB_PERFORM_P(x) (CB_TREE_TAG (x) == CB_TAG_PERFORM) 1347 1348 /* Struct for extended ACCEPT / DISPLAY */ 1349 1350 struct cb_attr_struct { 1351 cb_tree fgc; /* FOREGROUND COLOR */ 1352 cb_tree bgc; /* BACKGROUND COLOR */ 1353 cb_tree scroll; /* SCROLL */ 1354 cb_tree timeout; /* TIMEOUT */ 1355 cb_tree prompt; /* PROMPT */ 1356 cb_tree size_is; /* [PROTECTED] SIZE [IS] */ 1357 cob_flags_t dispattrs; /* Attributes */ 1358 }; 1359 1360 /* Exception handler type */ 1361 1362 enum cb_handler_type { 1363 NO_HANDLER = 0, 1364 DISPLAY_HANDLER, 1365 ACCEPT_HANDLER, 1366 SIZE_ERROR_HANDLER, 1367 OVERFLOW_HANDLER, 1368 AT_END_HANDLER, 1369 EOP_HANDLER, 1370 INVALID_KEY_HANDLER, 1371 XML_HANDLER, 1372 JSON_HANDLER 1373 }; 1374 1375 /* Statement */ 1376 1377 struct cb_statement { 1378 struct cb_tree_common common; /* Common values */ 1379 const char *name; /* Statement name */ 1380 cb_tree body; /* Statement body */ 1381 cb_tree file; /* File reference */ 1382 cb_tree ex_handler; /* Exception handler */ 1383 cb_tree not_ex_handler; /* Exception handler */ 1384 cb_tree handler3; /* INTO clause */ 1385 cb_tree null_check; /* NULL check */ 1386 cb_tree debug_check; /* Field DEBUG */ 1387 cb_tree debug_nodups; /* Field DEBUG dups */ 1388 struct cb_attr_struct *attr_ptr; /* Attributes */ 1389 enum cb_handler_type handler_type; /* Handler type */ 1390 unsigned int flag_no_based : 1; /* Check BASED */ 1391 unsigned int flag_in_debug : 1; /* In DEBUGGING */ 1392 unsigned int flag_merge : 1; /* Is MERGE */ 1393 unsigned int flag_callback : 1; /* DEBUG Callback */ 1394 unsigned int flag_implicit : 1; /* Is an implicit statement */ 1395 }; 1396 1397 #define CB_STATEMENT(x) (CB_TREE_CAST (CB_TAG_STATEMENT, struct cb_statement, x)) 1398 #define CB_STATEMENT_P(x) (CB_TREE_TAG (x) == CB_TAG_STATEMENT) 1399 1400 /* CONTINUE (*not* CONTINUE AFTER exp SECONDS) */ 1401 1402 struct cb_continue { 1403 struct cb_tree_common common; /* Common values */ 1404 }; 1405 1406 #define CB_CONTINUE(x) (CB_TREE_CAST (CB_TAG_CONTINUE, struct cb_continue, x)) 1407 #define CB_CONTINUE_P(x) (CB_TREE_TAG (x) == CB_TAG_CONTINUE) 1408 1409 /* SET ATTRIBUTE */ 1410 1411 struct cb_set_attr { 1412 struct cb_tree_common common; /* Common values */ 1413 struct cb_field *fld; 1414 cob_flags_t val_on; 1415 cob_flags_t val_off; 1416 }; 1417 1418 #define CB_SET_ATTR(x) (CB_TREE_CAST (CB_TAG_SET_ATTR, struct cb_set_attr, x)) 1419 #define CB_SET_ATTR_P(x) (CB_TREE_TAG (x) == CB_TAG_SET_ATTR) 1420 1421 /* List */ 1422 1423 struct cb_list { 1424 struct cb_tree_common common; /* Common values */ 1425 cb_tree chain; /* Next in list */ 1426 cb_tree value; /* Reference to item(s) */ 1427 cb_tree purpose; /* Purpose */ 1428 int sizes; /* BY VALUE SIZE */ 1429 }; 1430 1431 #define CB_LIST(x) (CB_TREE_CAST (CB_TAG_LIST, struct cb_list, x)) 1432 #define CB_LIST_P(x) (CB_TREE_TAG (x) == CB_TAG_LIST) 1433 1434 #define CB_PURPOSE(x) (CB_LIST (x)->purpose) 1435 #define CB_VALUE(x) (CB_LIST (x)->value) 1436 #define CB_CHAIN(x) (CB_LIST (x)->chain) 1437 #define CB_SIZES(x) (CB_LIST (x)->sizes) 1438 1439 #define CB_PURPOSE_INT(x) (CB_INTEGER (CB_PURPOSE (x))->val) 1440 1441 #define CB_SIZES_INT(x) ((CB_LIST (x)->sizes) & 0x07) 1442 #define CB_SIZES_INT_UNSIGNED(x) ((CB_LIST (x)->sizes) & CB_SIZE_UNSIGNED) 1443 1444 /* Pair */ 1445 1446 #define CB_PAIR_P(x) (CB_LIST_P (x) && CB_PAIR_X (x)) 1447 #define CB_PAIR_X(x) CB_PURPOSE (x) 1448 #define CB_PAIR_Y(x) CB_VALUE (x) 1449 1450 /* Report */ 1451 1452 struct cb_report { 1453 struct cb_tree_common common; /* Common values */ 1454 const char *name; /* Original name */ 1455 char *cname; /* Name used in C */ 1456 struct cb_file *file; /* File */ 1457 cb_tree line_counter; /* LINE-COUNTER */ 1458 cb_tree page_counter; /* PAGE-COUNTER */ 1459 cb_tree code_clause; /* CODE */ 1460 cb_tree controls; /* CONTROLS */ 1461 cb_tree t_lines; /* PAGE LIMIT LINES */ 1462 cb_tree t_columns; /* PAGE LIMIT COLUMNS */ 1463 cb_tree t_heading; /* HEADING */ 1464 cb_tree t_first_detail; /* FIRST DE */ 1465 cb_tree t_last_control; /* LAST CH */ 1466 cb_tree t_last_detail; /* LAST DE */ 1467 cb_tree t_footing; /* FOOTING */ 1468 int lines; /* PAGE LIMIT LINES */ 1469 int columns; /* PAGE LIMIT COLUMNS */ 1470 int heading; /* HEADING */ 1471 int first_detail; /* FIRST DE */ 1472 int last_control; /* LAST CH */ 1473 int last_detail; /* LAST DE */ 1474 int footing; /* FOOTING */ 1475 struct cb_field *records; /* First record definition of report */ 1476 int num_lines; /* Number of Lines defined */ 1477 struct cb_field **line_ids; /* array of LINE definitions */ 1478 int num_sums; /* Number of SUM counters defined */ 1479 struct cb_field **sums; /* Array of SUM fields */ 1480 int rcsz; /* Longest record */ 1481 int id; /* unique id for this report */ 1482 unsigned int control_final:1;/* CONTROL FINAL declared */ 1483 unsigned int global:1; /* IS GLOBAL declared */ 1484 unsigned int has_declarative:1;/* Has Declaratives Code to be executed */ 1485 unsigned int has_detail:1; /* Has DETAIL line */ 1486 }; 1487 1488 #define CB_REPORT(x) (CB_TREE_CAST (CB_TAG_REPORT, struct cb_report, x)) 1489 #define CB_REPORT_P(x) (CB_TREE_TAG (x) == CB_TAG_REPORT) 1490 1491 #define CB_REF_OR_REPORT_P(x) \ 1492 (CB_REFERENCE_P (x) ? CB_REPORT_P (cb_ref (x)) : CB_REPORT_P (x)) 1493 1494 #define CB_REPORT_PTR(x) \ 1495 (CB_REFERENCE_P (x) ? CB_REPORT (cb_ref (x)) : CB_REPORT (x)) 1496 1497 /* Mark-up Language output (JSON/XML GENERATE) tree */ 1498 1499 enum cb_ml_type { 1500 CB_ML_ATTRIBUTE, 1501 CB_ML_ELEMENT, 1502 CB_ML_CONTENT, 1503 CB_ML_ANY_TYPE 1504 }; 1505 1506 struct cb_ml_generate_tree { 1507 struct cb_tree_common common; 1508 /* Name of the ML element to generate */ 1509 cb_tree name; 1510 /* The type of the ML element to generate */ 1511 enum cb_ml_type type; 1512 /* The content of the ML element to generate */ 1513 cb_tree value; 1514 /* The condition under which generation of the element is suppressed */ 1515 cb_tree suppress_cond; 1516 /* ID for this struct when output */ 1517 int id; 1518 /* Attributes for this element */ 1519 struct cb_ml_generate_tree *attrs; 1520 /* Parent ML element */ 1521 struct cb_ml_generate_tree *parent; 1522 /* Children ML elements */ 1523 struct cb_ml_generate_tree *children; 1524 /* Preceding ML elements */ 1525 struct cb_ml_generate_tree *prev_sibling; 1526 /* Following ML elements */ 1527 struct cb_ml_generate_tree *sibling; 1528 }; 1529 1530 #define CB_ML_TREE(x) (CB_TREE_CAST (CB_TAG_ML_TREE, struct cb_ml_generate_tree, x)) 1531 #define CB_ML_TREE_P(x) (CB_TREE_TAG (x) == CB_TAG_ML_TREE) 1532 1533 /* Program */ 1534 1535 struct nested_list { 1536 struct nested_list *next; 1537 struct cb_program *nested_prog; 1538 }; 1539 1540 struct cb_program { 1541 struct cb_tree_common common; /* Common values */ 1542 1543 /* Program variables */ 1544 struct cb_program *next_program; /* Nested/contained */ 1545 struct cb_program *next_program_ordered; /* Nested/contained 1546 when cb_correct_program_order is set */ 1547 const char *program_name; /* Internal program-name */ 1548 const char *program_id; /* Demangled external PROGRAM-ID */ 1549 char *source_name; /* Source name */ 1550 char *orig_program_id; /* Original external PROGRAM-ID */ 1551 struct cb_word **word_table; /* Name hash table */ 1552 struct local_filename *local_include; /* Local include info */ 1553 struct nested_list *nested_prog_list; /* Callable contained */ 1554 struct nested_list *common_prog_list; /* COMMON contained */ 1555 cb_tree entry_list; /* Entry point list */ 1556 cb_tree entry_list_goto; /* Special Entry point list */ 1557 cb_tree file_list; /* File list */ 1558 cb_tree cd_list; /* CD list */ 1559 cb_tree exec_list; /* Executable statements */ 1560 cb_tree label_list; /* Label list */ 1561 cb_tree reference_list; /* Reference list */ 1562 cb_tree alphabet_name_list; /* ALPHABET list */ 1563 cb_tree symbolic_char_list; /* SYMBOLIC list */ 1564 cb_tree class_name_list; /* CLASS list */ 1565 cb_tree parameter_list; /* USING parameters */ 1566 cb_tree locale_list; /* LOCALE list */ 1567 cb_tree global_list; /* GLOBAL list */ 1568 cb_tree report_list; /* REPORT list */ 1569 cb_tree alter_list; /* ALTER list */ 1570 cb_tree debug_list; /* DEBUG ref list */ 1571 cb_tree cb_return_code; /* RETURN-CODE */ 1572 cb_tree cb_sort_return; /* SORT-RETURN */ 1573 cb_tree cb_call_params; /* Number of CALL params */ 1574 cb_tree mnemonic_spec_list; /* MNEMONIC spec */ 1575 cb_tree class_spec_list; /* CLASS spec */ 1576 cb_tree interface_spec_list; /* INTERFACE spec */ 1577 cb_tree function_spec_list; /* FUNCTION spec */ 1578 cb_tree user_spec_list; /* User FUNCTION spec */ 1579 cb_tree program_spec_list; /* PROGRAM spec */ 1580 cb_tree property_spec_list; /* PROPERTY spec */ 1581 struct cb_alter_id *alter_gotos; /* ALTER ids */ 1582 struct cb_field *working_storage; /* WORKING-STORAGE */ 1583 struct cb_field *local_storage; /* LOCAL-STORAGE */ 1584 struct cb_field *linkage_storage; /* LINKAGE */ 1585 struct cb_field *screen_storage; /* SCREEN */ 1586 struct cb_field *report_storage; /* REPORT */ 1587 cb_tree local_file_list; /* Local files */ 1588 cb_tree global_file_list; /* Global files */ 1589 struct handler_struct global_handler[5]; /* Global handlers */ 1590 cb_tree collating_sequence; /* COLLATING */ 1591 cb_tree collating_sequence_n; /* COLLATING FOR NATIONAL*/ 1592 cb_tree classification; /* CLASSIFICATION */ 1593 cb_tree apply_commit; /* APPLY COMMIT file- and data-items */ 1594 cb_tree cursor_pos; /* CURSOR */ 1595 cb_tree crt_status; /* CRT STATUS */ 1596 cb_tree xml_code; /* XML-CODE */ 1597 cb_tree xml_event; /* XML-EVENT */ 1598 cb_tree xml_information; /* XML-INFORMATION */ 1599 cb_tree xml_namespace; /* XML-NAMESPACE */ 1600 cb_tree xml_nnamespace; /* XML-NNAMESPACE */ 1601 cb_tree xml_namespace_prefix; /* XML-NAMESPACE-PREFIX */ 1602 cb_tree xml_nnamespace_prefix; /* XML-NNAMESPACE-PREFIX */ 1603 cb_tree xml_ntext; /* XML-NTEXT */ 1604 cb_tree xml_text; /* XML-TEXT */ 1605 cb_tree json_code; /* JSON-CODE */ 1606 cb_tree json_status; /* JSON-STATUS */ 1607 cb_tree returning; /* RETURNING */ 1608 struct cb_label *all_procedure; /* DEBUGGING */ 1609 struct cb_call_xref call_xref; /* CALL Xref list */ 1610 struct cb_ml_generate_tree *ml_trees; /* XML GENERATE trees */ 1611 const char *extfh; /* CALLFH for this program */ 1612 1613 int last_source_line; /* Line of (implicit) END PROGRAM/FUNCTION */ 1614 1615 /* Internal variables */ 1616 int loop_counter; /* Loop counters */ 1617 unsigned int decimal_index; /* cob_decimal count of this program */ 1618 unsigned int decimal_index_max; /* program group's max cob_decimal */ 1619 int nested_level; /* Nested program level */ 1620 unsigned int num_proc_params; /* PROC DIV params */ 1621 int toplev_count; /* Top level source count */ 1622 unsigned int max_call_param; /* Max params */ 1623 1624 unsigned char decimal_point; /* '.' or ',' */ 1625 unsigned char currency_symbol; /* '$' or user-specified */ 1626 unsigned char numeric_separator; /* ',' or '.' */ 1627 unsigned char prog_type; /* Program type (program = 0, function = 1) */ 1628 cb_tree entry_convention; /* ENTRY convention / PROCEDURE convention */ 1629 1630 unsigned int flag_main : 1; /* Gen main function */ 1631 unsigned int flag_common : 1; /* COMMON PROGRAM */ 1632 unsigned int flag_initial : 1; /* INITIAL PROGRAM */ 1633 unsigned int flag_recursive : 1; /* RECURSIVE PROGRAM */ 1634 unsigned int flag_screen : 1; /* Have SCREEN SECTION */ 1635 unsigned int flag_validated : 1; /* End program validate */ 1636 unsigned int flag_chained : 1; /* PROCEDURE CHAINING */ 1637 unsigned int flag_global_use : 1; /* USE GLOBAL */ 1638 1639 unsigned int flag_gen_error : 1; /* Gen error routine */ 1640 unsigned int flag_file_global : 1; /* Global FD */ 1641 unsigned int flag_has_external : 1; /* Has EXTERNAL */ 1642 unsigned int flag_segments : 1; /* Has segments */ 1643 unsigned int flag_trailing_separate : 1; /* TRAILING SEPARATE */ 1644 unsigned int flag_console_is_crt : 1; /* CONSOLE IS CRT */ 1645 unsigned int flag_debugging : 1; /* DEBUGGING MODE */ 1646 unsigned int flag_gen_debug : 1; /* DEBUGGING MODE */ 1647 1648 unsigned int flag_save_exception : 1; /* Save exception code */ 1649 unsigned int flag_report : 1; /* Have REPORT SECTION */ 1650 unsigned int flag_void : 1; /* void return for subprogram */ 1651 unsigned int flag_decimal_comp : 1; /* program group has decimal computations */ 1652 }; 1653 1654 #define CB_PROGRAM(x) (CB_TREE_CAST (CB_TAG_PROGRAM, struct cb_program, x)) 1655 1656 /* Function prototype */ 1657 1658 struct cb_prototype { 1659 struct cb_tree_common common; 1660 /* Name of prototype in the REPOSITORY */ 1661 const char *name; 1662 /* External name of the prototype/definition */ 1663 const char *ext_name; 1664 int type; 1665 }; 1666 1667 #define CB_PROTOTYPE(x) (CB_TREE_CAST (CB_TAG_PROTOTYPE, struct cb_prototype, x)) 1668 #define CB_PROTOTYPE_P(x) (CB_TREE_TAG (x) == CB_TAG_PROTOTYPE) 1669 1670 /* JSON/XML GENERATE SUPPRESS clause */ 1671 1672 enum cb_ml_suppress_target { 1673 CB_ML_SUPPRESS_IDENTIFIER, 1674 CB_ML_SUPPRESS_ALL, 1675 CB_ML_SUPPRESS_TYPE 1676 }; 1677 1678 enum cb_ml_suppress_category { 1679 CB_ML_SUPPRESS_CAT_NUMERIC, 1680 CB_ML_SUPPRESS_CAT_NONNUMERIC, 1681 CB_ML_SUPPRESS_CAT_ANY 1682 }; 1683 1684 struct cb_ml_suppress_clause { 1685 struct cb_tree_common common; 1686 /* What thing(s) the SUPPRESS clause applies to */ 1687 enum cb_ml_suppress_target target; 1688 /* If the target is IDENTIFIER, then the item targetted */ 1689 cb_tree identifier; 1690 /* What values the thing(s) should have to be SUPPRESSed */ 1691 cb_tree when_list; 1692 /* If the target is TYPE, then the type of ML elements to apply to */ 1693 enum cb_ml_type ml_type; 1694 /* If the target is TYPE, then the categories of items (of ML type 1695 ml_type) to apply to */ 1696 enum cb_ml_suppress_category category; 1697 }; 1698 1699 #define CB_ML_SUPPRESS(x) (CB_TREE_CAST (CB_TAG_ML_SUPPRESS, struct cb_ml_suppress_clause, x)) 1700 #define CB_ML_SUPPRESS_P(x) (CB_TREE_TAG (x) == CB_TAG_ML_SUPPRESS) 1701 1702 struct cb_ml_suppress_checks { 1703 struct cb_tree_common common; 1704 struct cb_ml_generate_tree *tree; 1705 }; 1706 1707 #define CB_ML_SUPPRESS_CHECKS(x) (CB_TREE_CAST (CB_TAG_ML_SUPPRESS_CHECKS, struct cb_ml_suppress_checks, x)) 1708 #define CB_ML_SUPPRESS_CHECKS_P(x) (CB_TREE_TAG (x) == CB_TAG_ML_SUPPRESS_CHECKS) 1709 1710 /* DISPLAY type */ 1711 1712 enum cb_display_type { 1713 UNKNOWN_DISPLAY, 1714 SCREEN_DISPLAY, 1715 FIELD_ON_SCREEN_DISPLAY, 1716 DEVICE_DISPLAY, 1717 MIXED_DISPLAY 1718 }; 1719 1720 /* INSPECT clauses */ 1721 1722 enum cb_inspect_clause { 1723 TALLYING_CLAUSE, 1724 REPLACING_CLAUSE, 1725 CONVERTING_CLAUSE, 1726 /* This is what happens when you support OS/VS COBOL. */ 1727 TRANSFORM_STATEMENT 1728 }; 1729 1730 /* Functions/variables */ 1731 1732 /* tree.c */ 1733 1734 extern cb_tree cb_any; 1735 extern cb_tree cb_true; 1736 extern cb_tree cb_false; 1737 extern cb_tree cb_null; 1738 extern cb_tree cb_zero; 1739 extern cb_tree cb_one; 1740 extern cb_tree cb_space; 1741 extern cb_tree cb_low; 1742 extern cb_tree cb_high; 1743 extern cb_tree cb_norm_low; 1744 extern cb_tree cb_norm_high; 1745 extern cb_tree cb_quote; 1746 extern cb_tree cb_int0; 1747 extern cb_tree cb_int1; 1748 extern cb_tree cb_int2; 1749 extern cb_tree cb_int3; 1750 extern cb_tree cb_int4; 1751 extern cb_tree cb_int5; 1752 extern cb_tree cb_int6; 1753 extern cb_tree cb_int7; 1754 extern cb_tree cb_int8; 1755 extern cb_tree cb_int16; 1756 extern cb_tree cb_i[COB_MAX_SUBSCRIPTS]; 1757 extern cb_tree cb_error_node; 1758 1759 extern cb_tree cb_intr_whencomp; 1760 1761 extern cb_tree cb_standard_error_handler; 1762 extern cb_tree cb_depend_check; 1763 1764 extern unsigned int gen_screen_ptr; 1765 1766 extern char *cb_name (cb_tree); 1767 extern char *cb_name_errmsg (cb_tree); 1768 extern cb_tree cb_exhbit_literal (cb_tree); 1769 extern enum cb_class cb_tree_class (cb_tree); 1770 extern enum cb_category cb_tree_category (cb_tree); 1771 extern int cb_tree_type (const cb_tree, 1772 const struct cb_field *); 1773 extern int cb_category_is_alpha (cb_tree); 1774 extern int cb_category_is_national (cb_tree); 1775 extern int cb_fits_int (const cb_tree); 1776 extern int cb_fits_long_long (const cb_tree); 1777 extern int cb_get_int (const cb_tree); 1778 extern cob_s64_t cb_get_long_long (const cb_tree); 1779 extern cob_u64_t cb_get_u_long_long (const cb_tree); 1780 1781 extern void cb_init_constants (void); 1782 1783 extern cb_tree cb_int (const int); 1784 extern cb_tree cb_int_hex (const int); 1785 1786 extern cb_tree cb_build_string (const void *, const size_t); 1787 1788 extern cb_tree cb_flags_t (const cob_flags_t); 1789 1790 extern cb_tree cb_build_class_name (cb_tree, cb_tree); 1791 1792 extern cb_tree cb_build_locale_name (cb_tree, cb_tree); 1793 1794 extern cb_tree cb_build_numeric_literal (int, 1795 const void *, 1796 const int); 1797 extern cb_tree cb_build_alphanumeric_literal (const void *, 1798 const size_t); 1799 extern cb_tree cb_build_national_literal (const void *, 1800 const size_t); 1801 extern cb_tree cb_build_numsize_literal (const void *, 1802 const size_t, 1803 const int); 1804 extern cb_tree cb_concat_literals (const cb_tree, 1805 const cb_tree); 1806 1807 extern cb_tree cb_build_decimal (const unsigned int); 1808 extern cb_tree cb_build_decimal_literal (const int); 1809 extern int cb_lookup_literal (cb_tree x, int make_decimal); 1810 1811 extern cb_tree cb_build_picture (const char *); 1812 extern cb_tree cb_build_comment (const char *); 1813 extern cb_tree cb_build_direct (const char *, 1814 const unsigned int); 1815 extern cb_tree cb_build_debug (const cb_tree, const char *, 1816 const cb_tree); 1817 extern cb_tree cb_build_debug_call (struct cb_label *); 1818 1819 extern struct cb_picture *cb_build_binary_picture (const char *, 1820 const cob_u32_t, 1821 const cob_u32_t); 1822 1823 extern cb_tree cb_build_field (cb_tree); 1824 extern cb_tree cb_build_implicit_field (cb_tree, const int); 1825 extern cb_tree cb_build_constant (cb_tree, cb_tree); 1826 extern int cb_build_generic_register (const char *, const char *); 1827 1828 extern void cb_build_symbolic_chars (const cb_tree, 1829 const cb_tree); 1830 1831 extern struct cb_field *cb_field_add (struct cb_field *, 1832 struct cb_field *); 1833 extern int cb_field_size (const cb_tree x); 1834 #define FIELD_SIZE_UNKNOWN -1 1835 extern struct cb_field *cb_field_founder (const struct cb_field * const); 1836 extern struct cb_field *cb_field_variable_size (const struct cb_field *); 1837 extern unsigned int cb_field_variable_address (const struct cb_field *); 1838 extern int cb_field_subordinate (const struct cb_field *, 1839 const struct cb_field *); 1840 1841 extern cb_tree cb_build_label (cb_tree, struct cb_label *); 1842 1843 extern struct cb_file *build_file (cb_tree); 1844 extern void validate_file (struct cb_file *, cb_tree); 1845 extern void finalize_file (struct cb_file *, 1846 struct cb_field *); 1847 1848 extern struct cb_cd * cb_build_cd (cb_tree name); 1849 extern void cb_finalize_cd (struct cb_cd *, 1850 struct cb_field *); 1851 1852 extern cb_tree cb_build_filler (void); 1853 extern cb_tree cb_build_reference (const char *); 1854 extern cb_tree cb_build_field_reference (struct cb_field *, 1855 cb_tree); 1856 extern const char *cb_define (cb_tree, cb_tree); 1857 extern char *cb_to_cname (const char *); 1858 extern void cb_set_system_names (void); 1859 extern cb_tree cb_ref (cb_tree); 1860 extern cb_tree cb_try_ref (cb_tree); 1861 1862 extern cb_tree cb_build_binary_op (cb_tree, const int, 1863 cb_tree); 1864 extern cb_tree cb_build_binary_list (cb_tree, const int); 1865 1866 extern cb_tree cb_build_funcall (const char *, const int, 1867 const cb_tree, const cb_tree, 1868 const cb_tree, const cb_tree, 1869 const cb_tree, const cb_tree, 1870 const cb_tree, const cb_tree, 1871 const cb_tree, const cb_tree, 1872 const cb_tree); 1873 1874 extern cb_tree cb_build_cast (const enum cb_cast_type, 1875 const cb_tree); 1876 extern cb_tree cb_build_cast_int (const cb_tree); 1877 extern cb_tree cb_build_cast_llint (const cb_tree); 1878 1879 extern cb_tree cb_build_assign (const cb_tree, const cb_tree); 1880 1881 extern cb_tree cb_build_intrinsic (cb_tree, cb_tree, 1882 cb_tree, const int); 1883 extern cb_tree cb_build_prototype (const cb_tree, 1884 const cb_tree, const int); 1885 extern cb_tree cb_build_any_intrinsic (cb_tree); 1886 1887 extern cb_tree cb_build_search (const int, 1888 const cb_tree, const cb_tree, 1889 const cb_tree, const cb_tree); 1890 1891 extern cb_tree cb_build_call (const cb_tree, const cb_tree, 1892 const cb_tree, const cb_tree, 1893 const cb_tree, const cob_u32_t, 1894 const int); 1895 1896 extern cb_tree cb_build_alter (const cb_tree, const cb_tree); 1897 1898 extern cb_tree cb_build_cancel (const cb_tree); 1899 1900 extern cb_tree cb_build_goto (const cb_tree, const cb_tree); 1901 1902 extern cb_tree cb_build_if (const cb_tree, const cb_tree, 1903 const cb_tree, const unsigned int); 1904 1905 extern cb_tree cb_build_perform (const enum cb_perform_type); 1906 extern cb_tree cb_build_perform_varying (cb_tree, cb_tree, 1907 cb_tree, cb_tree); 1908 1909 extern struct cb_statement *cb_build_statement (const char *); 1910 1911 extern cb_tree cb_build_continue (void); 1912 1913 extern cb_tree cb_build_list (cb_tree, cb_tree, cb_tree); 1914 extern cb_tree cb_list_add (cb_tree, cb_tree); 1915 extern cb_tree cb_pair_add (cb_tree, cb_tree, cb_tree); 1916 extern cb_tree cb_list_append (cb_tree, cb_tree); 1917 extern cb_tree cb_list_reverse (cb_tree); 1918 extern unsigned int cb_list_length (cb_tree); 1919 extern unsigned int cb_next_length (struct cb_next_elem *); 1920 1921 extern struct cb_report *build_report (cb_tree); 1922 extern void finalize_report (struct cb_report *, struct cb_field *); 1923 extern void build_sum_counter(struct cb_report *r, struct cb_field *f); 1924 extern struct cb_field *get_sum_data_field(struct cb_report *r, struct cb_field *f); 1925 1926 extern void cb_add_common_prog (struct cb_program *); 1927 extern void cb_insert_common_prog (struct cb_program *, 1928 struct cb_program *); 1929 1930 1931 extern struct cb_intrinsic_table *lookup_intrinsic (const char *, 1932 const int); 1933 1934 extern cb_tree cb_build_alphabet_name (cb_tree); 1935 1936 extern cb_tree cb_build_initialize (const cb_tree, const cb_tree, 1937 const cb_tree, 1938 const unsigned int, 1939 const unsigned int, 1940 const unsigned int); 1941 1942 struct cb_literal *build_literal (enum cb_category, 1943 const void *, 1944 const size_t); 1945 1946 extern cb_tree cb_build_system_name (const enum cb_system_name_category, 1947 const int); 1948 1949 extern const char *cb_get_usage_string (const enum cb_usage); 1950 1951 extern cb_tree cb_field_dup (struct cb_field *f, struct cb_reference *ref); 1952 1953 extern cb_tree cb_build_ml_suppress_clause (void); 1954 extern cb_tree cb_build_ml_tree (struct cb_field *, const int, 1955 const int, cb_tree, cb_tree, 1956 cb_tree); 1957 extern cb_tree cb_build_ml_suppress_checks (struct cb_ml_generate_tree *); 1958 1959 1960 /* parser.y */ 1961 extern cb_tree cobc_printer_node; 1962 extern int non_const_word; 1963 extern int suppress_data_exceptions; 1964 extern unsigned int cobc_repeat_last_token; 1965 extern unsigned int cobc_in_id; 1966 extern unsigned int cobc_in_procedure; 1967 extern unsigned int cobc_in_repository; 1968 extern unsigned int cobc_force_literal; 1969 extern unsigned int cobc_cs_check; 1970 extern unsigned int cobc_allow_program_name; 1971 extern unsigned int cobc_in_xml_generate_body; 1972 extern unsigned int cobc_in_json_generate_body; 1973 1974 /* reserved.c */ 1975 extern int is_reserved_word (const char *); 1976 extern int is_default_reserved_word (const char *); 1977 extern void remove_context_sensitivity (const char *, 1978 const int); 1979 extern struct cobc_reserved *lookup_reserved_word (const char *); 1980 extern cb_tree get_system_name (const char *); 1981 extern cb_tree get_system_name_translated (cb_tree); 1982 extern const char *cb_get_register_definition (const char *); 1983 extern void cb_list_reserved (void); 1984 extern void cb_list_intrinsics (void); 1985 extern void cb_list_system_names (void); 1986 extern void cb_list_registers (void); 1987 extern void cb_list_system_routines (void); 1988 extern int cb_list_map (cb_tree (*) (cb_tree), cb_tree); 1989 1990 /* error.c */ 1991 extern cb_tree get_cb_error_node (void); 1992 extern enum cb_warn_val cb_warning_x (const enum cb_warn_opt, cb_tree, const char *, ...) COB_A_FORMAT34; 1993 extern enum cb_warn_val cb_warning_dialect_x (const enum cb_support, cb_tree, const char *, ...) COB_A_FORMAT34; 1994 extern void cb_note_x (const enum cb_warn_opt, cb_tree, const char *, ...) COB_A_FORMAT34; 1995 extern void cb_inclusion_note (const char *, int); 1996 extern enum cb_warn_val cb_error_x (cb_tree, const char *, ...) COB_A_FORMAT23; 1997 extern unsigned int cb_verify (const enum cb_support, const char *); 1998 extern unsigned int cb_verify_x (const cb_tree, const enum cb_support, 1999 const char *); 2000 #if 0 /* CHECKME: Is there any place other than "note" where we want to do listing suppression? */ 2001 extern void listprint_suppress (void); 2002 extern void listprint_restore (void); 2003 #endif 2004 2005 extern enum cb_warn_val redefinition_error (cb_tree); 2006 extern enum cb_warn_val redefinition_warning (cb_tree, cb_tree); 2007 extern enum cb_warn_val undefined_error (cb_tree); 2008 extern enum cb_warn_val ambiguous_error (cb_tree); 2009 extern enum cb_warn_val group_error (cb_tree, const char *); 2010 extern enum cb_warn_val level_require_error (cb_tree, const char *); 2011 extern enum cb_warn_val level_except_error (cb_tree, const char *); 2012 extern int cb_set_ignore_error (int state); 2013 2014 /* field.c */ 2015 extern size_t cb_needs_01; 2016 extern int cb_get_level (cb_tree); 2017 extern cb_tree cb_build_field_tree (cb_tree, cb_tree, struct cb_field *, 2018 enum cb_storage, struct cb_file *, 2019 const int); 2020 extern cb_tree cb_build_full_field_reference (struct cb_field *); 2021 extern struct cb_field *cb_resolve_redefines (struct cb_field *, cb_tree); 2022 extern void copy_into_field (struct cb_field *, struct cb_field *); 2023 extern void cb_validate_field (struct cb_field *); 2024 extern void cb_validate_88_item (struct cb_field *); 2025 extern struct cb_field *cb_validate_78_item (struct cb_field *, const cob_u32_t); 2026 extern int cb_validate_renames_item (struct cb_field *, cb_tree, cb_tree); 2027 extern struct cb_field *cb_get_real_field (void); 2028 extern void cb_clear_real_field (void); 2029 extern int cb_is_figurative_constant (const cb_tree); 2030 extern int cb_field_is_ignored_in_ml_gen (struct cb_field * const); 2031 2032 /* typeck.c */ 2033 extern cb_tree cb_debug_item; 2034 extern cb_tree cb_debug_line; 2035 extern cb_tree cb_debug_name; 2036 extern cb_tree cb_debug_sub_1; 2037 extern cb_tree cb_debug_sub_2; 2038 extern cb_tree cb_debug_sub_3; 2039 extern cb_tree cb_debug_contents; 2040 2041 extern struct cb_program *cb_build_program (struct cb_program *, 2042 const int); 2043 2044 extern cb_tree cb_check_numeric_value (cb_tree); 2045 extern size_t cb_check_index_or_handle_p (cb_tree x); 2046 extern void cb_set_dmax (int scale); 2047 2048 extern void cb_set_intr_when_compiled (void); 2049 extern void cb_build_registers (void); 2050 extern void cb_add_external_defined_registers (void); 2051 extern const char *cb_register_list_get_first (const char **); 2052 extern const char *cb_register_list_get_next (const char **); 2053 extern void cb_build_debug_item (void); 2054 extern void cb_check_field_debug (cb_tree); 2055 extern void cb_trim_program_id (cb_tree); 2056 extern char *cb_encode_program_id (const char *, const int, const int); 2057 extern char *cb_build_program_id (const char *, const cob_u32_t); 2058 extern cb_tree cb_define_switch_name (cb_tree, cb_tree, const int); 2059 2060 extern void cb_check_word_length (unsigned int, const char *); 2061 extern cb_tree cb_build_section_name (cb_tree, const int); 2062 extern cb_tree cb_build_assignment_name (struct cb_file *, cb_tree); 2063 extern cb_tree cb_build_index (cb_tree, cb_tree, 2064 const unsigned int, struct cb_field *); 2065 extern cb_tree cb_build_identifier (cb_tree, const int); 2066 extern cb_tree cb_build_length (cb_tree); 2067 extern cb_tree cb_build_const_length (cb_tree); 2068 extern cb_tree cb_build_const_from (cb_tree); 2069 extern cb_tree cb_build_const_start (struct cb_field *, cb_tree); 2070 extern cb_tree cb_build_const_next (struct cb_field *); 2071 extern cb_tree cb_build_address (cb_tree); 2072 extern cb_tree cb_build_ppointer (cb_tree); 2073 2074 extern void cb_validate_program_environment (struct cb_program *); 2075 extern void cb_validate_program_data (struct cb_program *); 2076 extern void cb_validate_program_body (struct cb_program *); 2077 2078 extern cb_tree cb_build_expr (cb_tree); 2079 extern cb_tree cb_build_cond (cb_tree); 2080 2081 extern void cb_end_cond (cb_tree); 2082 extern void cb_save_cond (void); 2083 extern void cb_terminate_cond (void); 2084 extern void cb_true_side (void); 2085 extern void cb_false_side (void); 2086 extern void cb_end_statement (void); 2087 extern const char *explain_operator (const int); 2088 extern const char *enum_explain_storage (const enum cb_storage storage); 2089 2090 extern void cb_emit_arithmetic (cb_tree, const int, cb_tree); 2091 extern cb_tree cb_build_add (cb_tree, cb_tree, cb_tree); 2092 extern cb_tree cb_build_sub (cb_tree, cb_tree, cb_tree); 2093 extern void cb_emit_corresponding ( 2094 cb_tree (*) (cb_tree, cb_tree, cb_tree), 2095 cb_tree, cb_tree, cb_tree); 2096 extern void cb_emit_tab_arithmetic ( 2097 cb_tree (*) (cb_tree, cb_tree, cb_tree), 2098 cb_tree, cb_tree, cb_tree, cb_tree, cb_tree); 2099 extern void cb_emit_move_corresponding (cb_tree, cb_tree); 2100 2101 extern void cb_emit_accept (cb_tree, cb_tree, 2102 struct cb_attr_struct *); 2103 extern void cb_emit_accept_line_or_col (cb_tree, const int); 2104 extern void cb_emit_accept_escape_key (cb_tree); 2105 extern void cb_emit_accept_exception_status (cb_tree); 2106 extern void cb_emit_accept_user_name (cb_tree); 2107 extern void cb_emit_accept_date (cb_tree); 2108 extern void cb_emit_accept_date_yyyymmdd (cb_tree); 2109 extern void cb_emit_accept_day (cb_tree); 2110 extern void cb_emit_accept_day_yyyyddd (cb_tree); 2111 extern void cb_emit_accept_day_of_week (cb_tree); 2112 extern void cb_emit_accept_time (cb_tree); 2113 extern void cb_emit_accept_command_line (cb_tree); 2114 extern void cb_emit_accept_environment (cb_tree); 2115 extern void cb_emit_accept_mnemonic (cb_tree, cb_tree); 2116 extern void cb_emit_accept_name (cb_tree, cb_tree); 2117 extern void cb_emit_accept_arg_number (cb_tree); 2118 extern void cb_emit_accept_arg_value (cb_tree); 2119 extern void cb_emit_get_environment (cb_tree, cb_tree); 2120 2121 extern void cb_emit_allocate (cb_tree, cb_tree, 2122 cb_tree, cb_tree); 2123 extern void cb_emit_alter (cb_tree, cb_tree); 2124 extern void cb_emit_free (cb_tree); 2125 2126 extern void cb_emit_call (cb_tree, cb_tree, cb_tree, cb_tree, 2127 cb_tree, cb_tree, cb_tree, cb_tree, int); 2128 2129 extern void cb_emit_cancel (cb_tree); 2130 extern void cb_emit_close (cb_tree, cb_tree); 2131 extern void cb_emit_commit (void); 2132 extern void cb_emit_continue (cb_tree); 2133 extern void cb_emit_delete (cb_tree); 2134 extern void cb_emit_delete_file (cb_tree); 2135 2136 2137 extern void cb_emit_display_window (cb_tree, cb_tree, cb_tree, 2138 cb_tree, struct cb_attr_struct *); 2139 extern void cb_emit_close_window (cb_tree, cb_tree); 2140 extern void cb_emit_destroy (cb_tree); 2141 2142 extern void cb_emit_display (cb_tree, cb_tree, 2143 cb_tree, cb_tree, 2144 struct cb_attr_struct *, 2145 int, enum cb_display_type); 2146 extern cb_tree cb_build_display_mnemonic (cb_tree); 2147 extern cb_tree cb_build_display_name (cb_tree); 2148 2149 extern void cb_emit_env_name (cb_tree); 2150 extern void cb_emit_env_value (cb_tree); 2151 extern void cb_emit_arg_number (cb_tree); 2152 extern void cb_emit_command_line (cb_tree); 2153 2154 extern void cb_emit_divide (cb_tree, cb_tree, 2155 cb_tree, cb_tree); 2156 2157 extern void cb_emit_evaluate (cb_tree, cb_tree); 2158 2159 extern void cb_emit_goto (cb_tree, cb_tree); 2160 extern void cb_emit_goto_entry (cb_tree, cb_tree); 2161 extern void cb_emit_exit (const unsigned int); 2162 2163 extern void cb_emit_if (cb_tree, cb_tree, cb_tree); 2164 extern cb_tree cb_build_if_check_break (cb_tree, cb_tree); 2165 2166 extern void cb_emit_initialize (cb_tree, cb_tree, 2167 cb_tree, cb_tree, 2168 cb_tree); 2169 2170 extern void cb_emit_inspect (cb_tree, cb_tree, 2171 const enum cb_inspect_clause); 2172 extern void cb_init_tallying (void); 2173 extern cb_tree cb_build_tallying_data (cb_tree); 2174 extern cb_tree cb_build_tallying_characters (cb_tree); 2175 extern cb_tree cb_build_tallying_all (void); 2176 extern cb_tree cb_build_tallying_leading (void); 2177 extern cb_tree cb_build_tallying_trailing (void); 2178 extern cb_tree cb_build_tallying_value (cb_tree, cb_tree); 2179 extern cb_tree cb_build_replacing_characters (cb_tree, cb_tree); 2180 extern cb_tree cb_build_replacing_all (cb_tree, cb_tree, cb_tree); 2181 extern cb_tree cb_build_replacing_leading (cb_tree, cb_tree, cb_tree); 2182 extern cb_tree cb_build_replacing_first (cb_tree, cb_tree, cb_tree); 2183 extern cb_tree cb_build_replacing_trailing (cb_tree, cb_tree, cb_tree); 2184 extern cb_tree cb_build_converting (cb_tree, cb_tree, cb_tree); 2185 extern cb_tree cb_build_inspect_region_start (void); 2186 2187 extern int validate_move (cb_tree, cb_tree, const unsigned int, int *); 2188 extern cb_tree cb_build_move (cb_tree, cb_tree); 2189 extern void cb_emit_move (cb_tree, cb_tree); 2190 2191 extern void cb_emit_open (cb_tree, cb_tree, cb_tree); 2192 2193 extern void cb_emit_perform (cb_tree, cb_tree, cb_tree, cb_tree); 2194 extern cb_tree cb_build_perform_once (cb_tree); 2195 extern cb_tree cb_build_perform_times (cb_tree); 2196 extern cb_tree cb_build_perform_until (cb_tree, cb_tree); 2197 extern cb_tree cb_build_perform_forever (cb_tree); 2198 extern cb_tree cb_build_perform_exit (struct cb_label *); 2199 extern void cb_build_perform_after_until(void); 2200 2201 extern void cb_emit_read (cb_tree, cb_tree, cb_tree, 2202 cb_tree, cb_tree); 2203 2204 extern void cb_emit_ready_trace (void); 2205 extern void cb_emit_rewrite (cb_tree, cb_tree, cb_tree); 2206 2207 extern void cb_emit_release (cb_tree, cb_tree); 2208 extern void cb_emit_reset_trace (void); 2209 extern void cb_emit_return (cb_tree, cb_tree); 2210 2211 extern void cb_emit_rollback (void); 2212 2213 extern void cb_emit_search (cb_tree, cb_tree, 2214 cb_tree, cb_tree); 2215 extern void cb_emit_search_all (cb_tree, cb_tree, 2216 cb_tree, cb_tree); 2217 2218 extern void cb_emit_setenv (cb_tree, cb_tree); 2219 extern void cb_emit_set_to (cb_tree, cb_tree); 2220 extern void cb_emit_set_up_down (cb_tree, cb_tree, cb_tree); 2221 extern void cb_emit_set_on_off (cb_tree, cb_tree); 2222 extern void cb_emit_set_true (cb_tree); 2223 extern void cb_emit_set_false (cb_tree); 2224 extern void cb_emit_set_thread_priority (cb_tree, cb_tree); 2225 extern void cb_emit_set_attribute (cb_tree, 2226 const cob_flags_t, 2227 const cob_flags_t); 2228 extern cb_tree cb_build_set_attribute (const struct cb_field *, 2229 const cob_flags_t, 2230 const cob_flags_t); 2231 extern void cb_emit_set_last_exception_to_off (void); 2232 2233 extern void cb_emit_sort_init (cb_tree, cb_tree, cb_tree, cb_tree); 2234 extern void cb_emit_sort_using (cb_tree, cb_tree); 2235 extern void cb_emit_sort_input (cb_tree); 2236 extern void cb_emit_sort_giving (cb_tree, cb_tree); 2237 extern void cb_emit_sort_output (cb_tree); 2238 extern void cb_emit_sort_finish (cb_tree); 2239 2240 extern void cb_emit_start (cb_tree, cb_tree, cb_tree, cb_tree); 2241 2242 extern void cb_emit_stop_run (cb_tree); 2243 2244 extern void cb_emit_stop_thread (cb_tree); 2245 2246 extern void cb_emit_string (cb_tree, cb_tree, cb_tree); 2247 2248 extern void cb_emit_unlock (cb_tree); 2249 2250 extern void cb_emit_unstring (cb_tree, cb_tree, cb_tree, cb_tree, 2251 cb_tree); 2252 extern cb_tree cb_build_unstring_delimited (cb_tree, cb_tree); 2253 extern cb_tree cb_build_unstring_into (cb_tree, cb_tree, cb_tree); 2254 2255 extern void cb_emit_write (cb_tree, cb_tree, cb_tree, cb_tree); 2256 extern cb_tree cb_build_write_advancing_lines (cb_tree, cb_tree); 2257 extern cb_tree cb_build_write_advancing_mnemonic (cb_tree, cb_tree); 2258 extern cb_tree cb_build_write_advancing_page (cb_tree); 2259 extern cb_tree cb_check_sum_field (cb_tree x); 2260 extern void cb_emit_initiate (cb_tree rep); 2261 extern void cb_emit_terminate (cb_tree rep); 2262 extern void cb_emit_generate (cb_tree rep); 2263 extern void cb_emit_suppress (struct cb_field *f); 2264 extern void cb_emit_xml_generate (cb_tree, cb_tree, cb_tree, 2265 cb_tree, const int, const int, 2266 cb_tree, cb_tree, cb_tree, 2267 cb_tree); 2268 extern void cb_emit_json_generate (cb_tree, cb_tree, cb_tree, 2269 cb_tree, cb_tree); 2270 2271 #ifdef COB_TREE_DEBUG 2272 extern cb_tree cobc_tree_cast_check (const cb_tree, const char *, 2273 const int, const enum cb_tag); 2274 #endif 2275 2276 2277 /* codegen.c */ 2278 extern void codegen (struct cb_program *, const char *); 2279 extern int cb_wants_dump_comments; /* likely to be removed later */ 2280 2281 /* scanner.l */ 2282 extern void cb_unput_dot (void); 2283 extern void cb_add_78 (struct cb_field *); 2284 extern void cb_reset_78 (void); 2285 extern void cb_reset_global_78 (void); 2286 extern struct cb_field *check_level_78 (const char *); 2287 2288 extern struct cb_program *cb_find_defined_program_by_name (const char *); 2289 extern struct cb_program *cb_find_defined_program_by_id (const char *); 2290 2291 /* cobc.c */ 2292 #ifndef COB_EXTERNAL_XREF 2293 #define COB_INTERNAL_XREF 2294 #endif 2295 2296 #ifdef COB_INTERNAL_XREF 2297 extern void cobc_xref_link (struct cb_xref *, const int, const int); 2298 extern void cobc_xref_link_parent (const struct cb_field *); 2299 extern void cobc_xref_set_receiving (const cb_tree); 2300 extern void cobc_xref_call (const char *, const int, const int, const int); 2301 #else 2302 #define cobc_xref_link(x,l,r) 2303 #define cobc_xref_link_parent(f) 2304 #define cobc_xref_set_receiving(t) 2305 #define cobc_xref_call (n l,i,s) 2306 #endif 2307 extern unsigned int cb_correct_program_order; 2308 2309 /* Function defines */ 2310 2311 #define CB_BUILD_FUNCALL_0(f) \ 2312 cb_build_funcall (f, 0, NULL, NULL, NULL, NULL, NULL, \ 2313 NULL, NULL, NULL, NULL, NULL, NULL) 2314 2315 #define CB_BUILD_FUNCALL_1(f,a1) \ 2316 cb_build_funcall (f, 1, a1, NULL, NULL, NULL, NULL, \ 2317 NULL, NULL, NULL, NULL, NULL, NULL) 2318 2319 #define CB_BUILD_FUNCALL_2(f,a1,a2) \ 2320 cb_build_funcall (f, 2, a1, a2, NULL, NULL, NULL, \ 2321 NULL, NULL, NULL, NULL, NULL, NULL) 2322 2323 #define CB_BUILD_FUNCALL_3(f,a1,a2,a3) \ 2324 cb_build_funcall (f, 3, a1, a2, a3, NULL, NULL, NULL, \ 2325 NULL, NULL, NULL, NULL, NULL) 2326 2327 #define CB_BUILD_FUNCALL_4(f,a1,a2,a3,a4) \ 2328 cb_build_funcall (f, 4, a1, a2, a3, a4, NULL, \ 2329 NULL, NULL, NULL, NULL, NULL, NULL) 2330 2331 #define CB_BUILD_FUNCALL_5(f,a1,a2,a3,a4,a5) \ 2332 cb_build_funcall (f, 5, a1, a2, a3, a4, a5, \ 2333 NULL, NULL, NULL, NULL, NULL, NULL) 2334 2335 #define CB_BUILD_FUNCALL_6(f,a1,a2,a3,a4,a5,a6) \ 2336 cb_build_funcall (f, 6, a1, a2, a3, a4, a5, a6, \ 2337 NULL, NULL, NULL, NULL, NULL) 2338 2339 #define CB_BUILD_FUNCALL_7(f,a1,a2,a3,a4,a5,a6,a7) \ 2340 cb_build_funcall (f, 7, a1, a2, a3, a4, a5, a6, a7, \ 2341 NULL, NULL, NULL, NULL) 2342 2343 #define CB_BUILD_FUNCALL_8(f,a1,a2,a3,a4,a5,a6,a7,a8) \ 2344 cb_build_funcall (f, 8, a1, a2, a3, a4, a5, a6, a7, a8, \ 2345 NULL, NULL, NULL) 2346 2347 #define CB_BUILD_FUNCALL_9(f,a1,a2,a3,a4,a5,a6,a7,a8,a9) \ 2348 cb_build_funcall (f, 9, a1, a2, a3, a4, a5, a6, a7, a8, \ 2349 a9, NULL, NULL) 2350 2351 #define CB_BUILD_FUNCALL_10(f,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) \ 2352 cb_build_funcall (f, 10, a1, a2, a3, a4, a5, a6, a7, a8, \ 2353 a9, a10, NULL) 2354 2355 #define CB_BUILD_FUNCALL_11(f,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11) \ 2356 cb_build_funcall (f, 11, a1, a2, a3, a4, a5, a6, a7, a8, \ 2357 a9, a10, a11) 2358 2359 /* Miscellaneous defines */ 2360 2361 #define CB_BUILD_CAST_ADDRESS(x) cb_build_cast (CB_CAST_ADDRESS, x) 2362 #define CB_BUILD_CAST_ADDR_OF_ADDR(x) cb_build_cast (CB_CAST_ADDR_OF_ADDR, x) 2363 #define CB_BUILD_CAST_LENGTH(x) cb_build_cast (CB_CAST_LENGTH, x) 2364 #define CB_BUILD_CAST_PPOINTER(x) cb_build_cast (CB_CAST_PROGRAM_POINTER, x) 2365 2366 #define CB_BUILD_PARENTHESES(x) cb_build_binary_op (x, '@', NULL) 2367 #define CB_BUILD_NEGATION(x) cb_build_binary_op (x, '!', NULL) 2368 2369 #define CB_BUILD_STRING0(str) cb_build_string (str, strlen ((char *)(str))) 2370 2371 #define CB_LIST_INIT(x) cb_build_list (NULL, x, NULL) 2372 #define CB_BUILD_CHAIN(x,y) cb_build_list (NULL, x, y) 2373 #define CB_BUILD_PAIR(x,y) cb_build_list (x, y, NULL) 2374 #define CB_ADD_TO_CHAIN(x,y) y = CB_BUILD_CHAIN (x, y) 2375 #define CB_CHAIN_PAIR(x,y,z) x = cb_pair_add (x, y, z) 2376 #define CB_FIELD_ADD(x,y) x = cb_field_add (x, y) 2377 2378 2379 #endif /* CB_TREE_H */ 2380