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

Functions

static void print_error (const char *file, int line, const char *prefix, const char *fmt, va_list ap)
 
void cb_warning (const char *fmt,...)
 
void cb_error (const char *fmt,...)
 
void cb_plex_warning (const size_t sline, const char *fmt,...)
 
void cb_plex_error (const size_t sline, const char *fmt,...)
 
void configuration_error (const char *fname, const int line, const char *fmt,...)
 
void cb_warning_x (cb_tree x, const char *fmt,...)
 
void cb_error_x (cb_tree x, const char *fmt,...)
 
unsigned int cb_verify (const enum cb_support tag, const char *feature)
 
void redefinition_error (cb_tree x)
 
void redefinition_warning (cb_tree x, cb_tree y)
 
void undefined_error (cb_tree x)
 
void ambiguous_error (cb_tree x)
 
void group_error (cb_tree x, const char *clause)
 
void level_redundant_error (cb_tree x, const char *clause)
 
void level_require_error (cb_tree x, const char *clause)
 
void level_except_error (cb_tree x, const char *clause)
 

Variables

static char * errnamebuff = NULL
 
static struct cb_labellast_section = NULL
 
static struct cb_labellast_paragraph = NULL
 
static unsigned int conf_error_displayed = 0
 
size_t cb_msg_style
 

Function Documentation

void ambiguous_error ( cb_tree  x)

References _, CB_CHAIN, cb_error_x(), CB_FIELD, CB_LABEL, CB_NAME, cb_name(), CB_REFERENCE, CB_TAG_FIELD, CB_TAG_LABEL, CB_TREE, CB_TREE_TAG, CB_VALUE, COB_NORMAL_BUFF, COB_NORMAL_MAX, cobc_main_malloc(), errnamebuff, cb_word::error, cb_word::items, cb_label::name, cb_word::name, p, cb_field::parent, and cb_label::section.

Referenced by cb_ref().

290 {
291  struct cb_word *w;
292  struct cb_field *p;
293  struct cb_label *l2;
294  cb_tree l;
295  cb_tree y;
296 
297  w = CB_REFERENCE (x)->word;
298  if (w->error == 0) {
299  if (!errnamebuff) {
300  errnamebuff = cobc_main_malloc ((size_t)COB_NORMAL_BUFF);
301  }
302  /* Display error the first time */
303  snprintf (errnamebuff, (size_t)COB_NORMAL_MAX, "'%s'", CB_NAME (x));
304  for (l = CB_REFERENCE (x)->chain; l; l = CB_REFERENCE (l)->chain) {
305  strcat (errnamebuff, " in '");
306  strcat (errnamebuff, CB_NAME (l));
307  strcat (errnamebuff, "'");
308  }
309  cb_error_x (x, _("%s ambiguous; need qualification"), errnamebuff);
310  w->error = 1;
311 
312  /* Display all fields with the same name */
313  for (l = w->items; l; l = CB_CHAIN (l)) {
314  y = CB_VALUE (l);
315  snprintf (errnamebuff, (size_t)COB_NORMAL_MAX,
316  "'%s' ", w->name);
317  switch (CB_TREE_TAG (y)) {
318  case CB_TAG_FIELD:
319  for (p = CB_FIELD (y)->parent; p; p = p->parent) {
320  strcat (errnamebuff, "in '");
321  strcat (errnamebuff, cb_name (CB_TREE(p)));
322  strcat (errnamebuff, "' ");
323  }
324  break;
325  case CB_TAG_LABEL:
326  l2 = CB_LABEL (y);
327  if (l2->section) {
328  strcat (errnamebuff, "in '");
329  strcat (errnamebuff,
330  (const char *)(l2->section->name));
331  strcat (errnamebuff, "' ");
332  }
333  break;
334  default:
335  break;
336  }
337  strcat (errnamebuff, _("defined here"));
338  cb_error_x (y, errnamebuff);
339  }
340  }
341 }
void cb_error_x ( cb_tree  x,
const char *  fmt,
  ... 
)

