InadequacyList.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* IELR's inadequacy list.
  2. Copyright (C) 2009-2015, 2018-2021 Free Software Foundation, Inc.
  3. This file is part of Bison, the GNU Compiler Compiler.
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  14. #include <config.h>
  15. #include "system.h"
  16. #include "InadequacyList.h"
  17. #include <intprops.h>
  18. ContributionIndex const ContributionIndex__none = -1;
  19. ContributionIndex const ContributionIndex__error_action = -2;
  20. InadequacyList *
  21. InadequacyList__new_conflict (state *manifesting_state, symbol *token,
  22. bitset actions,
  23. InadequacyListNodeCount *node_count)
  24. {
  25. InadequacyList *result = xmalloc (sizeof *result);
  26. result->id = *node_count;
  27. IGNORE_TYPE_LIMITS_BEGIN
  28. if (INT_ADD_WRAPV (*node_count, 1, node_count))
  29. aver (false);
  30. IGNORE_TYPE_LIMITS_END
  31. result->next = NULL;
  32. result->manifestingState = manifesting_state;
  33. result->contributionCount = bitset_count (actions);
  34. result->inadequacy.conflict.token = token;
  35. result->inadequacy.conflict.actions = actions;
  36. return result;
  37. }
  38. void
  39. InadequacyList__delete (InadequacyList *self)
  40. {
  41. while (self)
  42. {
  43. InadequacyList *node = self;
  44. self = self->next;
  45. bitset_free (node->inadequacy.conflict.actions);
  46. free (node);
  47. }
  48. }
  49. ContributionIndex
  50. InadequacyList__getShiftContributionIndex (InadequacyList const *self)
  51. {
  52. if (!bitset_test (self->inadequacy.conflict.actions,
  53. self->manifestingState->reductions->num))
  54. return ContributionIndex__none;
  55. return self->contributionCount - 1;
  56. }
  57. symbol *
  58. InadequacyList__getContributionToken (InadequacyList const *self,
  59. ContributionIndex i)
  60. {
  61. aver (0 <= i && i < self->contributionCount); (void) i;
  62. return self->inadequacy.conflict.token;
  63. }
  64. void
  65. InadequacyList__prependTo (InadequacyList *self, InadequacyList **list)
  66. {
  67. InadequacyList *head_old = *list;
  68. *list = self;
  69. self->next = head_old;
  70. }