GnuCOBOL  2.0
A free COBOL compiler
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
reserved.c File Reference
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <ctype.h>
#include "cobc.h"
#include "tree.h"
#include "parser.h"
Include dependency graph for reserved.c:

Data Structures

struct  system_struct
 

Macros

#define SYSTEM_TAB_SIZE   sizeof(system_table) / sizeof(struct system_struct)
 
#define EXT_SYSTEM_TAB_SIZE   sizeof(ext_system_table) / sizeof(struct system_struct)
 
#define NUM_RESERVED_WORDS   sizeof (reserved_words) / sizeof (struct cobc_reserved)
 
#define NUM_INTRINSICS   sizeof(function_list) / sizeof(struct cb_intrinsic_table)
 

Functions

static int cob_strcasecmp (const void *s1, const void *s2)
 
static int reserve_comp (const void *p1, const void *p2)
 
static int intrinsic_comp (const void *p1, const void *p2)
 
static const char * res_get_feature (const enum cb_system_name_category category)
 
cb_tree lookup_system_name (const char *name)
 
struct cobc_reservedlookup_reserved_word (const char *name)
 
struct cb_intrinsic_tablelookup_intrinsic (const char *name, const int checkres, const int checkimpl)
 
void cb_list_reserved (void)
 
void cb_list_intrinsics (void)
 
void cb_list_mnemonics (void)
 
void cobc_init_reserved (void)
 

Variables

static struct system_struct system_table []
 
static struct system_struct ext_system_table []
 
static struct cobc_reserved reserved_words []
 
static struct cb_intrinsic_table function_list []
 
static unsigned char cob_lower_tab [256]
 
static const unsigned char pcob_lower_tab [] = "abcdefghijklmnopqrstuvwxyz"
 