References _, cobc_too_many_errors(), errorcount, print_error(), cb_tree_common::source_file, and cb_tree_common::source_line.

Referenced by ambiguous_error(), cb_build_address(), cb_build_binary_op(), cb_build_cond(), cb_build_display_mnemonic(), cb_build_display_name(), cb_build_field_tree(), cb_build_identifier(), cb_build_intrinsic(), cb_build_replacing_characters(), cb_build_tallying_all(), cb_build_tallying_characters(), cb_build_tallying_leading(), cb_build_tallying_trailing(), cb_build_tallying_value(), cb_build_write_advancing_mnemonic(), cb_check_group_name(), cb_check_integer_value(), cb_check_numeric_edited_name(), cb_check_numeric_name(), cb_check_numeric_value(), cb_define_switch_name(), cb_emit_accept(), cb_emit_accept_mnemonic(), cb_emit_accept_name(), cb_emit_allocate(), cb_emit_call(), cb_emit_close(), cb_emit_delete(), cb_emit_delete_file(), cb_emit_display(), cb_emit_free(), cb_emit_goto(), cb_emit_inspect(), cb_emit_move(), cb_emit_open(), cb_emit_read(), cb_emit_release(), cb_emit_rewrite(), cb_emit_set_attribute(), cb_emit_set_false(), cb_emit_set_to(), cb_emit_set_true(), cb_emit_sort_giving(), cb_emit_sort_init(), cb_emit_sort_using(), cb_emit_start(), cb_emit_write(), cb_get_level(), cb_resolve_redefines(), cb_validate_88_item(), cb_validate_collating(), cb_validate_one(), cb_validate_program_body(), cb_validate_program_data(), cb_validate_program_environment(), check_picture_item(), check_valid_key(), compute_size(), emit_entry(), evaluate_test(), file_error(), group_error(), level_except_error(), level_redundant_error(), level_require_error(), redefinition_error(), search_set_keys(), terminator_error(), undefined_error(), valid_const_date_time_args(), validate_field_1(), validate_field_clauses(), validate_inspect(), and validate_move().

185 {
186  va_list ap;
187 
188  va_start (ap, fmt);
189  print_error (x->source_file, x->source_line, _("Error: "), fmt, ap);
190  va_end (ap);
191  if (++errorcount > 100) {
193  }
194 }
void cb_plex_error ( const size_t  sline,
const char *  fmt,
  ... 
)

References _, cb_source_line, cobc_too_many_errors(), errorcount, NULL, and print_error().

Referenced by plex_action_directive(), ppinput(), and ppparse_error().

130 {
131  va_list ap;
132 
133  va_start (ap, fmt);
134  print_error (NULL, (int)(cb_source_line + sline), _("Error: "), fmt, ap);
135  va_end (ap);
136  if (++errorcount > 100) {
138  }
139 }
void cb_plex_warning ( const size_t  sline,
const char *  fmt,
  ... 
)

References _, cb_source_line, NULL, print_error(), and warningcount.

Referenced by ppinput(), and while().

119 {
120  va_list ap;
121 
122  va_start (ap, fmt);
123  print_error (NULL, (int)(cb_source_line + sline), _("Warning: "), fmt, ap);
124  va_end (ap);
125  warningcount++;
126 }
unsigned int cb_verify ( const enum cb_support  tag,
const char *  feature 
)

References _, CB_ARCHAIC, CB_ERROR, cb_error(), CB_IGNORE, CB_OBSOLETE, CB_OK, CB_SKIP, CB_UNCONFORMABLE, CB_WARNING, cb_warning(), and warningopt.

Referenced by cb_emit_goto(), check_comments(), compute_size(), validate_field_1(), and while().

