label.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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$ */
  6. /* L A B E L H A N D L I N G */
  7. #include "Lpars.h"
  8. #include "level.h"
  9. #include "idf.h"
  10. #include "label.h"
  11. #include "arith.h"
  12. #include "def.h"
  13. #include "type.h"
  14. #include "stack.h"
  15. extern char options[];
  16. enter_label(idf, defining)
  17. register struct idf *idf;
  18. {
  19. /* The identifier idf is entered as a label. If it is new,
  20. it is entered into the idf list with the largest possible
  21. scope, i.e., on the lowest possible level.
  22. If defining, the label comes from a label statement.
  23. */
  24. register struct def *def = idf->id_label;
  25. if (def) {
  26. if (defining && def->df_initialized)
  27. error("redeclaration of label %s", idf->id_text);
  28. }
  29. else {
  30. stack_idf(idf, stack_level_of(L_LOCAL));
  31. def = new_def();
  32. def->df_sc = LABEL;
  33. idf->id_label = def;
  34. def->df_file = idf->id_file;
  35. def->df_line = idf->id_line;
  36. }
  37. if (def->df_address == 0)
  38. def->df_address = (arith) text_label();
  39. if (defining)
  40. def->df_initialized = 1;
  41. }
  42. unstack_label(idf)
  43. register struct idf *idf;
  44. {
  45. /* The scope in which the label idf occurred is left.
  46. */
  47. if (!idf->id_label->df_initialized && !is_anon_idf(idf))
  48. error("label %s not defined", idf->id_text);
  49. }