GnuCOBOL  2.0
A free COBOL compiler
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:

Go to the source code of this file.

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_DEFAULT_RESERVED_WORDS   sizeof (default_reserved_words) / sizeof (struct cobc_reserved)
 
#define NUM_INTRINSICS   sizeof(function_list) / sizeof(struct cb_intrinsic_table)
 

Enumerations

enum  free_word_action { FREE_WORD_STR, DONT_FREE_WORD_STR }
 

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)
 
static struct cobc_reserved create_dummy_reserved (const char *word)
 
static void delete_reserved_word_from_list (struct reserved_word_list *const prev, const enum free_word_action action, struct reserved_word_list *to_delete)
 
static COB_INLINE COB_A_INLINE int has_context_sensitive_indicator (const char *word, const size_t size)
 
static void allocate_str_removing_asterisk (const char *word, const size_t size, char **const out_str)
 
static COB_INLINE COB_A_INLINE void initialize_word (const char *word, const size_t size, struct reserved_word_list *const reserved)
 
static void initialize_alias_for (const char *alias_for, struct reserved_word_list *const reserved, const char *fname, const int line)
 
static void add_reserved_word_without_init (const char *word, const char *fname, const int line)
 
static void initialize_user_res_list_if_needed (void)
 
static size_t get_length_of_user_res_list (void)
 
static COB_INLINE COB_A_INLINE struct cobc_reservedfind_default_reserved_word (struct cobc_reserved *to_find)
 
static struct cobc_reserved get_user_specified_reserved_word (struct reserved_word_list user_reserved)
 
static COB_INLINE COB_A_INLINE void pop_reserved_word (const enum free_word_action action)
 
static void get_reserved_words_from_user_list (void)
 
static void get_reserved_words_from_default_list (void)
 
static void initialize_reserved_words_if_needed (void)
 
cb_tree lookup_system_name (const char *name)
 
void remove_reserved_word (const char *word)
 
void add_reserved_word (const char *word, const char *fname, const int line)
 
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

struct reserved_word_listcobc_user_res_list = ((void*)0)
 
static const struct system_struct system_table []
 
static const struct system_struct ext_system_table []
 
static struct cobc_reservedreserved_words
 
static struct cobc_reserved default_reserved_words []
 
static size_t num_reserved_words
 
static const 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)

Definition at line 188 of file reserved.c.

Referenced by cb_list_mnemonics(), and lookup_system_name().

#define NUM_DEFAULT_RESERVED_WORDS   sizeof (default_reserved_words) / sizeof (struct cobc_reserved)
#define NUM_INTRINSICS   sizeof(function_list) / sizeof(struct cb_intrinsic_table)

Definition at line 2490 of file reserved.c.

Referenced by cb_list_intrinsics(), and lookup_intrinsic().

#define SYSTEM_TAB_SIZE   sizeof(system_table) / sizeof(struct system_struct)

Definition at line 114 of file reserved.c.

Referenced by cb_list_mnemonics(), and lookup_system_name().

Enumeration Type Documentation

Enumerator
FREE_WORD_STR 
DONT_FREE_WORD_STR 

Definition at line 2613 of file reserved.c.

2613  {
2614  FREE_WORD_STR,
2616 };

Function Documentation

void add_reserved_word ( const char *  word,
const char *  fname,
const int  line 
)

Definition at line 2903 of file reserved.c.

References add_reserved_word_without_init(), and initialize_user_res_list_if_needed().

Referenced by cb_config_entry().

2904 {
2906  add_reserved_word_without_init (word, fname, line);
2907 }
static void add_reserved_word_without_init(const char *word, const char *fname, const int line)
Definition: reserved.c:2683
static void initialize_user_res_list_if_needed(void)
Definition: reserved.c:2725
if fold fold static computed alternate extra correct stack on syntax debugging line
Definition: flag.def:90

Here is the call graph for this function:

Here is the caller graph for this function:

static void add_reserved_word_without_init ( const char *  word,
const char *  fname,
const int  line 
)
static

Definition at line 2683 of file reserved.c.

References reserved_word_list::alias_for, cob_strcasecmp(), cobc_main_malloc(), cobc_user_res_list, has_context_sensitive_indicator(), initialize_alias_for(), initialize_word(), reserved_word_list::is_context_sensitive, reserved_word_list::next, NULL, and reserved_word_list::word.

Referenced by add_reserved_word(), and initialize_user_res_list_if_needed().