198 {
199  switch (tag) {
200  case CB_OK:
201  return 1;
202  case CB_WARNING:
203  return 1;
204  case CB_ARCHAIC:
205  if (cb_warn_archaic) {
206  cb_warning (_("%s is archaic in %s"), feature, cb_config_name);
207  }
208  return 1;
209  case CB_OBSOLETE:
210  if (cb_warn_obsolete) {
211  cb_warning (_("%s is obsolete in %s"), feature, cb_config_name);
212  }
213  return 1;
214  case CB_SKIP:
215  return 0;
216  case CB_IGNORE:
217  if (warningopt) {
218  cb_warning (_("%s ignored"), feature);
219  }
220  return 0;
221  case CB_ERROR:
222  return 0;
223  case CB_UNCONFORMABLE:
224  cb_error (_("%s does not conform to %s"), feature, cb_config_name);
225  return 0;
226  default:
227  break;
228  }
229  return 0;
230 }
void cb_warning ( const char *  fmt,
  ... 
)
void configuration_error ( const char *  fname,
const int  line,
const char *  fmt,
  ... 
)

References _, and conf_error_displayed.

Referenced by cb_config_entry(), cb_load_conf(), invalid_value(), process_command_line(), and unsupported_value().

144 {
145  va_list args;
146 
147  if (!conf_error_displayed) {
149  fputs (_("Configuration Error"), stderr);
150  putc ('\n', stderr);
151  }
152 
153  if (fname) {
154  if (line) {
155  fprintf (stderr, "%s:%d: ", fname, line);
156  } else {
157  fprintf (stderr, "%s: ", fname);
158  }
159  } else {
160  fputs ("cb_conf: ", stderr);
161  }
162 
163  va_start(args, fmt);
164  vfprintf (stderr, fmt, args);
165  va_end(args);
166 
167  putc ('\n', stderr);
168  fflush (stderr);
169 }
void group_error ( cb_tree  x,
const char *  clause 
)

References _, cb_error_x(), and cb_name().

Referenced by validate_field_1().

345 {
346  cb_error_x (x, _("Group item '%s' cannot have %s clause"),
347  cb_name (x), clause);
348 }
void level_except_error ( cb_tree  x,
const char *  clause 
)

References _, cb_error_x(), CB_FIELD_PTR, cb_name(), cb_field::flag_item_78, and cb_field::level.

Referenced by cb_validate_78_item(), cb_validate_88_item(), and validate_field_1().

388 {
389  const char *s;
390  const struct cb_field *f;
391 
392  s = cb_name (x);
393  f = CB_FIELD_PTR (x);
394  if (f->flag_item_78) {
395  cb_error_x (x, _("Constant item '%s' can only have a %s clause"),
396  s, clause);
397  } else {
398  cb_error_x (x, _("Level %02d item '%s' can only have a %s clause"),
399  f->level,
400  s, clause);
401  }
402 }
void level_redundant_error ( cb_tree  x,
const char *  clause 
)

References _, cb_error_x(), CB_FIELD_PTR, cb_name(), cb_field::flag_item_78, and cb_field::level.

Referenced by validate_field_1().

352 {
353  const char *s;
354  const struct cb_field *f;
355 
356  s = cb_name (x);
357  f = CB_FIELD_PTR (x);
358  if (f->flag_item_78) {
359  cb_error_x (x, _("Constant item '%s' cannot have a %s clause"),
360  s, clause);
361  } else {
362  cb_error_x (x, _("Level %02d item '%s' cannot have a %s clause"),
363  f->level,
364  s, clause);
365  }
366 }
void level_require_error ( cb_tree  x,
const char *  clause 
)

References _, cb_error_x(), CB_FIELD_PTR, cb_name(), cb_field::flag_item_78, and cb_field::level.

Referenced by cb_validate_78_item(), cb_validate_88_item(), check_picture_item(), and validate_field_1().

370 {
371  const char *s;
372  const struct cb_field *f;
373 
374  s = cb_name (x);
375  f = CB_FIELD_PTR (x);
376  if (f->flag_item_78) {
377  cb_error_x (x, _("Constant item '%s' requires a %s clause"),
378  s, clause);
379  } else {
380  cb_error_x (x, _("Level %02d item '%s' requires a %s clause"),
381  f->level,
382  s, clause);
383  }
384 }
static void print_error ( const char *  file,
int  line,
const char *  prefix,
const char *  fmt,
va_list  ap 
)
static

References _, cb_msg_style, CB_MSG_STYLE_MSC, cb_source_file, cb_source_line, current_paragraph, current_section, cb_label::flag_dummy_paragraph, cb_label::flag_dummy_section, and cb_label::name.

Referenced by cb_error(), cb_error_x(), cb_plex_error(), cb_plex_warning(), cb_warning(), and cb_warning_x().

47 {
48  if (!file) {
50  }
51  if (!line) {
53  }
54 
55  /* Print section and/or paragraph name */
58  fprintf (stderr, "%s: ", file);
59  fputs (_("In section"), stderr);
60  fprintf (stderr, " '%s':\n",
61  (char *)current_section->name);
62  }
64  }
67  fprintf (stderr, "%s: ", file);
68  fputs (_("In paragraph"), stderr);
69  fprintf (stderr, " '%s':\n",
70  (char *)current_paragraph->name);
71  }
73  }
74 
75  /* Print the error */
77  fprintf (stderr, "%s (%d): %s", file, line, prefix);
78  } else {
79  fprintf (stderr, "%s: %d: %s", file, line, prefix);
80  }
81  vfprintf (stderr, fmt, ap);
82  putc ('\n', stderr);
83 }
void redefinition_error ( cb_tree  x)

References _, cb_error_x(), CB_REFERENCE, CB_VALUE, cb_word::items, and cb_word::name.

Referenced by cb_build_section_name(), and cb_validate_program_data().

234 {
235  struct cb_word *w;
236 
237  w = CB_REFERENCE (x)->word;
238  cb_error_x (x, _("Redefinition of '%s'"), w->name);
239  if (w->items) {
240  cb_error_x (CB_VALUE (w->items),
241  _("'%s' previously defined here"), w->name);
242  }
243 }
void redefinition_warning ( cb_tree  x,
cb_tree  y 
)

References _, CB_REFERENCE, CB_VALUE, cb_warning_x(), cb_word::items, cb_word::name, and NULL.

Referenced by cb_build_field_tree().

247 {
248  struct cb_word *w;
249  cb_tree z;
250 
251  w = CB_REFERENCE (x)->word;
252  cb_warning_x (x, _("Redefinition of '%s'"), w->name);
253  z = NULL;
254  if (y) {
255  z = y;
256  } else if (w->items) {
257  z = CB_VALUE (w->items);
258  }
259 
260  if (z) {
261  cb_warning_x (z, _("'%s' previously defined here"), w->name);
262  }
263 }
void undefined_error ( cb_tree  x)

References _, cb_error_x(), CB_NAME, CB_REFERENCE, cb_warning_x(), cb_reference::chain, COB_NORMAL_BUFF, COB_NORMAL_MAX, cobc_main_malloc(), errnamebuff, and cb_reference::flag_optional.

Referenced by cb_ref(), and cb_resolve_redefines().

267 {
268  struct cb_reference *r;
269  cb_tree c;
270 
271  if (!errnamebuff) {
272  errnamebuff = cobc_main_malloc ((size_t)COB_NORMAL_BUFF);
273  }
274  r = CB_REFERENCE (x);
275  snprintf (errnamebuff, (size_t)COB_NORMAL_MAX, "'%s'", CB_NAME (x));
276  for (c = r->chain; c; c = CB_REFERENCE (c)->chain) {
277  strcat (errnamebuff, " in '");
278  strcat (errnamebuff, CB_NAME (c));
279  strcat (errnamebuff, "'");
280  }
281  if (r->flag_optional) {
282  cb_warning_x (x, _("%s is not defined"), errnamebuff);
283  } else {
284  cb_error_x (x, _("%s is not defined"), errnamebuff);
285  }
286 }

Variable Documentation

size_t cb_msg_style

Referenced by cobc_print_info(), main(), and print_error().

unsigned int conf_error_displayed = 0
static

Referenced by configuration_error().

char* errnamebuff = NULL
static

Referenced by ambiguous_error(), and undefined_error().

struct cb_label* last_paragraph = NULL
static
struct cb_label* last_section = NULL
static