src/parser_graphqlperl_runtime.h

filter: Statementstmt 93.6% 995 / 1062 Branchbran 80.8% 469 / 580 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 89.1% 1464 / 1642 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« src/schema_compiler.h ↑ Summary blib/lib/GraphQL/Houtou/Role/Composite.pm »
1 /*
2 * Responsibility: graphql-perl mainline recursive-descent parser entrypoints
3 * and legacy AST builders used by the active parser surface.
4 */
5  
6 static void
7 2254124 gql_skip_ignored(gql_parser_t *p) {
8 4494608 ▶ while (p->pos < p->len) {
Branch: 1 branch
BranchTrueFalseTotal
while (p->pos < p->len) { 4493554 1054 4494608
9 4493554 unsigned char c = (unsigned char)p->src[p->pos];
10 4493554 ▶ if (c == 0xEF && p->pos + 2 < p->len &&
Branch: 2 branches
BranchTrueFalseTotal
if (c == 0xEF && p->pos + 2 < p->len && 1 4493553 4493554
if (c == 0xEF && p->pos + 2 < p->len && 1 0 1
11 1 ▶ (unsigned char)p->src[p->pos + 1] == 0xBB &&
Branch: 1 branch
BranchTrueFalseTotal
(unsigned char)p->src[p->pos + 1] == 0xBB && 1 0 1
12 1 ▶ (unsigned char)p->src[p->pos + 2] == 0xBF) {
Branch: 1 branch
BranchTrueFalseTotal
(unsigned char)p->src[p->pos + 2] == 0xBF) { 1 0 1
13 1 p->pos += 3;
14 1 continue;
15 }
16 4493553 ▶ if (c == ',' || c == ' ' || c == '\t' || c == '\n' || c == '\r') {
Branch: 5 branches
BranchTrueFalseTotal
if (c == ',' || c == ' ' || c == '\t' || c == '\n' || c == '\r') { 4488334 5219 4493553
if (c == ',' || c == ' ' || c == '\t' || c == '\n' || c == '\r') { 2255890 2232444 4488334
if (c == ',' || c == ' ' || c == '\t' || c == '\n' || c == '\r') { 2255889 1 2255890
if (c == ',' || c == ' ' || c == '\t' || c == '\n' || c == '\r') { 2253084 2805 2255889
if (c == ',' || c == ' ' || c == '\t' || c == '\n' || c == '\r') { 0 2253084 2253084
17 2240469 p->pos++;
18 2240469 continue;
19 }
20 2253084 ▶ if (c == '#') {
Branch: 1 branch
BranchTrueFalseTotal
if (c == '#') { 14 2253070 2253084
21 400584 ▶ while (p->pos < p->len) {
Branch: 1 branch
BranchTrueFalseTotal
while (p->pos < p->len) { 400584 0 400584
22 400584 c = (unsigned char)p->src[p->pos];
23 400584 p->pos++;
24 400584 ▶ if (c == '\n' || c == '\r') {
Branch: 2 branches
BranchTrueFalseTotal
if (c == '\n' || c == '\r') { 400570 14 400584
if (c == '\n' || c == '\r') { 400570 0 400570
25 break;
26 }
27 }
28 14 continue;
29 }
30 2253070 break;
31 }
32 2254124 }
33  
34 static void
35 2254124 gql_lex_token(pTHX_ gql_parser_t *p) {
36 STRLEN start;
37 unsigned char c;
38 2254124 start = p->pos;
39 2254124 p->tok_start = start;
40 2254124 p->tok_end = start;
41 2254124 p->val_start = start;
42 2254124 p->val_end = start;
43 2254124 ▶ if (start >= p->len) {
Branch: 1 branch
BranchTrueFalseTotal
if (start >= p->len) { 1054 2253070 2254124
44 1054 p->kind = TOK_EOF;
45 1054 return;
46 }
47 /* Bound total tokens (S2): a real token follows, so count it before
48 * lexing. EOF above is not counted. */
49 2253070 ▶ if (++p->token_count > GQL_PARSER_MAX_TOKENS) {
Branch: 1 branch
BranchTrueFalseTotal
if (++p->token_count > GQL_PARSER_MAX_TOKENS) { 1 2253069 2253070
50 1 gql_throw_simple_error(aTHX_ "Document has too many tokens (exceeds maximum token count)");
51 }
52 2253069 c = (unsigned char)p->src[p->pos];
53 2253069 switch (c) {
54 340 case '!':
55 340 p->kind = TOK_BANG;
56 340 p->pos++;
57 340 p->tok_end = p->pos;
58 340 return;
59 642 case '$':
60 642 p->kind = TOK_DOLLAR;
61 642 p->pos++;
62 642 p->tok_end = p->pos;
63 642 return;
64 2 case '&':
65 2 p->kind = TOK_AMP;
66 2 p->pos++;
67 2 p->tok_end = p->pos;
68 2 return;
69 1132 case '(':
70 1132 p->kind = TOK_LPAREN;
71 1132 p->pos++;
72 1132 p->tok_end = p->pos;
73 1132 return;
74 1120 case ')':
75 1120 p->kind = TOK_RPAREN;
76 1120 p->pos++;
77 1120 p->tok_end = p->pos;
78 1120 return;
79 4992 case ':':
80 4992 p->kind = TOK_COLON;
81 4992 p->pos++;
82 4992 p->tok_end = p->pos;
83 4992 return;
84 63 case '=':
85 63 p->kind = TOK_EQUALS;
86 63 p->pos++;
87 63 p->tok_end = p->pos;
88 63 return;
89 304 case '@':
90 304 p->kind = TOK_AT;
91 304 p->pos++;
92 304 p->tok_end = p->pos;
93 304 return;
94 2242 case '[':
95 2242 p->kind = TOK_LBRACKET;
96 2242 p->pos++;
97 2242 p->tok_end = p->pos;
98 2242 return;
99 706 case ']':
100 706 p->kind = TOK_RBRACKET;
101 706 p->pos++;
102 706 p->tok_end = p->pos;
103 706 return;
104 6368 case '{':
105 6368 p->kind = TOK_LBRACE;
106 6368 p->pos++;
107 6368 p->tok_end = p->pos;
108 6368 return;
109 4812 case '}':
110 4812 p->kind = TOK_RBRACE;
111 4812 p->pos++;
112 4812 p->tok_end = p->pos;
113 4812 return;
114 266 case '|':
115 266 p->kind = TOK_PIPE;
116 266 p->pos++;
117 266 p->tok_end = p->pos;
118 266 return;
119 188 case '.':
120 188 ▶ if (p->pos + 2 < p->len && p->src[p->pos + 1] == '.' && p->src[p->pos + 2] == '.') {
Branch: 3 branches
BranchTrueFalseTotal
if (p->pos + 2 < p->len && p->src[p->pos + 1] == '.' && p->src[p->pos + 2] == '.') { 188 0 188
if (p->pos + 2 < p->len && p->src[p->pos + 1] == '.' && p->src[p->pos + 2] == '.') { 188 0 188
if (p->pos + 2 < p->len && p->src[p->pos + 1] == '.' && p->src[p->pos + 2] == '.') { 188 0 188
121 188 p->kind = TOK_SPREAD;
122 188 p->pos += 3;
123 188 p->tok_end = p->pos;
124 188 return;
125 }
126 0 gql_throw(aTHX_ p, p->pos, "Expected \"...\"");
127 0 break;
128 611 case '"':
129 611 ▶ if (p->pos + 2 < p->len && p->src[p->pos + 1] == '"' && p->src[p->pos + 2] == '"') {
Branch: 3 branches
BranchTrueFalseTotal
if (p->pos + 2 < p->len && p->src[p->pos + 1] == '"' && p->src[p->pos + 2] == '"') { 611 0 611
if (p->pos + 2 < p->len && p->src[p->pos + 1] == '"' && p->src[p->pos + 2] == '"') { 291 320 611
if (p->pos + 2 < p->len && p->src[p->pos + 1] == '"' && p->src[p->pos + 2] == '"') { 290 1 291
130 290 STRLEN scan = p->pos + 3;
131 290 p->val_start = scan;
132 26119 ▶ while (scan < p->len) {
Branch: 1 branch
BranchTrueFalseTotal
while (scan < p->len) { 26118 1 26119
133 26118 ▶ if (scan + 2 < p->len && p->src[scan] == '"' && p->src[scan + 1] == '"' && p->src[scan + 2] == '"') {
Branch: 4 branches
BranchTrueFalseTotal
if (scan + 2 < p->len && p->src[scan] == '"' && p->src[scan + 1] == '"' && p->src[scan + 2] == '"') { 26116 2 26118
if (scan + 2 < p->len && p->src[scan] == '"' && p->src[scan + 1] == '"' && p->src[scan + 2] == '"') { 603 25513 26116
if (scan + 2 < p->len && p->src[scan] == '"' && p->src[scan + 1] == '"' && p->src[scan + 2] == '"') { 289 314 603
if (scan + 2 < p->len && p->src[scan] == '"' && p->src[scan + 1] == '"' && p->src[scan + 2] == '"') { 289 0 289
134 289 p->kind = TOK_BLOCK_STRING;
135 289 p->val_end = scan;
136 289 p->pos = scan + 3;
137 289 p->tok_end = p->pos;
138 289 return;
139 }
140 25829 ▶ if ((unsigned char)p->src[scan] < 0x20 &&
Branch: 1 branch
BranchTrueFalseTotal
if ((unsigned char)p->src[scan] < 0x20 && 355 25474 25829
141 355 ▶ p->src[scan] != '\t' && p->src[scan] != '\n' && p->src[scan] != '\r') {
Branch: 3 branches
BranchTrueFalseTotal
p->src[scan] != '\t' && p->src[scan] != '\n' && p->src[scan] != '\r') { 355 0 355
p->src[scan] != '\t' && p->src[scan] != '\n' && p->src[scan] != '\r') { 3 352 355
p->src[scan] != '\t' && p->src[scan] != '\n' && p->src[scan] != '\r') { 0 3 3
142 0 gql_throw(aTHX_ p, scan, "Invalid character within block string");
143 }
144 25829 ▶ if (scan + 3 < p->len &&
Branch: 1 branch
BranchTrueFalseTotal
if (scan + 3 < p->len && 25826 3 25829
145 25826 ▶ p->src[scan] == '\\' &&
Branch: 1 branch
BranchTrueFalseTotal
p->src[scan] == '\\' && 2 25824 25826
146 2 ▶ p->src[scan + 1] == '"' &&
Branch: 1 branch
BranchTrueFalseTotal
p->src[scan + 1] == '"' && 2 0 2
147 2 ▶ p->src[scan + 2] == '"' &&
Branch: 1 branch
BranchTrueFalseTotal
p->src[scan + 2] == '"' && 2 0 2
148 2 ▶ p->src[scan + 3] == '"') {
Branch: 1 branch
BranchTrueFalseTotal
p->src[scan + 3] == '"') { 2 0 2
149 2 scan += 4;
150 2 continue;
151 }
152 25827 scan++;
153 }
154 1 gql_throw(aTHX_ p, p->tok_start, "Unterminated block string");
155 } else {
156 321 STRLEN scan = p->pos + 1;
157 321 p->val_start = scan;
158 2264 ▶ while (scan < p->len) {
Branch: 1 branch
BranchTrueFalseTotal
while (scan < p->len) { 2263 1 2264
159 2263 unsigned char sc = (unsigned char)p->src[scan];
160 2263 ▶ if (p->src[scan] == '"') {
Branch: 1 branch
BranchTrueFalseTotal
if (p->src[scan] == '"') { 318 1945 2263
161 318 p->kind = TOK_STRING;
162 318 p->val_end = scan;
163 318 p->pos = scan + 1;
164 318 p->tok_end = p->pos;
165 318 return;
166 }
167 1945 ▶ if (p->src[scan] == '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if (p->src[scan] == '\\') { 9 1936 1945
168 9 scan++;
169 9 ▶ if (scan >= p->len) {
Branch: 1 branch
BranchTrueFalseTotal
if (scan >= p->len) { 0 9 9
170 0 gql_throw(aTHX_ p, p->tok_start, "Unterminated string");
171 }
172 9 ▶ if (strchr("\"\\/bfnrt", p->src[scan])) {
Branch: 1 branch
BranchTrueFalseTotal
if (strchr("\"\\/bfnrt", p->src[scan])) { 0 9 9
173 0 scan++;
174 0 continue;
175 }
176 9 ▶ if (p->src[scan] == 'u') {
Branch: 1 branch
BranchTrueFalseTotal
if (p->src[scan] == 'u') { 9 0 9
177 int i;
178 39 ▶ for (i = 0; i < 4; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < 4; i++) { 32 7 39
179 32 scan++;
180 32 ▶ if (scan >= p->len || !isXDIGIT((unsigned char)p->src[scan])) {
Branch: 2 branches
BranchTrueFalseTotal
if (scan >= p->len || !isXDIGIT((unsigned char)p->src[scan])) { 32 0 32
if (scan >= p->len || !isXDIGIT((unsigned char)p->src[scan])) { 2 30 32
181 2 gql_throw(aTHX_ p, p->tok_start, "Invalid Unicode escape sequence");
182 }
183 }
184 7 scan++;
185 7 continue;
186 }
187 0 gql_throw(aTHX_ p, p->tok_start, "Invalid character escape sequence");
188 }
189 1936 ▶ if (sc == '\n' || sc == '\r') {
Branch: 2 branches
BranchTrueFalseTotal
if (sc == '\n' || sc == '\r') { 1936 0 1936
if (sc == '\n' || sc == '\r') { 0 1936 1936
190 0 gql_throw(aTHX_ p, p->tok_start, "Unterminated string");
191 }
192 1936 ▶ if (sc == 0x00 || sc < 0x20) {
Branch: 2 branches
BranchTrueFalseTotal
if (sc == 0x00 || sc < 0x20) { 1936 0 1936
if (sc == 0x00 || sc < 0x20) { 0 1936 1936
193 0 gql_throw(aTHX_ p, p->tok_start, "Invalid character within string");
194 }
195 1936 scan++;
196 }
197 1 gql_throw(aTHX_ p, p->tok_start, "Unterminated string");
198 }
199 0 break;
200 2229281 default:
201 2229281 break;
202 }
203  
204 2229281 ▶ if (c == '-' || isDIGIT(c)) {
Branch: 2 branches
BranchTrueFalseTotal
if (c == '-' || isDIGIT(c)) { 2229280 1 2229281
if (c == '-' || isDIGIT(c)) { 5082 2224198 2229280
205 5083 STRLEN scan = p->pos;
206 5083 bool is_float = 0;
207 5083 ▶ if (p->src[scan] == '-') {
Branch: 1 branch
BranchTrueFalseTotal
if (p->src[scan] == '-') { 1 5082 5083
208 1 scan++;
209 1 ▶ if (scan >= p->len || !isDIGIT((unsigned char)p->src[scan])) {
Branch: 2 branches
BranchTrueFalseTotal
if (scan >= p->len || !isDIGIT((unsigned char)p->src[scan])) { 1 0 1
if (scan >= p->len || !isDIGIT((unsigned char)p->src[scan])) { 1 0 1
210 1 gql_throw(aTHX_ p, p->tok_start, "Invalid number, expected digit after \"-\"");
211 }
212 }
213 5082 ▶ if (p->src[scan] == '0') {
Branch: 1 branch
BranchTrueFalseTotal
if (p->src[scan] == '0') { 0 5082 5082
214 0 scan++;
215 0 ▶ if (scan < p->len && isDIGIT((unsigned char)p->src[scan])) {
Branch: 2 branches
BranchTrueFalseTotal
if (scan < p->len && isDIGIT((unsigned char)p->src[scan])) { 0 0 0
if (scan < p->len && isDIGIT((unsigned char)p->src[scan])) { 0 0 0
216 0 gql_throw(aTHX_ p, scan, "Invalid number, unexpected digit after 0");
217 }
218 } else {
219 15171 ▶ while (scan < p->len && isDIGIT((unsigned char)p->src[scan])) {
Branch: 2 branches
BranchTrueFalseTotal
while (scan < p->len && isDIGIT((unsigned char)p->src[scan])) { 15171 0 15171
while (scan < p->len && isDIGIT((unsigned char)p->src[scan])) { 10089 5082 15171
220 10089 scan++;
221 }
222 }
223 5082 ▶ if (scan < p->len && p->src[scan] == '.') {
Branch: 2 branches
BranchTrueFalseTotal
if (scan < p->len && p->src[scan] == '.') { 5082 0 5082
if (scan < p->len && p->src[scan] == '.') { 2 5080 5082
224 2 is_float = 1;
225 2 scan++;
226 2 ▶ if (scan >= p->len || !isDIGIT((unsigned char)p->src[scan])) {
Branch: 2 branches
BranchTrueFalseTotal
if (scan >= p->len || !isDIGIT((unsigned char)p->src[scan])) { 2 0 2
if (scan >= p->len || !isDIGIT((unsigned char)p->src[scan])) { 0 2 2
227 0 gql_throw(aTHX_ p, scan - 1, "Invalid number, expected digit after decimal point");
228 }
229 5 ▶ while (scan < p->len && isDIGIT((unsigned char)p->src[scan])) {
Branch: 2 branches
BranchTrueFalseTotal
while (scan < p->len && isDIGIT((unsigned char)p->src[scan])) { 5 0 5
while (scan < p->len && isDIGIT((unsigned char)p->src[scan])) { 3 2 5
230 3 scan++;
231 }
232 }
233 5082 ▶ if (scan < p->len && (p->src[scan] == 'e' || p->src[scan] == 'E')) {
Branch: 3 branches
BranchTrueFalseTotal
if (scan < p->len && (p->src[scan] == 'e' || p->src[scan] == 'E')) { 5082 0 5082
if (scan < p->len && (p->src[scan] == 'e' || p->src[scan] == 'E')) { 5080 2 5082
if (scan < p->len && (p->src[scan] == 'e' || p->src[scan] == 'E')) { 0 5080 5080
234 2 STRLEN exp_pos = scan;
235 2 bool had_sign = 0;
236 2 is_float = 1;
237 2 scan++;
238 2 ▶ if (scan < p->len && (p->src[scan] == '+' || p->src[scan] == '-')) {
Branch: 3 branches
BranchTrueFalseTotal
if (scan < p->len && (p->src[scan] == '+' || p->src[scan] == '-')) { 2 0 2
if (scan < p->len && (p->src[scan] == '+' || p->src[scan] == '-')) { 2 0 2
if (scan < p->len && (p->src[scan] == '+' || p->src[scan] == '-')) { 0 2 2
239 0 had_sign = 1;
240 0 scan++;
241 }
242 2 ▶ if (scan >= p->len || !isDIGIT((unsigned char)p->src[scan])) {
Branch: 2 branches
BranchTrueFalseTotal
if (scan >= p->len || !isDIGIT((unsigned char)p->src[scan])) { 2 0 2
if (scan >= p->len || !isDIGIT((unsigned char)p->src[scan])) { 0 2 2
243 0 STRLEN err_pos = exp_pos + 1;
244 0 ▶ if (!had_sign && scan < p->len &&
Branch: 2 branches
BranchTrueFalseTotal
if (!had_sign && scan < p->len && 0 0 0
if (!had_sign && scan < p->len && 0 0 0
245 0 ▶ ((p->src[scan] >= 'A' && p->src[scan] <= 'Z') ||
Branch: 2 branches
BranchTrueFalseTotal
((p->src[scan] >= 'A' && p->src[scan] <= 'Z') || 0 0 0
((p->src[scan] >= 'A' && p->src[scan] <= 'Z') || 0 0 0
246 0 ▶ (p->src[scan] >= 'a' && p->src[scan] <= 'z') ||
Branch: 2 branches
BranchTrueFalseTotal
(p->src[scan] >= 'a' && p->src[scan] <= 'z') || 0 0 0
(p->src[scan] >= 'a' && p->src[scan] <= 'z') || 0 0 0
247 0 ▶ p->src[scan] == '_')) {
Branch: 1 branch
BranchTrueFalseTotal
p->src[scan] == '_')) { 0 0 0
248 0 err_pos = exp_pos + 2;
249 }
250 0 gql_throw(aTHX_ p, err_pos, "Invalid number, expected digit after exponent indicator");
251 }
252 5003 ▶ while (scan < p->len && isDIGIT((unsigned char)p->src[scan])) {
Branch: 2 branches
BranchTrueFalseTotal
while (scan < p->len && isDIGIT((unsigned char)p->src[scan])) { 5003 0 5003
while (scan < p->len && isDIGIT((unsigned char)p->src[scan])) { 5001 2 5003
253 5001 scan++;
254 }
255 }
256 5082 ▶ p->kind = is_float ? TOK_FLOAT : TOK_INT;
Branch: 1 branch
BranchTrueFalseTotal
p->kind = is_float ? TOK_FLOAT : TOK_INT; 2 5080 5082
257 5082 p->pos = scan;
258 5082 p->tok_end = p->pos;
259 5082 p->val_start = p->tok_start;
260 5082 p->val_end = p->tok_end;
261 5082 return;
262 }
263  
264 2224198 ▶ if (c == '_' || isALPHA(c)) {
Branch: 2 branches
BranchTrueFalseTotal
if (c == '_' || isALPHA(c)) { 2224012 186 2224198
if (c == '_' || isALPHA(c)) { 2224008 4 2224012
265 2224194 STRLEN scan = p->pos + 1;
266 2509571 ▶ while (scan < p->len) {
Branch: 1 branch
BranchTrueFalseTotal
while (scan < p->len) { 2509563 8 2509571
267 2509563 unsigned char nc = (unsigned char)p->src[scan];
268 2509563 ▶ if (!(nc == '_' || isALNUM(nc))) {
Branch: 2 branches
BranchTrueFalseTotal
if (!(nc == '_' || isALNUM(nc))) { 2509064 499 2509563
if (!(nc == '_' || isALNUM(nc))) { 2224186 284878 2509064
269 2224186 break;
270 }
271 285377 scan++;
272 }
273 2224194 p->kind = TOK_NAME;
274 2224194 p->pos = scan;
275 2224194 p->tok_end = p->pos;
276 2224194 p->val_start = p->tok_start;
277 2224194 p->val_end = p->tok_end;
278 2224194 return;
279 }
280  
281 4 gql_throw_unexpected_character(aTHX_ p, p->pos, c);
282 }
283  
284 static void
285 2254124 gql_advance(pTHX_ gql_parser_t *p) {
286 2254124 ▶ if (p->tok_end > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->tok_end > 0) { 2253044 1080 2254124
287 2253044 p->last_pos = p->tok_end - 1;
288 }
289 2254124 gql_skip_ignored(p);
290 2254124 gql_lex_token(aTHX_ p);
291 2254114 }
292  
293 static int
294 6755 gql_peek_name(gql_parser_t *p, const char *name) {
295 6755 STRLEN len = strlen(name);
296 13308 return p->kind == TOK_NAME &&
297 8750 ▶ (p->tok_end - p->tok_start) == len &&
Branch: 2 branches
BranchTrueFalseTotal
(p->tok_end - p->tok_start) == len && 6553 202 6755
(p->tok_end - p->tok_start) == len && 1995 4558 6553
298 1995 ▶ memEQ(p->src + p->tok_start, name, len);
Branch: 1 branch
BranchTrueFalseTotal
memEQ(p->src + p->tok_start, name, len); 1632 363 1995
299 }
300  
301 static void
302 18518 gql_expect(pTHX_ gql_parser_t *p, gql_token_kind_t kind, const char *msg) {
303 18518 ▶ if (p->kind != kind) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind != kind) { 0 18518 18518
304 0 ▶ if (msg) {
Branch: 1 branch
BranchTrueFalseTotal
if (msg) { 0 0 0
305 0 gql_throw_expected_message(aTHX_ p, p->tok_start, msg);
306 }
307 0 gql_throw_expected_token(aTHX_ p, kind);
308 }
309 18518 gql_advance(aTHX_ p);
310 18511 }
311  
312 static SV *
313 622840 gql_parse_name(pTHX_ gql_parser_t *p, const char *msg) {
314 SV *sv;
315 622840 ▶ if (p->kind != TOK_NAME) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind != TOK_NAME) { 9 622831 622840
316 9 gql_throw_expected_message(aTHX_ p, p->tok_start, msg);
317 }
318 622831 sv = gql_copy_token_sv(aTHX_ p);
319 622831 gql_advance(aTHX_ p);
320 622830 return sv;
321 }
322  
323 static SV *
324 170 gql_parse_fragment_name(pTHX_ gql_parser_t *p) {
325 170 ▶ if (gql_peek_name(p, "on")) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_peek_name(p, "on")) { 0 170 170
326 0 gql_throw(aTHX_ p, p->tok_end, "Unexpected Name \"on\"");
327 }
328 170 return gql_parse_name(aTHX_ p, "Expected name");
329 }
330  
331 static gql_ir_span_t
332 0 gql_ir_parse_name_span(pTHX_ gql_parser_t *p, const char *msg) {
333 gql_ir_span_t span;
334  
335 0 ▶ if (p->kind != TOK_NAME) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind != TOK_NAME) { 0 0 0
336 0 gql_throw_expected_message(aTHX_ p, p->tok_start, msg);
337 }
338 0 span.start = (UV)p->tok_start;
339 0 span.end = (UV)p->tok_end;
340 0 gql_advance(aTHX_ p);
341 0 return span;
342 }
343  
344 static gql_ir_span_t
345 0 gql_ir_parse_fragment_name_span(pTHX_ gql_parser_t *p) {
346 0 ▶ if (gql_peek_name(p, "on")) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_peek_name(p, "on")) { 0 0 0
347 0 gql_throw(aTHX_ p, p->tok_end, "Unexpected Name \"on\"");
348 }
349 0 return gql_ir_parse_name_span(aTHX_ p, "Expected name");
350 }
351  
352 static void
353 1080 gql_parser_init(pTHX_ gql_parser_t *p, SV *source_sv, int no_location) {
354 STRLEN len;
355 1080 const char *src = SvPV(source_sv, len);
356 STRLEN i;
357 1080 I32 line_cap = 16;
358 1080 I32 line_count = 1;
359  
360 1080 p->src = src;
361 1080 p->len = len;
362 1080 p->pos = 0;
363 1080 p->last_pos = (STRLEN)-1;
364 1080 p->tok_start = 0;
365 1080 p->tok_end = 0;
366 1080 p->val_start = 0;
367 1080 p->val_end = 0;
368 1080 p->kind = TOK_EOF;
369 1080 p->is_utf8 = SvUTF8(source_sv) ? 1 : 0;
370 1080 p->no_location = no_location ? 1 : 0;
371 1080 p->line_starts = NULL;
372 1080 p->num_lines = 0;
373 1080 p->ir_arena = NULL;
374 1080 p->depth = 0;
375 1080 p->token_count = 0;
376 1080 p->validation_errors = NULL;
377  
378 1080 ▶ if (p->no_location) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->no_location) { 3 1077 1080
379 3 return;
380 }
381  
382 1077 Newx(p->line_starts, line_cap, UV);
383 1077 p->line_starts[0] = 0;
384  
385 2432107 ▶ for (i = 0; i < len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < len; i++) { 2431030 1077 2432107
386 2431030 ▶ if (src[i] == '\n' || src[i] == '\r') {
Branch: 2 branches
BranchTrueFalseTotal
if (src[i] == '\n' || src[i] == '\r') { 2427862 3168 2431030
if (src[i] == '\n' || src[i] == '\r') { 3 2427859 2427862
387 3171 ▶ if (line_count == line_cap) {
Branch: 1 branch
BranchTrueFalseTotal
if (line_count == line_cap) { 50 3121 3171
388 50 line_cap *= 2;
389 50 Renew(p->line_starts, line_cap, UV);
390 }
391 3171 ▶ if (src[i] == '\r' && i + 1 < len && src[i + 1] == '\n') {
Branch: 3 branches
BranchTrueFalseTotal
if (src[i] == '\r' && i + 1 < len && src[i + 1] == '\n') { 3 3168 3171
if (src[i] == '\r' && i + 1 < len && src[i + 1] == '\n') { 3 0 3
if (src[i] == '\r' && i + 1 < len && src[i + 1] == '\n') { 3 0 3
392 3 i++;
393 }
394 3171 p->line_starts[line_count++] = (UV)(i + 1);
395 }
396 }
397  
398 1077 p->num_lines = line_count;
399 1077 SAVEFREEPV(p->line_starts);
400 }
401  
402 static void
403 1045 gql_parser_invalidate(gql_parser_t *p) {
404 /* line_starts is freed by SAVEFREEPV during FREETMPS/LEAVE.
405 * This helper only clears borrowed pointers from the stack-local parser.
406 */
407 1045 p->line_starts = NULL;
408 1045 p->num_lines = 0;
409 1045 }
410  
411 static void
412 615003 gql_line_column_from_pos(gql_parser_t *p, STRLEN pos, IV *line, IV *column, int one_based) {
413 I32 low;
414 I32 high;
415 I32 found;
416 UV line_start;
417 615003 ▶ if (pos == (STRLEN)-1) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos == (STRLEN)-1) { 0 615003 615003
418 0 *line = 1;
419 0 *column = 0;
420 0 return;
421 }
422 615003 ▶ if (!p->line_starts || p->num_lines <= 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (!p->line_starts || p->num_lines <= 0) { 615003 0 615003
if (!p->line_starts || p->num_lines <= 0) { 0 615003 615003
423 0 *line = 1;
424 0 ▶ *column = (IV)(pos + (one_based ? 1 : 0));
Branch: 1 branch
BranchTrueFalseTotal
*column = (IV)(pos + (one_based ? 1 : 0)); 0 0 0
425 0 return;
426 }
427 615003 low = 0;
428 615003 high = p->num_lines - 1;
429 615003 found = 0;
430 1235613 ▶ while (low <= high) {
Branch: 1 branch
BranchTrueFalseTotal
while (low <= high) { 620610 615003 1235613
431 620610 I32 mid = low + ((high - low) / 2);
432 620610 UV start = p->line_starts[mid];
433 620610 ▶ if (start <= (UV)pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (start <= (UV)pos) { 617606 3004 620610
434 617606 found = mid;
435 617606 low = mid + 1;
436 } else {
437 3004 high = mid - 1;
438 }
439 }
440 615003 line_start = p->line_starts[found];
441 615003 *line = found + 1;
442 615003 ▶ *column = (IV)(pos - line_start + (one_based ? 1 : 0));
Branch: 1 branch
BranchTrueFalseTotal
*column = (IV)(pos - line_start + (one_based ? 1 : 0)); 613687 1316 615003
443 }
444  
445 static void
446 1316 gql_line_column_from_last(gql_parser_t *p, IV *line, IV *column) {
447 1316 gql_line_column_from_pos(p, p->last_pos, line, column, 0);
448 1316 }
449  
450 static SV *
451 865 gql_make_location(pTHX_ gql_parser_t *p) {
452 865 HV *hv = newHV();
453 IV line;
454 IV column;
455 865 gql_line_column_from_last(p, &line, &column);
456 865 gql_store_sv(hv, "line", newSViv(line));
457 865 gql_store_sv(hv, "column", newSViv(column));
458 865 return newRV_noinc((SV *)hv);
459 }
460  
461 static SV *
462 614506 gql_make_current_location(pTHX_ gql_parser_t *p) {
463 HV *hv;
464 IV line;
465 IV column;
466 614506 ▶ if (p->kind == TOK_EOF && p->tok_start <= p->last_pos + 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (p->kind == TOK_EOF && p->tok_start <= p->last_pos + 1) { 984 613522 614506
if (p->kind == TOK_EOF && p->tok_start <= p->last_pos + 1) { 865 119 984
467 865 return gql_make_location(aTHX_ p);
468 }
469 613641 hv = newHV();
470 613641 gql_line_column_from_pos(p, p->tok_start, &line, &column, 1);
471 613641 gql_store_sv(hv, "line", newSViv(line));
472 613641 gql_store_sv(hv, "column", newSViv(column));
473 613641 return newRV_noinc((SV *)hv);
474 }
475  
476 static void
477 614472 gql_store_current_location(pTHX_ gql_parser_t *p, HV *hv) {
478 614472 ▶ if (p->no_location) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->no_location) { 3 614469 614472
479 3 return;
480 }
481 614469 gql_store_sv(hv, "location", gql_make_current_location(aTHX_ p));
482 }
483  
484 static SV *
485 405 gql_make_endline_location(pTHX_ gql_parser_t *p) {
486 405 HV *hv = newHV();
487 IV line;
488 IV column;
489 405 gql_line_column_from_last(p, &line, &column);
490 405 gql_store_sv(hv, "line", newSViv(line));
491 405 gql_store_sv(hv, "column", newSViv(0));
492 405 return newRV_noinc((SV *)hv);
493 }
494  
495 static void
496 393 gql_store_endline_location(pTHX_ gql_parser_t *p, HV *hv) {
497 393 ▶ if (p->no_location) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->no_location) { 0 393 393
498 0 return;
499 }
500 393 gql_store_sv(hv, "location", gql_make_endline_location(aTHX_ p));
501 }
502  
503 static SV *
504 46 gql_make_current_or_endline_location(pTHX_ gql_parser_t *p) {
505 IV current_line;
506 IV current_column;
507 IV last_line;
508 IV last_column;
509 46 ▶ if (p->kind == TOK_EOF) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_EOF) { 0 46 46
510 0 return gql_make_current_location(aTHX_ p);
511 }
512 46 gql_line_column_from_pos(p, p->tok_start, &current_line, &current_column, 1);
513 46 gql_line_column_from_last(p, &last_line, &last_column);
514 46 ▶ if (current_line == last_line) {
Branch: 1 branch
BranchTrueFalseTotal
if (current_line == last_line) { 34 12 46
515 34 return gql_make_current_location(aTHX_ p);
516 }
517 12 return gql_make_endline_location(aTHX_ p);
518 }
519  
520 static void
521 46 gql_store_current_or_endline_location(pTHX_ gql_parser_t *p, HV *hv) {
522 46 ▶ if (p->no_location) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->no_location) { 0 46 46
523 0 return;
524 }
525 46 gql_store_sv(hv, "location", gql_make_current_or_endline_location(aTHX_ p));
526 }
527  
528 static SV *
529 504 gql_make_type_wrapper(pTHX_ SV *type_sv, const char *kind) {
530 504 AV *av = newAV();
531 504 HV *inner = newHV();
532 504 av_push(av, newSVpv(kind, 0));
533 504 gql_store_sv(inner, "type", type_sv);
534 504 av_push(av, newRV_noinc((SV *)inner));
535 504 return newRV_noinc((SV *)av);
536 }
537  
538 static SV *
539 2078 gql_parse_list_value(pTHX_ gql_parser_t *p, int is_const) {
540 AV *av;
541 /* Input-value nesting recurses only through list/object values; guard
542 * here so a deep [[[... cannot overflow the C stack (S1). */
543 2078 ▶ if (++p->depth > GQL_PARSER_MAX_DEPTH) {
Branch: 1 branch
BranchTrueFalseTotal
if (++p->depth > GQL_PARSER_MAX_DEPTH) { 3 2075 2078
544 3 gql_throw(aTHX_ p, p->tok_start,
545 "Value is too deeply nested (exceeds maximum nesting depth)");
546 }
547 2075 av = newAV();
548 2075 gql_expect(aTHX_ p, TOK_LBRACKET, NULL);
549 7624 ▶ while (p->kind != TOK_RBRACKET) {
Branch: 1 branch
BranchTrueFalseTotal
while (p->kind != TOK_RBRACKET) { 7082 542 7624
550 7082 av_push(av, gql_parse_value(aTHX_ p, is_const));
551 }
552 542 gql_expect(aTHX_ p, TOK_RBRACKET, NULL);
553 542 p->depth--;
554 542 return newRV_noinc((SV *)av);
555 }
556  
557 static SV *
558 86 gql_parse_object_value(pTHX_ gql_parser_t *p, int is_const) {
559 HV *hv;
560 86 ▶ if (++p->depth > GQL_PARSER_MAX_DEPTH) {
Branch: 1 branch
BranchTrueFalseTotal
if (++p->depth > GQL_PARSER_MAX_DEPTH) { 0 86 86
561 0 gql_throw(aTHX_ p, p->tok_start,
562 "Value is too deeply nested (exceeds maximum nesting depth)");
563 }
564 86 hv = newHV();
565 86 gql_expect(aTHX_ p, TOK_LBRACE, "Expected name");
566 176 ▶ while (p->kind != TOK_RBRACE) {
Branch: 1 branch
BranchTrueFalseTotal
while (p->kind != TOK_RBRACE) { 90 86 176
567 90 SV *name = gql_parse_name(aTHX_ p, "Expected name");
568 90 gql_expect(aTHX_ p, TOK_COLON, NULL);
569 90 ▶ if (p->validation_errors) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->validation_errors) { 6 84 90
570 STRLEN name_len;
571 6 const char *name_str = SvPV(name, name_len);
572 6 ▶ if (hv_exists(hv, name_str, (I32)name_len)) {
Branch: 1 branch
BranchTrueFalseTotal
if (hv_exists(hv, name_str, (I32)name_len)) { 1 5 6
573 1 HV *error_hv = newHV();
574 1 AV *locations_av = newAV();
575 1 SV *message = newSVpvf("Input field '%s' is provided more than once.", name_str);
576 1 gql_store_sv(error_hv, "message", message);
577 1 av_push(locations_av, gql_make_current_location(aTHX_ p));
578 1 gql_store_sv(error_hv, "locations", newRV_noinc((SV *)locations_av));
579 1 av_push(p->validation_errors, newRV_noinc((SV *)error_hv));
580 }
581 }
582 180 gql_store_sv(hv, SvPV_nolen(name), gql_parse_value(aTHX_ p, is_const));
583 90 SvREFCNT_dec(name);
584 }
585 86 gql_expect(aTHX_ p, TOK_RBRACE, NULL);
586 86 p->depth--;
587 86 return newRV_noinc((SV *)hv);
588 }
589  
590 static SV *
591 7970 gql_parse_value(pTHX_ gql_parser_t *p, int is_const) {
592 7970 switch (p->kind) {
593 325 case TOK_DOLLAR: {
594 SV *name;
595 325 ▶ if (is_const) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_const) { 1 324 325
596 1 gql_throw(aTHX_ p, p->tok_start, "Expected name or constant");
597 }
598 324 gql_advance(aTHX_ p);
599 324 name = gql_parse_name(aTHX_ p, "Expected name");
600 324 return newRV_noinc(name);
601 }
602 5080 case TOK_INT: {
603 5080 SV *sv = gql_copy_token_sv(aTHX_ p);
604 5080 sv_setiv(sv, SvIV(sv));
605 5080 gql_advance(aTHX_ p);
606 5080 return sv;
607 }
608 2 case TOK_FLOAT: {
609 2 SV *sv = gql_copy_token_sv(aTHX_ p);
610 2 sv_setnv(sv, SvNV(sv));
611 2 gql_advance(aTHX_ p);
612 2 return sv;
613 }
614 305 case TOK_STRING:
615 case TOK_BLOCK_STRING: {
616 305 SV *sv = gql_copy_value_sv(aTHX_ p);
617 305 gql_advance(aTHX_ p);
618 305 return sv;
619 }
620 94 case TOK_NAME: {
621 94 ▶ if (gql_peek_name(p, "true")) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_peek_name(p, "true")) { 65 29 94
622 65 gql_advance(aTHX_ p);
623 65 return gql_call_helper1(aTHX_ "GraphQL::Houtou::Parser::Internal::_make_bool", newSViv(1));
624 }
625 29 ▶ if (gql_peek_name(p, "false")) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_peek_name(p, "false")) { 12 17 29
626 12 gql_advance(aTHX_ p);
627 12 return gql_call_helper1(aTHX_ "GraphQL::Houtou::Parser::Internal::_make_bool", newSViv(0));
628 }
629 17 ▶ if (gql_peek_name(p, "null")) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_peek_name(p, "null")) { 7 10 17
630 7 gql_advance(aTHX_ p);
631 7 return newSV(0);
632 }
633 {
634 10 SV *name = gql_copy_token_sv(aTHX_ p);
635 10 SV *ref1 = newRV_noinc(name);
636 10 gql_advance(aTHX_ p);
637 10 return newRV_noinc(ref1);
638 }
639 }
640 2078 case TOK_LBRACKET:
641 2078 return gql_parse_list_value(aTHX_ p, is_const);
642 86 case TOK_LBRACE:
643 86 return gql_parse_object_value(aTHX_ p, is_const);
644 0 default:
645 0 ▶ gql_throw(aTHX_ p, p->tok_start, is_const ? "Expected name or constant" : "Expected value");
Branch: 1 branch
BranchTrueFalseTotal
gql_throw(aTHX_ p, p->tok_start, is_const ? "Expected name or constant" : "Expected value"); 0 0 0
646 }
647 0 return &PL_sv_undef;
648 }
649  
650 static SV *
651 716 gql_parse_arguments(pTHX_ gql_parser_t *p, int is_const) {
652 716 HV *hv = newHV();
653 716 gql_expect(aTHX_ p, TOK_LPAREN, NULL);
654 716 ▶ if (p->kind == TOK_RPAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_RPAREN) { 0 716 716
655 0 gql_throw_expected_message(aTHX_ p, p->tok_start, "Expected name");
656 }
657 1464 ▶ while (p->kind != TOK_RPAREN) {
Branch: 1 branch
BranchTrueFalseTotal
while (p->kind != TOK_RPAREN) { 760 704 1464
658 760 SV *name = gql_parse_name(aTHX_ p, "Expected name");
659 757 gql_expect(aTHX_ p, TOK_COLON, NULL);
660 752 ▶ if (p->validation_errors) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->validation_errors) { 94 658 752
661 STRLEN name_len;
662 94 const char *name_str = SvPV(name, name_len);
663 94 ▶ if (hv_exists(hv, name_str, (I32)name_len)) {
Branch: 1 branch
BranchTrueFalseTotal
if (hv_exists(hv, name_str, (I32)name_len)) { 1 93 94
664 1 HV *error_hv = newHV();
665 1 AV *locations_av = newAV();
666 1 SV *message = newSVpvf("Argument '%s' is provided more than once.", name_str);
667 1 gql_store_sv(error_hv, "message", message);
668 1 av_push(locations_av, gql_make_current_location(aTHX_ p));
669 1 gql_store_sv(error_hv, "locations", newRV_noinc((SV *)locations_av));
670 1 av_push(p->validation_errors, newRV_noinc((SV *)error_hv));
671 }
672 }
673 1500 gql_store_sv(hv, SvPV_nolen(name), gql_parse_value(aTHX_ p, is_const));
674 748 SvREFCNT_dec(name);
675 }
676 704 gql_expect(aTHX_ p, TOK_RPAREN, NULL);
677 704 return newRV_noinc((SV *)hv);
678 }
679  
680 static SV *
681 62 gql_parse_directive(pTHX_ gql_parser_t *p) {
682 62 HV *hv = newHV();
683 62 gql_expect(aTHX_ p, TOK_AT, NULL);
684 62 gql_store_sv(hv, "name", gql_parse_name(aTHX_ p, "Expected name"));
685 61 ▶ if (p->kind == TOK_LPAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_LPAREN) { 45 16 61
686 45 gql_store_sv(hv, "arguments", gql_parse_arguments(aTHX_ p, 0));
687 }
688 61 return newRV_noinc((SV *)hv);
689 }
690  
691 static SV *
692 58 gql_parse_directives(pTHX_ gql_parser_t *p) {
693 58 AV *av = newAV();
694 119 ▶ while (p->kind == TOK_AT) {
Branch: 1 branch
BranchTrueFalseTotal
while (p->kind == TOK_AT) { 62 57 119
695 62 av_push(av, gql_parse_directive(aTHX_ p));
696 }
697 57 return newRV_noinc((SV *)av);
698 }
699  
700 static SV *
701 102 gql_parse_const_directives(pTHX_ gql_parser_t *p) {
702 102 AV *av = newAV();
703 206 ▶ while (p->kind == TOK_AT) {
Branch: 1 branch
BranchTrueFalseTotal
while (p->kind == TOK_AT) { 105 101 206
704 105 HV *hv = newHV();
705 105 gql_expect(aTHX_ p, TOK_AT, NULL);
706 105 gql_store_sv(hv, "name", gql_parse_name(aTHX_ p, "Expected name"));
707 105 ▶ if (p->kind == TOK_LPAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_LPAREN) { 56 49 105
708 56 gql_store_sv(hv, "arguments", gql_parse_arguments(aTHX_ p, 1));
709 }
710 104 av_push(av, newRV_noinc((SV *)hv));
711 }
712 101 return newRV_noinc((SV *)av);
713 }
714  
715 static SV *
716 6047 gql_parse_selection_set(pTHX_ gql_parser_t *p) {
717 HV *hv;
718 AV *av;
719 6047 ▶ if (++p->depth > GQL_PARSER_MAX_DEPTH) {
Branch: 1 branch
BranchTrueFalseTotal
if (++p->depth > GQL_PARSER_MAX_DEPTH) { 3 6044 6047
720 3 gql_throw(aTHX_ p, p->tok_start,
721 "Query is too deeply nested (exceeds maximum nesting depth)");
722 }
723 6044 hv = newHV();
724 6044 av = newAV();
725 6044 gql_expect(aTHX_ p, TOK_LBRACE, "Expected name");
726 6042 ▶ if (p->kind == TOK_RBRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_RBRACE) { 0 6042 6042
727 0 gql_throw(aTHX_ p, p->tok_start, "Expected name");
728 }
729 619444 ▶ while (p->kind != TOK_RBRACE) {
Branch: 1 branch
BranchTrueFalseTotal
while (p->kind != TOK_RBRACE) { 614955 4489 619444
730 614955 av_push(av, gql_parse_selection(aTHX_ p));
731 }
732 4489 gql_expect(aTHX_ p, TOK_RBRACE, NULL);
733 4489 gql_store_sv(hv, "selections", newRV_noinc((SV *)av));
734 4489 p->depth--;
735 4489 return newRV_noinc((SV *)hv);
736 }
737  
738 static SV *
739 614767 gql_parse_field(pTHX_ gql_parser_t *p) {
740 614767 HV *hv = newHV();
741 614767 int had_directives = 0;
742 614767 int had_selection_set = 0;
743 614767 SV *first = gql_parse_name(aTHX_ p, "Expected name");
744 614763 ▶ if (p->kind == TOK_COLON) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_COLON) { 3072 611691 614763
745 3072 gql_store_sv(hv, "alias", first);
746 3072 gql_advance(aTHX_ p);
747 3072 gql_store_sv(hv, "name", gql_parse_name(aTHX_ p, "Expected name"));
748 } else {
749 611691 gql_store_sv(hv, "name", first);
750 }
751 614763 ▶ if (p->kind == TOK_LPAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_LPAREN) { 615 614148 614763
752 615 gql_store_sv(hv, "arguments", gql_parse_arguments(aTHX_ p, 0));
753 }
754 614752 ▶ if (p->kind == TOK_AT) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_AT) { 48 614704 614752
755 48 had_directives = 1;
756 48 gql_store_sv(hv, "directives", gql_parse_directives(aTHX_ p));
757 }
758 614751 ▶ if (p->kind == TOK_LBRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_LBRACE) { 4920 609831 614751
759 4920 had_selection_set = 1;
760 4920 SV *sel = gql_parse_selection_set(aTHX_ p);
761 3384 HV *selhv = (HV *)SvRV(sel);
762 3384 SV **svp = hv_fetch(selhv, "selections", 10, 0);
763 3384 gql_store_sv(hv, "selections", newSVsv(*svp));
764 3384 SvREFCNT_dec(sel);
765 }
766 613215 gql_store_sv(hv, "kind", newSVpv("field", 0));
767 613215 ▶ if (had_selection_set) {
Branch: 1 branch
BranchTrueFalseTotal
if (had_selection_set) { 3384 609831 613215
768 3384 gql_store_current_location(aTHX_ p, hv);
769 609831 ▶ } else if (had_directives) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (had_directives) { 43 609788 609831
770 43 gql_store_current_or_endline_location(aTHX_ p, hv);
771 } else {
772 609788 gql_store_current_location(aTHX_ p, hv);
773 }
774 613215 return newRV_noinc((SV *)hv);
775 }
776  
777 static SV *
778 614955 gql_parse_selection(pTHX_ gql_parser_t *p) {
779 614955 ▶ if (p->kind == TOK_SPREAD) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_SPREAD) { 188 614767 614955
780 188 HV *hv = newHV();
781 188 gql_advance(aTHX_ p);
782 188 ▶ if (gql_peek_name(p, "on")) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_peek_name(p, "on")) { 61 127 188
783 61 gql_parser_t lookahead = *p;
784 61 gql_advance(aTHX_ &lookahead);
785 61 ▶ if (lookahead.kind != TOK_NAME) {
Branch: 1 branch
BranchTrueFalseTotal
if (lookahead.kind != TOK_NAME) { 0 61 61
786 0 gql_throw(aTHX_ p, p->tok_start, "Unexpected Name \"on\"");
787 }
788 61 gql_advance(aTHX_ p);
789 61 gql_store_sv(hv, "on", gql_parse_name(aTHX_ p, "Expected name"));
790 61 ▶ if (p->kind == TOK_AT) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_AT) { 1 60 61
791 1 gql_store_sv(hv, "directives", gql_parse_directives(aTHX_ p));
792 }
793 {
794 61 SV *sel = gql_parse_selection_set(aTHX_ p);
795 61 HV *selhv = (HV *)SvRV(sel);
796 61 SV **svp = hv_fetch(selhv, "selections", 10, 0);
797 61 gql_store_sv(hv, "selections", newSVsv(*svp));
798 61 SvREFCNT_dec(sel);
799 }
800 61 gql_store_sv(hv, "kind", newSVpv("inline_fragment", 0));
801 61 gql_store_current_location(aTHX_ p, hv);
802 61 return newRV_noinc((SV *)hv);
803 }
804 127 ▶ if (p->kind == TOK_LBRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_LBRACE) { 1 126 127
805 1 SV *sel = gql_parse_selection_set(aTHX_ p);
806 1 HV *selhv = (HV *)SvRV(sel);
807 1 SV **svp = hv_fetch(selhv, "selections", 10, 0);
808 1 gql_store_sv(hv, "selections", newSVsv(*svp));
809 1 SvREFCNT_dec(sel);
810 1 gql_store_sv(hv, "kind", newSVpv("inline_fragment", 0));
811 1 gql_store_current_location(aTHX_ p, hv);
812 1 return newRV_noinc((SV *)hv);
813 }
814 126 ▶ if (p->kind == TOK_AT) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_AT) { 1 125 126
815 1 gql_store_sv(hv, "directives", gql_parse_directives(aTHX_ p));
816 {
817 1 SV *sel = gql_parse_selection_set(aTHX_ p);
818 1 HV *selhv = (HV *)SvRV(sel);
819 1 SV **svp = hv_fetch(selhv, "selections", 10, 0);
820 1 gql_store_sv(hv, "selections", newSVsv(*svp));
821 1 SvREFCNT_dec(sel);
822 }
823 1 gql_store_sv(hv, "kind", newSVpv("inline_fragment", 0));
824 1 gql_store_current_location(aTHX_ p, hv);
825 1 return newRV_noinc((SV *)hv);
826 }
827 125 gql_store_sv(hv, "name", gql_parse_fragment_name(aTHX_ p));
828 124 ▶ if (p->kind == TOK_AT) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_AT) { 3 121 124
829 3 gql_store_sv(hv, "directives", gql_parse_directives(aTHX_ p));
830 3 gql_store_sv(hv, "kind", newSVpv("fragment_spread", 0));
831 3 gql_store_current_or_endline_location(aTHX_ p, hv);
832 3 return newRV_noinc((SV *)hv);
833 }
834 121 gql_store_sv(hv, "kind", newSVpv("fragment_spread", 0));
835 121 gql_store_current_location(aTHX_ p, hv);
836 121 return newRV_noinc((SV *)hv);
837 }
838 614767 return gql_parse_field(aTHX_ p);
839 }
840  
841 static SV *
842 250 gql_parse_variable_definitions(pTHX_ gql_parser_t *p) {
843 250 HV *hv = newHV();
844 250 gql_expect(aTHX_ p, TOK_LPAREN, NULL);
845 250 ▶ if (p->kind == TOK_RPAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_RPAREN) { 0 250 250
846 0 gql_throw(aTHX_ p, p->tok_start, "Expected $argument: Type");
847 }
848 566 ▶ while (p->kind != TOK_RPAREN) {
Branch: 1 branch
BranchTrueFalseTotal
while (p->kind != TOK_RPAREN) { 317 249 566
849 317 SV *description = gql_parse_description(aTHX_ p);
850 317 HV *def = newHV();
851 SV *name;
852 317 gql_expect(aTHX_ p, TOK_DOLLAR, NULL);
853 317 name = gql_parse_name(aTHX_ p, "Expected name");
854 316 gql_expect(aTHX_ p, TOK_COLON, NULL);
855 316 gql_store_sv(def, "type", gql_parse_type_reference(aTHX_ p));
856 316 ▶ if (p->kind == TOK_EQUALS) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_EQUALS) { 23 293 316
857 23 gql_advance(aTHX_ p);
858 23 gql_store_sv(def, "default_value", gql_parse_value(aTHX_ p, 1));
859 }
860 316 ▶ if (p->kind == TOK_AT) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_AT) { 2 314 316
861 2 gql_store_sv(def, "directives", gql_parse_const_directives(aTHX_ p));
862 }
863 316 ▶ if (SvOK(description)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(description)) { 3 313 316
864 3 HV *description_hv = (HV *)SvRV(description);
865 3 SV **description_svp = hv_fetch(description_hv, "description", 11, 0);
866 3 gql_store_sv(def, "description", newSVsv(*description_svp));
867 3 SvREFCNT_dec(description);
868 }
869 316 ▶ if (p->validation_errors) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->validation_errors) { 15 301 316
870 STRLEN name_len;
871 15 const char *name_str = SvPV(name, name_len);
872 15 ▶ if (hv_exists(hv, name_str, (I32)name_len)) {
Branch: 1 branch
BranchTrueFalseTotal
if (hv_exists(hv, name_str, (I32)name_len)) { 1 14 15
873 1 HV *error_hv = newHV();
874 1 AV *locations_av = newAV();
875 1 SV *message = newSVpvf("Variable '$%s' is defined more than once.", name_str);
876 1 gql_store_sv(error_hv, "message", message);
877 1 av_push(locations_av, gql_make_current_location(aTHX_ p));
878 1 gql_store_sv(error_hv, "locations", newRV_noinc((SV *)locations_av));
879 1 av_push(p->validation_errors, newRV_noinc((SV *)error_hv));
880 }
881 }
882 632 gql_store_sv(hv, SvPV_nolen(name), newRV_noinc((SV *)def));
883 316 SvREFCNT_dec(name);
884 }
885 249 gql_expect(aTHX_ p, TOK_RPAREN, NULL);
886 {
887 249 HV *wrap = newHV();
888 249 gql_store_sv(wrap, "variables", newRV_noinc((SV *)hv));
889 249 return newRV_noinc((SV *)wrap);
890 }
891 }
892  
893 static SV *
894 1225 gql_parse_type_reference(pTHX_ gql_parser_t *p) {
895 SV *type_sv;
896 1225 ▶ if (p->kind == TOK_LBRACKET) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_LBRACKET) { 164 1061 1225
897 164 gql_advance(aTHX_ p);
898 164 type_sv = gql_parse_type_reference(aTHX_ p);
899 164 gql_expect(aTHX_ p, TOK_RBRACKET, NULL);
900 164 type_sv = gql_make_type_wrapper(aTHX_ type_sv, "list");
901 } else {
902 1061 type_sv = gql_parse_name(aTHX_ p, "Expected name");
903 }
904 1225 ▶ if (p->kind == TOK_BANG) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_BANG) { 340 885 1225
905 340 gql_advance(aTHX_ p);
906 340 type_sv = gql_make_type_wrapper(aTHX_ type_sv, "non_null");
907 }
908 1225 return type_sv;
909 }
910  
911 static SV *
912 1020 gql_parse_operation_definition(pTHX_ gql_parser_t *p, SV *description) {
913 1020 HV *hv = newHV();
914 1020 ▶ if (p->kind == TOK_LBRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_LBRACE) { 681 339 1020
915 681 SV *sel = gql_parse_selection_set(aTHX_ p);
916 659 HV *selhv = (HV *)SvRV(sel);
917 659 SV **svp = hv_fetch(selhv, "selections", 10, 0);
918 659 gql_store_sv(hv, "selections", newSVsv(*svp));
919 659 SvREFCNT_dec(sel);
920 659 gql_store_sv(hv, "kind", newSVpv("operation", 0));
921 659 gql_store_current_location(aTHX_ p, hv);
922 659 return newRV_noinc((SV *)hv);
923 }
924 339 ▶ if (!(gql_peek_name(p, "query") || gql_peek_name(p, "mutation") || gql_peek_name(p, "subscription"))) {
Branch: 3 branches
BranchTrueFalseTotal
if (!(gql_peek_name(p, "query") || gql_peek_name(p, "mutation") || gql_peek_name(p, "subscription"))) { 39 300 339
if (!(gql_peek_name(p, "query") || gql_peek_name(p, "mutation") || gql_peek_name(p, "subscription"))) { 16 23 39
if (!(gql_peek_name(p, "query") || gql_peek_name(p, "mutation") || gql_peek_name(p, "subscription"))) { 0 16 16
925 0 gql_throw(aTHX_ p, p->tok_start, "Expected executable definition");
926 }
927 339 gql_store_sv(hv, "operationType", gql_copy_token_sv(aTHX_ p));
928 339 gql_advance(aTHX_ p);
929 339 ▶ if (p->kind == TOK_NAME) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_NAME) { 318 21 339
930 318 gql_store_sv(hv, "name", gql_parse_name(aTHX_ p, "Expected name"));
931 }
932 339 ▶ if (p->kind == TOK_LPAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_LPAREN) { 250 89 339
933 250 SV *vars = gql_parse_variable_definitions(aTHX_ p);
934 249 HV *varhv = (HV *)SvRV(vars);
935 249 SV **svp = hv_fetch(varhv, "variables", 9, 0);
936 249 gql_store_sv(hv, "variables", newSVsv(*svp));
937 249 SvREFCNT_dec(vars);
938 }
939 338 ▶ if (p->kind == TOK_AT) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_AT) { 4 334 338
940 4 gql_store_sv(hv, "directives", gql_parse_directives(aTHX_ p));
941 }
942 {
943 338 SV *sel = gql_parse_selection_set(aTHX_ p);
944 338 HV *selhv = (HV *)SvRV(sel);
945 338 SV **svp = hv_fetch(selhv, "selections", 10, 0);
946 338 gql_store_sv(hv, "selections", newSVsv(*svp));
947 338 SvREFCNT_dec(sel);
948 }
949 338 ▶ if (SvOK(description)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(description)) { 3 335 338
950 3 HV *description_hv = (HV *)SvRV(description);
951 3 SV **description_svp = hv_fetch(description_hv, "description", 11, 0);
952 3 gql_store_sv(hv, "description", newSVsv(*description_svp));
953 3 SvREFCNT_dec(description);
954 }
955 338 gql_store_sv(hv, "kind", newSVpv("operation", 0));
956 338 gql_store_current_location(aTHX_ p, hv);
957 338 return newRV_noinc((SV *)hv);
958 }
959  
960 static SV *
961 45 gql_parse_fragment_definition(pTHX_ gql_parser_t *p, SV *description) {
962 45 HV *hv = newHV();
963 45 gql_advance(aTHX_ p);
964 45 gql_store_sv(hv, "name", gql_parse_fragment_name(aTHX_ p));
965 45 ▶ if (!gql_peek_name(p, "on")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_peek_name(p, "on")) { 0 45 45
966 0 gql_throw(aTHX_ p, p->tok_start, "Expected \"on\"");
967 }
968 45 gql_advance(aTHX_ p);
969 45 gql_store_sv(hv, "on", gql_parse_name(aTHX_ p, "Expected name"));
970 45 ▶ if (p->kind == TOK_AT) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_AT) { 1 44 45
971 1 gql_store_sv(hv, "directives", gql_parse_directives(aTHX_ p));
972 }
973 {
974 45 SV *sel = gql_parse_selection_set(aTHX_ p);
975 45 HV *selhv = (HV *)SvRV(sel);
976 45 SV **svp = hv_fetch(selhv, "selections", 10, 0);
977 45 gql_store_sv(hv, "selections", newSVsv(*svp));
978 45 SvREFCNT_dec(sel);
979 }
980 45 ▶ if (SvOK(description)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(description)) { 3 42 45
981 3 HV *description_hv = (HV *)SvRV(description);
982 3 SV **description_svp = hv_fetch(description_hv, "description", 11, 0);
983 3 gql_store_sv(hv, "description", newSVsv(*description_svp));
984 3 SvREFCNT_dec(description);
985 }
986 45 gql_store_sv(hv, "kind", newSVpv("fragment", 0));
987 45 gql_store_current_location(aTHX_ p, hv);
988 45 return newRV_noinc((SV *)hv);
989 }
990  
991 static SV *
992 1169 gql_parse_description(pTHX_ gql_parser_t *p) {
993 HV *hv;
994 SV *desc;
995 1169 ▶ if (!(p->kind == TOK_STRING || p->kind == TOK_BLOCK_STRING)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!(p->kind == TOK_STRING || p->kind == TOK_BLOCK_STRING)) { 1152 17 1169
if (!(p->kind == TOK_STRING || p->kind == TOK_BLOCK_STRING)) { 868 284 1152
996 868 return &PL_sv_undef;
997 }
998 301 desc = gql_copy_value_sv(aTHX_ p);
999 301 gql_advance(aTHX_ p);
1000 301 hv = newHV();
1001 301 gql_store_sv(hv, "description", desc);
1002 301 return newRV_noinc((SV *)hv);
1003 }
1004  
1005 static SV *
1006 312 gql_parse_input_value_definition(pTHX_ gql_parser_t *p) {
1007 312 SV *description = gql_parse_description(aTHX_ p);
1008 312 HV *def = newHV();
1009 312 SV *name = gql_parse_name(aTHX_ p, "Expected name");
1010 312 gql_expect(aTHX_ p, TOK_COLON, NULL);
1011 312 gql_store_sv(def, "type", gql_parse_type_reference(aTHX_ p));
1012 312 ▶ if (p->kind == TOK_EQUALS) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_EQUALS) { 23 289 312
1013 23 gql_advance(aTHX_ p);
1014 23 gql_store_sv(def, "default_value", gql_parse_value(aTHX_ p, 1));
1015 }
1016 312 ▶ if (p->kind == TOK_AT) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_AT) { 20 292 312
1017 20 gql_store_sv(def, "directives", gql_parse_const_directives(aTHX_ p));
1018 }
1019 312 ▶ if (SvOK(description)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(description)) { 2 310 312
1020 2 HV *dhv = (HV *)SvRV(description);
1021 2 SV **svp = hv_fetch(dhv, "description", 11, 0);
1022 2 gql_store_sv(def, "description", newSVsv(*svp));
1023 }
1024 {
1025 312 HV *wrap = newHV();
1026 624 gql_store_sv(wrap, SvPV_nolen(name), newRV_noinc((SV *)def));
1027 312 SvREFCNT_dec(name);
1028 312 ▶ if (SvOK(description)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(description)) { 2 310 312
1029 2 SvREFCNT_dec(description);
1030 }
1031 312 return newRV_noinc((SV *)wrap);
1032 }
1033 }
1034  
1035 static SV *
1036 166 gql_parse_arguments_definition(pTHX_ gql_parser_t *p) {
1037 166 HV *args = newHV();
1038 166 gql_expect(aTHX_ p, TOK_LPAREN, NULL);
1039 166 ▶ if (p->kind == TOK_RPAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_RPAREN) { 0 166 166
1040 0 gql_throw_expected_message(aTHX_ p, p->tok_start, "Expected name");
1041 }
1042 441 ▶ while (p->kind != TOK_RPAREN) {
Branch: 1 branch
BranchTrueFalseTotal
while (p->kind != TOK_RPAREN) { 275 166 441
1043 275 SV *item = gql_parse_input_value_definition(aTHX_ p);
1044 275 HV *ihv = (HV *)SvRV(item);
1045 275 hv_iterinit(ihv);
1046 275 HE *he = hv_iternext(ihv);
1047 275 ▶ if (p->validation_errors && hv_exists(args, HeKEY(he), HeKLEN(he))) {
Branch: 2 branches
BranchTrueFalseTotal
if (p->validation_errors && hv_exists(args, HeKEY(he), HeKLEN(he))) { 255 20 275
if (p->validation_errors && hv_exists(args, HeKEY(he), HeKLEN(he))) { 1 254 255
1048 1 HV *error_hv = newHV();
1049 1 gql_store_sv(error_hv, "message", newSVpvf(
1050 "Argument '%s' is defined more than once.", HeKEY(he)
1051 ));
1052 1 av_push(p->validation_errors, newRV_noinc((SV *)error_hv));
1053 }
1054 275 gql_store_sv(args, HeKEY(he), newSVsv(HeVAL(he)));
1055 275 SvREFCNT_dec(item);
1056 }
1057 166 gql_expect(aTHX_ p, TOK_RPAREN, NULL);
1058 {
1059 166 HV *wrap = newHV();
1060 166 gql_store_sv(wrap, "args", newRV_noinc((SV *)args));
1061 166 return newRV_noinc((SV *)wrap);
1062 }
1063 }
1064  
1065 static SV *
1066 433 gql_parse_field_definition(pTHX_ gql_parser_t *p) {
1067 433 SV *description = gql_parse_description(aTHX_ p);
1068 433 HV *def = newHV();
1069 433 SV *name = gql_parse_name(aTHX_ p, "Expected name");
1070 433 ▶ if (p->kind == TOK_LPAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_LPAREN) { 74 359 433
1071 74 SV *args = gql_parse_arguments_definition(aTHX_ p);
1072 74 HV *ahv = (HV *)SvRV(args);
1073 74 SV **svp = hv_fetch(ahv, "args", 4, 0);
1074 74 gql_store_sv(def, "args", newSVsv(*svp));
1075 74 SvREFCNT_dec(args);
1076 }
1077 433 gql_expect(aTHX_ p, TOK_COLON, NULL);
1078 433 gql_store_sv(def, "type", gql_parse_type_reference(aTHX_ p));
1079 433 ▶ if (p->kind == TOK_AT) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_AT) { 6 427 433
1080 6 gql_store_sv(def, "directives", gql_parse_const_directives(aTHX_ p));
1081 }
1082 433 ▶ if (SvOK(description)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(description)) { 218 215 433
1083 218 HV *dhv = (HV *)SvRV(description);
1084 218 SV **svp = hv_fetch(dhv, "description", 11, 0);
1085 218 gql_store_sv(def, "description", newSVsv(*svp));
1086 }
1087 {
1088 433 HV *wrap = newHV();
1089 866 gql_store_sv(wrap, SvPV_nolen(name), newRV_noinc((SV *)def));
1090 433 SvREFCNT_dec(name);
1091 433 ▶ if (SvOK(description)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(description)) { 218 215 433
1092 218 SvREFCNT_dec(description);
1093 }
1094 433 return newRV_noinc((SV *)wrap);
1095 }
1096 }
1097  
1098 static SV *
1099 7 gql_parse_schema_definition(pTHX_ gql_parser_t *p) {
1100 7 return gql_parse_schema_definition_extended(aTHX_ p, 0);
1101 }
1102  
1103 static SV *
1104 20 gql_parse_schema_definition_extended(pTHX_ gql_parser_t *p, int allow_empty_body) {
1105 20 HV *hv = newHV();
1106 20 int had_directives = 0;
1107 20 gql_advance(aTHX_ p);
1108 20 ▶ if (p->kind == TOK_AT) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_AT) { 11 9 20
1109 11 had_directives = 1;
1110 11 gql_store_sv(hv, "directives", gql_parse_const_directives(aTHX_ p));
1111 }
1112 20 ▶ if (allow_empty_body && p->kind != TOK_LBRACE) {
Branch: 2 branches
BranchTrueFalseTotal
if (allow_empty_body && p->kind != TOK_LBRACE) { 13 7 20
if (allow_empty_body && p->kind != TOK_LBRACE) { 11 2 13
1113 11 gql_store_sv(hv, "kind", newSVpv("schema", 0));
1114 11 ▶ if (had_directives) {
Branch: 1 branch
BranchTrueFalseTotal
if (had_directives) { 10 1 11
1115 10 gql_store_endline_location(aTHX_ p, hv);
1116 } else {
1117 1 gql_store_current_location(aTHX_ p, hv);
1118 }
1119 11 return newRV_noinc((SV *)hv);
1120 }
1121 9 gql_expect(aTHX_ p, TOK_LBRACE, NULL);
1122 9 ▶ if (p->kind == TOK_RBRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_RBRACE) { 0 9 9
1123 0 gql_throw(aTHX_ p, p->tok_start, "Expected name");
1124 }
1125 21 ▶ while (p->kind != TOK_RBRACE) {
Branch: 1 branch
BranchTrueFalseTotal
while (p->kind != TOK_RBRACE) { 12 9 21
1126 12 SV *op_name = gql_parse_name(aTHX_ p, "Expected name");
1127 12 gql_expect(aTHX_ p, TOK_COLON, NULL);
1128 24 gql_store_sv(hv, SvPV_nolen(op_name), gql_parse_name(aTHX_ p, "Expected name"));
1129 }
1130 9 gql_expect(aTHX_ p, TOK_RBRACE, NULL);
1131 9 gql_store_sv(hv, "kind", newSVpv("schema", 0));
1132 9 gql_store_endline_location(aTHX_ p, hv);
1133 9 return newRV_noinc((SV *)hv);
1134 }
1135  
1136 static SV *
1137 54 gql_parse_scalar_type_definition(pTHX_ gql_parser_t *p) {
1138 54 HV *hv = newHV();
1139 54 int had_directives = 0;
1140 54 gql_advance(aTHX_ p);
1141 54 gql_store_sv(hv, "name", gql_parse_name(aTHX_ p, "Expected name"));
1142 54 ▶ if (p->kind == TOK_AT) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_AT) { 8 46 54
1143 8 had_directives = 1;
1144 8 gql_store_sv(hv, "directives", gql_parse_const_directives(aTHX_ p));
1145 }
1146 54 gql_store_sv(hv, "kind", newSVpv("scalar", 0));
1147 54 ▶ if (had_directives) {
Branch: 1 branch
BranchTrueFalseTotal
if (had_directives) { 8 46 54
1148 8 gql_store_endline_location(aTHX_ p, hv);
1149 } else {
1150 46 gql_store_current_location(aTHX_ p, hv);
1151 }
1152 54 return newRV_noinc((SV *)hv);
1153 }
1154  
1155 static SV *
1156 215 gql_parse_object_type_definition(pTHX_ gql_parser_t *p, const char *kind) {
1157 215 HV *hv = newHV();
1158 215 int had_directives = 0;
1159 215 int had_body = 0;
1160 215 gql_advance(aTHX_ p);
1161 215 gql_store_sv(hv, "name", gql_parse_name(aTHX_ p, "Expected name"));
1162 215 ▶ if ((strcmp(kind, "type") == 0 || strcmp(kind, "interface") == 0)
Branch: 2 branches
BranchTrueFalseTotal
if ((strcmp(kind, "type") == 0 || strcmp(kind, "interface") == 0) 42 173 215
if ((strcmp(kind, "type") == 0 || strcmp(kind, "interface") == 0) 18 24 42
1163 191 ▶ && gql_peek_name(p, "implements")) {
Branch: 1 branch
BranchTrueFalseTotal
&& gql_peek_name(p, "implements")) { 17 174 191
1164 17 AV *interfaces = newAV();
1165 17 gql_advance(aTHX_ p);
1166 17 ▶ if (p->kind == TOK_AMP) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_AMP) { 0 17 17
1167 0 gql_advance(aTHX_ p);
1168 }
1169 17 av_push(interfaces, gql_parse_name(aTHX_ p, "Expected name"));
1170 19 ▶ while (p->kind == TOK_AMP) {
Branch: 1 branch
BranchTrueFalseTotal
while (p->kind == TOK_AMP) { 2 17 19
1171 2 gql_advance(aTHX_ p);
1172 2 av_push(interfaces, gql_parse_name(aTHX_ p, "Expected name"));
1173 }
1174 17 gql_store_sv(hv, "interfaces", newRV_noinc((SV *)interfaces));
1175 }
1176 215 ▶ if (p->kind == TOK_AT) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_AT) { 44 171 215
1177 44 had_directives = 1;
1178 44 gql_store_sv(hv, "directives", gql_parse_const_directives(aTHX_ p));
1179 }
1180 {
1181 214 HV *fields = newHV();
1182 214 ▶ if (p->kind == TOK_LBRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_LBRACE) { 203 11 214
1183 203 had_body = 1;
1184 203 gql_advance(aTHX_ p);
1185 203 ▶ if (p->kind == TOK_RBRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_RBRACE) { 0 203 203
1186 0 gql_throw(aTHX_ p, p->tok_start, "Expected name");
1187 }
1188 673 ▶ while (p->kind != TOK_RBRACE) {
Branch: 1 branch
BranchTrueFalseTotal
while (p->kind != TOK_RBRACE) { 470 203 673
1189 940 SV *item = (strcmp(kind, "input") == 0)
1190 37 ? gql_parse_input_value_definition(aTHX_ p)
1191 470 ▶ : gql_parse_field_definition(aTHX_ p);
Branch: 1 branch
BranchTrueFalseTotal
: gql_parse_field_definition(aTHX_ p); 37 433 470
1192 470 HV *ihv = (HV *)SvRV(item);
1193 470 hv_iterinit(ihv);
1194 470 HE *he = hv_iternext(ihv);
1195 470 ▶ if (p->validation_errors && hv_exists(fields, HeKEY(he), HeKLEN(he))) {
Branch: 2 branches
BranchTrueFalseTotal
if (p->validation_errors && hv_exists(fields, HeKEY(he), HeKLEN(he))) { 432 38 470
if (p->validation_errors && hv_exists(fields, HeKEY(he), HeKLEN(he))) { 2 430 432
1196 2 HV *error_hv = newHV();
1197 2 ▶ gql_store_sv(error_hv, "message", newSVpvf(
Branch: 1 branch
BranchTrueFalseTotal
gql_store_sv(error_hv, "message", newSVpvf( 1 1 2
1198 "%s field '%s' is defined more than once.",
1199 strcmp(kind, "input") == 0 ? "Input" : "Type", HeKEY(he)
1200 ));
1201 2 av_push(p->validation_errors, newRV_noinc((SV *)error_hv));
1202 }
1203 470 gql_store_sv(fields, HeKEY(he), newSVsv(HeVAL(he)));
1204 470 SvREFCNT_dec(item);
1205 }
1206 203 gql_expect(aTHX_ p, TOK_RBRACE, NULL);
1207 }
1208 214 gql_store_sv(hv, "fields", newRV_noinc((SV *)fields));
1209 }
1210 214 gql_store_sv(hv, "kind", newSVpv(kind, 0));
1211 214 ▶ if (had_directives || had_body) {
Branch: 2 branches
BranchTrueFalseTotal
if (had_directives || had_body) { 171 43 214
if (had_directives || had_body) { 165 6 171
1212 208 gql_store_endline_location(aTHX_ p, hv);
1213 } else {
1214 6 gql_store_current_location(aTHX_ p, hv);
1215 }
1216 214 return newRV_noinc((SV *)hv);
1217 }
1218  
1219 static SV *
1220 20 gql_parse_union_type_definition(pTHX_ gql_parser_t *p) {
1221 20 HV *hv = newHV();
1222 20 AV *types = newAV();
1223 20 int had_directives = 0;
1224 20 int had_members = 0;
1225 20 gql_advance(aTHX_ p);
1226 20 gql_store_sv(hv, "name", gql_parse_name(aTHX_ p, "Expected name"));
1227 20 ▶ if (p->kind == TOK_AT) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_AT) { 3 17 20
1228 3 had_directives = 1;
1229 3 gql_store_sv(hv, "directives", gql_parse_const_directives(aTHX_ p));
1230 }
1231 20 ▶ if (p->kind == TOK_EQUALS) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_EQUALS) { 17 3 20
1232 17 had_members = 1;
1233 17 gql_advance(aTHX_ p);
1234 17 ▶ if (p->kind == TOK_PIPE) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_PIPE) { 2 15 17
1235 2 gql_advance(aTHX_ p);
1236 }
1237 17 ▶ if (p->kind != TOK_NAME) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind != TOK_NAME) { 0 17 17
1238 0 gql_throw_expected_message(aTHX_ p, p->tok_start, "Expected name");
1239 }
1240 17 av_push(types, gql_parse_name(aTHX_ p, "Expected name"));
1241 22 ▶ while (p->kind == TOK_PIPE) {
Branch: 1 branch
BranchTrueFalseTotal
while (p->kind == TOK_PIPE) { 5 17 22
1242 5 gql_advance(aTHX_ p);
1243 5 av_push(types, gql_parse_name(aTHX_ p, "Expected name"));
1244 }
1245 }
1246 20 ▶ if (had_members) {
Branch: 1 branch
BranchTrueFalseTotal
if (had_members) { 17 3 20
1247 17 gql_store_sv(hv, "types", newRV_noinc((SV *)types));
1248 } else {
1249 3 SvREFCNT_dec((SV *)types);
1250 }
1251 20 gql_store_sv(hv, "kind", newSVpv("union", 0));
1252 20 ▶ if (had_members) {
Branch: 1 branch
BranchTrueFalseTotal
if (had_members) { 17 3 20
1253 17 gql_store_current_location(aTHX_ p, hv);
1254 3 ▶ } else if (had_directives) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (had_directives) { 1 2 3
1255 1 gql_store_endline_location(aTHX_ p, hv);
1256 } else {
1257 2 gql_store_current_location(aTHX_ p, hv);
1258 }
1259 20 return newRV_noinc((SV *)hv);
1260 }
1261  
1262 static SV *
1263 22 gql_parse_enum_type_definition(pTHX_ gql_parser_t *p) {
1264 22 HV *hv = newHV();
1265 22 HV *values = newHV();
1266 22 int had_directives = 0;
1267 22 int had_body = 0;
1268 22 gql_advance(aTHX_ p);
1269 22 gql_store_sv(hv, "name", gql_parse_name(aTHX_ p, "Expected name"));
1270 22 ▶ if (p->kind == TOK_AT) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_AT) { 2 20 22
1271 2 had_directives = 1;
1272 2 gql_store_sv(hv, "directives", gql_parse_const_directives(aTHX_ p));
1273 }
1274 22 ▶ if (p->kind == TOK_LBRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_LBRACE) { 19 3 22
1275 19 had_body = 1;
1276 19 gql_advance(aTHX_ p);
1277 19 ▶ if (p->kind == TOK_RBRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_RBRACE) { 0 19 19
1278 0 gql_throw(aTHX_ p, p->tok_start, "Expected name");
1279 }
1280 73 ▶ while (p->kind != TOK_RBRACE) {
Branch: 1 branch
BranchTrueFalseTotal
while (p->kind != TOK_RBRACE) { 35 19 54
1281 35 SV *description = gql_parse_description(aTHX_ p);
1282 35 HV *value_hv = newHV();
1283 35 SV *name = gql_parse_name(aTHX_ p, "Expected name");
1284 35 const char *name_str = SvPV_nolen(name);
1285 35 ▶ if (strEQ(name_str, "true") || strEQ(name_str, "false") || strEQ(name_str, "null")) {
Branch: 3 branches
BranchTrueFalseTotal
if (strEQ(name_str, "true") || strEQ(name_str, "false") || strEQ(name_str, "null")) { 35 0 35
if (strEQ(name_str, "true") || strEQ(name_str, "false") || strEQ(name_str, "null")) { 35 0 35
if (strEQ(name_str, "true") || strEQ(name_str, "false") || strEQ(name_str, "null")) { 0 35 35
1286 0 ▶ gql_throw(aTHX_ p, p->tok_start > 0 ? p->tok_start - 1 : p->tok_start, "Invalid enum value");
Branch: 1 branch
BranchTrueFalseTotal
gql_throw(aTHX_ p, p->tok_start > 0 ? p->tok_start - 1 : p->tok_start, "Invalid enum value"); 0 0 0
1287 }
1288 35 ▶ if (p->kind == TOK_AT) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_AT) { 6 29 35
1289 6 gql_store_sv(value_hv, "directives", gql_parse_const_directives(aTHX_ p));
1290 }
1291 35 ▶ if (p->validation_errors && hv_exists(values, name_str, (I32)SvCUR(name))) {
Branch: 2 branches
BranchTrueFalseTotal
if (p->validation_errors && hv_exists(values, name_str, (I32)SvCUR(name))) { 29 6 35
if (p->validation_errors && hv_exists(values, name_str, (I32)SvCUR(name))) { 1 28 29
1292 1 HV *error_hv = newHV();
1293 1 gql_store_sv(error_hv, "message", newSVpvf(
1294 "Enum value '%s' is defined more than once.", name_str
1295 ));
1296 1 av_push(p->validation_errors, newRV_noinc((SV *)error_hv));
1297 }
1298 35 ▶ if (SvOK(description)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(description)) { 6 29 35
1299 6 HV *dhv = (HV *)SvRV(description);
1300 6 SV **svp = hv_fetch(dhv, "description", 11, 0);
1301 6 gql_store_sv(value_hv, "description", newSVsv(*svp));
1302 }
1303 35 gql_store_sv(values, name_str, newRV_noinc((SV *)value_hv));
1304 35 SvREFCNT_dec(name);
1305 35 ▶ if (SvOK(description)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(description)) { 6 29 35
1306 6 SvREFCNT_dec(description);
1307 }
1308 }
1309 19 gql_expect(aTHX_ p, TOK_RBRACE, NULL);
1310 }
1311 22 gql_store_sv(hv, "values", newRV_noinc((SV *)values));
1312 22 gql_store_sv(hv, "kind", newSVpv("enum", 0));
1313 22 ▶ if (had_directives || had_body) {
Branch: 2 branches
BranchTrueFalseTotal
if (had_directives || had_body) { 20 2 22
if (had_directives || had_body) { 18 2 20
1314 20 gql_store_endline_location(aTHX_ p, hv);
1315 } else {
1316 2 gql_store_current_location(aTHX_ p, hv);
1317 }
1318 22 return newRV_noinc((SV *)hv);
1319 }
1320  
1321 static SV *
1322 137 gql_parse_directive_definition(pTHX_ gql_parser_t *p) {
1323 137 HV *hv = newHV();
1324 137 AV *locations = newAV();
1325 137 gql_advance(aTHX_ p);
1326 137 gql_expect(aTHX_ p, TOK_AT, NULL);
1327 137 gql_store_sv(hv, "name", gql_parse_name(aTHX_ p, "Expected name"));
1328 137 ▶ if (p->kind == TOK_LPAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_LPAREN) { 92 45 137
1329 92 SV *args = gql_parse_arguments_definition(aTHX_ p);
1330 92 HV *ahv = (HV *)SvRV(args);
1331 92 SV **svp = hv_fetch(ahv, "args", 4, 0);
1332 92 gql_store_sv(hv, "args", newSVsv(*svp));
1333 92 SvREFCNT_dec(args);
1334 }
1335 137 ▶ if (gql_peek_name(p, "repeatable")) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_peek_name(p, "repeatable")) { 49 88 137
1336 49 gql_store_sv(hv, "repeatable", newSViv(1));
1337 49 gql_advance(aTHX_ p);
1338 }
1339 137 ▶ if (!gql_peek_name(p, "on")) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_peek_name(p, "on")) { 0 137 137
1340 0 gql_throw(aTHX_ p, p->tok_start, "Expected \"on\"");
1341 }
1342 137 gql_advance(aTHX_ p);
1343 137 ▶ if (p->kind == TOK_PIPE) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_PIPE) { 1 136 137
1344 1 gql_advance(aTHX_ p);
1345 }
1346 137 ▶ if (p->kind != TOK_NAME) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind != TOK_NAME) { 0 137 137
1347 0 gql_throw_expected_message(aTHX_ p, p->tok_start, "Expected name");
1348 }
1349 137 av_push(locations, gql_parse_name(aTHX_ p, "Expected name"));
1350 395 ▶ while (p->kind == TOK_PIPE) {
Branch: 1 branch
BranchTrueFalseTotal
while (p->kind == TOK_PIPE) { 258 137 395
1351 258 gql_advance(aTHX_ p);
1352 258 av_push(locations, gql_parse_name(aTHX_ p, "Expected name"));
1353 }
1354 137 gql_store_sv(hv, "locations", newRV_noinc((SV *)locations));
1355 137 gql_store_sv(hv, "kind", newSVpv("directive", 0));
1356 137 gql_store_endline_location(aTHX_ p, hv);
1357 137 return newRV_noinc((SV *)hv);
1358 }
1359  
1360 static SV *
1361 470 gql_parse_type_system_definition(pTHX_ gql_parser_t *p, SV *description) {
1362 SV *node;
1363 470 int is_extend = 0;
1364 470 ▶ if (gql_peek_name(p, "extend")) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_peek_name(p, "extend")) { 48 422 470
1365 48 is_extend = 1;
1366 48 gql_advance(aTHX_ p);
1367 }
1368 470 ▶ if (gql_peek_name(p, "schema")) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_peek_name(p, "schema")) { 20 450 470
1369 20 node = is_extend
1370 13 ? gql_parse_schema_definition_extended(aTHX_ p, 1)
1371 20 ▶ : gql_parse_schema_definition(aTHX_ p);
Branch: 1 branch
BranchTrueFalseTotal
: gql_parse_schema_definition(aTHX_ p); 13 7 20
1372 450 ▶ } else if (gql_peek_name(p, "scalar")) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (gql_peek_name(p, "scalar")) { 54 396 450
1373 54 node = gql_parse_scalar_type_definition(aTHX_ p);
1374 396 ▶ } else if (gql_peek_name(p, "type")) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (gql_peek_name(p, "type")) { 173 223 396
1375 173 node = gql_parse_object_type_definition(aTHX_ p, "type");
1376 223 ▶ } else if (gql_peek_name(p, "interface")) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (gql_peek_name(p, "interface")) { 18 205 223
1377 18 node = gql_parse_object_type_definition(aTHX_ p, "interface");
1378 205 ▶ } else if (gql_peek_name(p, "input")) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (gql_peek_name(p, "input")) { 24 181 205
1379 24 node = gql_parse_object_type_definition(aTHX_ p, "input");
1380 181 ▶ } else if (gql_peek_name(p, "union")) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (gql_peek_name(p, "union")) { 20 161 181
1381 20 node = gql_parse_union_type_definition(aTHX_ p);
1382 161 ▶ } else if (gql_peek_name(p, "enum")) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (gql_peek_name(p, "enum")) { 22 139 161
1383 22 node = gql_parse_enum_type_definition(aTHX_ p);
1384 139 ▶ } else if (gql_peek_name(p, "directive")) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (gql_peek_name(p, "directive")) { 137 2 139
1385 137 node = gql_parse_directive_definition(aTHX_ p);
1386 } else {
1387 2 gql_throw(aTHX_ p, p->tok_start, "Expected type system definition");
1388 0 return &PL_sv_undef;
1389 }
1390 467 ▶ if (is_extend) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_extend) { 48 419 467
1391 48 HV *node_hv = (HV *)SvRV(node);
1392 48 SV **kind_svp = hv_fetch(node_hv, "kind", 4, 0);
1393 48 int has_content = 0;
1394 48 const char *array_keys[] = { "directives", "interfaces", "types" };
1395 48 const I32 array_lens[] = { 10, 10, 5 };
1396 48 const char *hash_keys[] = { "fields", "values" };
1397 48 const I32 hash_lens[] = { 6, 6 };
1398 int i;
1399 151 ▶ for (i = 0; i < 3 && !has_content; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < 3 && !has_content; i++) { 124 27 151
for (i = 0; i < 3 && !has_content; i++) { 103 21 124
1400 103 SV **svp = hv_fetch(node_hv, array_keys[i], array_lens[i], 0);
1401 126 ▶ has_content = svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVAV
Branch: 2 branches
BranchTrueFalseTotal
has_content = svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVAV 23 0 23
has_content = svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVAV 23 0 23
1402 126 ▶ && av_len((AV *)SvRV(*svp)) >= 0;
Branch: 2 branches
BranchTrueFalseTotal
&& av_len((AV *)SvRV(*svp)) >= 0; 23 80 103
&& av_len((AV *)SvRV(*svp)) >= 0; 23 0 23
1403 }
1404 84 ▶ for (i = 0; i < 2 && !has_content; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < 2 && !has_content; i++) { 73 11 84
for (i = 0; i < 2 && !has_content; i++) { 36 37 73
1405 36 SV **svp = hv_fetch(node_hv, hash_keys[i], hash_lens[i], 0);
1406 57 ▶ has_content = svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV
Branch: 2 branches
BranchTrueFalseTotal
has_content = svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV 21 0 21
has_content = svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV 21 0 21
1407 57 ▶ && HvTOTALKEYS((HV *)SvRV(*svp)) > 0;
Branch: 2 branches
BranchTrueFalseTotal
&& HvTOTALKEYS((HV *)SvRV(*svp)) > 0; 21 15 36
&& HvTOTALKEYS((HV *)SvRV(*svp)) > 0; 17 4 21
1408 }
1409 96 ▶ if (kind_svp && SvOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), "schema")) {
Branch: 3 branches
BranchTrueFalseTotal
if (kind_svp && SvOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), "schema")) { 48 0 48
if (kind_svp && SvOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), "schema")) { 48 0 48
if (kind_svp && SvOK(*kind_svp) && strEQ(SvPV_nolen(*kind_svp), "schema")) { 13 35 48
1410 15 ▶ has_content = has_content || hv_exists(node_hv, "query", 5)
Branch: 1 branch
BranchTrueFalseTotal
has_content = has_content || hv_exists(node_hv, "query", 5) 2 0 2
1411 2 ▶ || hv_exists(node_hv, "mutation", 8)
Branch: 1 branch
BranchTrueFalseTotal
|| hv_exists(node_hv, "mutation", 8) 1 1 2
1412 15 ▶ || hv_exists(node_hv, "subscription", 12);
Branch: 2 branches
BranchTrueFalseTotal
|| hv_exists(node_hv, "subscription", 12); 2 11 13
|| hv_exists(node_hv, "subscription", 12); 0 1 1
1413 }
1414 48 ▶ if (!has_content) {
Branch: 1 branch
BranchTrueFalseTotal
if (!has_content) { 7 41 48
1415 7 SvREFCNT_dec(node);
1416 7 gql_throw(aTHX_ p, p->tok_start, "Type system extension must add a directive or member");
1417 }
1418 41 gql_store_sv(node_hv, "extension", newSViv(1));
1419 }
1420 460 ▶ if (SvOK(description)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(description)) { 65 395 460
1421 65 HV *node_hv = (HV *)SvRV(node);
1422 65 HV *desc_hv = (HV *)SvRV(description);
1423 65 SV **svp = hv_fetch(desc_hv, "description", 11, 0);
1424 65 gql_store_sv(node_hv, "description", newSVsv(*svp));
1425 }
1426 460 ▶ if (SvOK(description)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(description)) { 65 395 460
1427 65 SvREFCNT_dec(description);
1428 }
1429 460 return node;
1430 }
1431  
1432 static SV *
1433 1535 gql_parse_definition(pTHX_ gql_parser_t *p) {
1434 1535 ▶ if (p->kind == TOK_LBRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->kind == TOK_LBRACE) { 681 854 1535
1435 681 return gql_parse_operation_definition(aTHX_ p, &PL_sv_undef);
1436 }
1437 854 ▶ if (p->kind == TOK_STRING || p->kind == TOK_BLOCK_STRING) {
Branch: 2 branches
BranchTrueFalseTotal
if (p->kind == TOK_STRING || p->kind == TOK_BLOCK_STRING) { 845 9 854
if (p->kind == TOK_STRING || p->kind == TOK_BLOCK_STRING) { 63 782 845
1438 72 SV *description = gql_parse_description(aTHX_ p);
1439 72 ▶ if (gql_peek_name(p, "fragment")) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_peek_name(p, "fragment")) { 3 69 72
1440 3 return gql_parse_fragment_definition(aTHX_ p, description);
1441 }
1442 69 ▶ if (gql_peek_name(p, "query") || gql_peek_name(p, "mutation") || gql_peek_name(p, "subscription")) {
Branch: 3 branches
BranchTrueFalseTotal
if (gql_peek_name(p, "query") || gql_peek_name(p, "mutation") || gql_peek_name(p, "subscription")) { 66 3 69
if (gql_peek_name(p, "query") || gql_peek_name(p, "mutation") || gql_peek_name(p, "subscription")) { 66 0 66
if (gql_peek_name(p, "query") || gql_peek_name(p, "mutation") || gql_peek_name(p, "subscription")) { 0 66 66
1443 3 return gql_parse_operation_definition(aTHX_ p, description);
1444 }
1445 66 return gql_parse_type_system_definition(aTHX_ p, description);
1446 }
1447 782 ▶ if (gql_peek_name(p, "fragment")) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_peek_name(p, "fragment")) { 42 740 782
1448 42 return gql_parse_fragment_definition(aTHX_ p, &PL_sv_undef);
1449 }
1450 740 ▶ if (gql_peek_name(p, "query") || gql_peek_name(p, "mutation") || gql_peek_name(p, "subscription")) {
Branch: 3 branches
BranchTrueFalseTotal
if (gql_peek_name(p, "query") || gql_peek_name(p, "mutation") || gql_peek_name(p, "subscription")) { 443 297 740
if (gql_peek_name(p, "query") || gql_peek_name(p, "mutation") || gql_peek_name(p, "subscription")) { 420 23 443
if (gql_peek_name(p, "query") || gql_peek_name(p, "mutation") || gql_peek_name(p, "subscription")) { 16 404 420
1451 336 return gql_parse_operation_definition(aTHX_ p, &PL_sv_undef);
1452 }
1453 404 return gql_parse_type_system_definition(aTHX_ p, &PL_sv_undef);
1454 }
1455  
1456 static AV *
1457 1077 gql_parse_definitions(pTHX_ gql_parser_t *p) {
1458 1077 AV *av = newAV();
1459 2579 ▶ while (p->kind != TOK_EOF) {
Branch: 1 branch
BranchTrueFalseTotal
while (p->kind != TOK_EOF) { 1535 1044 2579
1460 1535 av_push(av, gql_parse_definition(aTHX_ p));
1461 }
1462 1044 return av;
1463 }
1464  
1465 /* A token cannot occupy less than one source byte. Only documents large
1466 * enough to possibly exceed the token cap need this allocation-free
1467 * preflight. Without it, an extremely wide document can exhaust memory
1468 * building its AST before the incremental lexer limit is reached. */
1469 static void
1470 1079 gql_preflight_token_limit(pTHX_ SV *source_sv) {
1471 gql_parser_t scan;
1472  
1473 1079 ▶ if (SvCUR(source_sv) <= GQL_PARSER_MAX_TOKENS) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvCUR(source_sv) <= GQL_PARSER_MAX_TOKENS) { 1077 2 1079
1474 1077 return;
1475 }
1476  
1477 2 gql_parser_init(aTHX_ &scan, source_sv, 1);
1478 do {
1479 1600004 gql_advance(aTHX_ &scan);
1480 1600003 ▶ } while (scan.kind != TOK_EOF);
Branch: 1 branch
BranchTrueFalseTotal
} while (scan.kind != TOK_EOF); 1600002 1 1600003
1481 1 gql_parser_invalidate(&scan);
1482 }
1483  
1484 static SV *
1485 960 gql_parse_document(pTHX_ SV *source_sv, SV *no_location_sv) {
1486 gql_parser_t p;
1487 SV *ret;
1488  
1489 960 ENTER;
1490 960 SAVETMPS;
1491 960 gql_preflight_token_limit(aTHX_ source_sv);
1492 959 gql_parser_init(aTHX_ &p, source_sv, SvTRUE(no_location_sv) ? 1 : 0);
1493 959 gql_advance(aTHX_ &p);
1494 958 ret = newRV_noinc((SV *)gql_parse_definitions(aTHX_ &p));
1495 926 gql_parser_invalidate(&p);
1496 926 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 926 926
1497 926 LEAVE;
1498 926 return ret;
1499 }
1500  
1501 static SV *
1502 119 gql_parse_document_for_validation(
1503 pTHX_ SV *source_sv, SV *no_location_sv, AV *validation_errors
1504 ) {
1505 gql_parser_t p;
1506 SV *ret;
1507  
1508 119 ENTER;
1509 119 SAVETMPS;
1510 119 gql_preflight_token_limit(aTHX_ source_sv);
1511 119 gql_parser_init(aTHX_ &p, source_sv, SvTRUE(no_location_sv) ? 1 : 0);
1512 119 p.validation_errors = validation_errors;
1513 119 gql_advance(aTHX_ &p);
1514 119 ret = newRV_noinc((SV *)gql_parse_definitions(aTHX_ &p));
1515 118 gql_parser_invalidate(&p);
1516 118 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 118 118
1517 118 LEAVE;
1518 118 return ret;
1519 }
« src/schema_compiler.h ↑ Summary blib/lib/GraphQL/Houtou/Role/Composite.pm »