2685 {
2686  struct reserved_word_list *reserved;
2687  size_t size;
2688  char *equal_sign_pos;
2689 
2690  /* Check the word has not already been specified */
2691  for (reserved = cobc_user_res_list; reserved; reserved = reserved->next)
2692  {
2693  if (cob_strcasecmp (reserved->word, word) == 0) {
2694  return;
2695  }
2696  }
2697 
2698  /* Find how the length of the word */
2699  equal_sign_pos = strchr (word, '=');
2700  if (equal_sign_pos) {
2701  size = equal_sign_pos - word;
2702  } else {
2703  size = strlen (word);
2704  }
2705 
2706  reserved = cobc_main_malloc (sizeof (struct reserved_word_list));
2707  reserved->is_context_sensitive
2709  initialize_word (word, size, reserved);
2710 
2711  /* If it is an alias, copy what it is an alias for */
2712  if (equal_sign_pos) {
2713  initialize_alias_for (equal_sign_pos + 1, reserved, fname,
2714  line);
2715  } else {
2716  reserved->alias_for = NULL;
2717  }
2718 
2719  /* Insert word at beginning of cobc_user_res_list. */
2720  reserved->next = cobc_user_res_list;
2721  cobc_user_res_list = reserved;
2722 }
void * cobc_main_malloc(const size_t size)
Definition: cobc.c:702
static void initialize_alias_for(const char *alias_for, struct reserved_word_list *const reserved, const char *fname, const int line)
Definition: reserved.c:2670
struct reserved_word_list * cobc_user_res_list
Definition: reserved.c:36
int is_context_sensitive
Definition: cobc.h:225
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
struct reserved_word_list * next
Definition: cobc.h:223
char * alias_for
Definition: cobc.h:226
static int cob_strcasecmp(const void *s1, const void *s2)
Definition: reserved.c:2530
if fold fold static computed alternate extra correct stack on syntax debugging line
Definition: flag.def:90
static COB_INLINE COB_A_INLINE void initialize_word(const char *word, const size_t size, struct reserved_word_list *const reserved)
Definition: reserved.c:2663
char * word
Definition: cobc.h:224
static COB_INLINE COB_A_INLINE int has_context_sensitive_indicator(const char *word, const size_t size)
Definition: reserved.c:2640

Here is the call graph for this function:

Here is the caller graph for this function:

static void allocate_str_removing_asterisk ( const char *  word,
const size_t  size,
char **const  out_str 
)
static

Definition at line 2646 of file reserved.c.

References cobc_main_malloc(), and has_context_sensitive_indicator().

Referenced by initialize_alias_for(), and initialize_word().

2647 {
2648  size_t chars_to_copy;
2649 
2650  if (has_context_sensitive_indicator (word, size)) {
2651  /* Don't copy the trailing asterisk */
2652  chars_to_copy = size - 1;
2653  } else {
2654  chars_to_copy = size;
2655  }
2656 
2657  *out_str = cobc_main_malloc (chars_to_copy + 1U);
2658  strncpy (*out_str, word, chars_to_copy);
2659  (*out_str)[chars_to_copy] = '\0';
2660 }
void * cobc_main_malloc(const size_t size)
Definition: cobc.c:702
char * word
Definition: cobc.h:224
static COB_INLINE COB_A_INLINE int has_context_sensitive_indicator(const char *word, const size_t size)
Definition: reserved.c:2640

Here is the call graph for this function:

Here is the caller graph for this function:

void cb_list_intrinsics ( void  )

Definition at line 3052 of file reserved.c.

References _, cb_intrinsic_table::args, cob_free(), cob_malloc(), cb_intrinsic_table::implemented, cb_intrinsic_table::min_args, and NUM_INTRINSICS.

Referenced by process_command_line().

3053 {
3054  const char *s;
3055  const char *t;
3056  char *argnum;
3057  size_t i;
3058  size_t n;
3059 
3060  putchar ('\n');
3061  puts (_("Intrinsic Function\t\tImplemented\tParameters"));
3062  for (i = 0; i < NUM_INTRINSICS; ++i) {
3063  n = strlen (function_list[i].name);
3064  switch (n / 8) {
3065  case 0:
3066  s = "\t\t\t\t";
3067  break;
3068  case 1:
3069  s = "\t\t\t";
3070  break;
3071  case 2:
3072  s = "\t\t";
3073  break;
3074  default:
3075  s = "\t";
3076  break;
3077  }
3078  if (function_list[i].implemented) {
3079  t = _("Y");
3080  } else {
3081  t = _("N");
3082  }
3083  if (function_list[i].args == -1) {
3084  printf ("%s%s%s\t\t%s\n", function_list[i].name, s, t, _("Unlimited"));
3085  } else {
3086  if (function_list[i].args != function_list[i].min_args) {
3087  argnum = cob_malloc (7);
3088  snprintf (argnum, 7, "%d - %d", (int)function_list[i].min_args,
3089  (int)function_list[i].args);
3090  } else {
3091  argnum = cob_malloc (3);
3092  snprintf (argnum, 3, "%d", (int)function_list[i].args);
3093  }
3094  printf ("%s%s%s\t\t%s\n", function_list[i].name, s, t, argnum);
3095  cob_free (argnum);
3096  }
3097  }
3098 }
void cob_free(void *mptr)
Definition: common.c:1284
#define NUM_INTRINSICS
Definition: reserved.c:2490
static const struct cb_intrinsic_table function_list[]
Definition: reserved.c:1965
#define _(s)
Definition: cobcrun.c:59
void * cob_malloc(const size_t size)
Definition: common.c:1250

Here is the call graph for this function:

Here is the caller graph for this function:

void cb_list_mnemonics ( void  )

Definition at line 3101 of file reserved.c.

