Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / cemcom.ansi / label.c
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  */
5 /* $Id: label.c,v 1.8 1994/06/27 08:01:19 ceriel Exp $ */
6 /*              L A B E L   H A N D L I N G             */
7
8 #include        "Lpars.h"
9 #include        "level.h"
10 #include        "idf.h"
11 #include        "label.h"
12 #include        "arith.h"
13 #include        "def.h"
14 #include        "type.h"
15 #include        "stack.h"
16
17 extern char options[];
18
19 enter_label(idf, defining)
20         register struct idf *idf;
21 {
22         /*      The identifier idf is entered as a label. If it is new,
23                 it is entered into the idf list with the largest possible
24                 scope, i.e., on the lowest possible level.
25                 If defining, the label comes from a label statement.
26         */
27         register struct def *def = idf->id_label;
28
29         if (def)        {
30                 if (defining && def->df_initialized)
31                         error("redeclaration of label %s", idf->id_text);
32         }
33         else    {
34                 stack_idf(idf, stack_level_of(L_LOCAL));
35                 def = new_def();
36                 def->df_sc = LABEL;
37                 idf->id_label = def;
38                 def->df_file = idf->id_file;
39                 def->df_line = idf->id_line;
40         }
41         if (def->df_address == 0)
42                 def->df_address = (arith) text_label();
43         if (defining)
44                 def->df_initialized = 1;
45 }
46
47 unstack_label(idf)
48         register struct idf *idf;
49 {
50         /*      The scope in which the label idf occurred is left.
51         */
52         if (!idf->id_label->df_initialized && !is_anon_idf(idf))
53                 error("label %s not defined", idf->id_text);
54 }