Pristine Ack-5.5
[Ack-5.5.git] / lang / m2 / comp / misc.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  * Author: Ceriel J.H. Jacobs
6  */
7
8 /* M I S C E L L A N E O U S    R O U T I N E S */
9
10 /* $Id: misc.c,v 1.15 1994/06/24 12:41:41 ceriel Exp $ */
11
12 #include        <alloc.h>
13 #include        <em_arith.h>
14 #include        <em_label.h>
15
16 #include        "f_info.h"
17 #include        "misc.h"
18 #include        "LLlex.h"
19 #include        "idf.h"
20 #include        "node.h"
21
22 match_id(id1, id2)
23         register t_idf *id1, *id2;
24 {
25         /*      Check that identifiers id1 and id2 are equal. If they
26                 are not, check that we did'nt generate them in the
27                 first place, and if not, give an error message
28         */
29         if (id1 != id2 && !is_anon_idf(id1) && !is_anon_idf(id2)) {
30                 error("name \"%s\" does not match block name \"%s\"",
31                       id1->id_text,
32                       id2->id_text
33                 );
34         }
35 }
36
37 t_idf *
38 gen_anon_idf()
39 {
40         /*      A new idf is created out of nowhere, to serve as an
41                 anonymous name.
42         */
43         static int name_cnt;
44         char *s = Malloc(strlen(FileName)+50);
45         char *sprint();
46
47         sprint(s, "#%d in %s, line %u",
48                         ++name_cnt, FileName, LineNumber);
49         s = Realloc(s, strlen(s)+1);
50         return str2idf(s, 0);
51 }
52
53 not_declared(what, id, where)
54         char *what, *where;
55         register t_node *id;
56 {
57         /*      The identifier "id" is not declared. If it is not generated,
58                 give an error message
59         */
60         if (!is_anon_idf(id->nd_IDF)) {
61                 node_error(id,
62                            "%s \"%s\" not declared%s",
63                            what,
64                            id->nd_IDF->id_text,
65                            where);
66         }
67 }