References _, cb_intrinsic_table::category, EXT_SYSTEM_TAB_SIZE, res_get_feature(), and SYSTEM_TAB_SIZE.

Referenced by process_command_line().

3102 {
3103  const char *tabs;
3104  const char *feature;
3105  size_t i;
3106 
3107  putchar ('\n');
3108  puts (_("Mnemonic names"));
3109  for (i = 0; i < SYSTEM_TAB_SIZE; ++i) {
3110  if (strlen (system_table[i].name) < 8) {
3111  tabs = "\t\t";
3112  } else {
3113  tabs = "\t";
3114  }
3115  feature = res_get_feature (system_table[i].category);
3116  printf ("%s%s%s\n", system_table[i].name, tabs, feature);
3117  }
3118  putchar ('\n');
3119  puts (_("Extended mnemonic names (with -fsyntax-extension)"));
3120  for (i = 0; i < EXT_SYSTEM_TAB_SIZE; ++i) {
3121  if (strlen (ext_system_table[i].name) < 8) {
3122  tabs = "\t\t";
3123  } else {
3124  tabs = "\t";
3125  }
3126  feature = res_get_feature (ext_system_table[i].category);
3127  printf ("%s%s%s\n", ext_system_table[i].name, tabs, feature);
3128  }
3129 }
#define SYSTEM_TAB_SIZE
Definition: reserved.c:114
static const char * res_get_feature(const enum cb_system_name_category category)
Definition: reserved.c:2577
#define _(s)
Definition: cobcrun.c:59
#define EXT_SYSTEM_TAB_SIZE
Definition: reserved.c:188
static const struct system_struct ext_system_table[]
Definition: reserved.c:116

Here is the call graph for this function:

Here is the caller graph for this function:

void cb_list_reserved ( void  )

Definition at line 2989 of file reserved.c.

References _, initialize_reserved_words_if_needed(), num_reserved_words, and cb_intrinsic_table::token.

Referenced by process_command_line().

2990 {
2991  const char *s;
2992  const char *p;
2993  size_t i;
2994  size_t n;
2995 
2997 
2998  putchar ('\n');
2999  printf (_("Reserved Words\t\t\tImplemented (Y/N)"));
3000  puts ("\n");
3001  for (i = 0; i < num_reserved_words; ++i) {
3002  n = strlen (reserved_words[i].name);
3003  switch (n / 8) {
3004  case 0:
3005  s = "\t\t\t\t";
3006  break;
3007  case 1:
3008  s = "\t\t\t";
3009  break;
3010  case 2:
3011  s = "\t\t";
3012  break;
3013  default:
3014  s = "\t";
3015  break;
3016  }
3017  if (reserved_words[i].token > 0) {
3018  if (reserved_words[i].context_sens) {
3019  p = _("Y (Context sensitive)");
3020  } else {
3021  p = _("Y");
3022  }
3023  } else {
3024  if (reserved_words[i].context_sens) {
3025  p = _("N (Context sensitive)");
3026  } else {
3027  p = _("N");
3028  }
3029  }
3030  printf ("%s%s%s\n", reserved_words[i].name, s, p);
3031  }
3032  putchar ('\n');
3033  puts (_("Extra (obsolete) context sensitive words"));
3034  puts ("AUTHOR");
3035  puts ("DATE-COMPILED");
3036  puts ("DATE-MODIFIED");
3037  puts ("DATE-WRITTEN");
3038  puts ("INSTALLATION");
3039  puts ("REMARKS");
3040  puts ("SECURITY");
3041  putchar ('\n');
3042  puts (_("Extra internal registers\tDefinition"));
3043  puts ("RETURN-CODE\t\t\tUSAGE BINARY-LONG");
3044  puts ("SORT-RETURN\t\t\tUSAGE BINARY-LONG");
3045  puts ("NUMBER-OF-CALL-PARAMETERS\tUSAGE BINARY-LONG");
3046  puts ("COB-CRT-STATUS\t\t\tPIC 9(4)");
3047  puts ("TALLY\t\t\t\tGLOBAL PIC 9(5) USAGE BINARY VALUE ZERO");
3048  puts ("'LENGTH OF' phrase\t\tUSAGE BINARY-LONG");
3049 }
static size_t num_reserved_words
Definition: reserved.c:1953
static void initialize_reserved_words_if_needed(void)
Definition: reserved.c:2846
static struct cobc_reserved * reserved_words
Definition: reserved.c:198
#define _(s)
Definition: cobcrun.c:59

Here is the call graph for this function:

Here is the caller graph for this function:

static int cob_strcasecmp ( const void *  s1,
const void *  s2 
)
static

Definition at line 2530 of file reserved.c.

References cob_lower_tab.

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

