aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/bison/src/InadequacyList.c
blob: c958f8226dd0a44c6f8dbdafdab2849eedddebfe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* IELR's inadequacy list.

   Copyright (C) 2009-2015, 2018-2021 Free Software Foundation, Inc.

   This file is part of Bison, the GNU Compiler Compiler.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */

#include <config.h>
#include "system.h"

#include "InadequacyList.h"

#include <intprops.h>

ContributionIndex const ContributionIndex__none = -1;
ContributionIndex const ContributionIndex__error_action = -2;

InadequacyList *
InadequacyList__new_conflict (state *manifesting_state, symbol *token,
                              bitset actions,
                              InadequacyListNodeCount *node_count)
{
  InadequacyList *result = xmalloc (sizeof *result);
  result->id = *node_count;
  IGNORE_TYPE_LIMITS_BEGIN
  if (INT_ADD_WRAPV (*node_count, 1, node_count))
    aver (false);
  IGNORE_TYPE_LIMITS_END
  result->next = NULL;
  result->manifestingState = manifesting_state;
  result->contributionCount = bitset_count (actions);
  result->inadequacy.conflict.token = token;
  result->inadequacy.conflict.actions = actions;
  return result;
}

void
InadequacyList__delete (InadequacyList *self)
{
  while (self)
    {
      InadequacyList *node = self;
      self = self->next;
      bitset_free (node->inadequacy.conflict.actions);
      free (node);
    }
}

ContributionIndex
InadequacyList__getShiftContributionIndex (InadequacyList const *self)
{
  if (!bitset_test (self->inadequacy.conflict.actions,
                    self->manifestingState->reductions->num))
    return ContributionIndex__none;
  return self->contributionCount - 1;
}

symbol *
InadequacyList__getContributionToken (InadequacyList const *self,
                                      ContributionIndex i)
{
  aver (0 <= i && i < self->contributionCount); (void) i;
  return self->inadequacy.conflict.token;
}

void
InadequacyList__prependTo (InadequacyList *self, InadequacyList **list)
{
  InadequacyList *head_old = *list;
  *list = self;
  self->next = head_old;
}