• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Tehreer / SheenBidi / 15192346582

22 May 2025 04:13PM UTC coverage: 79.545% (+1.0%) from 78.546%
15192346582

push

github

mta452
[make] Set C++ standard version to 14

1400 of 1760 relevant lines covered (79.55%)

868008.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.56
/Source/BracketQueue.c
1
/*
2
 * Copyright (C) 2014-2025 Muhammad Tayyab Akram
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
#include <SBConfig.h>
18
#include <stddef.h>
19

20
#include "BidiChain.h"
21
#include "Object.h"
22
#include "SBAssert.h"
23
#include "SBBase.h"
24
#include "SBCodepoint.h"
25
#include "BracketQueue.h"
26

27
static SBBoolean BracketQueueInsertElement(BracketQueueRef queue)
329,475✔
28
{
29
    if (queue->_rearTop != BracketQueueList_MaxIndex) {
329,475✔
30
        queue->_rearTop += 1;
329,454✔
31
    } else {
32
        BracketQueueListRef previousList = queue->_rearList;
21✔
33
        BracketQueueListRef rearList = previousList->next;
21✔
34

35
        if (!rearList) {
21✔
36
            rearList = ObjectAddMemory(&queue->_object, sizeof(BracketQueueList));
21✔
37
            if (!rearList) {
21✔
38
                return SBFalse;
×
39
            }
40

41
            rearList->previous = previousList;
21✔
42
            rearList->next = NULL;
21✔
43

44
            previousList->next = rearList;
21✔
45
        }
46

47
        queue->_rearList = rearList;
21✔
48
        queue->_rearTop = 0;
21✔
49
    }
50
    queue->count += 1;
329,475✔
51

52
    return SBTrue;
329,475✔
53
}
54

55
static void BracketQueueFinalizePairs(BracketQueueRef queue, BracketQueueListRef list, SBInteger top)
139,723✔
56
{
57
    do {
58
        SBInteger limit = (list == queue->_rearList ? queue->_rearTop : BracketQueueList_MaxIndex);
140,171✔
59

60
        while (++top <= limit) {
188,195✔
61
            if (list->openingLink[top] != BidiLinkNone
48,024✔
62
                && list->closingLink[top] == BidiLinkNone) {
48,016✔
63
                list->openingLink[top] = BidiLinkNone;
20,528✔
64
            }
65
        }
66

67
        list = list->next;
140,171✔
68
        top = 0;
140,171✔
69
    } while (list);
140,171✔
70
}
139,723✔
71

72
SB_INTERNAL void BracketQueueInitialize(BracketQueueRef queue)
861,949✔
73
{
74
    ObjectInitialize(&queue->_object);
861,949✔
75

76
    queue->_firstList.previous = NULL;
861,949✔
77
    queue->_firstList.next = NULL;
861,949✔
78
    queue->_frontList = NULL;
861,949✔
79
    queue->_rearList = NULL;
861,949✔
80
    queue->count = 0;
861,949✔
81
    queue->shouldDequeue = SBFalse;
861,949✔
82
}
861,949✔
83

84
SB_INTERNAL void BracketQueueReset(BracketQueueRef queue, SBBidiType direction)
1,257,049✔
85
{
86
    queue->_frontList = &queue->_firstList;
1,257,049✔
87
    queue->_rearList = &queue->_firstList;
1,257,049✔
88
    queue->_frontTop = 0;
1,257,049✔
89
    queue->_rearTop = -1;
1,257,049✔
90
    queue->count = 0;
1,257,049✔
91
    queue->shouldDequeue = SBFalse;
1,257,049✔
92
    queue->_direction = direction;
1,257,049✔
93
}
1,257,049✔
94

95
SB_INTERNAL SBBoolean BracketQueueEnqueue(BracketQueueRef queue,
329,475✔
96
   BidiLink priorStrongLink, BidiLink openingLink, SBCodepoint bracket)
97
{
98
    /* The queue can only take a maximum of 63 elements. */
99
    SBAssert(queue->count < BracketQueueGetMaxCapacity());
329,475✔
100

101
    if (BracketQueueInsertElement(queue)) {
329,475✔
102
        BracketQueueListRef list = queue->_rearList;
329,475✔
103
        SBInteger top = queue->_rearTop;
329,475✔
104

105
        list->priorStrongLink[top] = priorStrongLink;
329,475✔
106
        list->openingLink[top] = openingLink;
329,475✔
107
        list->closingLink[top] = BidiLinkNone;
329,475✔
108
        list->bracket[top] = bracket;
329,475✔
109
        list->strongType[top] = SBBidiTypeNil;
329,475✔
110

111
        return SBTrue;
329,475✔
112
    }
113

114
    return SBFalse;
×
115
}
116