2531 {
2532  const unsigned char *p1;
2533  const unsigned char *p2;
2534  unsigned char c1;
2535  unsigned char c2;
2536 
2537  p1 = (const unsigned char *)s1;
2538  p2 = (const unsigned char *)s2;
2539 
2540  for (;;) {
2541  if (cob_lower_tab[*p1]) {
2542  c1 = cob_lower_tab[*p1++];
2543  } else {
2544  c1 = *p1++;
2545  }
2546 
2547  if (cob_lower_tab[*p2]) {
2548  c2 = cob_lower_tab[*p2++];
2549  } else {
2550  c2 = *p2++;
2551  }
2552 
2553  if (c1 != c2) {
2554  return c1 < c2 ? -1 : 1;
2555  }
2556  if (!c1) {
2557  break;
2558  }
2559  }
2560  return 0;
2561 }
static unsigned char cob_lower_tab[256]
Definition: reserved.c:2522

Here is the caller graph for this function:

void cobc_init_reserved ( void  )

Definition at line 3133 of file reserved.c.

References cob_lower_tab, pcob_lower_tab, and pcob_lower_val.

Referenced by main().

3134 {
3135  const unsigned char *p;
3136  const unsigned char *v;
3137 
3138  memset (cob_lower_tab, 0, sizeof(cob_lower_tab));
3139  p = pcob_lower_tab;
3140  v = pcob_lower_val;
3141  for (; *p; ++p, ++v) {
3142  cob_lower_tab[*p] = *v;
3143  }
3144 }
static unsigned char cob_lower_tab[256]
Definition: reserved.c:2522
static const unsigned char pcob_lower_val[]
Definition: reserved.c:2524
static const unsigned char pcob_lower_tab[]
Definition: reserved.c:2523

Here is the caller graph for this function:

static struct cobc_reserved create_dummy_reserved ( const char *  word)
static

Definition at line 2599 of file reserved.c.

References cobc_reserved::context_sens, cobc_reserved::context_set, cobc_reserved::context_test, cobc_reserved::name, cobc_reserved::nodegen, and cobc_reserved::token.

Referenced by get_reserved_words_from_user_list(), get_user_specified_reserved_word(), and lookup_reserved_word().

2600 {
2601  struct cobc_reserved ret;
2602 
2603  ret.name = word;
2604  ret.nodegen = 0;
2605  ret.context_sens = 0;
2606  ret.token = -1;
2607  ret.context_set = 0;
2608  ret.context_test = 0;
2609 
2610  return ret;
2611 }
const char * name
Definition: tree.h:418

Here is the caller graph for this function:

static void delete_reserved_word_from_list ( struct reserved_word_list *const  prev,
const enum free_word_action  action,
struct reserved_word_list to_delete 
)
static

Definition at line 2619 of file reserved.c.

References reserved_word_list::alias_for, cobc_main_free(), FREE_WORD_STR, reserved_word_list::next, and reserved_word_list::word.

Referenced by pop_reserved_word(), and remove_reserved_word().

2622 {
2623  if (prev) {
2624  prev->next = to_delete->next;
2625  }
2626  if (to_delete == cobc_user_res_list) {
2627  cobc_user_res_list = to_delete->next;
2628  }
2629 
2630  if (action == FREE_WORD_STR) {
2631  cobc_main_free (to_delete->word);
2632  }
2633 
2634  cobc_main_free (to_delete->alias_for);
2635 
2636  cobc_main_free (to_delete);
2637 }
void cobc_main_free(void *prevptr)
Definition: cobc.c:778
struct reserved_word_list * cobc_user_res_list
Definition: reserved.c:36
struct reserved_word_list * next
Definition: cobc.h:223
char * alias_for
Definition: cobc.h:226
char * word
Definition: cobc.h:224

Here is the call graph for this function:

Here is the caller graph for this function:

static COB_INLINE COB_A_INLINE struct cobc_reserved* find_default_reserved_word ( struct cobc_reserved to_find)
static

Definition at line 2752 of file reserved.c.

References NUM_DEFAULT_RESERVED_WORDS, and reserve_comp().

Referenced by get_reserved_words_from_user_list(), and get_user_specified_reserved_word().

2753 {
2754  return bsearch (to_find, default_reserved_words,
2756  sizeof (struct cobc_reserved), reserve_comp);
2757 }
static struct cobc_reserved default_reserved_words[]
Definition: reserved.c:200
static int reserve_comp(const void *p1, const void *p2)
Definition: reserved.c:2564
#define NUM_DEFAULT_RESERVED_WORDS
Definition: reserved.c:1954

Here is the call graph for this function:

Here is the caller graph for this function:

static size_t get_length_of_user_res_list ( void  )
static

Definition at line 2742 of file reserved.c.

References cobc_user_res_list, and reserved_word_list::next.

Referenced by get_reserved_words_from_user_list().

2743 {
2745  size_t length;
2746 
2747  for (length = 0; l; ++length, l = l->next);
2748  return length;
2749 }
struct reserved_word_list * cobc_user_res_list
Definition: reserved.c:36
struct reserved_word_list * next
Definition: cobc.h:223

Here is the caller graph for this function:

static void get_reserved_words_from_default_list ( void  )
static

Definition at line 2839 of file reserved.c.

References default_reserved_words, NUM_DEFAULT_RESERVED_WORDS, and num_reserved_words.

Referenced by initialize_reserved_words_if_needed().

