Pristine Ack-5.5
[Ack-5.5.git] / lang / pc / comp / misc.c
1 /* M I S C E L L A N E O U S    R O U T I N E S */
2
3 #include        <alloc.h>
4 #include        <em.h>
5
6 #include        "LLlex.h"
7 #include        "f_info.h"
8 #include        "idf.h"
9 #include        "main.h"
10 #include        "misc.h"
11 #include        "node.h"
12
13 struct idf *
14 gen_anon_idf()
15 {
16         /*      A new idf is created out of nowhere, to serve as an
17                 anonymous name.
18         */
19         static int name_cnt;
20         char *s = Malloc(strlen(FileName) + 50);
21         char *sprint();
22
23         sprint(s, "#%d in %s, line %u", ++name_cnt, FileName, LineNumber);
24         s = Realloc(s, strlen(s)+1);
25         return str2idf(s, 0);
26 }
27
28 not_declared(what, id, where)
29         char *what, *where;
30         register struct node *id;
31 {
32         /*      The identifier "id" is not declared. If it is not generated,
33                 give an error message
34         */
35         if( !is_anon_idf(id->nd_IDF) )  {
36                 node_error(id, "%s \"%s\" not declared%s",
37                                         what, id->nd_IDF->id_text, where);
38         }
39 }
40
41 char *
42 gen_proc_name(id, inp)
43         register struct idf *id;
44 {
45         /* generate pseudo and internal name for procedure or function */
46
47         static int name_cnt;
48         static char buf[256];
49         char *sprint(), *Salloc();
50
51         if( inp )       {
52                 sprint(buf, "_%d%s", ++name_cnt, id->id_text);
53                 C_inp(buf);
54                 return Salloc(buf, (unsigned) (strlen(buf) + 1));
55         }
56         else    {
57                 C_exp(id->id_text);
58                 return id->id_text;
59         }
60
61 }