static const unsigned char pcob_lower_val [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 

Macro Definition Documentation

#define EXT_SYSTEM_TAB_SIZE   sizeof(ext_system_table) / sizeof(struct system_struct)
#define NUM_INTRINSICS   sizeof(function_list) / sizeof(struct cb_intrinsic_table)
#define NUM_RESERVED_WORDS   sizeof (reserved_words) / sizeof (struct cobc_reserved)
#define SYSTEM_TAB_SIZE   sizeof(system_table) / sizeof(struct system_struct)

Function Documentation

void cb_list_intrinsics ( void  )

References _, and NUM_INTRINSICS.

Referenced by process_command_line().

2726 {
2727  const char *s;
2728  const char *t;
2729  size_t i;
2730  size_t n;
2731 
2732  putchar ('\n');
2733  puts (_("Intrinsic Function\t\tImplemented\tParameters"));
2734  for (i = 0; i < NUM_INTRINSICS; ++i) {
2735  n = strlen (function_list[i].name);
2736  switch (n / 8) {
2737  case 0:
2738  s = "\t\t\t\t";
2739  break;
2740  case 1:
2741  s = "\t\t\t";
2742  break;
2743  case 2:
2744  s = "\t\t";
2745  break;
2746  default:
2747  s = "\t";
2748  break;
2749  }
2750  if (function_list[i].implemented) {
2751  t = _("Y");
2752  } else {
2753  t = _("N");
2754  }
2755  if (function_list[i].args < 0) {
2756  printf ("%s%s%s\t\tVariable\n", function_list[i].name,
2757  s, t);
2758  } else {
2759  printf ("%s%s%s\t\t%d\n", function_list[i].name,
2760  s, t, function_list[i].args);
2761  }
2762  }
2763 }
void cb_list_mnemonics ( void  )

References _, EXT_SYSTEM_TAB_SIZE, res_get_feature(), and SYSTEM_TAB_SIZE.

Referenced by process_command_line().

2767 {
2768  const char *tabs;
2769  const char *feature;
2770  size_t i;
2771 
2772  putchar ('\n');
2773  puts (_("Mnemonic names"));
2774  for (i = 0; i < SYSTEM_TAB_SIZE; ++i) {
2775  if (strlen (system_table[i].name) < 8) {
2776  tabs = "\t\t";
2777  } else {
2778  tabs = "\t";
2779  }
2780  feature = res_get_feature (system_table[i].category);
2781  printf ("%s%s%s\n", system_table[i].name, tabs, feature);
2782  }
2783  putchar ('\n');
2784  puts (_("Extended mnemonic names (with -fsyntax-extension)"));
2785  for (i = 0; i < EXT_SYSTEM_TAB_SIZE; ++i) {
2786  if (strlen (ext_system_table[i].name) < 8) {
2787  tabs = "\t\t";
2788  } else {
2789  tabs = "\t";
2790  }
2791  feature = res_get_feature (ext_system_table[i].category);
2792  printf ("%s%s%s\n", ext_system_table[i].name, tabs, feature);
2793  }
2794 }
void cb_list_reserved ( void  )

References _, NUM_RESERVED_WORDS, and p.

Referenced by process_command_line().

2664 {
2665  const char *s;
2666  const char *p;
2667  size_t i;
2668  size_t n;
2669 
2670  putchar ('\n');
2671  printf (_("Reserved Words\t\t\tImplemented (Y/N)"));
2672  puts ("\n");
2673  for (i = 0; i < NUM_RESERVED_WORDS; ++i) {
2674  n = strlen (reserved_words[i].name);
2675  switch (n / 8) {
2676  case 0:
2677  s = "\t\t\t\t";
2678  break;
2679  case 1:
2680  s = "\t\t\t";
2681  break;
2682  case 2:
2683  s = "\t\t";
2684  break;
2685  default:
2686  s = "\t";
2687  break;
2688  }
2689  if (reserved_words[i].token == 0) {
2690  p = _("N (85 obsolete)");
2691  } else if (reserved_words[i].token > 0) {
2692  if (reserved_words[i].context_sens) {
2693  p = _("Y (Context sensitive)");
2694  } else {
2695  p = _("Y");
2696  }
2697  } else {
2698  if (reserved_words[i].context_sens) {
2699  p = _("N (Context sensitive)");
2700  } else {
2701  p = _("N");
2702  }
2703  }
2704  printf ("%s%s%s\n", reserved_words[i].name, s, p);
2705  }
2706  putchar ('\n');
2707  puts (_("Extra (obsolete) context sensitive words"));
2708  puts ("AUTHOR");
2709  puts ("DATE-COMPILED");
2710  puts ("DATE-MODIFIED");
2711  puts ("DATE-WRITTEN");
2712  puts ("INSTALLATION");
2713  puts ("REMARKS");
2714  puts ("SECURITY");
2715  putchar ('\n');
2716  puts (_("Extra internal registers\tDefinition"));
2717  puts ("RETURN-CODE\t\t\tUSAGE BINARY-LONG");
2718  puts ("SORT-RETURN\t\t\tUSAGE BINARY-LONG");
2719  puts ("NUMBER-OF-CALL-PARAMETERS\tUSAGE BINARY-LONG");
2720  puts ("COB-CRT-STATUS\t\t\tPIC 9(4)");
2721  puts ("'LENGTH OF' phrase\t\tUSAGE BINARY-LONG");
2722 }
static int cob_strcasecmp ( const void *  s1,
const void *  s2 
)
static

References cob_lower_tab.

Referenced by intrinsic_comp(), lookup_system_name(), and reserve_comp().

2480 {
2481  const unsigned char *p1;
2482  const unsigned char *p2;
2483  unsigned char c1;
2484  unsigned char c2;
2485 
2486  /* Note - second parameter is assumed already upper case */
2487 
2488  p1 = (const unsigned char *)s1;
2489  p2 = (const unsigned char *)s2;
2490 
2491  for (;;) {
2492  if (cob_lower_tab[*p1]) {
2493  c1 = cob_lower_tab[*p1++];
2494  } else {
2495  c1 = *p1++;
2496  }
2497  c2 = *p2++;
2498  if (c1 != c2) {
2499  return c1 < c2 ? -1 : 1;
2500  }
2501  if (!c1) {
2502  break;
2503  }
2504  }
2505  return 0;
2506 }
void cobc_init_reserved ( void  )

References cob_lower_tab, p, pcob_lower_tab, and pcob_lower_val.

Referenced by main().

2799 {
2800  const unsigned char *p;
2801  const unsigned char *v;
2802 
2803  memset (cob_lower_tab, 0, sizeof(cob_lower_tab));
2804  p = pcob_lower_tab;
2805  v = pcob_lower_val;
2806  for (; *p; ++p, ++v) {
2807  cob_lower_tab[*p] = *v;
2808  }
2809 }
static int intrinsic_comp ( const void *  p1,
const void *  p2 
)
static

References cob_strcasecmp(), and cb_intrinsic_table::name.

Referenced by lookup_intrinsic().

2516 {
2517  return cob_strcasecmp (p1, ((struct cb_intrinsic_table *)p2)->name);
2518 }
struct cb_intrinsic_table* lookup_intrinsic ( const char *  name,
const int  checkres,
const int  checkimpl 
)
read

References cobc_nores_base, cb_intrinsic_table::implemented, intrinsic_comp(), noreserve::next, noreserve::noresword, NULL, NUM_INTRINSICS, and unlikely.

Referenced by cb_build_any_intrinsic(), cb_build_intrinsic(), cobc_deciph_funcs(), and while().

2643 {
2644  struct cb_intrinsic_table *cbp;
2645  struct noreserve *nr;
2646 
2647  if (unlikely(cobc_nores_base && checkres)) {
2648  for (nr = cobc_nores_base; nr; nr = nr->next) {
2649  if (strcasecmp (name, nr->noresword) == 0) {
2650  return NULL;
2651  }
2652  }
2653  }
2654  cbp = bsearch (name, function_list, NUM_INTRINSICS,
2655  sizeof (struct cb_intrinsic_table), intrinsic_comp);
2656  if (cbp && (checkimpl || cbp->implemented)) {
2657  return cbp;
2658  }
2659  return NULL;
2660 }
struct cobc_reserved* lookup_reserved_word ( const char *  name)
read

References _, CB_CS_PROGRAM_ID, cb_error(), cobc_cs_check, cobc_force_literal, cobc_in_procedure, cobc_in_repository, cobc_nores_base, cobc_reserved::context_sens, cobc_reserved::context_set, cobc_reserved::context_test, FUNCTION_ID, INTRINSIC, noreserve::next, noreserve::noresword, NULL, NUM_RESERVED_WORDS, p, PROGRAM_ID, REPOSITORY, reserve_comp(), cobc_reserved::token, and unlikely.

Referenced by while().

2568 {
2569  struct cobc_reserved *p;
2570  struct noreserve *nr;
2571 
2572  p = bsearch (name, reserved_words, NUM_RESERVED_WORDS,
2573  sizeof (struct cobc_reserved), reserve_comp);
2574  if (!p) {
2575  return NULL;
2576  }
2577 
2578  /* Allow obsolete/unimplemented 85 keywords as user names */
2579  if (!p->token && !cb_cobol85_reserved) {
2580  return NULL;
2581  }
2582 
2583  /* Check if the configuration has unreserved the word */
2584  for (nr = cobc_nores_base; nr; nr = nr->next) {
2585  if (strcasecmp (name, nr->noresword) == 0) {
2586  return NULL;
2587  }
2588  }
2589 
2590  /* Check word is implemented */
2591  if (unlikely(p->token <= 0)) {
2592  /* Not implemented - If context sensitive, no error */
2593  if (!p->context_sens) {
2594  cb_error (_("'%s' reserved word, but not supported"), name);
2595  }
2596  return NULL;
2597  }
2598 
2599  /* Special actions / Context sensitive */
2600  if (p->context_set) {
2601  if (unlikely(p->context_test)) {
2602  /* Dependent words */
2603  if (!(cobc_cs_check & p->context_test)) {
2604  return p;
2605  }
2606  }
2607  cobc_cs_check |= p->context_set;
2608  return p;
2609  }
2610 
2611  if (p->context_test) {
2612 #if 0 /* RXWRXW - CS check */
2613  if (!(cobc_cs_check & p->context_test)) {
2614 #endif
2615  if ((cobc_cs_check & p->context_test) != p->context_test) {
2616  return NULL;
2617  }
2618  if (!cobc_in_procedure) {
2619  cobc_cs_check = 0;
2620  }
2621  return p;
2622  }
2623 
2624  if (p->token == FUNCTION_ID) {
2625  cobc_cs_check = 0;
2626  cobc_force_literal = 1;
2627  } else if (p->token == INTRINSIC) {
2628  if (!cobc_in_repository) {
2629  return NULL;
2630  }
2631  } else if (p->token == PROGRAM_ID) {
2633  cobc_force_literal = 1;
2634  } else if (p->token == REPOSITORY) {
2635  cobc_in_repository = 1;
2636  }
2637 
2638  return p;
2639 }
cb_tree lookup_system_name ( const char *  name)

References cb_intrinsic_table::category, cb_build_system_name(), cob_strcasecmp(), EXT_SYSTEM_TAB_SIZE, NULL, SYSTEM_TAB_SIZE, and cb_intrinsic_table::token.

Referenced by cb_build_display_name(), cb_define_system_name(), and cb_emit_accept_name().

2546 {
2547  size_t i;
2548 
2549  for (i = 0; i < SYSTEM_TAB_SIZE; ++i) {
2550  if (cob_strcasecmp (name, system_table[i].name) == 0) {
2551  return cb_build_system_name (system_table[i].category,
2552  system_table[i].token);
2553  }
2554  }
2555  if (cb_flag_syntax_extension) {
2556  for (i = 0; i < EXT_SYSTEM_TAB_SIZE; ++i) {
2557  if (cob_strcasecmp (name, ext_system_table[i].name) == 0) {
2558  return cb_build_system_name (ext_system_table[i].category,
2559  ext_system_table[i].token);
2560  }
2561  }
2562  }
2563  return NULL;
2564 }
static const char* res_get_feature ( const enum cb_system_name_category  category)
static

References _, CB_DEVICE_NAME, CB_FEATURE_NAME, and CB_SWITCH_NAME.

Referenced by cb_list_mnemonics().

2522 {
2523  const char *s;
2524 
2525  switch (category) {
2526  case CB_DEVICE_NAME:
2527  s = _("Device name");
2528  break;
2529  case CB_SWITCH_NAME:
2530  s = _("Switch name");
2531  break;
2532  case CB_FEATURE_NAME:
2533  s = _("Feature name");
2534  break;
2535  default:
2536  s = _("Unknown");
2537  break;
2538  }
2539  return s;
2540 }
static int reserve_comp ( const void *  p1,
const void *  p2 
)
static

References cob_strcasecmp(), and cb_intrinsic_table::name.

Referenced by lookup_reserved_word().

2510 {
2511  return cob_strcasecmp (p1, ((struct cobc_reserved *)p2)->name);
2512 }

Variable Documentation

unsigned char cob_lower_tab[256]
static
struct cb_intrinsic_table function_list[]
static
const unsigned char pcob_lower_tab[] = "abcdefghijklmnopqrstuvwxyz"
static

Referenced by cobc_init_reserved().

const unsigned char pcob_lower_val[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
static

Referenced by cobc_init_reserved().

struct cobc_reserved reserved_words[]
static
struct system_struct system_table[]
static