2840 {
2843 }
static size_t num_reserved_words
Definition: reserved.c:1953
static struct cobc_reserved default_reserved_words[]
Definition: reserved.c:200
static struct cobc_reserved * reserved_words
Definition: reserved.c:198
#define NUM_DEFAULT_RESERVED_WORDS
Definition: reserved.c:1954

Here is the caller graph for this function:

static void get_reserved_words_from_user_list ( void  )
static

Definition at line 2793 of file reserved.c.

References cobc_main_malloc(), cobc_user_res_list, create_dummy_reserved(), DONT_FREE_WORD_STR, find_default_reserved_word(), FREE_WORD_STR, get_length_of_user_res_list(), get_user_specified_reserved_word(), num_reserved_words, pop_reserved_word(), reserve_comp(), and reserved_word_list::word.

Referenced by initialize_reserved_words_if_needed().

2794 {
2795  int i;
2796  struct cobc_reserved to_find;
2797  struct cobc_reserved *p;
2798 
2801  * sizeof (struct cobc_reserved));
2802 
2803  /*
2804  Populate reserved_words array with data from default_reserved_words,
2805  where possible. Free each word once processed.
2806  */
2807  for (i = 0; cobc_user_res_list; ++i) {
2809  p = find_default_reserved_word (&to_find);
2810  if (p) {
2811  reserved_words[i] = *p;
2812  /*
2813  Note that we ignore if the user specified this word
2814  as context-sensitive.
2815  */
2816 
2817  /*
2818  We use the string literal in the default_reserved_
2819  words array.
2820  */
2822  } else {
2824 
2825  /*
2826  We use the string copy allocated for cobc_user_res_
2827  list.
2828  */
2830  }
2831  }
2832 
2833  /* Later code assumes the array to be sorted */
2835  sizeof (struct cobc_reserved), reserve_comp);
2836 }
static COB_INLINE COB_A_INLINE void pop_reserved_word(const enum free_word_action action)
Definition: reserved.c:2787
static size_t get_length_of_user_res_list(void)
Definition: reserved.c:2742
void * cobc_main_malloc(const size_t size)
Definition: cobc.c:702
static size_t num_reserved_words
Definition: reserved.c:1953
struct reserved_word_list * cobc_user_res_list
Definition: reserved.c:36
static struct cobc_reserved * reserved_words
Definition: reserved.c:198
static int reserve_comp(const void *p1, const void *p2)
Definition: reserved.c:2564
static COB_INLINE COB_A_INLINE struct cobc_reserved * find_default_reserved_word(struct cobc_reserved *to_find)
Definition: reserved.c:2752
static struct cobc_reserved create_dummy_reserved(const char *word)
Definition: reserved.c:2599
char * word
Definition: cobc.h:224
static struct cobc_reserved get_user_specified_reserved_word(struct reserved_word_list user_reserved)
Definition: reserved.c:2760

Here is the call graph for this function:

Here is the caller graph for this function:

static struct cobc_reserved get_user_specified_reserved_word ( struct reserved_word_list  user_reserved)
static

Definition at line 2760 of file reserved.c.

References _, configuration_error(), cobc_reserved::context_sens, create_dummy_reserved(), find_default_reserved_word(), NULL, and cobc_reserved::token.

Referenced by get_reserved_words_from_user_list().

2761 {
2762  struct cobc_reserved to_find;
2764  = create_dummy_reserved (user_reserved.word);
2765  struct cobc_reserved *p;
2766 
2767  if (!user_reserved.alias_for) {
2768  cobc_reserved.context_sens
2769  = user_reserved.is_context_sensitive;
2770  } else {
2771  to_find = create_dummy_reserved (user_reserved.alias_for);
2772  p = find_default_reserved_word (&to_find);
2773 
2774  if (p) {
2775  cobc_reserved.token = p->token;
2776  } else {
2777  configuration_error (NULL, 0, 1,
2778  _("Alias target '%s' is not a default reserved word"),
2779  user_reserved.alias_for);
2780  }
2781  }
2782 
2783  return cobc_reserved;
2784 }
unsigned short context_sens
Definition: tree.h:420
int is_context_sensitive
Definition: cobc.h:225
#define _(s)
Definition: cobcrun.c:59
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static COB_INLINE COB_A_INLINE struct cobc_reserved * find_default_reserved_word(struct cobc_reserved *to_find)
Definition: reserved.c:2752
char * alias_for
Definition: cobc.h:226
static struct cobc_reserved create_dummy_reserved(const char *word)
Definition: reserved.c:2599
void configuration_error(const char *, const int, const int, const char *,...) COB_A_FORMAT45
Definition: error.c:178
int token
Definition: tree.h:421
char * word
Definition: cobc.h:224

Here is the call graph for this function:

Here is the caller graph for this function:

static COB_INLINE COB_A_INLINE int has_context_sensitive_indicator ( const char *  word,
const size_t  size 
)
static

Definition at line 2640 of file reserved.c.

Referenced by add_reserved_word_without_init(), allocate_str_removing_asterisk(), and initialize_alias_for().

2641 {
2642  return word[size - 1] == '*';
2643 }

