| 1505 | } |
| 1506 | |
| 1507 | static TSNode csharp_callable_value_site(TSNode node, TSNode parent, const char *parent_field, |
| 1508 | TSTreeCursor *cursor) { |
| 1509 | const char *kind = ts_node_type(node); |
| 1510 | if (strcmp(kind, "identifier") != 0 && strcmp(kind, "simple_identifier") != 0) { |
| 1511 | return (TSNode){0}; |
| 1512 | } |
| 1513 | |
| 1514 | /* The caller has already resolved node's parent (and the field it occupies) |
| 1515 | * with the cursor, so the climb starts from that pair instead of asking for |
| 1516 | * it again. Invariant below: `parent`/`field` always describe `site`. */ |
| 1517 | TSNode site = node; |
| 1518 | const char *field = parent_field; |
| 1519 | if (!ts_node_is_null(parent) && strcmp(ts_node_type(parent), "generic_name") == 0) { |
| 1520 | TSNode name = ts_node_child_by_field_name(parent, TS_FIELD("name")); |
| 1521 | if (ts_node_is_null(name) && ts_node_named_child_count(parent) > 0) { |
| 1522 | name = ts_node_named_child(parent, 0); |
| 1523 | } |
| 1524 | if (ts_node_is_null(name) || !ts_node_eq(name, node)) { |
| 1525 | return (TSNode){0}; |
| 1526 | } |
| 1527 | site = parent; |
| 1528 | if (!csharp_site_parent(cursor, site, &parent, &field)) { |
| 1529 | return (TSNode){0}; |
| 1530 | } |
| 1531 | } |
| 1532 | |
| 1533 | if (!ts_node_is_null(parent) && strcmp(ts_node_type(parent), "member_access_expression") == 0) { |
| 1534 | TSNode member = ts_node_child_by_field_name(parent, TS_FIELD("name")); |
| 1535 | if (ts_node_is_null(member) || !ts_node_eq(member, site)) { |
| 1536 | return (TSNode){0}; |
| 1537 | } |
| 1538 | site = parent; |
| 1539 | if (!csharp_site_parent(cursor, site, &parent, &field)) { |
| 1540 | return (TSNode){0}; |
| 1541 | } |
| 1542 | } |
| 1543 | |
| 1544 | while (!ts_node_is_null(parent) && |
| 1545 | strcmp(ts_node_type(parent), "parenthesized_expression") == 0) { |
| 1546 | TSNode inner = ts_node_child_by_field_name(parent, TS_FIELD("expression")); |
| 1547 | if (ts_node_is_null(inner) && ts_node_named_child_count(parent) == 1) { |
| 1548 | inner = ts_node_named_child(parent, 0); |
| 1549 | } |
| 1550 | if (ts_node_is_null(inner) || !ts_node_eq(inner, site)) { |
| 1551 | return (TSNode){0}; |
| 1552 | } |
| 1553 | site = parent; |
| 1554 | if (!csharp_site_parent(cursor, site, &parent, &field)) { |
| 1555 | return (TSNode){0}; |
| 1556 | } |
| 1557 | } |
| 1558 | |
| 1559 | /* The wrapper chain proves admission, but the semantic row is keyed to the |
| 1560 | * terminal method-name identifier. Keep the raw carrier on that leaf. */ |
| 1561 | if (ts_node_is_null(parent)) { |
| 1562 | return (TSNode){0}; |
| 1563 | } |
| 1564 | return is_direct_argument_value_from(parent, field, cursor) ? node : (TSNode){0}; |
no test coverage detected