Read the declaration a keyword starts from the text and add it as an item, * unless the tree already has a node for it (`parsed`: the name positions of * the tree's namespaces and types). A header ends where the next declaration * keyword stands (`stop`): reading past it would read the file once per * keyword. */
| 2403 | * keyword stands (`stop`): reading past it would read the file once per |
| 2404 | * keyword. */ |
| 2405 | static void cs_text_item(cs_scan_t *s, const cs_head_t *h, uint32_t stop, const uint32_t *parsed, |
| 2406 | int nparsed) { |
| 2407 | const char *src = s->ctx->source; |
| 2408 | uint32_t n = s->root_end_byte; |
| 2409 | uint32_t a = cs_skip_space(src, h->end, n); |
| 2410 | if (a == h->end) { |
| 2411 | return; /* the keyword runs into something: not a declaration */ |
| 2412 | } |
| 2413 | bool is_ns = h->kind == 'N'; |
| 2414 | if (bsearch(&a, parsed, (size_t)nparsed, sizeof(uint32_t), cs_u32_cmp)) { |
| 2415 | return; |
| 2416 | } |
| 2417 | char *name = NULL; |
| 2418 | int brace = CBM_NOT_FOUND; |
| 2419 | const char *tparams = ""; |
| 2420 | char tag = 'T'; |
| 2421 | if (is_ns) { |
| 2422 | uint32_t after = cs_namespace_header_end(s, a, stop); |
| 2423 | name = cs_namespace_name_dup(s, a, after); |
| 2424 | if (name && src[a] != '@' && cs_not_a_name(name)) { |
| 2425 | name = NULL; /* bare keywords stay unplaced; verbatim identifiers are names */ |
| 2426 | } |
| 2427 | if (after < n && src[after] == '{') { |
| 2428 | brace = cs_open_brace_at(s, after); |
| 2429 | tag = 'N'; |
| 2430 | } else if (after < n && src[after] == ';') { |
| 2431 | tag = 'F'; |
| 2432 | } else { |
| 2433 | return; |
| 2434 | } |
| 2435 | if (tag == 'N' && brace < 0) { |
| 2436 | return; |
| 2437 | } |
| 2438 | /* An invalid name must still push an unplaced namespace frame. */ |
| 2439 | } else { |
| 2440 | uint32_t b = cs_ident_end(src, a, n, false); |
| 2441 | name = cs_ident_dup(s, a, b); |
| 2442 | if (!name || cs_not_a_name(name)) { |
| 2443 | return; |
| 2444 | } |
| 2445 | uint32_t pos = b; |
| 2446 | tparams = cs_text_tparams(s, &pos, stop); |
| 2447 | bool bodyless = false; |
| 2448 | brace = tparams ? cs_text_body(s, pos, stop, &bodyless) : CBM_NOT_FOUND; |
| 2449 | if (!tparams || (brace < 0 && !bodyless)) { |
| 2450 | return; |
| 2451 | } |
| 2452 | } |
| 2453 | int i = cs_item_new(s, tag); |
| 2454 | if (i < 0) { |
| 2455 | return; |
| 2456 | } |
| 2457 | cs_item_t *it = &s->items[i]; |
| 2458 | it->from_text = true; |
| 2459 | it->tree_idx = CS_ITEM_TEXT; |
| 2460 | it->partial = h->partial; |
| 2461 | it->kind = is_ns ? 0 : h->kind; |
| 2462 | it->text_name = name; |
no test coverage detected