Here is the caller graph for this function:

static void initialize_alias_for ( const char *  alias_for,
struct reserved_word_list *const  reserved,
const char *  fname,
const int  line 
)
static

Definition at line 2670 of file reserved.c.

References _, reserved_word_list::alias_for, allocate_str_removing_asterisk(), configuration_warning(), and has_context_sensitive_indicator().

Referenced by add_reserved_word_without_init().

2673 {
2674  const size_t size = strlen (alias_for);
2675 
2676  if (has_context_sensitive_indicator (alias_for, size)) {
2677  configuration_warning (fname, line, _("Ignored asterisk at end of alias target"));
2678  }
2679  allocate_str_removing_asterisk (alias_for, size, &reserved->alias_for);
2680 }
void configuration_warning(const char *, const int, const char *,...) COB_A_FORMAT34
Definition: error.c:144
#define _(s)
Definition: cobcrun.c:59
static void allocate_str_removing_asterisk(const char *word, const size_t size, char **const out_str)
Definition: reserved.c:2646
char * alias_for
Definition: cobc.h:226
if fold fold static computed alternate extra correct stack on syntax debugging line
Definition: flag.def:90
static COB_INLINE COB_A_INLINE int has_context_sensitive_indicator(const char *word, const size_t size)
Definition: reserved.c:2640

Here is the call graph for this function:

Here is the caller graph for this function:

static void initialize_reserved_words_if_needed ( void  )
static

Definition at line 2846 of file reserved.c.

References get_reserved_words_from_default_list(), and get_reserved_words_from_user_list().

Referenced by cb_list_reserved(), and lookup_reserved_word().

2847 {
2848  if (!reserved_words) {
2849  if (cobc_user_res_list) {
2851  } else {
2853  }
2854  }
2855 }
static void get_reserved_words_from_user_list(void)
Definition: reserved.c:2793
struct reserved_word_list * cobc_user_res_list
Definition: reserved.c:36
static struct cobc_reserved * reserved_words
Definition: reserved.c:198
static void get_reserved_words_from_default_list(void)
Definition: reserved.c:2839

Here is the call graph for this function:

Here is the caller graph for this function:

static void initialize_user_res_list_if_needed ( void  )
static

Definition at line 2725 of file reserved.c.

References add_reserved_word_without_init(), likely, NULL, and NUM_DEFAULT_RESERVED_WORDS.

Referenced by add_reserved_word(), and remove_reserved_word().

2726 {
2727  const size_t num_default_words = NUM_DEFAULT_RESERVED_WORDS;
2728  int i;
2729 
2730  if (likely (cobc_user_res_list || cb_specify_all_reserved)) {
2731  return;
2732  }
2733 
2734  /* Initialize the list with the words from the default list. */
2735  for (i = 0; i < num_default_words; ++i) {
2737  NULL, 0);
2738  }
2739 }
static void add_reserved_word_without_init(const char *word, const char *fname, const int line)
Definition: reserved.c:2683
static struct cobc_reserved default_reserved_words[]
Definition: reserved.c:200
struct reserved_word_list * cobc_user_res_list
Definition: reserved.c:36
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
const char * name
Definition: tree.h:418
#define NUM_DEFAULT_RESERVED_WORDS
Definition: reserved.c:1954
#define likely(x)
Definition: common.h:436

Here is the call graph for this function:

Here is the caller graph for this function:

static COB_INLINE COB_A_INLINE void initialize_word ( const char *  word,
const size_t  size,
struct reserved_word_list *const  reserved 
)
static

Definition at line 2663 of file reserved.c.

References allocate_str_removing_asterisk(), and reserved_word_list::word.

Referenced by add_reserved_word_without_init().

2665 {
2666  allocate_str_removing_asterisk (word, size, &reserved->word);
2667 }
static void allocate_str_removing_asterisk(const char *word, const size_t size, char **const out_str)
Definition: reserved.c:2646
char * word
Definition: cobc.h:224

Here is the call graph for this function:

Here is the caller graph for this function:

static int intrinsic_comp ( const void *  p1,
const void *  p2 
)
static

Definition at line 2571 of file reserved.c.

References cob_strcasecmp(), and cb_intrinsic_table::name.

Referenced by lookup_intrinsic().

2572 {
2573  return cob_strcasecmp (p1, ((struct cb_intrinsic_table *)p2)->name);
2574 }
static int cob_strcasecmp(const void *s1, const void *s2)
Definition: reserved.c:2530
const char * name
Definition: tree.h:418

Here is the call graph for this function:

Here is the caller graph for this function:

struct cb_intrinsic_table* lookup_intrinsic ( const char *  name,
const int  checkres,
const int  checkimpl 
)

Definition at line 2976 of file reserved.c.

References cb_intrinsic_table::implemented, intrinsic_comp(), NULL, and NUM_INTRINSICS.

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