117
SB_INTERNAL void BracketQueueDequeue(BracketQueueRef queue)
329,475✔
118
{
119
    /* The queue must NOT be empty. */
120
    SBAssert(queue->count != 0);
329,475✔
121

122
    if (queue->_frontTop != BracketQueueList_MaxIndex) {
329,475✔
123
        queue->_frontTop += 1;
329,454✔
124
    } else {
125
        BracketQueueListRef frontList = queue->_frontList;
21✔
126

127
        if (frontList == queue->_rearList) {
21✔
128
            queue->_rearTop = -1;
×
129
        } else {
130
            queue->_frontList = frontList->next;
21✔
131
        }
132

133
        queue->_frontTop = 0;
21✔
134
    }
135

136
    queue->count -= 1;
329,475✔
137
}
329,475✔
138

139
SB_INTERNAL void BracketQueueSetStrongType(BracketQueueRef queue, SBBidiType strongType)
186,688✔
140
{
141
    BracketQueueListRef list = queue->_rearList;
186,688✔
142
    SBInteger top = queue->_rearTop;
186,688✔
143

144
    while (1) {
14✔
145
        SBInteger limit = (list == queue->_frontList ? queue->_frontTop : 0);
186,702✔
146

147
        do {
148
            if (list->closingLink[top] == BidiLinkNone
315,203✔
149
                && list->strongType[top] != queue->_direction) {
265,403✔
150
                list->strongType[top] = strongType;
206,184✔
151
            }
152
        } while (top-- > limit);
315,203✔
153

154
        if (list == queue->_frontList) {
186,702✔
155
            break;
186,688✔
156
        }
157

158
        list = list->previous;
14✔
159
        top = BracketQueueList_MaxIndex;
14✔
160
    }
161
}
186,688✔
162

163
SB_INTERNAL void BracketQueueClosePair(BracketQueueRef queue, BidiLink closingLink, SBCodepoint bracket)
154,290✔
164
{
165
    BracketQueueListRef list = queue->_rearList;
154,290✔
166
    SBInteger top = queue->_rearTop;
154,290✔
167
    SBCodepoint canonical;
168

169
    switch (bracket) {
154,290✔
170
    case 0x232A:
4✔
171
        canonical = 0x3009;
4✔
172
        break;
4✔
173

174
    case 0x3009:
4✔
175
        canonical = 0x232A;
4✔
176
        break;
4✔
177

178
    default:
154,282✔
179
        canonical = bracket;
154,282✔
180
        break;
154,282✔
181
    }
182

183
    while (1) {
448✔
184
        SBBoolean isFrontList = (list == queue->_frontList);
154,738✔
185
        SBInteger limit = (isFrontList ? queue->_frontTop : 0);
154,738✔
186

187
        do {
188
            if (list->openingLink[top] != BidiLinkNone
227,002✔
189
                && list->closingLink[top] == BidiLinkNone
214,876✔
190
                && (list->bracket[top] == bracket || list->bracket[top] == canonical)) {
174,818✔
191
                list->closingLink[top] = closingLink;
139,723✔
192
                BracketQueueFinalizePairs(queue, list, top);
139,723✔
193

194
                if (isFrontList && top == queue->_frontTop) {
139,723✔
195
                    queue->shouldDequeue = SBTrue;
62,172✔
196
                }
197

198
                return;
139,723✔
199
            }
200
        } while (top-- > limit);
87,279✔
201

202
        if (isFrontList) {
15,015✔
203
            break;
14,567✔
204
        }
205

206
        list = list->previous;
448✔
207
        top = BracketQueueList_MaxIndex;
448✔
208
    }
209
}
210

211
SB_INTERNAL SBBoolean BracketQueueShouldDequeue(BracketQueueRef queue)
154,290✔
212
{
213
    return queue->shouldDequeue;
154,290✔
214
}
215

216
SB_INTERNAL BidiLink BracketQueueGetPriorStrongLink(BracketQueueRef queue)
28,864✔
217
{
218
    return queue->_frontList->priorStrongLink[queue->_frontTop];
28,864✔
219
}
220

221
SB_INTERNAL BidiLink BracketQueueGetOpeningLink(BracketQueueRef queue)
329,475✔
222
{
223
    return queue->_frontList->openingLink[queue->_frontTop];
329,475✔
224
}
225

226
SB_INTERNAL BidiLink BracketQueueGetClosingLink(BracketQueueRef queue)
329,475✔
227
{
228
    return queue->_frontList->closingLink[queue->_frontTop];
329,475✔
229
}
230

231
SB_INTERNAL SBBidiType BracketQueueGetStrongType(BracketQueueRef queue)
139,723✔
232
{
233
    return queue->_frontList->strongType[queue->_frontTop];
139,723✔
234
}
235

236
SB_INTERNAL void BracketQueueFinalize(BracketQueueRef queue)
861,949✔
237
{
238
    ObjectFinalize(&queue->_object);
861,949✔
239
}
861,949✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc