示例#1
0
void
ambiguous_error (cb_tree x)
{
	struct cb_word	*w;
	struct cb_field	*p;
	struct cb_label	*l2;
	cb_tree		l;
	cb_tree		y;

	w = CB_REFERENCE (x)->word;
	if (w->error == 0) {
		if (!errnamebuff) {
			errnamebuff = cobc_malloc (COB_NORMAL_BUFF);
		}
		/* display error on the first time */
		snprintf (errnamebuff, COB_NORMAL_MAX, "'%s'", CB_NAME (x));
		for (l = CB_REFERENCE (x)->chain; l; l = CB_REFERENCE (l)->chain) {
			strcat (errnamebuff, " in '");
			strcat (errnamebuff, CB_NAME (l));
			strcat (errnamebuff, "'");
		}
		cb_error_x (x, _("%s ambiguous; need qualification"), errnamebuff);
		w->error = 1;

		/* display all fields with the same name */
		for (l = w->items; l; l = CB_CHAIN (l)) {
			y = CB_VALUE (l);
			snprintf (errnamebuff, COB_NORMAL_MAX, "'%s' ", w->name);
			switch (CB_TREE_TAG (y)) {
			case CB_TAG_FIELD:
				for (p = CB_FIELD (y)->parent; p; p = p->parent) {
					strcat (errnamebuff, "in '");
					strcat (errnamebuff, p->name);
					strcat (errnamebuff, "' ");
				}
				break;
			case CB_TAG_LABEL:
				l2 = CB_LABEL (y);
				if (l2->section) {
					strcat (errnamebuff, "in '");
					strcat (errnamebuff, (const char *)(l2->section->name));
					strcat (errnamebuff, "' ");
				}
				break;
			default:
				break;
			}
			strcat (errnamebuff, _("defined here"));
			cb_error_x (y, errnamebuff);
		}
	}
}
示例#2
0
void
undefined_error (cb_tree x)
{
	struct cb_reference	*r;
	cb_tree			c;

	if (!errnamebuff) {
		errnamebuff = cobc_malloc (COB_NORMAL_BUFF);
	}
	r = CB_REFERENCE (x);
	snprintf (errnamebuff, COB_NORMAL_MAX, "'%s'", CB_NAME (x));
	for (c = r->chain; c; c = CB_REFERENCE (c)->chain) {
		strcat (errnamebuff, " in '");
		strcat (errnamebuff, CB_NAME (c));
		strcat (errnamebuff, "'");
	}
	cb_error_x (x, _("%s undefined"), errnamebuff);
}
示例#3
0
void
redefinition_error (cb_tree x)
{
	struct cb_word	*w;

	w = CB_REFERENCE (x)->word;
	cb_error_x (x, _("Redefinition of '%s'"), w->name);
	cb_error_x (CB_VALUE (w->items), _("'%s' previously defined here"), w->name);
}
示例#4
0
void
redefinition_warning (cb_tree x, cb_tree y)
{
	struct cb_word	*w;

	w = CB_REFERENCE (x)->word;
	cb_warning_x (x, _("Redefinition of '%s'"), w->name);
	if (y) {
		cb_warning_x (y, _("'%s' previously defined here"), w->name);
	} else {
		cb_warning_x (CB_VALUE (w->items), _("'%s' previously defined here"), w->name);
	}
}
示例#5
0
cb_tree
cb_build_field_tree (cb_tree level, cb_tree name,
		     struct cb_field *last_field,
		     enum cb_storage storage, struct cb_file *fn)
{
	struct cb_reference	*r;
	struct cb_field		*f;
	struct cb_field		*p;
	struct cb_field		*field_fill;
	cb_tree			dummy_fill;
	cb_tree			l;
	cb_tree			x;
	int			lv;

	if (level == cb_error_node || name == cb_error_node) {
		return cb_error_node;
	}

	/* check the level number */
	lv = cb_get_level (level);
	if (!lv) {
		return cb_error_node;
	}

	/* build the field */
	r = CB_REFERENCE (name);
	f = CB_FIELD (cb_build_field (name));
	f->storage = storage;
	last_real_field = last_field;
	if (lv == 78) {
		f->level = 01;
		f->flag_item_78 = 1;
		return CB_TREE (f);
	} else {
		f->level = lv;
	}
	if (f->level == 01 && storage == CB_STORAGE_FILE) {
		if (fn->external) {
			f->flag_external = 1;
			has_external = 1;
		} else if (fn->global) {
			f->flag_is_global = 1;
		}
	}
	if (last_field) {
		if (last_field->level == 77 && f->level != 01 &&
		    f->level != 77 && f->level != 66 && f->level != 88) {
			cb_error_x (name, _("Level number must begin with 01 or 77"));
			return cb_error_node;
		}
	}

