label.c 1.3 KB

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