| 1 |
|
| |
| 2 |
|
| static void * |
| 3 |
0 |
| gql_ir_arena_alloc_zero(gql_ir_arena_t *arena, Size_t size) { |
| 4 |
|
| gql_ir_arena_chunk_t *chunk; |
| 5 |
|
| Size_t aligned_used; |
| 6 |
|
| Size_t next_used; |
| 7 |
|
| Size_t chunk_cap; |
| 8 |
|
| char *ptr; |
| 9 |
|
| |
| 10 |
0 |
| chunk = arena->tail; |
| 11 |
0 |
▶ | aligned_used = chunk ? ((chunk->used + sizeof(void *) - 1) & ~(sizeof(void *) - 1)) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| aligned_used = chunk ? ((chunk->used + sizeof(void *) - 1) & ~(sizeof(void *) - 1)) : 0; |
0 |
0 |
0 |
|
| 12 |
0 |
| next_used = aligned_used + size; |
| 13 |
0 |
▶ | if (!chunk || next_used > chunk->cap) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!chunk || next_used > chunk->cap) { |
0 |
0 |
0 |
| if (!chunk || next_used > chunk->cap) { |
0 |
0 |
0 |
|
| 14 |
0 |
| chunk_cap = 4096; |
| 15 |
0 |
▶ | while (chunk_cap < size) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (chunk_cap < size) { |
0 |
0 |
0 |
|
| 16 |
0 |
| chunk_cap *= 2; |
| 17 |
|
| } |
| 18 |
0 |
| Newxz(chunk, 1, gql_ir_arena_chunk_t); |
| 19 |
0 |
| Newx(chunk->buf, chunk_cap, char); |
| 20 |
0 |
| chunk->cap = chunk_cap; |
| 21 |
0 |
▶ | if (arena->tail) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (arena->tail) { |
0 |
0 |
0 |
|
| 22 |
0 |
| arena->tail->next = chunk; |
| 23 |
|
| } else { |
| 24 |
0 |
| arena->head = chunk; |
| 25 |
|
| } |
| 26 |
0 |
| arena->tail = chunk; |
| 27 |
0 |
| aligned_used = 0; |
| 28 |
0 |
| next_used = size; |
| 29 |
|
| } |
| 30 |
0 |
| ptr = chunk->buf + aligned_used; |
| 31 |
0 |
| Zero(ptr, size, char); |
| 32 |
0 |
| chunk->used = next_used; |
| 33 |
0 |
| return ptr; |
| 34 |
|
| } |
| 35 |
|
| |
| 36 |
|
| static void |
| 37 |
0 |
| gql_ir_arena_free(gql_ir_arena_t *arena) { |
| 38 |
0 |
| gql_ir_arena_chunk_t *chunk = arena->head; |
| 39 |
|
| |
| 40 |
0 |
▶ | while (chunk) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (chunk) { |
0 |
0 |
0 |
|
| 41 |
0 |
| gql_ir_arena_chunk_t *next = chunk->next; |
| 42 |
0 |
▶ | if (chunk->buf) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (chunk->buf) { |
0 |
0 |
0 |
|
| 43 |
0 |
| Safefree(chunk->buf); |
| 44 |
|
| } |
| 45 |
0 |
| Safefree(chunk); |
| 46 |
0 |
| chunk = next; |
| 47 |
|
| } |
| 48 |
0 |
| arena->head = NULL; |
| 49 |
0 |
| arena->tail = NULL; |
| 50 |
0 |
| } |
| 51 |
|
| |
| 52 |
|
| static void |
| 53 |
0 |
| gql_ir_ptr_array_push(gql_ir_ptr_array_t *array, void *item) { |
| 54 |
0 |
▶ | if (array->count == array->cap) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (array->count == array->cap) { |
0 |
0 |
0 |
|
| 55 |
0 |
▶ | I32 next_cap = array->cap ? array->cap * 2 : 4; |
Branch: 1 branch
| Branch | True | False | Total |
| I32 next_cap = array->cap ? array->cap * 2 : 4; |
0 |
0 |
0 |
|
| 56 |
0 |
| Renew(array->items, next_cap, void *); |
| 57 |
0 |
| array->cap = next_cap; |
| 58 |
|
| } |
| 59 |
0 |
| array->items[array->count++] = item; |
| 60 |
0 |
| } |
| 61 |
|
| |
| 62 |
|
| static void |
| 63 |
0 |
| gql_ir_ptr_array_free(gql_ir_ptr_array_t *array) { |
| 64 |
0 |
▶ | if (array->items) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (array->items) { |
0 |
0 |
0 |
|
| 65 |
0 |
| Safefree(array->items); |
| 66 |
|
| } |
| 67 |
0 |
| array->items = NULL; |
| 68 |
0 |
| array->count = 0; |
| 69 |
0 |
| array->cap = 0; |
| 70 |
0 |
| } |
| 71 |
|
| |
| 72 |
|
| static gql_ir_type_t * |
| 73 |
0 |
| gql_ir_parse_type_reference(pTHX_ gql_parser_t *p) { |
| 74 |
|
| gql_ir_type_t *type; |
| 75 |
0 |
| UV start_pos = (UV)p->tok_start; |
| 76 |
|
| |
| 77 |
0 |
| type = (gql_ir_type_t *)gql_ir_arena_alloc_zero(p->ir_arena, sizeof(gql_ir_type_t)); |
| 78 |
0 |
| type->start_pos = start_pos; |
| 79 |
0 |
▶ | if (p->kind == TOK_LBRACKET) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p->kind == TOK_LBRACKET) { |
0 |
0 |
0 |
|
| 80 |
0 |
| type->kind = GQL_IR_TYPE_LIST; |
| 81 |
0 |
| gql_advance(aTHX_ p); |
| 82 |
0 |
| type->inner = gql_ir_parse_type_reference(aTHX_ p); |
| 83 |
0 |
| gql_expect(aTHX_ p, TOK_RBRACKET, NULL); |
| 84 |
|
| } else { |
| 85 |
0 |
| type->kind = GQL_IR_TYPE_NAMED; |
| 86 |
0 |
| type->name = gql_ir_parse_name_span(aTHX_ p, "Expected name"); |
| 87 |
|
| } |
| 88 |
|
| |
| 89 |
0 |
▶ | if (p->kind == TOK_BANG) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p->kind == TOK_BANG) { |
0 |
0 |
0 |
|
| 90 |
|
| gql_ir_type_t *wrapped; |
| 91 |
0 |
| gql_advance(aTHX_ p); |
| 92 |
0 |
| wrapped = (gql_ir_type_t *)gql_ir_arena_alloc_zero(p->ir_arena, sizeof(gql_ir_type_t)); |
| 93 |
0 |
| wrapped->kind = GQL_IR_TYPE_NON_NULL; |
| 94 |
0 |
| wrapped->start_pos = type->start_pos; |
| 95 |
0 |
| wrapped->inner = type; |
| 96 |
0 |
| type = wrapped; |
| 97 |
|
| } |
| 98 |
|
| |
| 99 |
0 |
| return type; |
| 100 |
|
| } |
| 101 |
|
| |
| 102 |
|
| static gql_ir_value_t * |
| 103 |
0 |
| gql_ir_parse_value(pTHX_ gql_parser_t *p, int is_const) { |
| 104 |
|
| gql_ir_value_t *value; |
| 105 |
0 |
| UV start_pos = (UV)p->tok_start; |
| 106 |
|
| |
| 107 |
0 |
| value = (gql_ir_value_t *)gql_ir_arena_alloc_zero(p->ir_arena, sizeof(gql_ir_value_t)); |
| 108 |
0 |
| value->start_pos = start_pos; |
| 109 |
0 |
| switch (p->kind) { |
| 110 |
0 |
| case TOK_DOLLAR: |
| 111 |
0 |
▶ | if (is_const) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_const) { |
0 |
0 |
0 |
|
| 112 |
0 |
| gql_throw(aTHX_ p, p->tok_start, "Expected name or constant"); |
| 113 |
|
| } |
| 114 |
0 |
| value->kind = GQL_IR_VALUE_VARIABLE; |
| 115 |
0 |
| gql_advance(aTHX_ p); |
| 116 |
0 |
| value->name_pos = (UV)p->tok_start; |
| 117 |
0 |
| value->as.span = gql_ir_parse_name_span(aTHX_ p, "Expected name"); |
| 118 |
0 |
| return value; |
| 119 |
0 |
| case TOK_INT: |
| 120 |
0 |
| value->kind = GQL_IR_VALUE_INT; |
| 121 |
0 |
| value->as.span.start = (UV)p->tok_start; |
| 122 |
0 |
| value->as.span.end = (UV)p->tok_end; |
| 123 |
0 |
| gql_advance(aTHX_ p); |
| 124 |
0 |
| return value; |
| 125 |
0 |
| case TOK_FLOAT: |
| 126 |
0 |
| value->kind = GQL_IR_VALUE_FLOAT; |
| 127 |
0 |
| value->as.span.start = (UV)p->tok_start; |
| 128 |
0 |
| value->as.span.end = (UV)p->tok_end; |
| 129 |
0 |
| gql_advance(aTHX_ p); |
| 130 |
0 |
| return value; |
| 131 |
0 |
| case TOK_STRING: |
| 132 |
|
| case TOK_BLOCK_STRING: |
| 133 |
0 |
| value->kind = GQL_IR_VALUE_STRING; |
| 134 |
0 |
| value->is_block_string = p->kind == TOK_BLOCK_STRING ? 1 : 0; |
| 135 |
0 |
| value->as.span.start = (UV)p->val_start; |
| 136 |
0 |
| value->as.span.end = (UV)p->val_end; |
| 137 |
0 |
| gql_advance(aTHX_ p); |
| 138 |
0 |
| return value; |
| 139 |
0 |
| case TOK_NAME: |
| 140 |
0 |
▶ | if (gql_peek_name(p, "true")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (gql_peek_name(p, "true")) { |
0 |
0 |
0 |
|
| 141 |
0 |
| value->kind = GQL_IR_VALUE_BOOL; |
| 142 |
0 |
| value->as.boolean = 1; |
| 143 |
0 |
| gql_advance(aTHX_ p); |
| 144 |
0 |
| return value; |
| 145 |
|
| } |
| 146 |
0 |
▶ | if (gql_peek_name(p, "false")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (gql_peek_name(p, "false")) { |
0 |
0 |
0 |
|
| 147 |
0 |
| value->kind = GQL_IR_VALUE_BOOL; |
| 148 |
0 |
| value->as.boolean = 0; |
| 149 |
0 |
| gql_advance(aTHX_ p); |
| 150 |
0 |
| return value; |
| 151 |
|
| } |
| 152 |
0 |
▶ | if (gql_peek_name(p, "null")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (gql_peek_name(p, "null")) { |
0 |
0 |
0 |
|
| 153 |
0 |
| value->kind = GQL_IR_VALUE_NULL; |
| 154 |
0 |
| gql_advance(aTHX_ p); |
| 155 |
0 |
| return value; |
| 156 |
|
| } |
| 157 |
0 |
| value->kind = GQL_IR_VALUE_ENUM; |
| 158 |
0 |
| value->as.span.start = (UV)p->tok_start; |
| 159 |
0 |
| value->as.span.end = (UV)p->tok_end; |
| 160 |
0 |
| gql_advance(aTHX_ p); |
| 161 |
0 |
| return value; |
| 162 |
0 |
| case TOK_LBRACKET: |
| 163 |
0 |
| value->kind = GQL_IR_VALUE_LIST; |
| 164 |
0 |
| gql_expect(aTHX_ p, TOK_LBRACKET, NULL); |
| 165 |
0 |
▶ | while (p->kind != TOK_RBRACKET) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p->kind != TOK_RBRACKET) { |
0 |
0 |
0 |
|
| 166 |
0 |
| gql_ir_ptr_array_push(&value->as.list_items, gql_ir_parse_value(aTHX_ p, is_const)); |
| 167 |
|
| } |
| 168 |
0 |
| gql_expect(aTHX_ p, TOK_RBRACKET, NULL); |
| 169 |
0 |
| return value; |
| 170 |
0 |
| case TOK_LBRACE: |
| 171 |
0 |
| value->kind = GQL_IR_VALUE_OBJECT; |
| 172 |
0 |
| gql_expect(aTHX_ p, TOK_LBRACE, "Expected name"); |
| 173 |
0 |
▶ | while (p->kind != TOK_RBRACE) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p->kind != TOK_RBRACE) { |
0 |
0 |
0 |
|
| 174 |
|
| gql_ir_object_field_t *field; |
| 175 |
0 |
| field = (gql_ir_object_field_t *)gql_ir_arena_alloc_zero(p->ir_arena, sizeof(gql_ir_object_field_t)); |
| 176 |
0 |
| field->start_pos = (UV)p->tok_start; |
| 177 |
0 |
| field->name = gql_ir_parse_name_span(aTHX_ p, "Expected name"); |
| 178 |
0 |
| gql_expect(aTHX_ p, TOK_COLON, NULL); |
| 179 |
0 |
| field->value = gql_ir_parse_value(aTHX_ p, is_const); |
| 180 |
0 |
| gql_ir_ptr_array_push(&value->as.object_fields, field); |
| 181 |
|
| } |
| 182 |
0 |
| gql_expect(aTHX_ p, TOK_RBRACE, NULL); |
| 183 |
0 |
| return value; |
| 184 |
0 |
| default: |
| 185 |
0 |
▶ | gql_throw(aTHX_ p, p->tok_start, is_const ? "Expected name or constant" : "Expected value"); |
Branch: 1 branch
| Branch | True | False | Total |
| gql_throw(aTHX_ p, p->tok_start, is_const ? "Expected name or constant" : "Expected value"); |
0 |
0 |
0 |
|
| 186 |
|
| } |
| 187 |
0 |
| return NULL; |
| 188 |
|
| } |
| 189 |
|
| |
| 190 |
|
| static gql_ir_ptr_array_t |
| 191 |
0 |
| gql_ir_parse_arguments(pTHX_ gql_parser_t *p, int is_const) { |
| 192 |
0 |
| gql_ir_ptr_array_t arguments = { 0, 0, NULL }; |
| 193 |
|
| |
| 194 |
0 |
| gql_expect(aTHX_ p, TOK_LPAREN, NULL); |
| 195 |
0 |
▶ | if (p->kind == TOK_RPAREN) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p->kind == TOK_RPAREN) { |
0 |
0 |
0 |
|
| 196 |
0 |
| gql_throw_expected_message(aTHX_ p, p->tok_start, "Expected name"); |
| 197 |
|
| } |
| 198 |
0 |
▶ | while (p->kind != TOK_RPAREN) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p->kind != TOK_RPAREN) { |
0 |
0 |
0 |
|
| 199 |
|
| gql_ir_argument_t *argument; |
| 200 |
0 |
| argument = (gql_ir_argument_t *)gql_ir_arena_alloc_zero(p->ir_arena, sizeof(gql_ir_argument_t)); |
| 201 |
0 |
| argument->start_pos = (UV)p->tok_start; |
| 202 |
0 |
| argument->name = gql_ir_parse_name_span(aTHX_ p, "Expected name"); |
| 203 |
0 |
| gql_expect(aTHX_ p, TOK_COLON, NULL); |
| 204 |
0 |
| argument->value = gql_ir_parse_value(aTHX_ p, is_const); |
| 205 |
0 |
| gql_ir_ptr_array_push(&arguments, argument); |
| 206 |
|
| } |
| 207 |
0 |
| gql_expect(aTHX_ p, TOK_RPAREN, NULL); |
| 208 |
0 |
| return arguments; |
| 209 |
|
| } |
| 210 |
|
| |
| 211 |
|
| static gql_ir_ptr_array_t |
| 212 |
0 |
| gql_ir_parse_directives(pTHX_ gql_parser_t *p) { |
| 213 |
0 |
| gql_ir_ptr_array_t directives = { 0, 0, NULL }; |
| 214 |
|
| |
| 215 |
0 |
▶ | while (p->kind == TOK_AT) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p->kind == TOK_AT) { |
0 |
0 |
0 |
|
| 216 |
|
| gql_ir_directive_t *directive; |
| 217 |
0 |
| directive = (gql_ir_directive_t *)gql_ir_arena_alloc_zero(p->ir_arena, sizeof(gql_ir_directive_t)); |
| 218 |
0 |
| directive->start_pos = (UV)p->tok_start; |
| 219 |
0 |
| gql_expect(aTHX_ p, TOK_AT, NULL); |
| 220 |
0 |
| directive->name_pos = (UV)p->tok_start; |
| 221 |
0 |
| directive->name = gql_ir_parse_name_span(aTHX_ p, "Expected name"); |
| 222 |
0 |
▶ | if (p->kind == TOK_LPAREN) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p->kind == TOK_LPAREN) { |
0 |
0 |
0 |
|
| 223 |
0 |
| directive->arguments = gql_ir_parse_arguments(aTHX_ p, 0); |
| 224 |
|
| } |
| 225 |
0 |
| gql_ir_ptr_array_push(&directives, directive); |
| 226 |
|
| } |
| 227 |
|
| |
| 228 |
0 |
| return directives; |
| 229 |
|
| } |
| 230 |
|
| |
| 231 |
|
| static gql_ir_selection_set_t * |
| 232 |
0 |
| gql_ir_parse_selection_set(pTHX_ gql_parser_t *p) { |
| 233 |
|
| gql_ir_selection_set_t *selection_set; |
| 234 |
|
| |
| 235 |
0 |
| selection_set = (gql_ir_selection_set_t *)gql_ir_arena_alloc_zero(p->ir_arena, sizeof(gql_ir_selection_set_t)); |
| 236 |
0 |
| selection_set->start_pos = (UV)p->tok_start; |
| 237 |
0 |
| gql_expect(aTHX_ p, TOK_LBRACE, "Expected name"); |
| 238 |
0 |
▶ | if (p->kind == TOK_RBRACE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p->kind == TOK_RBRACE) { |
0 |
0 |
0 |
|
| 239 |
0 |
| gql_throw(aTHX_ p, p->tok_start, "Expected name"); |
| 240 |
|
| } |
| 241 |
0 |
▶ | while (p->kind != TOK_RBRACE) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p->kind != TOK_RBRACE) { |
0 |
0 |
0 |
|
| 242 |
0 |
| gql_ir_ptr_array_push(&selection_set->selections, gql_ir_parse_selection(aTHX_ p)); |
| 243 |
|
| } |
| 244 |
0 |
| gql_expect(aTHX_ p, TOK_RBRACE, NULL); |
| 245 |
0 |
| return selection_set; |
| 246 |
|
| } |
| 247 |
|
| |
| 248 |
|
| static gql_ir_selection_t * |
| 249 |
0 |
| gql_ir_parse_selection(pTHX_ gql_parser_t *p) { |
| 250 |
|
| gql_ir_selection_t *selection; |
| 251 |
|
| |
| 252 |
0 |
| selection = (gql_ir_selection_t *)gql_ir_arena_alloc_zero(p->ir_arena, sizeof(gql_ir_selection_t)); |
| 253 |
0 |
▶ | if (p->kind == TOK_SPREAD) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p->kind == TOK_SPREAD) { |
0 |
0 |
0 |
|
| 254 |
0 |
| UV spread_start = (UV)p->tok_start; |
| 255 |
0 |
| gql_advance(aTHX_ p); |
| 256 |
0 |
▶ | if (gql_peek_name(p, "on")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (gql_peek_name(p, "on")) { |
0 |
0 |
0 |
|
| 257 |
0 |
| gql_parser_t lookahead = *p; |
| 258 |
|
| gql_ir_inline_fragment_t *fragment; |
| 259 |
0 |
| gql_advance(aTHX_ &lookahead); |
| 260 |
0 |
▶ | if (lookahead.kind != TOK_NAME) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (lookahead.kind != TOK_NAME) { |
0 |
0 |
0 |
|
| 261 |
0 |
| gql_throw(aTHX_ p, p->tok_start, "Unexpected Name \"on\""); |
| 262 |
|
| } |
| 263 |
0 |
| selection->kind = GQL_IR_SELECTION_INLINE_FRAGMENT; |
| 264 |
0 |
| fragment = (gql_ir_inline_fragment_t *)gql_ir_arena_alloc_zero(p->ir_arena, sizeof(gql_ir_inline_fragment_t)); |
| 265 |
0 |
| fragment->start_pos = spread_start; |
| 266 |
0 |
| gql_advance(aTHX_ p); |
| 267 |
0 |
| fragment->type_condition_pos = (UV)p->tok_start; |
| 268 |
0 |
| fragment->type_condition = gql_ir_parse_name_span(aTHX_ p, "Expected name"); |
| 269 |
0 |
▶ | if (p->kind == TOK_AT) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p->kind == TOK_AT) { |
0 |
0 |
0 |
|
| 270 |
0 |
| fragment->directives = gql_ir_parse_directives(aTHX_ p); |
| 271 |
|
| } |
| 272 |
0 |
| fragment->selection_set = gql_ir_parse_selection_set(aTHX_ p); |
| 273 |
0 |
| selection->as.inline_fragment = fragment; |
| 274 |
0 |
| return selection; |
| 275 |
|
| } |
| 276 |
0 |
▶ | if (p->kind == TOK_LBRACE || p->kind == TOK_AT) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (p->kind == TOK_LBRACE || p->kind == TOK_AT) { |
0 |
0 |
0 |
| if (p->kind == TOK_LBRACE || p->kind == TOK_AT) { |
0 |
0 |
0 |
|
| 277 |
|
| gql_ir_inline_fragment_t *fragment; |
| 278 |
0 |
| selection->kind = GQL_IR_SELECTION_INLINE_FRAGMENT; |
| 279 |
0 |
| fragment = (gql_ir_inline_fragment_t *)gql_ir_arena_alloc_zero(p->ir_arena, sizeof(gql_ir_inline_fragment_t)); |
| 280 |
0 |
| fragment->start_pos = spread_start; |
| 281 |
0 |
▶ | if (p->kind == TOK_AT) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p->kind == TOK_AT) { |
0 |
0 |
0 |
|
| 282 |
0 |
| fragment->directives = gql_ir_parse_directives(aTHX_ p); |
| 283 |
|
| } |
| 284 |
0 |
| fragment->selection_set = gql_ir_parse_selection_set(aTHX_ p); |
| 285 |
0 |
| selection->as.inline_fragment = fragment; |
| 286 |
0 |
| return selection; |
| 287 |
|
| } |
| 288 |
|
| { |
| 289 |
|
| gql_ir_fragment_spread_t *spread; |
| 290 |
0 |
| selection->kind = GQL_IR_SELECTION_FRAGMENT_SPREAD; |
| 291 |
0 |
| spread = (gql_ir_fragment_spread_t *)gql_ir_arena_alloc_zero(p->ir_arena, sizeof(gql_ir_fragment_spread_t)); |
| 292 |
0 |
| spread->start_pos = spread_start; |
| 293 |
0 |
| spread->name_pos = (UV)p->tok_start; |
| 294 |
0 |
| spread->name = gql_ir_parse_fragment_name_span(aTHX_ p); |
| 295 |
0 |
▶ | if (p->kind == TOK_AT) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p->kind == TOK_AT) { |
0 |
0 |
0 |
|
| 296 |
0 |
| spread->directives = gql_ir_parse_directives(aTHX_ p); |
| 297 |
|
| } |
| 298 |
0 |
| selection->as.fragment_spread = spread; |
| 299 |
0 |
| return selection; |
| 300 |
|
| } |
| 301 |
|
| } |
| 302 |
|
| |
| 303 |
|
| { |
| 304 |
|
| gql_ir_field_t *field; |
| 305 |
|
| gql_ir_span_t first_name; |
| 306 |
0 |
| selection->kind = GQL_IR_SELECTION_FIELD; |
| 307 |
0 |
| field = (gql_ir_field_t *)gql_ir_arena_alloc_zero(p->ir_arena, sizeof(gql_ir_field_t)); |
| 308 |
0 |
| field->start_pos = (UV)p->tok_start; |
| 309 |
0 |
| field->name_pos = (UV)p->tok_start; |
| 310 |
0 |
| first_name = gql_ir_parse_name_span(aTHX_ p, "Expected name"); |
| 311 |
0 |
▶ | if (p->kind == TOK_COLON) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p->kind == TOK_COLON) { |
0 |
0 |
0 |
|
| 312 |
0 |
| field->alias_pos = field->name_pos; |
| 313 |
0 |
| field->alias = first_name; |
| 314 |
0 |
| gql_advance(aTHX_ p); |
| 315 |
0 |
| field->name_pos = (UV)p->tok_start; |
| 316 |
0 |
| field->name = gql_ir_parse_name_span(aTHX_ p, "Expected name"); |
| 317 |
|
| } else { |
| 318 |
0 |
| field->name = first_name; |
| 319 |
|
| } |
| 320 |
0 |
▶ | if (p->kind == TOK_LPAREN) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p->kind == TOK_LPAREN) { |
0 |
0 |
0 |
|
| 321 |
0 |
| field->arguments = gql_ir_parse_arguments(aTHX_ p, 0); |
| 322 |
|
| } |
| 323 |
0 |
▶ | if (p->kind == TOK_AT) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p->kind == TOK_AT) { |
0 |
0 |
0 |
|
| 324 |
0 |
| field->directives = gql_ir_parse_directives(aTHX_ p); |
| 325 |
|
| } |
| 326 |
0 |
▶ | if (p->kind == TOK_LBRACE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p->kind == TOK_LBRACE) { |
0 |
0 |
0 |
|
| 327 |
0 |
| field->selection_set = gql_ir_parse_selection_set(aTHX_ p); |
| 328 |
|
| } |
| 329 |
0 |
| selection->as.field = field; |
| 330 |
0 |
| return selection; |
| 331 |
|
| } |
| 332 |
|
| } |
| 333 |
|
| |
| 334 |
|
| static void |
| 335 |
0 |
| gql_ir_free_type(gql_ir_type_t *type) { |
| 336 |
0 |
▶ | if (!type) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!type) { |
0 |
0 |
0 |
|
| 337 |
0 |
| return; |
| 338 |
|
| } |
| 339 |
0 |
| gql_ir_free_type(type->inner); |
| 340 |
|
| } |
| 341 |
|
| |
| 342 |
|
| static void |
| 343 |
0 |
| gql_ir_free_argument(gql_ir_argument_t *argument) { |
| 344 |
0 |
▶ | if (!argument) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!argument) { |
0 |
0 |
0 |
|
| 345 |
0 |
| return; |
| 346 |
|
| } |
| 347 |
0 |
| gql_ir_free_value(argument->value); |
| 348 |
|
| } |
| 349 |
|
| |
| 350 |
|
| static void |
| 351 |
0 |
| gql_ir_free_object_field(gql_ir_object_field_t *field) { |
| 352 |
0 |
▶ | if (!field) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!field) { |
0 |
0 |
0 |
|
| 353 |
0 |
| return; |
| 354 |
|
| } |
| 355 |
0 |
| gql_ir_free_value(field->value); |
| 356 |
|
| } |
| 357 |
|
| |
| 358 |
|
| static void |
| 359 |
0 |
| gql_ir_free_value(gql_ir_value_t *value) { |
| 360 |
|
| I32 i; |
| 361 |
|
| |
| 362 |
0 |
▶ | if (!value) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!value) { |
0 |
0 |
0 |
|
| 363 |
0 |
| return; |
| 364 |
|
| } |
| 365 |
0 |
| switch (value->kind) { |
| 366 |
0 |
| case GQL_IR_VALUE_LIST: |
| 367 |
0 |
▶ | for (i = 0; i < value->as.list_items.count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < value->as.list_items.count; i++) { |
0 |
0 |
0 |
|
| 368 |
0 |
| gql_ir_free_value((gql_ir_value_t *)value->as.list_items.items[i]); |
| 369 |
|
| } |
| 370 |
0 |
| gql_ir_ptr_array_free(&value->as.list_items); |
| 371 |
0 |
| break; |
| 372 |
0 |
| case GQL_IR_VALUE_OBJECT: |
| 373 |
0 |
▶ | for (i = 0; i < value->as.object_fields.count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < value->as.object_fields.count; i++) { |
0 |
0 |
0 |
|
| 374 |
0 |
| gql_ir_free_object_field((gql_ir_object_field_t *)value->as.object_fields.items[i]); |
| 375 |
|
| } |
| 376 |
0 |
| gql_ir_ptr_array_free(&value->as.object_fields); |
| 377 |
0 |
| break; |
| 378 |
0 |
| default: |
| 379 |
0 |
| break; |
| 380 |
|
| } |
| 381 |
|
| } |
| 382 |
|
| |
| 383 |
|
| static void |
| 384 |
0 |
| gql_ir_free_directive(gql_ir_directive_t *directive) { |
| 385 |
|
| I32 i; |
| 386 |
|
| |
| 387 |
0 |
▶ | if (!directive) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!directive) { |
0 |
0 |
0 |
|
| 388 |
0 |
| return; |
| 389 |
|
| } |
| 390 |
0 |
▶ | for (i = 0; i < directive->arguments.count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < directive->arguments.count; i++) { |
0 |
0 |
0 |
|
| 391 |
0 |
| gql_ir_free_argument((gql_ir_argument_t *)directive->arguments.items[i]); |
| 392 |
|
| } |
| 393 |
0 |
| gql_ir_ptr_array_free(&directive->arguments); |
| 394 |
|
| } |
| 395 |
|
| |
| 396 |
|
| static void |
| 397 |
0 |
| gql_ir_free_variable_definition(gql_ir_variable_definition_t *definition) { |
| 398 |
|
| I32 i; |
| 399 |
|
| |
| 400 |
0 |
▶ | if (!definition) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!definition) { |
0 |
0 |
0 |
|
| 401 |
0 |
| return; |
| 402 |
|
| } |
| 403 |
0 |
| gql_ir_free_type(definition->type); |
| 404 |
0 |
| gql_ir_free_value(definition->default_value); |
| 405 |
0 |
▶ | for (i = 0; i < definition->directives.count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < definition->directives.count; i++) { |
0 |
0 |
0 |
|
| 406 |
0 |
| gql_ir_free_directive((gql_ir_directive_t *)definition->directives.items[i]); |
| 407 |
|
| } |
| 408 |
0 |
| gql_ir_ptr_array_free(&definition->directives); |
| 409 |
|
| } |
| 410 |
|
| |
| 411 |
|
| static void |
| 412 |
0 |
| gql_ir_free_selection_set(gql_ir_selection_set_t *selection_set) { |
| 413 |
|
| I32 i; |
| 414 |
|
| |
| 415 |
0 |
▶ | if (!selection_set) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!selection_set) { |
0 |
0 |
0 |
|
| 416 |
0 |
| return; |
| 417 |
|
| } |
| 418 |
0 |
▶ | for (i = 0; i < selection_set->selections.count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < selection_set->selections.count; i++) { |
0 |
0 |
0 |
|
| 419 |
0 |
| gql_ir_free_selection((gql_ir_selection_t *)selection_set->selections.items[i]); |
| 420 |
|
| } |
| 421 |
0 |
| gql_ir_ptr_array_free(&selection_set->selections); |
| 422 |
|
| } |
| 423 |
|
| |
| 424 |
|
| static void |
| 425 |
0 |
| gql_ir_free_selection(gql_ir_selection_t *selection) { |
| 426 |
0 |
▶ | if (!selection) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!selection) { |
0 |
0 |
0 |
|
| 427 |
0 |
| return; |
| 428 |
|
| } |
| 429 |
0 |
| switch (selection->kind) { |
| 430 |
0 |
| case GQL_IR_SELECTION_FIELD: |
| 431 |
0 |
▶ | if (selection->as.field) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (selection->as.field) { |
0 |
0 |
0 |
|
| 432 |
0 |
| gql_ir_field_t *field = selection->as.field; |
| 433 |
|
| I32 i; |
| 434 |
0 |
▶ | for (i = 0; i < field->arguments.count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < field->arguments.count; i++) { |
0 |
0 |
0 |
|
| 435 |
0 |
| gql_ir_free_argument((gql_ir_argument_t *)field->arguments.items[i]); |
| 436 |
|
| } |
| 437 |
0 |
| gql_ir_ptr_array_free(&field->arguments); |
| 438 |
0 |
▶ | for (i = 0; i < field->directives.count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < field->directives.count; i++) { |
0 |
0 |
0 |
|
| 439 |
0 |
| gql_ir_free_directive((gql_ir_directive_t *)field->directives.items[i]); |
| 440 |
|
| } |
| 441 |
0 |
| gql_ir_ptr_array_free(&field->directives); |
| 442 |
0 |
| gql_ir_free_selection_set(field->selection_set); |
| 443 |
|
| } |
| 444 |
0 |
| break; |
| 445 |
0 |
| case GQL_IR_SELECTION_FRAGMENT_SPREAD: |
| 446 |
0 |
▶ | if (selection->as.fragment_spread) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (selection->as.fragment_spread) { |
0 |
0 |
0 |
|
| 447 |
0 |
| gql_ir_fragment_spread_t *spread = selection->as.fragment_spread; |
| 448 |
|
| I32 i; |
| 449 |
0 |
▶ | for (i = 0; i < spread->directives.count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < spread->directives.count; i++) { |
0 |
0 |
0 |
|
| 450 |
0 |
| gql_ir_free_directive((gql_ir_directive_t *)spread->directives.items[i]); |
| 451 |
|
| } |
| 452 |
0 |
| gql_ir_ptr_array_free(&spread->directives); |
| 453 |
|
| } |
| 454 |
0 |
| break; |
| 455 |
0 |
| case GQL_IR_SELECTION_INLINE_FRAGMENT: |
| 456 |
0 |
▶ | if (selection->as.inline_fragment) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (selection->as.inline_fragment) { |
0 |
0 |
0 |
|
| 457 |
0 |
| gql_ir_inline_fragment_t *fragment = selection->as.inline_fragment; |
| 458 |
|
| I32 i; |
| 459 |
0 |
▶ | for (i = 0; i < fragment->directives.count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < fragment->directives.count; i++) { |
0 |
0 |
0 |
|
| 460 |
0 |
| gql_ir_free_directive((gql_ir_directive_t *)fragment->directives.items[i]); |
| 461 |
|
| } |
| 462 |
0 |
| gql_ir_ptr_array_free(&fragment->directives); |
| 463 |
0 |
| gql_ir_free_selection_set(fragment->selection_set); |
| 464 |
|
| } |
| 465 |
0 |
| break; |
| 466 |
|
| } |
| 467 |
|
| } |
| 468 |
|
| |
| 469 |
|
| static void |
| 470 |
0 |
| gql_ir_free_operation_definition(gql_ir_operation_definition_t *definition) { |
| 471 |
|
| I32 i; |
| 472 |
|
| |
| 473 |
0 |
▶ | if (!definition) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!definition) { |
0 |
0 |
0 |
|
| 474 |
0 |
| return; |
| 475 |
|
| } |
| 476 |
0 |
▶ | for (i = 0; i < definition->variable_definitions.count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < definition->variable_definitions.count; i++) { |
0 |
0 |
0 |
|
| 477 |
0 |
| gql_ir_free_variable_definition((gql_ir_variable_definition_t *)definition->variable_definitions.items[i]); |
| 478 |
|
| } |
| 479 |
0 |
| gql_ir_ptr_array_free(&definition->variable_definitions); |
| 480 |
0 |
▶ | for (i = 0; i < definition->directives.count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < definition->directives.count; i++) { |
0 |
0 |
0 |
|
| 481 |
0 |
| gql_ir_free_directive((gql_ir_directive_t *)definition->directives.items[i]); |
| 482 |
|
| } |
| 483 |
0 |
| gql_ir_ptr_array_free(&definition->directives); |
| 484 |
0 |
| gql_ir_free_selection_set(definition->selection_set); |
| 485 |
|
| } |
| 486 |
|
| |
| 487 |
|
| static void |
| 488 |
0 |
| gql_ir_free_fragment_definition(gql_ir_fragment_definition_t *definition) { |
| 489 |
|
| I32 i; |
| 490 |
|
| |
| 491 |
0 |
▶ | if (!definition) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!definition) { |
0 |
0 |
0 |
|
| 492 |
0 |
| return; |
| 493 |
|
| } |
| 494 |
0 |
▶ | for (i = 0; i < definition->directives.count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < definition->directives.count; i++) { |
0 |
0 |
0 |
|
| 495 |
0 |
| gql_ir_free_directive((gql_ir_directive_t *)definition->directives.items[i]); |
| 496 |
|
| } |
| 497 |
0 |
| gql_ir_ptr_array_free(&definition->directives); |
| 498 |
0 |
| gql_ir_free_selection_set(definition->selection_set); |
| 499 |
|
| } |
| 500 |
|
| |
| 501 |
|
| static void |
| 502 |
0 |
| gql_ir_free_definition(gql_ir_definition_t *definition) { |
| 503 |
0 |
▶ | if (!definition) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!definition) { |
0 |
0 |
0 |
|
| 504 |
0 |
| return; |
| 505 |
|
| } |
| 506 |
0 |
▶ | if (definition->kind == GQL_IR_DEFINITION_OPERATION) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (definition->kind == GQL_IR_DEFINITION_OPERATION) { |
0 |
0 |
0 |
|
| 507 |
0 |
| gql_ir_free_operation_definition(definition->as.operation); |
| 508 |
|
| } else { |
| 509 |
0 |
| gql_ir_free_fragment_definition(definition->as.fragment); |
| 510 |
|
| } |
| 511 |
|
| } |
| 512 |
|
| |
| 513 |
|
| static void |
| 514 |
0 |
| gql_ir_free_document(gql_ir_document_t *document) { |
| 515 |
|
| I32 i; |
| 516 |
|
| |
| 517 |
0 |
▶ | if (!document) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!document) { |
0 |
0 |
0 |
|
| 518 |
0 |
| return; |
| 519 |
|
| } |
| 520 |
0 |
▶ | for (i = 0; i < document->definitions.count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < document->definitions.count; i++) { |
0 |
0 |
0 |
|
| 521 |
0 |
| gql_ir_free_definition((gql_ir_definition_t *)document->definitions.items[i]); |
| 522 |
|
| } |
| 523 |
0 |
| gql_ir_ptr_array_free(&document->definitions); |
| 524 |
0 |
| gql_ir_arena_free(&document->arena); |
| 525 |
0 |
| Safefree(document); |
| 526 |
|
| } |
| 527 |
|
| |
| 528 |
|
| static SV * |
| 529 |
0 |
| gql_ir_make_sv_from_span(pTHX_ gql_ir_document_t *document, gql_ir_span_t span) { |
| 530 |
|
| SV *sv; |
| 531 |
|
| |
| 532 |
0 |
▶ | if (!document || span.end < span.start) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!document || span.end < span.start) { |
0 |
0 |
0 |
| if (!document || span.end < span.start) { |
0 |
0 |
0 |
|
| 533 |
0 |
| return newSVpvn("", 0); |
| 534 |
|
| } |
| 535 |
0 |
| sv = newSVpvn(document->src + span.start, span.end - span.start); |
| 536 |
0 |
▶ | if (document->is_utf8) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (document->is_utf8) { |
0 |
0 |
0 |
|
| 537 |
0 |
| SvUTF8_on(sv); |
| 538 |
|
| } |
| 539 |
0 |
| return sv; |
| 540 |
|
| } |
| 541 |
|
| |
| 542 |
|
| static SV * |
| 543 |
0 |
| gql_ir_make_string_value_sv(pTHX_ gql_ir_document_t *document, gql_ir_value_t *value) { |
| 544 |
|
| SV *raw; |
| 545 |
|
| SV *ret; |
| 546 |
|
| |
| 547 |
0 |
| raw = gql_ir_make_sv_from_span(aTHX_ document, value->as.span); |
| 548 |
0 |
▶ | if (value->is_block_string) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (value->is_block_string) { |
0 |
0 |
0 |
|
| 549 |
0 |
| ret = gql_call_helper1(aTHX_ "GraphQL::Houtou::Parser::Internal::_block_string_value", raw); |
| 550 |
|
| } else { |
| 551 |
0 |
| ret = gql_unescape_string_sv(aTHX_ raw); |
| 552 |
|
| } |
| 553 |
0 |
| SvREFCNT_dec(raw); |
| 554 |
0 |
| return ret; |
| 555 |
|
| } |
| 556 |
|
| |
| 557 |
|
| static SV * |
| 558 |
0 |
| gql_parser_build_type_from_ir(pTHX_ gql_parser_loc_context_t *ctx, gql_ir_document_t *document, gql_ir_type_t *type) { |
| 559 |
|
| HV *hv; |
| 560 |
|
| SV *node_sv; |
| 561 |
|
| SV *name_sv; |
| 562 |
|
| |
| 563 |
0 |
▶ | if (!type) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!type) { |
0 |
0 |
0 |
|
| 564 |
0 |
| return &PL_sv_undef; |
| 565 |
|
| } |
| 566 |
0 |
▶ | if (type->kind == GQL_IR_TYPE_NAMED) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (type->kind == GQL_IR_TYPE_NAMED) { |
0 |
0 |
0 |
|
| 567 |
0 |
| SV *type_name_sv = gql_ir_make_sv_from_span(aTHX_ document, type->name); |
| 568 |
0 |
| node_sv = gql_parser_new_named_type_node_sv(aTHX_ type_name_sv); |
| 569 |
0 |
| SvREFCNT_dec(type_name_sv); |
| 570 |
0 |
▶ | if (ctx) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx) { |
0 |
0 |
0 |
|
| 571 |
0 |
▶ | if (ctx->compact_location) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->compact_location) { |
0 |
0 |
0 |
|
| 572 |
0 |
| gql_parser_set_rewritten_loc_node(aTHX_ ctx, node_sv, type->start_pos); |
| 573 |
|
| } else { |
| 574 |
0 |
| name_sv = gql_parser_fetch_sv(gql_parser_node_hv(node_sv), "name"); |
| 575 |
0 |
| gql_parser_set_shared_rewritten_loc_nodes(aTHX_ ctx, type->start_pos, node_sv, name_sv); |
| 576 |
|
| } |
| 577 |
|
| } |
| 578 |
0 |
| return node_sv; |
| 579 |
|
| } |
| 580 |
|
| |
| 581 |
0 |
▶ | hv = gql_parser_new_node_hv_sized(type->kind == GQL_IR_TYPE_LIST ? "ListType" : "NonNullType", 2); |
Branch: 1 branch
| Branch | True | False | Total |
| hv = gql_parser_new_node_hv_sized(type->kind == GQL_IR_TYPE_LIST ? "ListType" : "NonNullType", 2); |
0 |
0 |
0 |
|
| 582 |
0 |
| node_sv = gql_parser_build_type_from_ir(aTHX_ ctx, document, type->inner); |
| 583 |
0 |
| hv_stores(hv, "type", node_sv); |
| 584 |
0 |
| node_sv = newRV_noinc((SV *)hv); |
| 585 |
0 |
▶ | if (ctx) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx) { |
0 |
0 |
0 |
|
| 586 |
0 |
| gql_parser_set_rewritten_loc_node(aTHX_ ctx, node_sv, type->start_pos); |
| 587 |
|
| } |
| 588 |
0 |
| return node_sv; |
| 589 |
|
| } |
| 590 |
|
| |
| 591 |
|
| static AV * |
| 592 |
0 |
| gql_parser_build_object_fields_from_ir(pTHX_ gql_parser_loc_context_t *ctx, gql_ir_document_t *document, gql_ir_ptr_array_t *fields, SV *state_sv) { |
| 593 |
0 |
| AV *av = newAV(); |
| 594 |
|
| I32 i; |
| 595 |
|
| |
| 596 |
0 |
▶ | if (!fields) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!fields) { |
0 |
0 |
0 |
|
| 597 |
0 |
| return av; |
| 598 |
|
| } |
| 599 |
0 |
▶ | if (fields->count > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (fields->count > 0) { |
0 |
0 |
0 |
|
| 600 |
0 |
| av_extend(av, fields->count - 1); |
| 601 |
|
| } |
| 602 |
0 |
▶ | for (i = 0; i < fields->count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < fields->count; i++) { |
0 |
0 |
0 |
|
| 603 |
0 |
| gql_ir_object_field_t *field = (gql_ir_object_field_t *)fields->items[i]; |
| 604 |
0 |
| HV *field_hv = gql_parser_new_node_hv_sized("ObjectField", 3); |
| 605 |
|
| SV *field_sv; |
| 606 |
0 |
| SV *field_name_value_sv = gql_ir_make_sv_from_span(aTHX_ document, field->name); |
| 607 |
0 |
| SV *field_name_sv = gql_parser_new_name_node_sv(aTHX_ field_name_value_sv); |
| 608 |
0 |
| SvREFCNT_dec(field_name_value_sv); |
| 609 |
0 |
| hv_stores(field_hv, "name", field_name_sv); |
| 610 |
0 |
| hv_stores(field_hv, "value", gql_parser_build_value_from_ir(aTHX_ ctx, document, field->value, state_sv)); |
| 611 |
0 |
| field_sv = newRV_noinc((SV *)field_hv); |
| 612 |
0 |
▶ | if (ctx) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx) { |
0 |
0 |
0 |
|
| 613 |
0 |
▶ | if (ctx->compact_location) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->compact_location) { |
0 |
0 |
0 |
|
| 614 |
0 |
| gql_parser_set_rewritten_loc_node(aTHX_ ctx, field_sv, field->start_pos); |
| 615 |
|
| } else { |
| 616 |
0 |
| gql_parser_set_shared_rewritten_loc_nodes(aTHX_ ctx, field->start_pos, field_sv, field_name_sv); |
| 617 |
|
| } |
| 618 |
|
| } |
| 619 |
0 |
| av_push(av, field_sv); |
| 620 |
|
| } |
| 621 |
|
| |
| 622 |
0 |
| return av; |
| 623 |
|
| } |
| 624 |
|
| |
| 625 |
|
| static SV * |
| 626 |
0 |
| gql_parser_build_value_from_ir(pTHX_ gql_parser_loc_context_t *ctx, gql_ir_document_t *document, gql_ir_value_t *value, SV *state_sv) { |
| 627 |
|
| HV *hv; |
| 628 |
|
| I32 i; |
| 629 |
0 |
| SV *node_sv = &PL_sv_undef; |
| 630 |
|
| SV *name_sv; |
| 631 |
|
| |
| 632 |
0 |
▶ | if (!value) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!value) { |
0 |
0 |
0 |
|
| 633 |
0 |
| return &PL_sv_undef; |
| 634 |
|
| } |
| 635 |
0 |
| switch (value->kind) { |
| 636 |
0 |
| case GQL_IR_VALUE_NULL: |
| 637 |
0 |
| node_sv = gql_parser_new_node_ref("NullValue"); |
| 638 |
0 |
| break; |
| 639 |
0 |
| case GQL_IR_VALUE_BOOL: |
| 640 |
0 |
| hv = gql_parser_new_node_hv_sized("BooleanValue", 2); |
| 641 |
0 |
| hv_stores(hv, "value", newSViv(value->as.boolean ? 1 : 0)); |
| 642 |
0 |
| node_sv = newRV_noinc((SV *)hv); |
| 643 |
0 |
| break; |
| 644 |
0 |
| case GQL_IR_VALUE_INT: |
| 645 |
0 |
| hv = gql_parser_new_node_hv_sized("IntValue", 2); |
| 646 |
0 |
| hv_stores(hv, "value", gql_ir_make_sv_from_span(aTHX_ document, value->as.span)); |
| 647 |
0 |
| node_sv = newRV_noinc((SV *)hv); |
| 648 |
0 |
| break; |
| 649 |
0 |
| case GQL_IR_VALUE_FLOAT: |
| 650 |
0 |
| hv = gql_parser_new_node_hv_sized("FloatValue", 2); |
| 651 |
0 |
| hv_stores(hv, "value", gql_ir_make_sv_from_span(aTHX_ document, value->as.span)); |
| 652 |
0 |
| node_sv = newRV_noinc((SV *)hv); |
| 653 |
0 |
| break; |
| 654 |
0 |
| case GQL_IR_VALUE_STRING: |
| 655 |
0 |
| hv = gql_parser_new_node_hv_sized("StringValue", 2); |
| 656 |
0 |
| hv_stores(hv, "value", gql_ir_make_string_value_sv(aTHX_ document, value)); |
| 657 |
0 |
| node_sv = newRV_noinc((SV *)hv); |
| 658 |
0 |
| break; |
| 659 |
0 |
| case GQL_IR_VALUE_ENUM: |
| 660 |
0 |
| hv = gql_parser_new_node_hv_sized("EnumValue", 2); |
| 661 |
0 |
| hv_stores(hv, "value", gql_ir_make_sv_from_span(aTHX_ document, value->as.span)); |
| 662 |
0 |
| node_sv = newRV_noinc((SV *)hv); |
| 663 |
0 |
| break; |
| 664 |
0 |
| case GQL_IR_VALUE_VARIABLE: |
| 665 |
|
| { |
| 666 |
0 |
| SV *var_name_sv = gql_ir_make_sv_from_span(aTHX_ document, value->as.span); |
| 667 |
0 |
| node_sv = gql_parser_new_variable_node_sv(aTHX_ var_name_sv); |
| 668 |
0 |
| SvREFCNT_dec(var_name_sv); |
| 669 |
|
| } |
| 670 |
0 |
▶ | if (ctx) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx) { |
0 |
0 |
0 |
|
| 671 |
0 |
| gql_parser_set_rewritten_loc_node(aTHX_ ctx, node_sv, value->start_pos); |
| 672 |
0 |
▶ | if (!ctx->compact_location) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ctx->compact_location) { |
0 |
0 |
0 |
|
| 673 |
0 |
| name_sv = gql_parser_fetch_sv(gql_parser_node_hv(node_sv), "name"); |
| 674 |
0 |
| gql_parser_set_rewritten_loc_node(aTHX_ ctx, name_sv, value->name_pos); |
| 675 |
|
| } |
| 676 |
|
| } |
| 677 |
0 |
| return node_sv; |
| 678 |
0 |
| case GQL_IR_VALUE_LIST: { |
| 679 |
0 |
| AV *items = newAV(); |
| 680 |
0 |
| hv = gql_parser_new_node_hv_sized("ListValue", 2); |
| 681 |
0 |
▶ | if (value->as.list_items.count > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (value->as.list_items.count > 0) { |
0 |
0 |
0 |
|
| 682 |
0 |
| av_extend(items, value->as.list_items.count - 1); |
| 683 |
|
| } |
| 684 |
0 |
▶ | for (i = 0; i < value->as.list_items.count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < value->as.list_items.count; i++) { |
0 |
0 |
0 |
|
| 685 |
0 |
| av_push(items, gql_parser_build_value_from_ir(aTHX_ ctx, document, (gql_ir_value_t *)value->as.list_items.items[i], state_sv)); |
| 686 |
|
| } |
| 687 |
0 |
| hv_stores(hv, "values", newRV_noinc((SV *)items)); |
| 688 |
0 |
| node_sv = newRV_noinc((SV *)hv); |
| 689 |
0 |
| break; |
| 690 |
|
| } |
| 691 |
0 |
| case GQL_IR_VALUE_OBJECT: { |
| 692 |
0 |
| hv = gql_parser_new_node_hv_sized("ObjectValue", 2); |
| 693 |
0 |
▶ | if (value->as.object_fields.count > 0 && state_sv) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (value->as.object_fields.count > 0 && state_sv) { |
0 |
0 |
0 |
| if (value->as.object_fields.count > 0 && state_sv) { |
0 |
0 |
0 |
|
| 694 |
0 |
| hv_stores(hv, "fields", gql_parser_new_lazy_object_fields_sv(aTHX_ state_sv, &value->as.object_fields)); |
| 695 |
|
| } else { |
| 696 |
0 |
| hv_stores(hv, "fields", newRV_noinc((SV *)gql_parser_build_object_fields_from_ir( |
| 697 |
|
| aTHX_ ctx, |
| 698 |
|
| document, |
| 699 |
|
| &value->as.object_fields, |
| 700 |
|
| state_sv |
| 701 |
|
| ))); |
| 702 |
|
| } |
| 703 |
0 |
| node_sv = newRV_noinc((SV *)hv); |
| 704 |
0 |
| break; |
| 705 |
|
| } |
| 706 |
|
| } |
| 707 |
|
| |
| 708 |
0 |
▶ | if (ctx && node_sv && node_sv != &PL_sv_undef) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (ctx && node_sv && node_sv != &PL_sv_undef) { |
0 |
0 |
0 |
| if (ctx && node_sv && node_sv != &PL_sv_undef) { |
0 |
0 |
0 |
| if (ctx && node_sv && node_sv != &PL_sv_undef) { |
0 |
0 |
0 |
|
| 709 |
0 |
| gql_parser_set_rewritten_loc_node(aTHX_ ctx, node_sv, value->start_pos); |
| 710 |
|
| } |
| 711 |
0 |
| return node_sv; |
| 712 |
|
| } |
| 713 |
|
| |
| 714 |
|
| static AV * |
| 715 |
0 |
| gql_parser_build_arguments_from_ir(pTHX_ gql_parser_loc_context_t *ctx, gql_ir_document_t *document, gql_ir_ptr_array_t *arguments, SV *state_sv) { |
| 716 |
0 |
| AV *av = newAV(); |
| 717 |
|
| I32 i; |
| 718 |
|
| |
| 719 |
0 |
▶ | if (!arguments) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!arguments) { |
0 |
0 |
0 |
|
| 720 |
0 |
| return av; |
| 721 |
|
| } |
| 722 |
0 |
▶ | if (arguments->count > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (arguments->count > 0) { |
0 |
0 |
0 |
|
| 723 |
0 |
| av_extend(av, arguments->count - 1); |
| 724 |
|
| } |
| 725 |
0 |
▶ | for (i = 0; i < arguments->count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < arguments->count; i++) { |
0 |
0 |
0 |
|
| 726 |
0 |
| gql_ir_argument_t *argument = (gql_ir_argument_t *)arguments->items[i]; |
| 727 |
0 |
| HV *arg_hv = gql_parser_new_node_hv_sized("Argument", 3); |
| 728 |
|
| SV *arg_sv; |
| 729 |
0 |
| SV *name_value_sv = gql_ir_make_sv_from_span(aTHX_ document, argument->name); |
| 730 |
0 |
| SV *name_sv = gql_parser_new_name_node_sv(aTHX_ name_value_sv); |
| 731 |
0 |
| SvREFCNT_dec(name_value_sv); |
| 732 |
0 |
| hv_stores(arg_hv, "name", name_sv); |
| 733 |
0 |
| hv_stores(arg_hv, "value", gql_parser_build_value_from_ir(aTHX_ ctx, document, argument->value, state_sv)); |
| 734 |
0 |
| arg_sv = newRV_noinc((SV *)arg_hv); |
| 735 |
0 |
▶ | if (ctx) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx) { |
0 |
0 |
0 |
|
| 736 |
0 |
▶ | if (ctx->compact_location) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->compact_location) { |
0 |
0 |
0 |
|
| 737 |
0 |
| gql_parser_set_rewritten_loc_node(aTHX_ ctx, arg_sv, argument->start_pos); |
| 738 |
|
| } else { |
| 739 |
0 |
| gql_parser_set_shared_rewritten_loc_nodes(aTHX_ ctx, argument->start_pos, arg_sv, name_sv); |
| 740 |
|
| } |
| 741 |
|
| } |
| 742 |
0 |
| av_push(av, arg_sv); |
| 743 |
|
| } |
| 744 |
0 |
| return av; |
| 745 |
|
| } |
| 746 |
|
| |
| 747 |
|
| static AV * |
| 748 |
0 |
| gql_parser_build_directives_from_ir(pTHX_ gql_parser_loc_context_t *ctx, gql_ir_document_t *document, gql_ir_ptr_array_t *directives, SV *state_sv) { |
| 749 |
0 |
| AV *av = newAV(); |
| 750 |
|
| I32 i; |
| 751 |
|
| |
| 752 |
0 |
▶ | if (!directives) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!directives) { |
0 |
0 |
0 |
|
| 753 |
0 |
| return av; |
| 754 |
|
| } |
| 755 |
0 |
▶ | if (directives->count > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (directives->count > 0) { |
0 |
0 |
0 |
|
| 756 |
0 |
| av_extend(av, directives->count - 1); |
| 757 |
|
| } |
| 758 |
0 |
▶ | for (i = 0; i < directives->count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < directives->count; i++) { |
0 |
0 |
0 |
|
| 759 |
0 |
| gql_ir_directive_t *directive = (gql_ir_directive_t *)directives->items[i]; |
| 760 |
0 |
| HV *dir_hv = gql_parser_new_node_hv_sized("Directive", 3); |
| 761 |
|
| SV *dir_sv; |
| 762 |
0 |
| SV *name_value_sv = gql_ir_make_sv_from_span(aTHX_ document, directive->name); |
| 763 |
0 |
| SV *name_sv = gql_parser_new_name_node_sv(aTHX_ name_value_sv); |
| 764 |
0 |
| SvREFCNT_dec(name_value_sv); |
| 765 |
0 |
| hv_stores(dir_hv, "name", name_sv); |
| 766 |
0 |
▶ | if (state_sv && directive->arguments.count > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (state_sv && directive->arguments.count > 0) { |
0 |
0 |
0 |
| if (state_sv && directive->arguments.count > 0) { |
0 |
0 |
0 |
|
| 767 |
0 |
| hv_stores(dir_hv, "arguments", gql_parser_new_lazy_arguments_sv(aTHX_ state_sv, &directive->arguments)); |
| 768 |
|
| } else { |
| 769 |
0 |
| hv_stores(dir_hv, "arguments", newRV_noinc((SV *)gql_parser_build_arguments_from_ir(aTHX_ ctx, document, &directive->arguments, state_sv))); |
| 770 |
|
| } |
| 771 |
0 |
| dir_sv = newRV_noinc((SV *)dir_hv); |
| 772 |
0 |
▶ | if (ctx) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx) { |
0 |
0 |
0 |
|
| 773 |
0 |
| gql_parser_set_rewritten_loc_node(aTHX_ ctx, dir_sv, directive->start_pos); |
| 774 |
0 |
▶ | if (!ctx->compact_location) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ctx->compact_location) { |
0 |
0 |
0 |
|
| 775 |
0 |
| gql_parser_set_rewritten_loc_node(aTHX_ ctx, name_sv, directive->name_pos); |
| 776 |
|
| } |
| 777 |
|
| } |
| 778 |
0 |
| av_push(av, dir_sv); |
| 779 |
|
| } |
| 780 |
0 |
| return av; |
| 781 |
|
| } |
| 782 |
|
| |
| 783 |
|
| static SV * |
| 784 |
0 |
| gql_parser_build_selection_from_ir(pTHX_ gql_parser_loc_context_t *ctx, gql_ir_document_t *document, gql_ir_selection_t *selection, SV *state_sv) { |
| 785 |
|
| HV *hv; |
| 786 |
|
| SV *node_sv; |
| 787 |
|
| |
| 788 |
0 |
▶ | if (!selection) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!selection) { |
0 |
0 |
0 |
|
| 789 |
0 |
| return &PL_sv_undef; |
| 790 |
|
| } |
| 791 |
0 |
| switch (selection->kind) { |
| 792 |
0 |
| case GQL_IR_SELECTION_FIELD: { |
| 793 |
0 |
| gql_ir_field_t *field = selection->as.field; |
| 794 |
0 |
| hv = gql_parser_new_node_hv_sized("Field", 6); |
| 795 |
0 |
▶ | if (field->alias.start != field->alias.end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (field->alias.start != field->alias.end) { |
0 |
0 |
0 |
|
| 796 |
0 |
| SV *alias_value_sv = gql_ir_make_sv_from_span(aTHX_ document, field->alias); |
| 797 |
0 |
| SV *alias_sv = gql_parser_new_name_node_sv(aTHX_ alias_value_sv); |
| 798 |
0 |
| SvREFCNT_dec(alias_value_sv); |
| 799 |
0 |
| hv_stores(hv, "alias", alias_sv); |
| 800 |
0 |
▶ | if (ctx && !ctx->compact_location) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (ctx && !ctx->compact_location) { |
0 |
0 |
0 |
| if (ctx && !ctx->compact_location) { |
0 |
0 |
0 |
|
| 801 |
0 |
| gql_parser_set_rewritten_loc_node(aTHX_ ctx, alias_sv, field->alias_pos); |
| 802 |
|
| } |
| 803 |
|
| } |
| 804 |
|
| { |
| 805 |
0 |
| SV *name_value_sv = gql_ir_make_sv_from_span(aTHX_ document, field->name); |
| 806 |
0 |
| SV *name_sv = gql_parser_new_name_node_sv(aTHX_ name_value_sv); |
| 807 |
0 |
| SvREFCNT_dec(name_value_sv); |
| 808 |
0 |
| hv_stores(hv, "name", name_sv); |
| 809 |
0 |
▶ | if (ctx && !ctx->compact_location) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (ctx && !ctx->compact_location) { |
0 |
0 |
0 |
| if (ctx && !ctx->compact_location) { |
0 |
0 |
0 |
|
| 810 |
0 |
▶ | if (field->alias.start != field->alias.end || field->start_pos != field->name_pos) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (field->alias.start != field->alias.end || field->start_pos != field->name_pos) { |
0 |
0 |
0 |
| if (field->alias.start != field->alias.end || field->start_pos != field->name_pos) { |
0 |
0 |
0 |
|
| 811 |
0 |
| gql_parser_set_rewritten_loc_node(aTHX_ ctx, name_sv, field->name_pos); |
| 812 |
|
| } |
| 813 |
|
| } |
| 814 |
|
| } |
| 815 |
0 |
▶ | if (state_sv && field->arguments.count > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (state_sv && field->arguments.count > 0) { |
0 |
0 |
0 |
| if (state_sv && field->arguments.count > 0) { |
0 |
0 |
0 |
|
| 816 |
0 |
| hv_stores(hv, "arguments", gql_parser_new_lazy_arguments_sv(aTHX_ state_sv, &field->arguments)); |
| 817 |
|
| } else { |
| 818 |
0 |
| hv_stores(hv, "arguments", newRV_noinc((SV *)gql_parser_build_arguments_from_ir(aTHX_ ctx, document, &field->arguments, state_sv))); |
| 819 |
|
| } |
| 820 |
0 |
▶ | if (state_sv && field->directives.count > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (state_sv && field->directives.count > 0) { |
0 |
0 |
0 |
| if (state_sv && field->directives.count > 0) { |
0 |
0 |
0 |
|
| 821 |
0 |
| hv_stores(hv, "directives", gql_parser_new_lazy_directives_sv(aTHX_ state_sv, &field->directives)); |
| 822 |
|
| } else { |
| 823 |
0 |
| hv_stores(hv, "directives", newRV_noinc((SV *)gql_parser_build_directives_from_ir(aTHX_ ctx, document, &field->directives, state_sv))); |
| 824 |
|
| } |
| 825 |
0 |
▶ | if (field->selection_set) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (field->selection_set) { |
0 |
0 |
0 |
|
| 826 |
0 |
| hv_stores(hv, "selectionSet", gql_parser_build_selection_set_from_ir(aTHX_ ctx, document, field->selection_set, state_sv)); |
| 827 |
|
| } |
| 828 |
0 |
| node_sv = newRV_noinc((SV *)hv); |
| 829 |
0 |
▶ | if (ctx) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx) { |
0 |
0 |
0 |
|
| 830 |
0 |
▶ | if (!ctx->compact_location && field->alias.start == field->alias.end && field->start_pos == field->name_pos) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!ctx->compact_location && field->alias.start == field->alias.end && field->start_pos == field->name_pos) { |
0 |
0 |
0 |
| if (!ctx->compact_location && field->alias.start == field->alias.end && field->start_pos == field->name_pos) { |
0 |
0 |
0 |
| if (!ctx->compact_location && field->alias.start == field->alias.end && field->start_pos == field->name_pos) { |
0 |
0 |
0 |
|
| 831 |
0 |
| SV *name_sv = gql_parser_fetch_sv(hv, "name"); |
| 832 |
0 |
| gql_parser_set_shared_rewritten_loc_nodes(aTHX_ ctx, field->start_pos, node_sv, name_sv); |
| 833 |
|
| } else { |
| 834 |
0 |
| gql_parser_set_rewritten_loc_node(aTHX_ ctx, node_sv, field->start_pos); |
| 835 |
|
| } |
| 836 |
|
| } |
| 837 |
0 |
| return node_sv; |
| 838 |
|
| } |
| 839 |
0 |
| case GQL_IR_SELECTION_FRAGMENT_SPREAD: { |
| 840 |
0 |
| gql_ir_fragment_spread_t *spread = selection->as.fragment_spread; |
| 841 |
0 |
| hv = gql_parser_new_node_hv_sized("FragmentSpread", 3); |
| 842 |
|
| { |
| 843 |
0 |
| SV *name_value_sv = gql_ir_make_sv_from_span(aTHX_ document, spread->name); |
| 844 |
0 |
| SV *name_sv = gql_parser_new_name_node_sv(aTHX_ name_value_sv); |
| 845 |
0 |
| SvREFCNT_dec(name_value_sv); |
| 846 |
0 |
| hv_stores(hv, "name", name_sv); |
| 847 |
0 |
▶ | if (ctx && !ctx->compact_location) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (ctx && !ctx->compact_location) { |
0 |
0 |
0 |
| if (ctx && !ctx->compact_location) { |
0 |
0 |
0 |
|
| 848 |
0 |
| gql_parser_set_rewritten_loc_node(aTHX_ ctx, name_sv, spread->name_pos); |
| 849 |
|
| } |
| 850 |
|
| } |
| 851 |
0 |
▶ | if (state_sv && spread->directives.count > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (state_sv && spread->directives.count > 0) { |
0 |
0 |
0 |
| if (state_sv && spread->directives.count > 0) { |
0 |
0 |
0 |
|
| 852 |
0 |
| hv_stores(hv, "directives", gql_parser_new_lazy_directives_sv(aTHX_ state_sv, &spread->directives)); |
| 853 |
|
| } else { |
| 854 |
0 |
| hv_stores(hv, "directives", newRV_noinc((SV *)gql_parser_build_directives_from_ir(aTHX_ ctx, document, &spread->directives, state_sv))); |
| 855 |
|
| } |
| 856 |
0 |
| node_sv = newRV_noinc((SV *)hv); |
| 857 |
0 |
▶ | if (ctx) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx) { |
0 |
0 |
0 |
|
| 858 |
0 |
| gql_parser_set_rewritten_loc_node(aTHX_ ctx, node_sv, spread->start_pos); |
| 859 |
|
| } |
| 860 |
0 |
| return node_sv; |
| 861 |
|
| } |
| 862 |
0 |
| case GQL_IR_SELECTION_INLINE_FRAGMENT: { |
| 863 |
0 |
| gql_ir_inline_fragment_t *fragment = selection->as.inline_fragment; |
| 864 |
0 |
| hv = gql_parser_new_node_hv_sized("InlineFragment", 4); |
| 865 |
0 |
▶ | if (fragment->type_condition.start != fragment->type_condition.end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (fragment->type_condition.start != fragment->type_condition.end) { |
0 |
0 |
0 |
|
| 866 |
0 |
| SV *type_name_sv = gql_ir_make_sv_from_span(aTHX_ document, fragment->type_condition); |
| 867 |
0 |
| SV *type_sv = gql_parser_new_named_type_node_sv(aTHX_ type_name_sv); |
| 868 |
0 |
| SvREFCNT_dec(type_name_sv); |
| 869 |
0 |
| hv_stores(hv, "typeCondition", type_sv); |
| 870 |
0 |
▶ | if (ctx) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx) { |
0 |
0 |
0 |
|
| 871 |
0 |
▶ | if (ctx->compact_location) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->compact_location) { |
0 |
0 |
0 |
|
| 872 |
0 |
| gql_parser_set_rewritten_loc_node(aTHX_ ctx, type_sv, fragment->type_condition_pos); |
| 873 |
|
| } else { |
| 874 |
0 |
| SV *type_name_sv = gql_parser_fetch_sv(gql_parser_node_hv(type_sv), "name"); |
| 875 |
0 |
| gql_parser_set_shared_rewritten_loc_nodes(aTHX_ ctx, fragment->type_condition_pos, type_sv, type_name_sv); |
| 876 |
|
| } |
| 877 |
|
| } |
| 878 |
|
| } |
| 879 |
0 |
▶ | if (state_sv && fragment->directives.count > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (state_sv && fragment->directives.count > 0) { |
0 |
0 |
0 |
| if (state_sv && fragment->directives.count > 0) { |
0 |
0 |
0 |
|
| 880 |
0 |
| hv_stores(hv, "directives", gql_parser_new_lazy_directives_sv(aTHX_ state_sv, &fragment->directives)); |
| 881 |
|
| } else { |
| 882 |
0 |
| hv_stores(hv, "directives", newRV_noinc((SV *)gql_parser_build_directives_from_ir(aTHX_ ctx, document, &fragment->directives, state_sv))); |
| 883 |
|
| } |
| 884 |
0 |
| hv_stores(hv, "selectionSet", gql_parser_build_selection_set_from_ir(aTHX_ ctx, document, fragment->selection_set, state_sv)); |
| 885 |
0 |
| node_sv = newRV_noinc((SV *)hv); |
| 886 |
0 |
▶ | if (ctx) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx) { |
0 |
0 |
0 |
|
| 887 |
0 |
| gql_parser_set_rewritten_loc_node(aTHX_ ctx, node_sv, fragment->start_pos); |
| 888 |
|
| } |
| 889 |
0 |
| return node_sv; |
| 890 |
|
| } |
| 891 |
|
| } |
| 892 |
|
| |
| 893 |
0 |
| return &PL_sv_undef; |
| 894 |
|
| } |
| 895 |
|
| |
| 896 |
|
| static SV * |
| 897 |
0 |
| gql_parser_build_selection_set_from_ir(pTHX_ gql_parser_loc_context_t *ctx, gql_ir_document_t *document, gql_ir_selection_set_t *selection_set, SV *state_sv) { |
| 898 |
0 |
| HV *hv = gql_parser_new_node_hv_sized("SelectionSet", 2); |
| 899 |
0 |
| AV *selections = newAV(); |
| 900 |
|
| I32 i; |
| 901 |
|
| SV *node_sv; |
| 902 |
|
| |
| 903 |
0 |
▶ | if (selection_set && selection_set->selections.count > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (selection_set && selection_set->selections.count > 0) { |
0 |
0 |
0 |
| if (selection_set && selection_set->selections.count > 0) { |
0 |
0 |
0 |
|
| 904 |
0 |
| av_extend(selections, selection_set->selections.count - 1); |
| 905 |
|
| } |
| 906 |
0 |
▶ | for (i = 0; selection_set && i < selection_set->selections.count; i++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (i = 0; selection_set && i < selection_set->selections.count; i++) { |
0 |
0 |
0 |
| for (i = 0; selection_set && i < selection_set->selections.count; i++) { |
0 |
0 |
0 |
|
| 907 |
0 |
| av_push(selections, gql_parser_build_selection_from_ir(aTHX_ ctx, document, (gql_ir_selection_t *)selection_set->selections.items[i], state_sv)); |
| 908 |
|
| } |
| 909 |
0 |
| hv_stores(hv, "selections", newRV_noinc((SV *)selections)); |
| 910 |
0 |
| node_sv = newRV_noinc((SV *)hv); |
| 911 |
0 |
▶ | if (ctx && selection_set) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (ctx && selection_set) { |
0 |
0 |
0 |
| if (ctx && selection_set) { |
0 |
0 |
0 |
|
| 912 |
0 |
| gql_parser_set_rewritten_loc_node(aTHX_ ctx, node_sv, selection_set->start_pos); |
| 913 |
|
| } |
| 914 |
0 |
| return node_sv; |
| 915 |
|
| } |
| 916 |
|
| |
| 917 |
|
| static AV * |
| 918 |
0 |
| gql_parser_build_variable_definitions_from_ir(pTHX_ gql_parser_loc_context_t *ctx, gql_ir_document_t *document, gql_ir_ptr_array_t *definitions, SV *state_sv) { |
| 919 |
0 |
| AV *av = newAV(); |
| 920 |
|
| I32 i; |
| 921 |
|
| |
| 922 |
0 |
▶ | if (!definitions) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!definitions) { |
0 |
0 |
0 |
|
| 923 |
0 |
| return av; |
| 924 |
|
| } |
| 925 |
0 |
▶ | if (definitions->count > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (definitions->count > 0) { |
0 |
0 |
0 |
|
| 926 |
0 |
| av_extend(av, definitions->count - 1); |
| 927 |
|
| } |
| 928 |
0 |
▶ | for (i = 0; i < definitions->count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < definitions->count; i++) { |
0 |
0 |
0 |
|
| 929 |
0 |
| gql_ir_variable_definition_t *definition = (gql_ir_variable_definition_t *)definitions->items[i]; |
| 930 |
0 |
| HV *def_hv = gql_parser_new_node_hv_sized("VariableDefinition", 5); |
| 931 |
|
| SV *def_sv; |
| 932 |
0 |
| SV *variable_name_value_sv = gql_ir_make_sv_from_span(aTHX_ document, definition->name); |
| 933 |
0 |
| SV *variable_sv = gql_parser_new_variable_node_sv(aTHX_ variable_name_value_sv); |
| 934 |
0 |
| SvREFCNT_dec(variable_name_value_sv); |
| 935 |
0 |
| hv_stores(def_hv, "variable", variable_sv); |
| 936 |
0 |
| hv_stores(def_hv, "type", gql_parser_build_type_from_ir(aTHX_ ctx, document, definition->type)); |
| 937 |
0 |
▶ | if (definition->default_value) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (definition->default_value) { |
0 |
0 |
0 |
|
| 938 |
0 |
| hv_stores(def_hv, "defaultValue", gql_parser_build_value_from_ir(aTHX_ ctx, document, definition->default_value, state_sv)); |
| 939 |
|
| } |
| 940 |
0 |
▶ | if (state_sv && definition->directives.count > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (state_sv && definition->directives.count > 0) { |
0 |
0 |
0 |
| if (state_sv && definition->directives.count > 0) { |
0 |
0 |
0 |
|
| 941 |
0 |
| hv_stores(def_hv, "directives", gql_parser_new_lazy_directives_sv(aTHX_ state_sv, &definition->directives)); |
| 942 |
|
| } else { |
| 943 |
0 |
| hv_stores(def_hv, "directives", newRV_noinc((SV *)gql_parser_build_directives_from_ir(aTHX_ ctx, document, &definition->directives, state_sv))); |
| 944 |
|
| } |
| 945 |
0 |
| def_sv = newRV_noinc((SV *)def_hv); |
| 946 |
0 |
▶ | if (ctx) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx) { |
0 |
0 |
0 |
|
| 947 |
0 |
| SV *variable_name_sv = gql_parser_fetch_sv(gql_parser_node_hv(variable_sv), "name"); |
| 948 |
0 |
| gql_parser_set_shared_rewritten_loc_nodes(aTHX_ ctx, definition->start_pos, def_sv, variable_sv); |
| 949 |
0 |
▶ | if (!ctx->compact_location) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ctx->compact_location) { |
0 |
0 |
0 |
|
| 950 |
0 |
| gql_parser_set_rewritten_loc_node(aTHX_ ctx, variable_name_sv, definition->name_pos); |
| 951 |
|
| } |
| 952 |
|
| } |
| 953 |
0 |
| av_push(av, def_sv); |
| 954 |
|
| } |
| 955 |
0 |
| return av; |
| 956 |
|
| } |
| 957 |
|
| |
| 958 |
|
| static SV * |
| 959 |
0 |
| gqlperl_location_from_gql_parser_node(pTHX_ SV *node_sv) { |
| 960 |
|
| HV *src_hv; |
| 961 |
|
| HV *loc_hv; |
| 962 |
|
| HV *dst_hv; |
| 963 |
|
| SV *line_sv; |
| 964 |
|
| SV *column_sv; |
| 965 |
|
| SV *loc_sv; |
| 966 |
|
| |
| 967 |
0 |
▶ | if (!node_sv || !SvROK(node_sv) || SvTYPE(SvRV(node_sv)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!node_sv || !SvROK(node_sv) || SvTYPE(SvRV(node_sv)) != SVt_PVHV) { |
0 |
0 |
0 |
| if (!node_sv || !SvROK(node_sv) || SvTYPE(SvRV(node_sv)) != SVt_PVHV) { |
0 |
0 |
0 |
| if (!node_sv || !SvROK(node_sv) || SvTYPE(SvRV(node_sv)) != SVt_PVHV) { |
0 |
0 |
0 |
|
| 968 |
0 |
| return &PL_sv_undef; |
| 969 |
|
| } |
| 970 |
0 |
| src_hv = (HV *)SvRV(node_sv); |
| 971 |
0 |
| loc_sv = gql_parser_fetch_sv(src_hv, "loc"); |
| 972 |
0 |
▶ | if (!loc_sv || !SvROK(loc_sv) || SvTYPE(SvRV(loc_sv)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!loc_sv || !SvROK(loc_sv) || SvTYPE(SvRV(loc_sv)) != SVt_PVHV) { |
0 |
0 |
0 |
| if (!loc_sv || !SvROK(loc_sv) || SvTYPE(SvRV(loc_sv)) != SVt_PVHV) { |
0 |
0 |
0 |
| if (!loc_sv || !SvROK(loc_sv) || SvTYPE(SvRV(loc_sv)) != SVt_PVHV) { |
0 |
0 |
0 |
|
| 973 |
0 |
| return &PL_sv_undef; |
| 974 |
|
| } |
| 975 |
|
| |
| 976 |
0 |
| loc_hv = (HV *)SvRV(loc_sv); |
| 977 |
0 |
| line_sv = gql_parser_fetch_sv(loc_hv, "line"); |
| 978 |
0 |
| column_sv = gql_parser_fetch_sv(loc_hv, "column"); |
| 979 |
0 |
▶ | if (!line_sv || !column_sv) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!line_sv || !column_sv) { |
0 |
0 |
0 |
| if (!line_sv || !column_sv) { |
0 |
0 |
0 |
|
| 980 |
0 |
| return &PL_sv_undef; |
| 981 |
|
| } |
| 982 |
|
| |
| 983 |
0 |
| dst_hv = newHV(); |
| 984 |
0 |
| gql_store_sv(dst_hv, "line", newSViv(SvIV(line_sv))); |
| 985 |
0 |
| gql_store_sv(dst_hv, "column", newSViv(SvIV(column_sv))); |
| 986 |
0 |
| return newRV_noinc((SV *)dst_hv); |
| 987 |
|
| } |
| 988 |
|
| |
| 989 |
|
| static void |
| 990 |
0 |
| gqlperl_store_location_from_gql_parser_node(pTHX_ HV *dst_hv, SV *node_sv) { |
| 991 |
0 |
| SV *location_sv = gqlperl_location_from_gql_parser_node(aTHX_ node_sv); |
| 992 |
0 |
▶ | if (location_sv && location_sv != &PL_sv_undef) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (location_sv && location_sv != &PL_sv_undef) { |
0 |
0 |
0 |
| if (location_sv && location_sv != &PL_sv_undef) { |
0 |
0 |
0 |
|
| 993 |
0 |
| gql_store_sv(dst_hv, "location", location_sv); |
| 994 |
|
| } |
| 995 |
0 |
| } |
| 996 |
|
| |
| 997 |
|
| static SV * |
| 998 |
0 |
| gqlperl_convert_type_from_gqljs(pTHX_ SV *node_sv) { |
| 999 |
|
| HV *src_hv; |
| 1000 |
|
| const char *kind; |
| 1001 |
|
| |
| 1002 |
0 |
▶ | if (!node_sv || !SvROK(node_sv) || SvTYPE(SvRV(node_sv)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!node_sv || !SvROK(node_sv) || SvTYPE(SvRV(node_sv)) != SVt_PVHV) { |
0 |
0 |
0 |
| if (!node_sv || !SvROK(node_sv) || SvTYPE(SvRV(node_sv)) != SVt_PVHV) { |
0 |
0 |
0 |
| if (!node_sv || !SvROK(node_sv) || SvTYPE(SvRV(node_sv)) != SVt_PVHV) { |
0 |
0 |
0 |
|
| 1003 |
0 |
| return &PL_sv_undef; |
| 1004 |
|
| } |
| 1005 |
0 |
| src_hv = (HV *)SvRV(node_sv); |
| 1006 |
0 |
| kind = gql_parser_fetch_kind(src_hv); |
| 1007 |
|
| |
| 1008 |
0 |
▶ | if (strEQ(kind, "NamedType")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(kind, "NamedType")) { |
0 |
0 |
0 |
|
| 1009 |
0 |
| return newSVpv(gql_parser_name_value(gql_parser_fetch_sv(src_hv, "name")), 0); |
| 1010 |
|
| } |
| 1011 |
0 |
▶ | if (strEQ(kind, "ListType") || strEQ(kind, "NonNullType")) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (strEQ(kind, "ListType") || strEQ(kind, "NonNullType")) { |
0 |
0 |
0 |
| if (strEQ(kind, "ListType") || strEQ(kind, "NonNullType")) { |
0 |
0 |
0 |
|
| 1012 |
0 |
| AV *av = newAV(); |
| 1013 |
0 |
| HV *inner_hv = newHV(); |
| 1014 |
0 |
▶ | av_push(av, newSVpv(strEQ(kind, "ListType") ? "list" : "non_null", 0)); |
Branch: 1 branch
| Branch | True | False | Total |
| av_push(av, newSVpv(strEQ(kind, "ListType") ? "list" : "non_null", 0)); |
0 |
0 |
0 |
|
| 1015 |
0 |
| gql_store_sv(inner_hv, "type", |
| 1016 |
|
| gqlperl_convert_type_from_gqljs(aTHX_ gql_parser_fetch_sv(src_hv, "type"))); |
| 1017 |
0 |
| av_push(av, newRV_noinc((SV *)inner_hv)); |
| 1018 |
0 |
| return newRV_noinc((SV *)av); |
| 1019 |
|
| } |
| 1020 |
|
| |
| 1021 |
0 |
| croak("Unsupported parser type node '%s'.", kind); |
| 1022 |
|
| } |
| 1023 |
|
| |
| 1024 |
|
| static SV * |
| 1025 |
0 |
| gqlperl_convert_value_from_gqljs(pTHX_ SV *node_sv) { |
| 1026 |
|
| HV *src_hv; |
| 1027 |
|
| const char *kind; |
| 1028 |
|
| SV *value_sv; |
| 1029 |
|
| |
| 1030 |
0 |
▶ | if (!node_sv || !SvROK(node_sv) || SvTYPE(SvRV(node_sv)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!node_sv || !SvROK(node_sv) || SvTYPE(SvRV(node_sv)) != SVt_PVHV) { |
0 |
0 |
0 |
| if (!node_sv || !SvROK(node_sv) || SvTYPE(SvRV(node_sv)) != SVt_PVHV) { |
0 |
0 |
0 |
| if (!node_sv || !SvROK(node_sv) || SvTYPE(SvRV(node_sv)) != SVt_PVHV) { |
0 |
0 |
0 |
|
| 1031 |
0 |
| return &PL_sv_undef; |
| 1032 |
|
| } |
| 1033 |
0 |
| src_hv = (HV *)SvRV(node_sv); |
| 1034 |
0 |
| kind = gql_parser_fetch_kind(src_hv); |
| 1035 |
|
| |
| 1036 |
0 |
▶ | if (strEQ(kind, "Variable")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(kind, "Variable")) { |
0 |
0 |
0 |
|
| 1037 |
0 |
| return newRV_noinc(newSVpv(gql_parser_name_value(gql_parser_fetch_sv(src_hv, "name")), 0)); |
| 1038 |
|
| } |
| 1039 |
0 |
▶ | if (strEQ(kind, "IntValue")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(kind, "IntValue")) { |
0 |
0 |
0 |
|
| 1040 |
0 |
| value_sv = gql_parser_fetch_sv(src_hv, "value"); |
| 1041 |
0 |
| return newSViv(SvIV(value_sv)); |
| 1042 |
|
| } |
| 1043 |
0 |
▶ | if (strEQ(kind, "FloatValue")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(kind, "FloatValue")) { |
0 |
0 |
0 |
|
| 1044 |
0 |
| value_sv = gql_parser_fetch_sv(src_hv, "value"); |
| 1045 |
0 |
| return newSVnv(SvNV(value_sv)); |
| 1046 |
|
| } |
| 1047 |
0 |
▶ | if (strEQ(kind, "StringValue")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(kind, "StringValue")) { |
0 |
0 |
0 |
|
| 1048 |
0 |
| value_sv = gql_parser_fetch_sv(src_hv, "value"); |
| 1049 |
0 |
| return newSVsv(value_sv); |
| 1050 |
|
| } |
| 1051 |
0 |
▶ | if (strEQ(kind, "BooleanValue")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(kind, "BooleanValue")) { |
0 |
0 |
0 |
|
| 1052 |
0 |
| value_sv = gql_parser_fetch_sv(src_hv, "value"); |
| 1053 |
0 |
| return gql_call_helper1(aTHX_ "GraphQL::Houtou::Parser::Internal::_make_bool", |
| 1054 |
0 |
| newSViv(SvTRUE(value_sv) ? 1 : 0)); |
| 1055 |
|
| } |
| 1056 |
0 |
▶ | if (strEQ(kind, "NullValue")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(kind, "NullValue")) { |
0 |
0 |
0 |
|
| 1057 |
0 |
| return newSV(0); |
| 1058 |
|
| } |
| 1059 |
0 |
▶ | if (strEQ(kind, "EnumValue")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(kind, "EnumValue")) { |
0 |
0 |
0 |
|
| 1060 |
0 |
| SV *enum_sv = newSVsv(gql_parser_fetch_sv(src_hv, "value")); |
| 1061 |
0 |
| SV *inner_ref = newRV_noinc(enum_sv); |
| 1062 |
0 |
| return newRV_noinc(inner_ref); |
| 1063 |
|
| } |
| 1064 |
0 |
▶ | if (strEQ(kind, "ListValue")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(kind, "ListValue")) { |
0 |
0 |
0 |
|
| 1065 |
0 |
| AV *src_av = gql_parser_fetch_array(src_hv, "values"); |
| 1066 |
0 |
| AV *dst_av = newAV(); |
| 1067 |
|
| I32 i; |
| 1068 |
0 |
▶ | for (i = 0; src_av && i <= av_len(src_av); i++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (i = 0; src_av && i <= av_len(src_av); i++) { |
0 |
0 |
0 |
| for (i = 0; src_av && i <= av_len(src_av); i++) { |
0 |
0 |
0 |
|
| 1069 |
0 |
| SV **svp = av_fetch(src_av, i, 0); |
| 1070 |
0 |
▶ | if (svp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (svp) { |
0 |
0 |
0 |
|
| 1071 |
0 |
| av_push(dst_av, gqlperl_convert_value_from_gqljs(aTHX_ *svp)); |
| 1072 |
|
| } |
| 1073 |
|
| } |
| 1074 |
0 |
| return newRV_noinc((SV *)dst_av); |
| 1075 |
|
| } |
| 1076 |
0 |
▶ | if (strEQ(kind, "ObjectValue")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(kind, "ObjectValue")) { |
0 |
0 |
0 |
|
| 1077 |
0 |
| AV *fields_av = gql_parser_fetch_array(src_hv, "fields"); |
| 1078 |
0 |
| HV *dst_hv = newHV(); |
| 1079 |
|
| I32 i; |
| 1080 |
0 |
▶ | for (i = 0; fields_av && i <= av_len(fields_av); i++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (i = 0; fields_av && i <= av_len(fields_av); i++) { |
0 |
0 |
0 |
| for (i = 0; fields_av && i <= av_len(fields_av); i++) { |
0 |
0 |
0 |
|
| 1081 |
0 |
| SV **svp = av_fetch(fields_av, i, 0); |
| 1082 |
|
| HV *field_hv; |
| 1083 |
|
| const char *name; |
| 1084 |
0 |
▶ | if (!svp || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!svp || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVHV) { |
0 |
0 |
0 |
| if (!svp || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVHV) { |
0 |
0 |
0 |
| if (!svp || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVHV) { |
0 |
0 |
0 |
|
| 1085 |
0 |
| continue; |
| 1086 |
|
| } |
| 1087 |
0 |
| field_hv = (HV *)SvRV(*svp); |
| 1088 |
0 |
| name = gql_parser_name_value(gql_parser_fetch_sv(field_hv, "name")); |
| 1089 |
0 |
| gql_store_sv(dst_hv, name, |
| 1090 |
|
| gqlperl_convert_value_from_gqljs(aTHX_ gql_parser_fetch_sv(field_hv, "value"))); |
| 1091 |
|
| } |
| 1092 |
0 |
| return newRV_noinc((SV *)dst_hv); |
| 1093 |
|
| } |
| 1094 |
|
| |
| 1095 |
0 |
| croak("Unsupported parser value node '%s'.", kind); |
| 1096 |
|
| } |
| 1097 |
|
| |
| 1098 |
|
| static SV * |
| 1099 |
0 |
| gqlperl_convert_arguments_from_gqljs(pTHX_ AV *av) { |
| 1100 |
0 |
| HV *dst_hv = newHV(); |
| 1101 |
|
| I32 i; |
| 1102 |
|
| |
| 1103 |
0 |
▶ | if (!av || av_len(av) < 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!av || av_len(av) < 0) { |
0 |
0 |
0 |
| if (!av || av_len(av) < 0) { |
0 |
0 |
0 |
|
| 1104 |
0 |
| SvREFCNT_dec((SV *)dst_hv); |
| 1105 |
0 |
| return &PL_sv_undef; |
| 1106 |
|
| } |
| 1107 |
|
| |
| 1108 |
0 |
▶ | for (i = 0; i <= av_len(av); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(av); i++) { |
0 |
0 |
0 |
|
| 1109 |
0 |
| SV **svp = av_fetch(av, i, 0); |
| 1110 |
|
| HV *arg_hv; |
| 1111 |
|
| const char *name; |
| 1112 |
0 |
▶ | if (!svp || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!svp || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVHV) { |
0 |
0 |
0 |
| if (!svp || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVHV) { |
0 |
0 |
0 |
| if (!svp || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVHV) { |
0 |
0 |
0 |
|
| 1113 |
0 |
| continue; |
| 1114 |
|
| } |
| 1115 |
0 |
| arg_hv = (HV *)SvRV(*svp); |
| 1116 |
0 |
| name = gql_parser_name_value(gql_parser_fetch_sv(arg_hv, "name")); |
| 1117 |
0 |
| gql_store_sv(dst_hv, name, |
| 1118 |
|
| gqlperl_convert_value_from_gqljs(aTHX_ gql_parser_fetch_sv(arg_hv, "value"))); |
| 1119 |
|
| } |
| 1120 |
|
| |
| 1121 |
0 |
| return newRV_noinc((SV *)dst_hv); |
| 1122 |
|
| } |
| 1123 |
|
| |
| 1124 |
|
| static SV * |
| 1125 |
0 |
| gqlperl_convert_directives_from_gqljs(pTHX_ AV *av) { |
| 1126 |
0 |
| AV *dst_av = newAV(); |
| 1127 |
|
| I32 i; |
| 1128 |
|
| |
| 1129 |
0 |
▶ | if (!av || av_len(av) < 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!av || av_len(av) < 0) { |
0 |
0 |
0 |
| if (!av || av_len(av) < 0) { |
0 |
0 |
0 |
|
| 1130 |
0 |
| return newRV_noinc((SV *)dst_av); |
| 1131 |
|
| } |
| 1132 |
|
| |
| 1133 |
0 |
▶ | for (i = 0; i <= av_len(av); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(av); i++) { |
0 |
0 |
0 |
|
| 1134 |
0 |
| SV **svp = av_fetch(av, i, 0); |
| 1135 |
|
| HV *src_hv; |
| 1136 |
|
| HV *dst_hv; |
| 1137 |
|
| SV *arguments_sv; |
| 1138 |
0 |
▶ | if (!svp || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!svp || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVHV) { |
0 |
0 |
0 |
| if (!svp || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVHV) { |
0 |
0 |
0 |
| if (!svp || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVHV) { |
0 |
0 |
0 |
|
| 1139 |
0 |
| continue; |
| 1140 |
|
| } |
| 1141 |
0 |
| src_hv = (HV *)SvRV(*svp); |
| 1142 |
0 |
| dst_hv = newHV(); |
| 1143 |
0 |
| gql_store_sv(dst_hv, "name", |
| 1144 |
|
| newSVpv(gql_parser_name_value(gql_parser_fetch_sv(src_hv, "name")), 0)); |
| 1145 |
0 |
| arguments_sv = gqlperl_convert_arguments_from_gqljs(aTHX_ gql_parser_fetch_array(src_hv, "arguments")); |
| 1146 |
0 |
▶ | if (arguments_sv && arguments_sv != &PL_sv_undef) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (arguments_sv && arguments_sv != &PL_sv_undef) { |
0 |
0 |
0 |
| if (arguments_sv && arguments_sv != &PL_sv_undef) { |
0 |
0 |
0 |
|
| 1147 |
0 |
| gql_store_sv(dst_hv, "arguments", arguments_sv); |
| 1148 |
|
| } |
| 1149 |
0 |
| gqlperl_store_location_from_gql_parser_node(aTHX_ dst_hv, *svp); |
| 1150 |
0 |
| av_push(dst_av, newRV_noinc((SV *)dst_hv)); |
| 1151 |
|
| } |
| 1152 |
|
| |
| 1153 |
0 |
| return newRV_noinc((SV *)dst_av); |
| 1154 |
|
| } |
| 1155 |
|
| |
| 1156 |
|
| static AV * |
| 1157 |
0 |
| gqlperl_convert_selections_from_gqljs(pTHX_ AV *av) { |
| 1158 |
0 |
| AV *dst_av = newAV(); |
| 1159 |
|
| I32 i; |
| 1160 |
|
| |
| 1161 |
0 |
▶ | for (i = 0; av && i <= av_len(av); i++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (i = 0; av && i <= av_len(av); i++) { |
0 |
0 |
0 |
| for (i = 0; av && i <= av_len(av); i++) { |
0 |
0 |
0 |
|
| 1162 |
0 |
| SV **svp = av_fetch(av, i, 0); |
| 1163 |
0 |
▶ | if (svp) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (svp) { |
0 |
0 |
0 |
|
| 1164 |
0 |
| av_push(dst_av, gqlperl_convert_selection_from_gqljs(aTHX_ *svp)); |
| 1165 |
|
| } |
| 1166 |
|
| } |
| 1167 |
|
| |
| 1168 |
0 |
| return dst_av; |
| 1169 |
|
| } |
| 1170 |
|
| |
| 1171 |
|
| static SV * |
| 1172 |
0 |
| gqlperl_convert_selection_from_gqljs(pTHX_ SV *node_sv) { |
| 1173 |
|
| HV *src_hv; |
| 1174 |
|
| HV *dst_hv; |
| 1175 |
|
| const char *kind; |
| 1176 |
|
| SV *arguments_sv; |
| 1177 |
|
| SV *directives_sv; |
| 1178 |
|
| AV *selection_av; |
| 1179 |
|
| |
| 1180 |
0 |
▶ | if (!node_sv || !SvROK(node_sv) || SvTYPE(SvRV(node_sv)) != SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!node_sv || !SvROK(node_sv) || SvTYPE(SvRV(node_sv)) != SVt_PVHV) { |
0 |
0 |
0 |
| if (!node_sv || !SvROK(node_sv) || SvTYPE(SvRV(node_sv)) != SVt_PVHV) { |
0 |
0 |
0 |
| if (!node_sv || !SvROK(node_sv) || SvTYPE(SvRV(node_sv)) != SVt_PVHV) { |
0 |
0 |
0 |
|
| 1181 |
0 |
| croak("Unsupported parser selection node"); |
| 1182 |
|
| } |
| 1183 |
0 |
| src_hv = (HV *)SvRV(node_sv); |
| 1184 |
0 |
| kind = gql_parser_fetch_kind(src_hv); |
| 1185 |
0 |
| dst_hv = newHV(); |
| 1186 |
|
| |
| 1187 |
0 |
▶ | if (strEQ(kind, "Field")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(kind, "Field")) { |
0 |
0 |
0 |
|
| 1188 |
0 |
| gql_store_sv(dst_hv, "kind", newSVpv("field", 0)); |
| 1189 |
0 |
| gql_store_sv(dst_hv, "name", newSVpv(gql_parser_name_value(gql_parser_fetch_sv(src_hv, "name")), 0)); |
| 1190 |
0 |
▶ | if (gql_parser_fetch_sv(src_hv, "alias")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (gql_parser_fetch_sv(src_hv, "alias")) { |
0 |
0 |
0 |
|
| 1191 |
0 |
| gql_store_sv(dst_hv, "alias", |
| 1192 |
|
| newSVpv(gql_parser_name_value(gql_parser_fetch_sv(src_hv, "alias")), 0)); |
| 1193 |
|
| } |
| 1194 |
0 |
| arguments_sv = gqlperl_convert_arguments_from_gqljs(aTHX_ gql_parser_fetch_array(src_hv, "arguments")); |
| 1195 |
0 |
▶ | if (arguments_sv && arguments_sv != &PL_sv_undef) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (arguments_sv && arguments_sv != &PL_sv_undef) { |
0 |
0 |
0 |
| if (arguments_sv && arguments_sv != &PL_sv_undef) { |
0 |
0 |
0 |
|
| 1196 |
0 |
| gql_store_sv(dst_hv, "arguments", arguments_sv); |
| 1197 |
|
| } |
| 1198 |
0 |
| directives_sv = gqlperl_convert_directives_from_gqljs(aTHX_ gql_parser_fetch_array(src_hv, "directives")); |
| 1199 |
0 |
▶ | if (directives_sv && SvROK(directives_sv) && av_len((AV *)SvRV(directives_sv)) >= 0) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (directives_sv && SvROK(directives_sv) && av_len((AV *)SvRV(directives_sv)) >= 0) { |
0 |
0 |
0 |
| if (directives_sv && SvROK(directives_sv) && av_len((AV *)SvRV(directives_sv)) >= 0) { |
0 |
0 |
0 |
| if (directives_sv && SvROK(directives_sv) && av_len((AV *)SvRV(directives_sv)) >= 0) { |
0 |
0 |
0 |
|
| 1200 |
0 |
| gql_store_sv(dst_hv, "directives", directives_sv); |
| 1201 |
0 |
▶ | } else if (directives_sv && directives_sv != &PL_sv_undef) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (directives_sv && directives_sv != &PL_sv_undef) { |
0 |
0 |
0 |
| } else if (directives_sv && directives_sv != &PL_sv_undef) { |
0 |
0 |
0 |
|
| 1202 |
0 |
| SvREFCNT_dec(directives_sv); |
| 1203 |
|
| } |
| 1204 |
0 |
▶ | if (gql_parser_fetch_sv(src_hv, "selectionSet")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (gql_parser_fetch_sv(src_hv, "selectionSet")) { |
0 |
0 |
0 |
|
| 1205 |
0 |
| selection_av = gqlperl_convert_selections_from_gqljs(aTHX_ |
| 1206 |
0 |
| gql_parser_fetch_array((HV *)SvRV(gql_parser_fetch_sv(src_hv, "selectionSet")), "selections")); |
| 1207 |
0 |
▶ | if (av_len(selection_av) >= 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_len(selection_av) >= 0) { |
0 |
0 |
0 |
|
| 1208 |
0 |
| gql_store_sv(dst_hv, "selections", newRV_noinc((SV *)selection_av)); |
| 1209 |
|
| } else { |
| 1210 |
0 |
| SvREFCNT_dec((SV *)selection_av); |
| 1211 |
|
| } |
| 1212 |
|
| } |
| 1213 |
0 |
| gqlperl_store_location_from_gql_parser_node(aTHX_ dst_hv, node_sv); |
| 1214 |
0 |
| return newRV_noinc((SV *)dst_hv); |
| 1215 |
|
| } |
| 1216 |
|
| |
| 1217 |
0 |
▶ | if (strEQ(kind, "FragmentSpread")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(kind, "FragmentSpread")) { |
0 |
0 |
0 |
|
| 1218 |
0 |
| gql_store_sv(dst_hv, "kind", newSVpv("fragment_spread", 0)); |
| 1219 |
0 |
| gql_store_sv(dst_hv, "name", newSVpv(gql_parser_name_value(gql_parser_fetch_sv(src_hv, "name")), 0)); |
| 1220 |
0 |
| directives_sv = gqlperl_convert_directives_from_gqljs(aTHX_ gql_parser_fetch_array(src_hv, "directives")); |
| 1221 |
0 |
▶ | if (directives_sv && SvROK(directives_sv) && av_len((AV *)SvRV(directives_sv)) >= 0) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (directives_sv && SvROK(directives_sv) && av_len((AV *)SvRV(directives_sv)) >= 0) { |
0 |
0 |
0 |
| if (directives_sv && SvROK(directives_sv) && av_len((AV *)SvRV(directives_sv)) >= 0) { |
0 |
0 |
0 |
| if (directives_sv && SvROK(directives_sv) && av_len((AV *)SvRV(directives_sv)) >= 0) { |
0 |
0 |
0 |
|
| 1222 |
0 |
| gql_store_sv(dst_hv, "directives", directives_sv); |
| 1223 |
0 |
▶ | } else if (directives_sv && directives_sv != &PL_sv_undef) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (directives_sv && directives_sv != &PL_sv_undef) { |
0 |
0 |
0 |
| } else if (directives_sv && directives_sv != &PL_sv_undef) { |
0 |
0 |
0 |
|
| 1224 |
0 |
| SvREFCNT_dec(directives_sv); |
| 1225 |
|
| } |
| 1226 |
0 |
| gqlperl_store_location_from_gql_parser_node(aTHX_ dst_hv, node_sv); |
| 1227 |
0 |
| return newRV_noinc((SV *)dst_hv); |
| 1228 |
|
| } |
| 1229 |
|
| |
| 1230 |
0 |
▶ | if (strEQ(kind, "InlineFragment")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(kind, "InlineFragment")) { |
0 |
0 |
0 |
|
| 1231 |
0 |
| gql_store_sv(dst_hv, "kind", newSVpv("inline_fragment", 0)); |
| 1232 |
0 |
▶ | if (gql_parser_fetch_sv(src_hv, "typeCondition")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (gql_parser_fetch_sv(src_hv, "typeCondition")) { |
0 |
0 |
0 |
|
| 1233 |
0 |
| gql_store_sv(dst_hv, "on", |
| 1234 |
0 |
| newSVpv(gql_parser_name_value(gql_parser_fetch_sv((HV *)SvRV(gql_parser_fetch_sv(src_hv, "typeCondition")), "name")), 0)); |
| 1235 |
|
| } |
| 1236 |
0 |
| directives_sv = gqlperl_convert_directives_from_gqljs(aTHX_ gql_parser_fetch_array(src_hv, "directives")); |
| 1237 |
0 |
▶ | if (directives_sv && SvROK(directives_sv) && av_len((AV *)SvRV(directives_sv)) >= 0) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (directives_sv && SvROK(directives_sv) && av_len((AV *)SvRV(directives_sv)) >= 0) { |
0 |
0 |
0 |
| if (directives_sv && SvROK(directives_sv) && av_len((AV *)SvRV(directives_sv)) >= 0) { |
0 |
0 |
0 |
| if (directives_sv && SvROK(directives_sv) && av_len((AV *)SvRV(directives_sv)) >= 0) { |
0 |
0 |
0 |
|
| 1238 |
0 |
| gql_store_sv(dst_hv, "directives", directives_sv); |
| 1239 |
0 |
▶ | } else if (directives_sv && directives_sv != &PL_sv_undef) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (directives_sv && directives_sv != &PL_sv_undef) { |
0 |
0 |
0 |
| } else if (directives_sv && directives_sv != &PL_sv_undef) { |
0 |
0 |
0 |
|
| 1240 |
0 |
| SvREFCNT_dec(directives_sv); |
| 1241 |
|
| } |
| 1242 |
0 |
| selection_av = gqlperl_convert_selections_from_gqljs(aTHX_ |
| 1243 |
0 |
| gql_parser_fetch_array((HV *)SvRV(gql_parser_fetch_sv(src_hv, "selectionSet")), "selections")); |
| 1244 |
0 |
| gql_store_sv(dst_hv, "selections", newRV_noinc((SV *)selection_av)); |
| 1245 |
0 |
| gqlperl_store_location_from_gql_parser_node(aTHX_ dst_hv, node_sv); |
| 1246 |
0 |
| return newRV_noinc((SV *)dst_hv); |
| 1247 |
|
| } |
| 1248 |
|
| |
| 1249 |
0 |
| SvREFCNT_dec((SV *)dst_hv); |
| 1250 |
0 |
| croak("Unsupported parser selection node '%s'.", kind); |
| 1251 |
|
| } |