	/* checks for redefinition */
	if (cb_warn_redefinition) {
		if (r->word->count > 1) {
			if (f->level == 01 || f->level == 77) {
				redefinition_warning (name, NULL);
			} else {
				for (l = r->word->items; l; l = CB_CHAIN (l)) {
					x = CB_VALUE (l);
					if (!CB_FIELD_P (x)
					    || CB_FIELD (x)->level == 01
					    || CB_FIELD (x)->level == 77
					    || (f->level == last_field->level
						&& CB_FIELD (x)->parent == last_field->parent)) {
						redefinition_warning (name, x);
						break;
					}
				}
			}
		}
	}

	if (last_field && last_field->level == 88) {
		last_field = last_field->parent;
	}

	/* link the field into the tree */
	if (f->level == 01 || f->level == 77) {
		/* top level */
		cb_needs_01 = 0;
		if (last_field) {
/*
			cb_field_add (cb_field_founder (last_field), f);
*/
			cb_field_founder (last_field)->sister = f;
		}
	} else if (!last_field || cb_needs_01) {
		/* invalid top level */
		cb_error_x (name, _("Level number must begin with 01 or 77"));
		return cb_error_node;
	} else if (f->level == 66) {
		/* level 66 */
		f->parent = cb_field_founder (last_field);
		for (p = f->parent->children; p && p->sister; p = p->sister) ;
		if (p) {
			p->sister = f;
		}
	} else if (f->level == 88) {
		/* level 88 */
		f->parent = last_field;
	} else if (f->level > last_field->level) {
		/* lower level */
		last_field->children = f;
		f->parent = last_field;
	} else if (f->level == last_field->level) {
		/* same level */
same_level:
		last_field->sister = f;
		f->parent = last_field->parent;
	} else {
		/* upper level */
		for (p = last_field->parent; p; p = p->parent) {
			if (p->level == f->level) {
				last_field = p;
				goto same_level;
			}
			if (cb_relax_level_hierarchy && p->level < f->level) {
				break;
			}
		}
		if (cb_relax_level_hierarchy) {
			dummy_fill = cb_build_filler ();
			field_fill = CB_FIELD (cb_build_field (dummy_fill));
			cb_warning_x (name, _("No previous data item of level %02d"), f->level);
			field_fill->level = f->level;
			field_fill->storage = storage;
			field_fill->children = p->children;
			field_fill->parent = p;
			for (p = p->children; p != NULL; p = p->sister) {
				p->parent = field_fill;
			}
			field_fill->parent->children = field_fill;
			field_fill->sister = f;
			f->parent = field_fill->parent;
			last_field = field_fill;
		} else {
			cb_error_x (name, _("No previous data item of level %02d"), f->level);
			return cb_error_node;
		}
	}

	/* inherit parent's properties */
	if (f->parent) {
		f->usage = f->parent->usage;
		f->indexes = f->parent->indexes;
		f->flag_sign_leading = f->parent->flag_sign_leading;
		f->flag_sign_separate = f->parent->flag_sign_separate;
		f->flag_is_global = f->parent->flag_is_global;
	}
	return CB_TREE (f);
}
示例#6
0
struct cb_field *
cb_resolve_redefines (struct cb_field *field, cb_tree redefines)
{
	struct cb_field		*f;
	struct cb_reference	*r;
	const char		*name;
	cb_tree			x;

	r = CB_REFERENCE (redefines);
	name = CB_NAME (redefines);
	x = CB_TREE (field);

	/* check qualification */
	if (r->chain) {
		cb_error_x (x, _("'%s' cannot be qualified here"), name);
		return NULL;
	}

	/* check subscripts */
	if (r->subs) {
		cb_error_x (x, _("'%s' cannot be subscripted here"), name);
		return NULL;
	}

	/* resolve the name in the current group (if any) */
	if (field->parent && field->parent->children) {
		for (f = field->parent->children; f; f = f->sister) {
			if (strcasecmp (f->name, name) == 0) {
				break;
			}
		}
		if (f == NULL) {
			cb_error_x (x, _("'%s' undefined in '%s'"), name, field->parent->name);
			return NULL;
		}
	} else {
		if (cb_ref (redefines) == cb_error_node) {
			return NULL;
		}
		f = cb_field (redefines);
	}

	/* check level number */
	if (f->level != field->level) {
		cb_error_x (x, _("Level number of REDEFINES entries must be identical"));
		return NULL;
	}
	if (f->level == 66 || f->level == 88) {
		cb_error_x (x, _("Level number of REDEFINES entry cannot be 66 or 88"));
		return NULL;
	}

	if (!cb_indirect_redefines && f->redefines) {
		cb_error_x (x, _("'%s' not the original definition"), f->name);
		return NULL;
	}

	/* return the original definition */
	while (f->redefines) {
		f = f->redefines;
	}
	return f;
}