2977 {
2978  struct cb_intrinsic_table *cbp;
2979 
2980  cbp = bsearch (name, function_list, NUM_INTRINSICS,
2981  sizeof (struct cb_intrinsic_table), intrinsic_comp);
2982  if (cbp && (checkimpl || cbp->implemented)) {
2983  return cbp;
2984  }
2985  return NULL;
2986 }
const char * name
Definition: tree.h:979
const int implemented
Definition: tree.h:983
#define NUM_INTRINSICS
Definition: reserved.c:2490
static int intrinsic_comp(const void *p1, const void *p2)
Definition: reserved.c:2571
static const struct cb_intrinsic_table function_list[]
Definition: reserved.c:1965
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95

Here is the call graph for this function:

Here is the caller graph for this function:

struct cobc_reserved* lookup_reserved_word ( const char *  name)

Definition at line 2910 of file reserved.c.

References _, CB_CS_PROGRAM_ID, cb_error(), cobc_cs_check, cobc_force_literal, cobc_in_procedure, cobc_in_repository, cobc_reserved::context_sens, cobc_reserved::context_set, cobc_reserved::context_test, create_dummy_reserved(), FUNCTION_ID, initialize_reserved_words_if_needed(), INTRINSIC, NULL, num_reserved_words, PROGRAM_ID, REPOSITORY, reserve_comp(), cobc_reserved::token, and unlikely.

Referenced by yylex().

2911 {
2912  struct cobc_reserved *p;
2913  struct cobc_reserved to_find;
2914 
2916 
2917  to_find = create_dummy_reserved (name);
2918  p = bsearch (&to_find, reserved_words, num_reserved_words,
2919  sizeof (struct cobc_reserved), reserve_comp);
2920  if (!p) {
2921  return NULL;
2922  }
2923 
2924  /* Check word is implemented */
2925  if (unlikely(p->token <= 0)) {
2926  /* Not implemented - If context sensitive, no error */
2927  if (!p->context_sens) {
2928  cb_error (_("'%s' reserved word, but not supported"), name);
2929  }
2930  return NULL;
2931  }
2932 
2933  /* Special actions / Context sensitive */
2934  if (p->context_set) {
2935  if (unlikely(p->context_test)) {
2936  /* Dependent words */
2937  if (!(cobc_cs_check & p->context_test)) {
2938  return p;
2939  }
2940  }
2941  cobc_cs_check |= p->context_set;
2942  return p;
2943  }
2944 
2945  if (p->context_test) {
2946 #if 0 /* RXWRXW - CS check */
2947  if (!(cobc_cs_check & p->context_test)) {
2948 #endif
2949  if ((cobc_cs_check & p->context_test) != p->context_test) {
2950  return NULL;
2951  }
2952  if (!cobc_in_procedure) {
2953  cobc_cs_check = 0;
2954  }
2955  return p;
2956  }
2957 
2958  if (p->token == FUNCTION_ID) {
2959  cobc_cs_check = 0;
2960  cobc_force_literal = 1;
2961  } else if (p->token == INTRINSIC) {
2962  if (!cobc_in_repository) {
2963  return NULL;
2964  }
2965  } else if (p->token == PROGRAM_ID) {
2967  cobc_force_literal = 1;
2968  } else if (p->token == REPOSITORY) {
2969  cobc_in_repository = 1;
2970  }
2971 
2972  return p;
2973 }
unsigned int cobc_force_literal
Definition: parser.c:181
static size_t num_reserved_words
Definition: reserved.c:1953
unsigned short context_sens
Definition: tree.h:420
static void initialize_reserved_words_if_needed(void)
Definition: reserved.c:2846
static struct cobc_reserved * reserved_words
Definition: reserved.c:198
static int reserve_comp(const void *p1, const void *p2)
Definition: reserved.c:2564
unsigned int context_set
Definition: tree.h:422
unsigned int cobc_in_repository
Definition: parser.c:180
#define _(s)
Definition: cobcrun.c:59
#define unlikely(x)
Definition: common.h:437
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
void cb_error(const char *,...) COB_A_FORMAT12
Definition: error.c:98
static struct cobc_reserved create_dummy_reserved(const char *word)
Definition: reserved.c:2599
unsigned int cobc_in_procedure
Definition: parser.c:179
int token
Definition: tree.h:421
const char * name
Definition: tree.h:418
unsigned int cobc_cs_check
Definition: parser.c:182
#define CB_CS_PROGRAM_ID
Definition: cobc.h:114
unsigned int context_test
Definition: tree.h:423

Here is the call graph for this function:

Here is the caller graph for this function:

cb_tree lookup_system_name ( const char *  name)

Definition at line 2860 of file reserved.c.

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

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

2861 {
2862  size_t i;
2863 
2864  for (i = 0; i < SYSTEM_TAB_SIZE; ++i) {
2865  if (cob_strcasecmp (name, system_table[i].name) == 0) {
2866  return cb_build_system_name (system_table[i].category,
2867  system_table[i].token);
2868  }
2869  }
2870  if (cb_flag_syntax_extension) {
2871  for (i = 0; i < EXT_SYSTEM_TAB_SIZE; ++i) {
2872  if (cob_strcasecmp (name, ext_system_table[i].name) == 0) {
2873  return cb_build_system_name (ext_system_table[i].category,
2874  ext_system_table[i].token);
2875  }
2876  }
2877  }
2878  return NULL;
2879 }
#define SYSTEM_TAB_SIZE
Definition: reserved.c:114
#define EXT_SYSTEM_TAB_SIZE
Definition: reserved.c:188
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static int cob_strcasecmp(const void *s1, const void *s2)
Definition: reserved.c:2530
int token
Definition: tree.h:421
const char * name
Definition: tree.h:418
static const struct system_struct ext_system_table[]
Definition: reserved.c:116
cb_tree cb_build_system_name(const enum cb_system_name_category category, const int token)
Definition: tree.c:1667

Here is the call graph for this function:

Here is the caller graph for this function:

static COB_INLINE COB_A_INLINE void pop_reserved_word ( const enum free_word_action  action)
static

Definition at line 2787 of file reserved.c.

References delete_reserved_word_from_list(), and NULL.

Referenced by get_reserved_words_from_user_list().

2788 {
2790 }
struct reserved_word_list * cobc_user_res_list
Definition: reserved.c:36
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static void delete_reserved_word_from_list(struct reserved_word_list *const prev, const enum free_word_action action, struct reserved_word_list *to_delete)
Definition: reserved.c:2619

Here is the call graph for this function:

Here is the caller graph for this function:

void remove_reserved_word ( const char *  word)

Definition at line 2882 of file reserved.c.

References cob_strcasecmp(), delete_reserved_word_from_list(), FREE_WORD_STR, initialize_user_res_list_if_needed(), reserved_word_list::next, NULL, and reserved_word_list::word.

Referenced by cb_config_entry().

2883 {
2884  struct reserved_word_list *reserved;
2885  struct reserved_word_list *prev = NULL;
2886 
2888 
2889  for (reserved = cobc_user_res_list; reserved; reserved = reserved->next) {
2890  /*
2891  We can only remove the word if it has already been specified.
2892  */
2893  if (cob_strcasecmp (reserved->word, word) == 0) {
2895  reserved);
2896  return;
2897  }
2898  prev = reserved;
2899  }
2900 }
static void initialize_user_res_list_if_needed(void)
Definition: reserved.c:2725
struct reserved_word_list * cobc_user_res_list
Definition: reserved.c:36
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
struct reserved_word_list * next
Definition: cobc.h:223
static int cob_strcasecmp(const void *s1, const void *s2)
Definition: reserved.c:2530
static void delete_reserved_word_from_list(struct reserved_word_list *const prev, const enum free_word_action action, struct reserved_word_list *to_delete)
Definition: reserved.c:2619
char * word
Definition: cobc.h:224

