misc.c 1.2 KB

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