a few more warnings
[suif.git] / src / basesuif / check / check.cc
blob11ce4422529ee899afe62a96fca42cba270bbe5b
1 /* Main program for the checking library. */
3 /* Copyright (c) 1994 Stanford University
5 All rights reserved.
7 This software is provided under the terms described in
8 the "suif_copyright.h" include file. */
10 #include <suif_copyright.h>
12 #define _MODULE_ "libcheck.a"
14 #pragma implementation "check.h"
16 #define RCS_BASE_FILE check_cc
18 #include "check.h"
19 #include "check_internal.h"
20 #include <string.h>
22 RCS_BASE(
23 "$Id: check.cc,v 1.1.1.1 1998/06/16 15:15:43 brm Exp $")
25 /*----------------------------------------------------------------------*
26 Begin Documentation
27 *----------------------------------------------------------------------*
29 Summary
30 -------
32 The SUIF ``check'' library provides functions for user
33 programs to check the legality and consistency of various SUIF
34 objects for debugging purposes. An entire SUIF file can be
35 checked by using the ``checksuif'' program, which uses the
36 routines in this library.
39 *----------------------------------------------------------------------*
40 End Documentation
41 *----------------------------------------------------------------------*/
43 DECLARE_DLIST_CLASS(label_sym_list, label_sym *);
44 DECLARE_DLIST_CLASS(label_sym_list_list, label_sym_list *);
45 DECLARE_DLIST_CLASS(string_index_list, string_index *);
47 boolean checkfail = FALSE;
48 boolean checkabort = FALSE;
49 boolean pointer_freedom = FALSE;
51 base_symtab *current_scope = NULL;
52 tree_node *current_node = NULL;
54 static instruction_list *pending_instr_ops = NULL;
55 static string_index *defined_labs = NULL;
56 static label_sym_list *used_labs = NULL;
57 static string_index_list *old_defined_labs = NULL;
58 static label_sym_list_list *old_used_labs = NULL;
59 static boolean in_annote = FALSE;
61 static void check_node_list(tree_node_list *the_node_list);
62 static void check_suif_object(suif_object *the_suif_object);
63 static void check_annote_list(annote_list *the_annotes);
64 static void check_annote(annote *the_annote);
65 static void check_immed_list(immed_list *the_immeds);
66 static void check_immed(immed *the_immed);
67 static void check_sym_addr(sym_addr *the_addr);
68 static void check_fse_ref(file_set_entry *the_fse);
69 static void check_tree_instr_ref(tree_instr *the_tree_instr);
70 static void check_tree_block_ref(tree_block *the_block);
71 static void check_tree_proc_ref(tree_proc *the_tree_proc);
72 static void check_tree_node_ref(tree_node *the_node);
73 static void check_instruction_ref(instruction *the_instr);
74 static void check_symtab_ref(base_symtab *the_symtab);
75 static void check_var_sym_ref(var_sym *the_var);
76 static void check_proc_sym_ref(proc_sym *the_proc);
77 static void check_label_sym_ref(label_sym *the_label);
78 static void check_sym_node_ref(sym_node *symbol);
79 static void check_array_bound(array_bound the_bound);
80 static void check_func_type_ref(func_type *the_func_type);
81 static boolean check_object_type_ref(type_node *the_type);
82 static boolean check_type_ref(type_node *the_type);
83 static boolean scope_in_scope(base_symtab *outer, base_symtab *inner);
84 static void push_label_scope(void);
85 static void pop_label_scope(void);
86 static void register_label_def(label_sym *the_label);
87 static void register_label_use(label_sym *the_label);
89 extern void init_check(int & /* argc */, char * /* argv */ [])
91 return;
94 extern void exit_check(void)
96 return;
99 extern void check_global_symtab(global_symtab *the_global_symtab)
101 if (the_global_symtab == NULL)
103 problem("NULL pointer for global_symtab *");
104 return;
107 push_clue(the_global_symtab);
109 base_symtab *the_base_symtab = the_global_symtab;
111 if (the_base_symtab->kind() != SYMTAB_GLOBAL)
113 problem("object passed as global_symtab isn't a global_symtab");
114 pop_clue(the_global_symtab);
115 return;
118 check_symtab(the_base_symtab);
120 pop_clue(the_global_symtab);
123 extern void check_file_symtab(file_symtab *the_file_symtab)
125 if (the_file_symtab == NULL)
127 problem("NULL pointer used as file_symtab *");
128 return;
131 push_clue(the_file_symtab);
133 base_symtab *the_base_symtab = the_file_symtab;
135 if (the_base_symtab->kind() != SYMTAB_FILE)
137 problem("object passed as file_symtab isn't a file_symtab");
138 pop_clue(the_file_symtab);
139 return;
142 check_symtab(the_base_symtab);
144 pop_clue(the_file_symtab);
147 extern void check_symtab(base_symtab *the_symtab)
149 if (the_symtab == NULL)
151 problem("NULL pointer used for base_symtab *");
152 return;
155 push_clue(the_symtab);
157 suif_object *the_suif_object = the_symtab;
159 if (the_suif_object->object_kind() != SYMTAB_OBJ)
161 problem("object passed as symtab isn't a symtab");
162 pop_clue(the_symtab);
163 return;
166 base_symtab *old_scope = current_scope;
167 current_scope = the_symtab;
169 check_suif_object(the_suif_object);
171 if (the_symtab->name() == NULL)
172 problem("NULL name in symtab");
174 base_symtab *parent_symtab = the_symtab->parent();
175 if (parent_symtab != NULL)
177 check_symtab_ref(parent_symtab);
178 base_symtab_list_iter child_iter(parent_symtab->children());
179 while (TRUE)
181 if (child_iter.is_empty())
183 problem("child symtab not in parent's children() list");
184 break;
186 base_symtab *test_symtab = child_iter.step();
187 if (test_symtab == the_symtab)
188 break;
192 if (the_symtab->symbols() == NULL)
194 problem("NULL symbol list in symbol table");
195 current_scope = old_scope;
196 pop_clue(the_symtab);
197 return;
200 sym_node_list_iter sym_iter(the_symtab->symbols());
201 while (!sym_iter.is_empty())
203 sym_node *this_symbol = sym_iter.step();
204 check_suif_object(this_symbol);
205 check_sym_node_ref(this_symbol);
207 push_clue(this_symbol);
209 if (this_symbol->parent() != the_symtab)
210 problem("symbol's parent() != the table containing it");
212 switch (this_symbol->kind())
214 case SYM_PROC:
216 proc_sym *this_proc = (proc_sym *)this_symbol;
218 file_set_entry *this_fse = this_proc->file();
219 if (this_fse != NULL)
220 check_fse_ref(this_fse);
222 check_func_type_ref(this_proc->type());
224 tree_proc *the_tree_proc = this_proc->block();
225 if (the_tree_proc != NULL)
226 check_tree_proc_ref(the_tree_proc);
228 if (!the_symtab->is_global())
229 problem("proc_sym in non-global symbol table");
231 break;
233 case SYM_LABEL:
235 break;
237 case SYM_VAR:
239 var_sym *this_var = (var_sym *)this_symbol;
241 check_object_type_ref(this_var->type());
242 if ((this_var->type()->size() == 0) &&
243 (this_var->is_auto() || this_var->has_var_def()))
245 problem("var_sym with zero size");
248 var_sym *parent_var = this_var->parent_var();
249 if (parent_var != NULL)
251 check_var_sym_ref(parent_var);
252 if (parent_var->parent() != the_symtab)
253 problem("parent_var() in different table");
254 unsigned num_children = parent_var->num_children();
255 unsigned child_num;
256 for (child_num = 0; child_num < num_children; ++child_num)
258 if (parent_var->child_var(child_num) == this_var)
259 break;
261 if (child_num == num_children)
262 problem("parent_var() doesn't contain child");
265 unsigned num_children = this_var->num_children();
266 for (unsigned child_num = 0; child_num < num_children;
267 ++child_num)
269 var_sym *this_child = this_var->child_var(child_num);
270 check_var_sym_ref(this_child);
271 if (this_child->parent() != the_symtab)
272 problem("child_var() in different table");
273 if (this_child->parent_var() != this_var)
274 problem("child_var() with different parent_var()");
277 if ((this_var->parent_var() == NULL) &&
278 ((the_symtab->is_block() && this_var->is_static()) ||
279 the_symtab->is_file()))
281 if (!this_var->has_var_def())
282 problem("`%s' has no definition", this_var->name());
284 else
286 if (((parent_var != NULL) ||
287 (the_symtab->kind() != SYMTAB_GLOBAL)) &&
288 this_var->has_var_def())
290 problem("`%s' shouldn't have a definition, but does",
291 this_var->name());
295 if (this_var->has_var_def())
297 var_def *this_def = this_var->definition();
298 if (this_def == NULL)
300 problem("var_def for `%s' not found",
301 this_var->name());
305 if (this_var->is_param())
307 if (!the_symtab->is_proc())
309 problem("parameter symbol in non-procedure symtab");
311 else
313 proc_symtab *the_proc_tab = (proc_symtab *)the_symtab;
314 sym_node_list_iter param_iter(the_proc_tab->params());
315 while (TRUE)
317 if (param_iter.is_empty())
319 problem("symbol `%s' marked param is not in"
320 " parameter list", this_var->name());
321 break;
323 sym_node *test_sym = param_iter.step();
324 if (test_sym == this_var)
325 break;
330 break;
332 default:
333 problem("illegal symbol type");
336 pop_clue(this_symbol);
339 if (the_symtab->var_defs() == NULL)
341 problem("NULL var_def list in symbol table");
342 current_scope = old_scope;
343 pop_clue(the_symtab);
344 return;
347 var_def_list_iter def_iter(the_symtab->var_defs());
348 while (!def_iter.is_empty())
350 var_def *this_def = def_iter.step();
352 if (this_def == NULL)
354 problem("NULL var_def * in symtab var_def list");
355 continue;
358 push_clue(this_def);
360 suif_object *the_suif_object = this_def;
362 if (the_suif_object->object_kind() != DEF_OBJ)
364 problem("object in symtab var_def list isn't a var_def");
365 continue;
368 check_suif_object(the_suif_object);
370 if (this_def->parent() != the_symtab)
371 problem("var_def's parent() != the table containing it");
373 var_sym *this_var = this_def->variable();
374 check_var_sym_ref(this_var);
376 if ((this_var->parent() != the_symtab) &&
377 ((this_var->parent() != fileset->globals()) ||
378 (the_symtab->parent() != fileset->globals())))
380 problem("var_sym for `%s' in different symbol table than its"
381 " var_def", this_var->name());
384 if (this_def->alignment() != get_alignment(this_var->type()))
385 problem("wrong alignment for variable `%s'", this_var->name());
387 if (!type_is_compatible_with_initializations(this_var->type(),
388 this_def))
390 problem("misalignment of initialization data");
393 pop_clue(this_def);
396 if (the_symtab->types() == NULL)
398 problem("NULL type list in symbol table");
399 current_scope = old_scope;
400 pop_clue(the_symtab);
401 return;
404 type_node_list_iter type_iter(the_symtab->types());
405 while (!type_iter.is_empty())
407 type_node *this_type = type_iter.step();
408 check_suif_object(this_type);
409 check_type_ref(this_type);
411 push_clue(this_type);
413 if (this_type->parent() != the_symtab)
414 problem("type's parent() != the table containing it");
416 switch (this_type->op())
418 case TYPE_INT:
420 base_type *this_base_type = (base_type *)this_type;
421 if (this_base_type->size() < 0)
422 problem("integer type with negative size");
423 if (this_base_type->size() == 0)
424 problem("integer type with zero size");
425 break;
427 case TYPE_FLOAT:
429 base_type *this_base_type = (base_type *)this_type;
430 if (this_base_type->size() < 0)
431 problem("floating-point type with negative size");
432 if (this_base_type->size() == 0)
433 problem("floating-point type with zero size");
434 if (!this_base_type->is_signed())
435 problem("unsigned floating-point type");
436 break;
438 case TYPE_VOID:
440 base_type *this_base_type = (base_type *)this_type;
441 if (this_base_type->size() != 0)
442 problem("void type with non-zero size");
443 break;
445 case TYPE_PTR:
447 ptr_type *this_ptr = (ptr_type *)this_type;
448 check_type_ref(this_ptr->ref_type());
449 break;
451 case TYPE_ARRAY:
453 array_type *this_array = (array_type *)this_type;
454 type_node *elem_type = this_array->elem_type();
455 check_object_type_ref(elem_type);
456 check_array_bound(this_array->lower_bound());
457 check_array_bound(this_array->upper_bound());
458 if (this_array->lower_bound().is_unknown())
459 problem("array type with unknown lower bound");
460 if (elem_type->unqual()->is_array())
462 array_type *elem_array =
463 (array_type *)(elem_type->unqual());
464 if (elem_array->upper_bound().is_unknown())
465 problem("sub-array with unknown upper bound");
467 break;
469 case TYPE_FUNC:
471 func_type *this_func = (func_type *)this_type;
472 check_object_type_ref(this_func->return_type());
473 if (!this_func->args_known())
475 if (this_func->has_varargs())
477 problem("function with unknown args but varargs flag"
478 " set");
480 if (this_func->num_args() != 0)
481 problem("function with unknown args num_args() != 0");
483 unsigned num_args = this_func->num_args();
484 for (unsigned arg_num = 0; arg_num < num_args; ++arg_num)
485 check_object_type_ref(this_func->arg_type(arg_num));
486 break;
488 case TYPE_GROUP:
489 case TYPE_STRUCT:
490 case TYPE_UNION:
492 struct_type *this_struct = (struct_type *)this_type;
493 if (this_struct->name() == NULL)
494 problem("struct type with NULL name");
495 int total_size = this_struct->size();
496 if (total_size < 0)
497 problem("struct_type with negative size");
498 int last_field_end = 0;
499 unsigned num_fields = this_struct->num_fields();
500 for (unsigned field_num = 0; field_num < num_fields;
501 ++field_num)
503 int this_offset = this_struct->offset(field_num);
504 type_node *field_type = this_struct->field_type(field_num);
505 check_object_type_ref(field_type);
506 int field_size = field_type->size();
507 if (this_offset + field_size > total_size)
508 problem("field goes past end of struct type");
509 if (this_offset < 0)
510 problem("field with negative offset in struct type");
511 if (field_size < 0)
512 problem("struct type with field of negative size");
513 else if (field_size == 0)
514 problem("struct type with field of zero size");
515 if (this_struct->op() == TYPE_STRUCT)
517 if (this_offset < last_field_end)
518 problem("out-of-order fields in struct type");
519 last_field_end = this_offset + field_size;
521 else if (this_struct->op() == TYPE_UNION)
523 if (this_offset != 0)
524 problem("union with non-zero field offset");
527 break;
529 case TYPE_ENUM:
531 enum_type *this_enum = (enum_type *)this_type;
532 if (this_enum->size() < 0)
533 problem("enumerated type with negative size");
534 if (this_enum->size() == 0)
535 problem("enumerated type with zero size");
536 break;
538 case TYPE_CONST:
539 case TYPE_VOLATILE:
540 case TYPE_CALL_BY_REF:
541 case TYPE_NULL:
543 modifier_type *this_modifier = (modifier_type *)this_type;
544 check_object_type_ref(this_modifier->base());
545 break;
547 default:
548 problem("unknown type op()");
551 pop_clue(this_type);
554 if (the_symtab->children() == NULL)
556 problem("NULL children list in symbol table");
557 current_scope = old_scope;
558 pop_clue(the_symtab);
559 return;
562 base_symtab_list_iter child_iter(the_symtab->children());
563 while (!child_iter.is_empty())
565 base_symtab *this_child = child_iter.step();
566 check_symtab_ref(this_child);
567 push_clue(this_child);
568 if (this_child->parent() != the_symtab)
569 problem("child symtab with wrong parent");
570 pop_clue(this_child);
573 switch (the_symtab->kind())
575 case SYMTAB_GLOBAL:
576 break;
577 case SYMTAB_FILE:
579 file_symtab *the_file_symtab = (file_symtab *)the_symtab;
580 check_fse_ref(the_file_symtab->fse());
581 break;
583 case SYMTAB_PROC:
585 proc_symtab *the_proc_symtab = (proc_symtab *)the_symtab;
586 tree_block *the_tree_block = the_proc_symtab->block();
587 if (!the_tree_block->is_proc())
588 problem("proc_symtab with non-proc block");
589 tree_proc *the_tree_proc = (tree_proc *)the_tree_block;
590 check_tree_proc_ref(the_tree_proc);
591 if (the_tree_proc->proc_syms() != the_proc_symtab)
592 problem("block() of proc_symtab has different proc_syms()");
593 sym_node_list_iter param_iter(the_proc_symtab->params());
594 while (!param_iter.is_empty())
596 sym_node *this_param = param_iter.step();
597 if (!this_param->is_var())
599 problem("non-variable in parameter list");
601 else
603 var_sym *this_var = (var_sym *)this_param;
604 check_var_sym_ref(this_var);
605 if (this_var->parent() != the_proc_symtab)
607 problem("variable in parameter list is from a "
608 "different symbol table");
610 if (!this_var->is_param())
611 problem("non-parameter in parameter list");
614 break;
616 case SYMTAB_BLOCK:
618 block_symtab *the_block_symtab = (block_symtab *)the_symtab;
619 tree_block *the_tree_block = the_block_symtab->block();
620 check_tree_block_ref(the_tree_block);
621 if (the_tree_block->symtab() != the_block_symtab)
622 problem("block() of block_symtab has different symtab()");
623 break;
625 default:
626 problem("unknown symtab kind()");
629 current_scope = old_scope;
630 pop_clue(the_symtab);
633 extern void check_proc(tree_proc *the_proc)
635 tree_node *the_tree_node = (tree_node *)the_proc;
636 check_node(the_tree_node);
637 push_clue(the_proc);
638 if (!the_tree_node->is_proc())
639 problem("object used as a tree_proc isn't a tree_proc");
640 pop_clue(the_proc);
643 extern void check_node(tree_node *the_node)
645 if (the_node == NULL)
647 problem("NULL pointer used as tree_node *");
648 return;
651 push_clue(the_node);
653 suif_object *the_suif_object = the_node;
655 if (the_suif_object->object_kind() != TREE_OBJ)
657 problem("object used as a tree_node isn't a tree_node");
658 pop_clue(the_node);
659 return;
662 check_suif_object(the_suif_object);
664 tree_node *old_node = current_node;
665 current_node = the_node;
667 tree_node_list_e *list_e = the_node->list_e();
668 if (list_e != NULL)
670 if (list_e->contents != the_node)
671 problem("list_e() of tree_node does not contain it");
674 tree_node_list *parent = the_node->parent();
675 if (parent != NULL)
677 if (list_e == NULL)
678 problem("tree_node with non-NULL parent() but NULL list_e()");
679 tree_node_list_e *follow_e = parent->head();
680 while (TRUE)
682 if (follow_e == NULL)
684 problem("parent of tree_node does not contain it");
685 break;
687 if (follow_e == list_e)
688 break;
689 follow_e = follow_e->next();
693 base_symtab *node_scope = the_node->scope();
694 if (node_scope != NULL)
696 suif_object *scope_suif_object = node_scope;
697 if (scope_suif_object->object_kind() != SYMTAB_OBJ)
699 problem("scope() in tree_node isn't really a base_symtab");
700 node_scope = NULL;
704 base_symtab *old_scope = current_scope;
705 if (node_scope != NULL)
707 if (current_scope == NULL)
709 current_scope = node_scope;
711 else
713 if (current_scope != node_scope)
714 problem("scope() in tree_node is wrong");
718 switch (the_node->kind())
720 case TREE_INSTR:
722 tree_instr *the_tree_instr = (tree_instr *)the_node;
723 instruction *the_instr = the_tree_instr->instr();
724 check_instruction(the_instr);
725 if (the_instr->parent() != the_tree_instr)
727 problem("instr() of tree_instr does not have the tree_instr"
728 " as parent()");
730 break;
732 case TREE_LOOP:
734 tree_loop *the_loop = (tree_loop *)the_node;
736 check_label_sym_ref(the_loop->contlab());
737 check_label_sym_ref(the_loop->brklab());
738 check_label_sym_ref(the_loop->toplab());
740 push_label_scope();
741 register_label_def(the_loop->contlab());
742 register_label_def(the_loop->brklab());
743 check_node_list(the_loop->body());
744 pop_label_scope();
746 push_label_scope();
747 register_label_def(the_loop->toplab());
748 check_node_list(the_loop->test());
749 pop_label_scope();
751 break;
753 case TREE_FOR:
755 tree_for *the_for = (tree_for *)the_node;
757 var_sym *index = the_for->index();
758 boolean index_signed = FALSE;
759 boolean index_type_known = FALSE;
760 if (index == NULL)
762 problem("NULL index in tree_for");
764 else
766 check_var_sym_ref(index);
767 if (check_object_type_ref(index->type()) &&
768 check_object_type_ref(index->type()->unqual()))
770 type_node *ind_type_unqual = index->type()->unqual();
771 if (ind_type_unqual->op() == TYPE_INT)
773 base_type *the_base = (base_type *)ind_type_unqual;
774 index_type_known = TRUE;
775 index_signed = the_base->is_signed();
777 else
779 problem("type of tree_for index is not an integer");
784 switch (the_for->test())
786 case FOR_EQ:
787 case FOR_NEQ:
788 break;
789 case FOR_SGELE:
790 case FOR_SGT:
791 case FOR_SGTE:
792 case FOR_SLT:
793 case FOR_SLTE:
794 if (index_type_known && !index_signed)
795 problem("signed test on unsigned index in tree_for");
796 break;
797 case FOR_UGELE:
798 case FOR_UGT:
799 case FOR_UGTE:
800 case FOR_ULT:
801 case FOR_ULTE:
802 if (index_type_known && index_signed)
803 problem("unsigned test on signed index in tree_for");
804 break;
805 default:
806 problem("illegal tree_node kind");
809 if (!the_for->lb_op().type()->is_same(index->type()))
810 problem("bad lb_op() type");
811 if (!the_for->ub_op().type()->is_same(index->type()))
812 problem("bad ub_op() type");
813 if (!the_for->step_op().type()->op() == TYPE_INT)
814 problem("type of tree_for step_op() is not an integer");
816 check_label_sym_ref(the_for->contlab());
817 check_label_sym_ref(the_for->brklab());
819 push_label_scope();
820 check_node_list(the_for->lb_list());
821 pop_label_scope();
823 push_label_scope();
824 check_node_list(the_for->ub_list());
825 pop_label_scope();
827 push_label_scope();
828 check_node_list(the_for->step_list());
829 pop_label_scope();
831 push_label_scope();
832 register_label_def(the_for->contlab());
833 register_label_def(the_for->brklab());
834 check_node_list(the_for->body());
835 pop_label_scope();
837 push_label_scope();
838 check_node_list(the_for->landing_pad());
839 pop_label_scope();
841 break;
843 case TREE_IF:
845 tree_if *the_if = (tree_if *)the_node;
847 check_label_sym_ref(the_if->jumpto());
849 push_label_scope();
850 register_label_def(the_if->jumpto());
851 check_node_list(the_if->header());
852 pop_label_scope();
854 push_label_scope();
855 check_node_list(the_if->then_part());
856 pop_label_scope();
858 push_label_scope();
859 check_node_list(the_if->else_part());
860 pop_label_scope();
862 break;
864 case TREE_BLOCK:
866 tree_block *the_block = (tree_block *)the_node;
868 block_symtab *the_symtab = the_block->symtab();
869 check_symtab(the_symtab);
870 if (the_symtab->block() != the_block)
871 problem("block with symtab() with wrong block() pointer");
873 base_symtab *the_base_symtab = the_symtab;
874 if (!the_base_symtab->is_block())
875 problem("symtab of block is not block_symtab");
877 if (the_block->is_proc())
878 push_label_scope();
880 base_symtab *save_scope = current_scope;
881 current_scope = the_block->symtab();
882 check_node_list(the_block->body());
883 current_scope = save_scope;
885 if (the_block->is_proc())
886 pop_label_scope();
888 if (the_block->is_proc())
890 tree_proc *the_tree_proc = (tree_proc *)the_block;
891 proc_sym *the_proc_sym = the_tree_proc->proc();
892 check_proc_sym_ref(the_proc_sym);
893 if (!the_symtab->is_proc())
894 problem("symtab of proc is not proc_symtab");
896 func_type *the_func_type = the_proc_sym->type();
897 if (the_func_type->args_known())
899 proc_symtab *the_proc_symtab = (proc_symtab *)the_symtab;
900 sym_node_list_iter param_iter(the_proc_symtab->params());
901 unsigned num_args = the_func_type->num_args();
902 for (unsigned arg_num = 0; arg_num < num_args; ++arg_num)
904 sym_node *this_sym = param_iter.step();
905 if (this_sym == NULL)
907 problem("number of parameters in formal argument "
908 "list (%lu) is less than the number in "
909 "the function type (%lu)",
910 (unsigned long)arg_num,
911 (unsigned long)num_args);
912 break;
914 if (!this_sym->is_var())
915 continue;
916 var_sym *this_param = (var_sym *)this_sym;
917 if (this_param->type() !=
918 the_func_type->arg_type(arg_num))
920 problem("mismatch between the type of formal "
921 "argument %u and the type in the function "
922 "type", arg_num);
925 if (!param_iter.is_empty())
927 problem("number of parameters in formal argument list "
928 "(%lu) is greater than the number in the "
929 "function type (%lu)",
930 (unsigned long)
931 (the_proc_symtab->params()->count()),
932 (unsigned long)num_args);
937 break;
939 default:
940 problem("illegal tree_node kind");
943 current_scope = old_scope;
944 current_node = old_node;
945 pop_clue(the_node);
948 extern void check_operand(operand the_operand)
950 switch (the_operand.kind())
952 case OPER_NULL:
953 break;
954 case OPER_SYM:
955 check_var_sym_ref(the_operand.symbol());
956 break;
957 case OPER_INSTR:
959 instruction *this_instr = the_operand.instr();
960 if (the_operand.is_expr())
961 check_instruction(this_instr);
962 else
963 check_instruction_ref(this_instr);
964 if (this_instr->dst_op().is_symbol())
965 problem("instruction used as operand with symbol destination");
966 break;
968 default:
969 problem("unknown kind() for operand");
973 extern void check_instruction(instruction *the_instr)
975 if (the_instr == NULL)
977 problem("NULL pointer used as instruction *");
978 return;
981 push_clue(the_instr);
983 suif_object *the_suif_object = the_instr;
985 if (the_suif_object->object_kind() != INSTR_OBJ)
987 problem("object passed as an instruction isn't an instruction");
988 pop_clue(the_instr);
989 return;
992 check_suif_object(the_suif_object);
994 check_object_type_ref(the_instr->result_type());
996 tree_instr *parent = the_instr->parent();
997 if (parent != NULL)
998 check_tree_instr_ref(parent);
1000 operand dest_op = the_instr->dst_op();
1001 switch (dest_op.kind())
1003 case OPER_NULL:
1004 break;
1005 case OPER_SYM:
1006 check_var_sym_ref(dest_op.symbol());
1007 break;
1008 case OPER_INSTR:
1010 instruction *dest_instr = dest_op.instr();
1011 check_instruction_ref(dest_instr);
1012 unsigned num_dest_srcs = dest_instr->num_srcs();
1013 unsigned src_num;
1014 for (src_num = 0; src_num < num_dest_srcs; ++src_num)
1016 if (dest_instr->src_op(src_num) == operand(the_instr))
1017 break;
1019 if (src_num == num_dest_srcs)
1020 problem("destination does not use instruction as source");
1021 if ((!operand(the_instr).is_expr()) && (pending_instr_ops != NULL))
1022 pending_instr_ops->append(the_instr);
1023 break;
1025 default:
1026 problem("unknown kind() for destination operand");
1029 switch (the_instr->format())
1031 case inf_none:
1033 problem("instruction with format() ``inf_none''");
1034 break;
1036 case inf_rrr:
1038 break;
1040 case inf_bj:
1042 in_bj *the_bj = (in_bj *)the_instr;
1043 check_label_sym_ref(the_bj->target());
1044 register_label_use(the_bj->target());
1045 break;
1047 case inf_ldc:
1049 in_ldc *the_ldc = (in_ldc *)the_instr;
1051 immed value = the_ldc->value();
1052 check_immed(&value);
1054 type_ops result_base_op = the_instr->result_type()->unqual()->op();
1055 switch (value.kind())
1057 case im_int:
1058 case im_extended_int:
1059 if ((result_base_op != TYPE_INT) &&
1060 (result_base_op != TYPE_ENUM) &&
1061 (result_base_op != TYPE_PTR))
1063 problem("ldc of integer constant with non-integer,"
1064 " non-pointer type");
1066 break;
1067 case im_float:
1068 case im_extended_float:
1069 if (result_base_op != TYPE_FLOAT)
1071 problem("ldc of floating-point constant with "
1072 "non-floating-point type");
1074 break;
1075 case im_symbol:
1077 sym_node *the_symbol = value.symbol();
1078 if (the_symbol->is_var())
1080 var_sym *the_var = (var_sym *)the_symbol;
1081 if (!the_var->is_addr_taken())
1083 problem("ldc of address of symbol `%s' with "
1084 "is_addr_taken() flag FALSE",
1085 the_var->name());
1088 if (!the_instr->result_type()->unqual()->is_ptr())
1089 problem("ldc of symbol with non-pointer result type");
1090 break;
1092 default:
1093 problem("illegal immed kind `%s' in ldc instruction",
1094 value.kind());
1095 break;
1098 if (!immed_fits(value, the_instr->result_type()))
1099 problem("value of ldc does not fit result type");
1101 break;
1103 case inf_cal:
1105 break;
1107 case inf_array:
1109 break;
1111 case inf_mbr:
1113 in_mbr *the_mbr = (in_mbr *)the_instr;
1114 check_label_sym_ref(the_mbr->default_lab());
1115 register_label_use(the_mbr->default_lab());
1116 unsigned num_labs = the_mbr->num_labs();
1117 for (unsigned lab_num = 0; lab_num < num_labs; ++lab_num)
1119 check_label_sym_ref(the_mbr->label(lab_num));
1120 register_label_use(the_mbr->label(lab_num));
1122 break;
1124 case inf_lab:
1126 in_lab *the_lab_instr = (in_lab *)the_instr;
1127 check_label_sym_ref(the_lab_instr->label());
1128 register_label_def(the_lab_instr->label());
1129 break;
1131 case inf_gen:
1133 in_gen *the_gen_instr = (in_gen *)the_instr;
1134 const char *name = the_gen_instr->name();
1135 if (name == NULL)
1137 problem("in_gen with NULL name");
1139 else if (name != lexicon->enter(name)->sp)
1141 problem("in_gen instruction with name not in lexicon");
1143 break;
1145 default:
1147 problem("unknown format() for instruction");
1148 break;
1152 check_type_instr(the_instr, the_instr->parent());
1154 unsigned num_srcs = the_instr->num_srcs();
1155 for (unsigned src_num = 0; src_num < num_srcs; ++src_num)
1157 operand this_op = the_instr->src_op(src_num);
1158 check_operand(this_op);
1159 if (this_op.is_instr())
1161 instruction *this_src_instr = this_op.instr();
1162 if (this_src_instr->dst_op() != operand(the_instr))
1164 problem("instruction source operand does not use instruction"
1165 " as destination");
1167 if ((!this_op.is_expr()) && (pending_instr_ops != NULL))
1169 instruction_list_e *follow_instr = pending_instr_ops->head();
1170 while (TRUE)
1172 if (follow_instr == NULL)
1174 problem("instruction used as source is not live");
1175 break;
1177 if (follow_instr->contents == this_src_instr)
1179 pending_instr_ops->remove(follow_instr);
1180 break;
1182 follow_instr = follow_instr->next();
1188 pop_clue(the_instr);
1191 extern void problem(char *fmt, ...)
1193 va_list ap;
1195 va_start(ap, fmt);
1196 vproblem(fmt, ap);
1197 va_end(ap);
1200 extern void vproblem(char *fmt, va_list ap)
1202 char *new_fmt = new char[strlen(fmt) + 13];
1203 sprintf(new_fmt, "%s%s", (in_annote ? "[in annote] " : ""), fmt);
1204 if (checkfail)
1205 verror_line(checkabort ? 0 : 1, current_node, new_fmt, ap);
1206 else
1207 vwarning_line(current_node, new_fmt, ap);
1208 delete[] new_fmt;
1209 if (checkabort)
1210 abort();
1213 extern void problem_instr(tree_node *the_node, instruction *the_instr,
1214 char *fmt, ...)
1216 va_list ap;
1218 va_start(ap, fmt);
1219 vproblem_instr(the_node, the_instr, fmt, ap);
1220 va_end(ap);
1223 extern void vproblem_instr(tree_node *the_node, instruction *the_instr,
1224 char *fmt, va_list ap)
1226 tree_node *old_current = current_node;
1227 if (the_node != NULL)
1228 current_node = the_node;
1229 char *new_fmt = new char[strlen(fmt) + 30];
1230 sprintf(new_fmt, "instruction (%u) - %s", the_instr->number(), fmt);
1231 vproblem(new_fmt, ap);
1232 delete[] new_fmt;
1233 current_node = old_current;
1236 static void check_node_list(tree_node_list *the_node_list)
1238 if (the_node_list == NULL)
1240 problem("NULL pointer used as tree_node_list *");
1241 return;
1244 tree_node *parent = the_node_list->parent();
1245 if (parent != NULL)
1247 check_tree_node_ref(parent);
1248 boolean not_used = FALSE;
1249 switch (parent->kind())
1251 case TREE_INSTR:
1252 problem("tree_node_list with tree_instr as parent");
1253 break;
1254 case TREE_LOOP:
1256 tree_loop *the_loop = (tree_loop *)parent;
1257 not_used = ((the_loop->body() != the_node_list) &&
1258 (the_loop->test() != the_node_list));
1259 break;
1261 case TREE_FOR:
1263 tree_for *the_for = (tree_for *)parent;
1264 not_used = ((the_for->body() != the_node_list) &&
1265 (the_for->landing_pad() != the_node_list) &&
1266 (the_for->lb_list() != the_node_list) &&
1267 (the_for->ub_list() != the_node_list) &&
1268 (the_for->step_list() != the_node_list));
1269 break;
1271 case TREE_IF:
1273 tree_if *the_if = (tree_if *)parent;
1274 not_used = ((the_if->header() != the_node_list) &&
1275 (the_if->then_part() != the_node_list) &&
1276 (the_if->else_part() != the_node_list));
1277 break;
1279 case TREE_BLOCK:
1281 tree_block *the_block = (tree_block *)parent;
1282 not_used = (the_block->body() != the_node_list);
1283 break;
1285 default:
1286 problem("unknown kind() for parent of tree_node_list");
1289 if (not_used)
1290 problem("parent of tree_node_list does not use it");
1293 if ((pending_instr_ops != NULL) && (!pending_instr_ops->is_empty()))
1294 problem("instruction operand live across list beginning");
1295 instruction_list *old_pending_instrs = pending_instr_ops;
1296 pending_instr_ops = new instruction_list;
1298 tree_node_list_iter node_iter(the_node_list);
1299 while (!node_iter.is_empty())
1301 tree_node *this_node = node_iter.step();
1302 check_node(this_node);
1305 if (!pending_instr_ops->is_empty())
1306 problem("instruction operand live across list end");
1307 delete pending_instr_ops;
1308 pending_instr_ops = old_pending_instrs;
1311 static void check_suif_object(suif_object *the_suif_object)
1313 if (the_suif_object == NULL)
1315 problem("NULL pointer used as suif_object *");
1316 return;
1319 push_clue(the_suif_object);
1321 object_kinds this_kind = the_suif_object->object_kind();
1322 switch (this_kind)
1324 case FILE_OBJ:
1325 case TREE_OBJ:
1326 case INSTR_OBJ:
1327 case SYMTAB_OBJ:
1328 case SYM_OBJ:
1329 case DEF_OBJ:
1330 case TYPE_OBJ:
1331 break;
1332 default:
1333 problem("object passed as a suif_object isn't a suif_object");
1334 pop_clue(the_suif_object);
1335 return;
1338 annote_list *the_annotes = the_suif_object->annotes();
1339 check_annote_list(the_annotes);
1341 pop_clue(the_suif_object);
1344 static void check_annote_list(annote_list *the_annotes)
1346 if (the_annotes == NULL)
1348 problem("NULL pointer used as annote_list *");
1349 return;
1352 annote_list_iter the_iter(the_annotes);
1353 while (!the_iter.is_empty())
1355 annote *this_annote = the_iter.step();
1356 check_annote(this_annote);
1360 static void check_annote(annote *the_annote)
1362 boolean old_in_annote = in_annote;
1363 in_annote = TRUE;
1365 if (the_annote == NULL)
1367 problem("NULL annote");
1368 return;
1371 push_clue(the_annote);
1373 const char *name = the_annote->name();
1374 if (name == NULL)
1376 problem("annote with NULL name");
1377 pop_clue(the_annote);
1378 return;
1381 if (name != lexicon->enter(name)->sp)
1383 problem("annote with name not in lexicon");
1384 pop_clue(the_annote);
1385 return;
1388 annote_def *definition = lookup_annote(name);
1389 if ((definition != NULL) && (!definition->is_structured()))
1391 immed_list *the_immeds = (immed_list *)the_annote->data();
1392 if (the_immeds != NULL)
1393 check_immed_list(the_immeds);
1396 in_annote = old_in_annote;
1397 pop_clue(the_annote);
1400 static void check_immed_list(immed_list *the_immeds)
1402 if (the_immeds == NULL)
1404 problem("NULL pointer used as immed_list *");
1405 return;
1408 immed_list_iter the_iter(the_immeds);
1409 while (!the_iter.is_empty())
1411 immed this_immed = the_iter.step();
1412 check_immed(&this_immed);
1416 static void check_immed(immed *the_immed)
1418 switch (the_immed->kind())
1420 case im_int:
1421 break;
1422 case im_extended_int:
1423 if (the_immed->ext_integer() == NULL)
1425 problem("NULL data for extended integer immed");
1427 else if (the_immed->ext_integer() !=
1428 lexicon->enter(the_immed->ext_integer())->sp)
1430 problem("extended integer immed data not in lexicon");
1432 else
1434 const char *follow = the_immed->ext_integer();
1435 if (*follow == '-')
1436 ++follow;
1437 if (*follow == 0)
1438 problem("empty digit string for extended integer immed");
1439 while (*follow != 0)
1441 if (*follow == '-')
1443 problem("dash in extended integer not in the first"
1444 " position");
1445 break;
1447 if ((*follow < '0') || (*follow > '9'))
1449 problem("non-digit `%c' in extended integer", *follow);
1450 break;
1452 ++follow;
1455 break;
1456 case im_string:
1457 if (the_immed->string() == NULL)
1459 problem("NULL for string immed");
1461 else if (the_immed->string() !=
1462 lexicon->enter(the_immed->string())->sp)
1464 problem("string immed with data that is not entered in the"
1465 " lexicon");
1467 break;
1468 case im_float:
1469 break;
1470 case im_extended_float:
1471 if (the_immed->ext_flt() == NULL)
1473 problem("NULL data for extended floating-point immed");
1475 else if (the_immed->ext_flt() !=
1476 lexicon->enter(the_immed->ext_flt())->sp)
1478 problem("extended floating-point immed data not in lexicon");
1480 else
1482 const char *follow = the_immed->ext_flt();
1483 if (*follow == '-')
1484 ++follow;
1485 if ((*follow == 0) || (*follow == 'e') || (*follow == 'E'))
1487 problem("empty mantissa for extended floating-point"
1488 " immed");
1490 boolean decimal_point_seen = FALSE;
1491 boolean in_exponent = FALSE;
1492 while (*follow != 0)
1494 if (*follow == '-')
1496 problem("dash in %s of extended floating-point immed"
1497 " not in the first position",
1498 (in_exponent ? "exponent" : "mantissa"));
1499 break;
1501 else if (*follow == '.')
1503 if (in_exponent)
1505 problem("decimal point in exponent of extended"
1506 " floating-point immed");
1507 break;
1509 else
1511 if (decimal_point_seen)
1513 problem("more than one decimal point in "
1514 "mantissa of extended floating-point"
1515 " immed");
1516 break;
1518 else
1520 decimal_point_seen = TRUE;
1524 else if ((*follow == 'e') || (*follow == 'E'))
1526 if (in_exponent)
1528 problem("multiple exponents in extended "
1529 "floating-point immed");
1530 break;
1532 else
1534 in_exponent = TRUE;
1535 if (follow[1] == '-')
1536 ++follow;
1537 if (follow[1] == 0)
1539 problem("empty exponent in extended "
1540 "floating-point immed");
1544 else if ((*follow < '0') || (*follow > '9'))
1546 problem("illegal character `%c' in extended "
1547 "floating-point immed", *follow);
1548 break;
1550 ++follow;
1553 break;
1554 case im_symbol:
1556 sym_addr this_addr = the_immed->addr();
1557 check_sym_addr(&this_addr);
1558 break;
1560 case im_type:
1561 check_type_ref(the_immed->type());
1562 break;
1563 case im_op:
1564 check_operand(the_immed->op());
1565 break;
1566 case im_instr:
1567 check_instruction(the_immed->instr());
1568 break;
1569 case im_undef:
1570 break;
1571 default:
1572 problem("illegal immed kind `%c'", the_immed->kind());
1573 break;
1577 static void check_sym_addr(sym_addr *the_addr)
1579 sym_node *the_sym = the_addr->symbol();
1580 check_sym_node_ref(the_sym);
1581 if (the_addr->offset() != 0)
1583 if (!the_sym->is_var())
1585 problem("address of non-var sym `%s' used with non-zero offset",
1586 the_sym->name());
1591 static void check_fse_ref(file_set_entry *the_fse)
1593 if (the_fse == NULL)
1595 problem("NULL pointer used as file_set_entry *");
1596 return;
1599 push_clue(the_fse);
1601 suif_object *the_suif_object = the_fse;
1603 if (the_suif_object->object_kind() != FILE_OBJ)
1605 problem("object used as file_set_entry isn't a file_set_entry");
1606 pop_clue(the_fse);
1607 return;
1610 pop_clue(the_fse);
1613 static void check_tree_instr_ref(tree_instr *the_tree_instr)
1615 tree_node *the_tree_node = the_tree_instr;
1616 check_tree_node_ref(the_tree_node);
1617 push_clue(the_tree_instr);
1618 if (!the_tree_node->is_instr())
1619 problem("object used as tree_instr isn't a tree_instr");
1620 pop_clue(the_tree_instr);
1623 static void check_tree_block_ref(tree_block *the_block)
1625 tree_node *the_tree_node = the_block;
1626 check_tree_node_ref(the_tree_node);
1627 push_clue(the_block);
1628 if (!the_tree_node->is_block())
1629 problem("object used as tree_block isn't a tree_block");
1630 pop_clue(the_block);
1633 static void check_tree_proc_ref(tree_proc *the_tree_proc)
1635 tree_block *the_block = the_tree_proc;
1636 check_tree_block_ref(the_block);
1637 push_clue(the_tree_proc);
1638 if (!the_block->is_proc())
1639 problem("object used as tree_proc isn't a tree_proc");
1640 pop_clue(the_tree_proc);
1643 static void check_tree_node_ref(tree_node *the_node)
1645 if (the_node == NULL)
1647 problem("NULL pointer used as tree_node *");
1648 return;
1651 push_clue(the_node);
1653 suif_object *the_suif_object = the_node;
1655 if (the_suif_object->object_kind() != TREE_OBJ)
1657 problem("object used as tree_node isn't a tree_node");
1658 pop_clue(the_node);
1659 return;
1662 pop_clue(the_node);
1665 static void check_instruction_ref(instruction *the_instr)
1667 if (the_instr == NULL)
1669 problem("NULL pointer used as instruction *");
1670 return;
1673 push_clue(the_instr);
1675 suif_object *the_suif_object = the_instr;
1677 if (the_suif_object->object_kind() != INSTR_OBJ)
1678 problem("object used as instruction isn't an instruction");
1680 pop_clue(the_instr);
1683 static void check_symtab_ref(base_symtab *the_symtab)
1685 if (the_symtab == NULL)
1687 problem("NULL pointer used as base_symtab *");
1688 return;
1691 push_clue(the_symtab);
1693 suif_object *the_suif_object = the_symtab;
1695 if (the_suif_object->object_kind() != SYMTAB_OBJ)
1697 problem("object used as base_symtab isn't a base_symtab");
1698 pop_clue(the_symtab);
1699 return;
1702 pop_clue(the_symtab);
1705 static void check_var_sym_ref(var_sym *the_var)
1707 sym_node *this_sym = the_var;
1708 check_sym_node_ref(the_var);
1709 push_clue(the_var);
1710 if (this_sym->kind() != SYM_VAR)
1711 problem("object used as var_sym isn't a var_sym");
1712 pop_clue(the_var);
1715 static void check_proc_sym_ref(proc_sym *the_proc)
1717 sym_node *this_sym = the_proc;
1718 check_sym_node_ref(the_proc);
1719 push_clue(the_proc);
1720 if (this_sym->kind() != SYM_PROC)
1721 problem("object used as proc_sym isn't a proc_sym");
1722 pop_clue(the_proc);
1725 static void check_label_sym_ref(label_sym *the_label)
1727 sym_node *this_sym = the_label;
1728 check_sym_node_ref(the_label);
1729 push_clue(the_label);
1730 if (this_sym->kind() != SYM_LABEL)
1731 problem("object used as label_sym isn't a label_sym");
1732 pop_clue(the_label);
1735 static void check_sym_node_ref(sym_node *symbol)
1737 if (symbol == NULL)
1739 problem("NULL pointer used as sym_node *");
1740 return;
1743 push_clue(symbol);
1745 suif_object *the_suif_object = symbol;
1747 if (the_suif_object->object_kind() != SYM_OBJ)
1749 problem("object used as sym_node isn't a sym_node");
1750 pop_clue(symbol);
1751 return;
1754 if (symbol->name() == NULL)
1756 problem("symbol has NULL name");
1757 pop_clue(symbol);
1758 return;
1761 base_symtab *parent = symbol->parent();
1762 if (parent == NULL)
1764 problem("symbol `%s' has no symbol table", symbol->name());
1765 pop_clue(symbol);
1766 return;
1769 check_symtab_ref(parent);
1771 sym_node_list_iter sym_iter(parent->symbols());
1772 while (TRUE)
1774 if (sym_iter.is_empty())
1776 problem("symbol `%s' is not in the list of symbols for its parent",
1777 symbol->name());
1778 pop_clue(symbol);
1779 return;
1781 sym_node *test_sym = sym_iter.step();
1782 if (test_sym == symbol)
1783 break;
1786 if (current_scope == NULL)
1788 pop_clue(symbol);
1789 return;
1792 if (!scope_in_scope(parent, current_scope))
1793 problem("symbol `%s' used out of its scope", symbol->name());
1795 pop_clue(symbol);
1798 static void check_array_bound(array_bound the_bound)
1800 if (the_bound.is_variable())
1801 check_var_sym_ref(the_bound.variable());
1804 static void check_func_type_ref(func_type *the_func_type)
1806 type_node *the_type_node = (type_node *)the_func_type;
1807 check_type_ref(the_type_node);
1808 push_clue(the_func_type);
1809 if (!the_type_node->is_func())
1810 problem("non-function type used as function type");
1811 pop_clue(the_func_type);
1814 static boolean check_object_type_ref(type_node *the_type)
1816 boolean ok = check_type_ref(the_type);
1817 if (!ok)
1818 return FALSE;
1819 push_clue(the_type);
1820 if (the_type->is_func())
1822 problem("function type used as object type");
1823 pop_clue(the_type);
1824 return FALSE;
1826 pop_clue(the_type);
1827 return TRUE;
1830 static boolean check_type_ref(type_node *the_type)
1832 if (the_type == NULL)
1834 problem("NULL pointer used as type_node *");
1835 return FALSE;
1838 push_clue(the_type);
1840 suif_object *the_suif_object = the_type;
1842 if (the_suif_object->object_kind() != TYPE_OBJ)
1844 problem("object passed as type_node isn't a type_node");
1845 pop_clue(the_type);
1846 return FALSE;
1849 base_symtab *parent = the_type->parent();
1850 if (parent == NULL)
1852 problem("type has no symbol table");
1853 pop_clue(the_type);
1854 return FALSE;
1857 check_symtab_ref(parent);
1859 type_node_list_iter type_iter(parent->types());
1860 while (TRUE)
1862 if (type_iter.is_empty())
1864 problem("type `%u' is not in the list of types for its parent",
1865 the_type->type_id());
1866 pop_clue(the_type);
1867 return FALSE;
1869 type_node *test_type = type_iter.step();
1870 if (test_type == the_type)
1871 break;
1874 if (current_scope == NULL)
1876 pop_clue(the_type);
1877 return TRUE;
1880 if (!scope_in_scope(parent, current_scope))
1881 problem("type used out of its scope");
1883 pop_clue(the_type);
1884 return TRUE;
1887 static boolean scope_in_scope(base_symtab *outer, base_symtab *inner)
1889 if ((outer == NULL) || (inner == NULL))
1890 return FALSE;
1892 base_symtab *follow = inner;
1894 while (follow != NULL)
1896 if (follow == outer)
1897 return TRUE;
1898 follow = follow->parent();
1901 return FALSE;
1904 static void push_label_scope(void)
1906 if (defined_labs != NULL)
1908 if (old_defined_labs == NULL)
1909 old_defined_labs = new string_index_list;
1910 old_defined_labs->push(defined_labs);
1912 defined_labs = new tree_string_index;
1914 if (used_labs != NULL)
1916 if (old_used_labs == NULL)
1917 old_used_labs = new label_sym_list_list;
1918 old_used_labs->push(used_labs);
1920 used_labs = new label_sym_list;
1923 static void pop_label_scope(void)
1925 assert(used_labs != NULL);
1926 assert(defined_labs != NULL);
1927 while (!used_labs->is_empty())
1929 label_sym *this_lab = used_labs->pop();
1930 if (!defined_labs->exists(this_lab->name()))
1932 problem("label `%s' used as target outside of its legal range",
1933 this_lab->name());
1937 delete used_labs;
1938 delete defined_labs;
1940 if (old_defined_labs != NULL)
1942 assert(old_used_labs != NULL);
1943 assert(!old_defined_labs->is_empty());
1944 assert(!old_used_labs->is_empty());
1945 defined_labs = old_defined_labs->pop();
1946 used_labs = old_used_labs->pop();
1947 if (old_defined_labs->is_empty())
1949 assert(old_used_labs->is_empty());
1950 delete old_defined_labs;
1951 delete old_used_labs;
1952 old_defined_labs = NULL;
1953 old_used_labs = NULL;
1955 else
1957 assert(!old_used_labs->is_empty());
1960 else
1962 assert(old_used_labs == NULL);
1963 defined_labs = NULL;
1964 used_labs = NULL;
1968 static void register_label_def(label_sym *the_label)
1970 if (defined_labs != NULL)
1971 defined_labs->enter(the_label->name(), the_label);
1974 static void register_label_use(label_sym *the_label)
1976 if (used_labs != NULL)
1977 used_labs->append(the_label);