Here is the call graph for this function:

Here is the caller graph for this function:

static const char* res_get_feature ( const enum cb_system_name_category  category)
static

Definition at line 2577 of file reserved.c.

References _, CB_DEVICE_NAME, CB_FEATURE_NAME, and CB_SWITCH_NAME.

Referenced by cb_list_mnemonics().

2578 {
2579  const char *s;
2580 
2581  switch (category) {
2582  case CB_DEVICE_NAME:
2583  s = _("Device name");
2584  break;
2585  case CB_SWITCH_NAME:
2586  s = _("Switch name");
2587  break;
2588  case CB_FEATURE_NAME:
2589  s = _("Feature name");
2590  break;
2591  default:
2592  s = _("Unknown");
2593  break;
2594  }
2595  return s;
2596 }
#define _(s)
Definition: cobcrun.c:59

Here is the caller graph for this function:

static int reserve_comp ( const void *  p1,
const void *  p2 
)
static

Definition at line 2564 of file reserved.c.

References cob_strcasecmp(), and cb_intrinsic_table::name.

Referenced by find_default_reserved_word(), get_reserved_words_from_user_list(), and lookup_reserved_word().

2565 {
2566  return cob_strcasecmp (((struct cobc_reserved *)p1)->name,
2567  ((struct cobc_reserved *)p2)->name);
2568 }
static int cob_strcasecmp(const void *s1, const void *s2)
Definition: reserved.c:2530

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

unsigned char cob_lower_tab[256]
static

Definition at line 2522 of file reserved.c.

Referenced by cob_strcasecmp(), and cobc_init_reserved().

struct reserved_word_list* cobc_user_res_list = ((void*)0)
struct cobc_reserved default_reserved_words[]
static

Definition at line 200 of file reserved.c.

Referenced by get_reserved_words_from_default_list().

const struct system_struct ext_system_table[]
static

Definition at line 116 of file reserved.c.

const struct cb_intrinsic_table function_list[]
static

Definition at line 1965 of file reserved.c.

size_t num_reserved_words
static
const unsigned char pcob_lower_tab[] = "abcdefghijklmnopqrstuvwxyz"
static

Definition at line 2523 of file reserved.c.

Referenced by cobc_init_reserved().

const unsigned char pcob_lower_val[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
static

Definition at line 2524 of file reserved.c.

Referenced by cobc_init_reserved().

struct cobc_reserved* reserved_words
static

Definition at line 198 of file reserved.c.

const struct system_struct system_table[]
static

Definition at line 46 of file reserved.c.