|
23 | 23 | // Tree traversal limits. |
24 | 24 | enum { |
25 | 25 | TEMPLATE_DEPTH_LIMIT = 4, |
26 | | - DECLARATOR_DEPTH_LIMIT = 8, |
| 26 | + DECLARATOR_DEPTH_LIMIT = CBM_DECLARATOR_DEPTH_LIMIT, // shared define in helpers.h |
| 27 | + |
27 | 28 | EXPORT_ANCESTOR_DEPTH = 4, |
28 | 29 | DECORATOR_SCAN_LIMIT = 3, |
29 | 30 | C_RETURN_WALK_DEPTH = 5, |
@@ -457,27 +458,6 @@ static TSNode resolve_func_name_fp(TSNode node, CBMLanguage lang, const char *ki |
457 | 458 | return null_node; |
458 | 459 | } |
459 | 460 |
|
460 | | -// Check if a node type is a terminal C declarator name. |
461 | | -static bool is_c_terminal_name(const char *dk) { |
462 | | - return strcmp(dk, "identifier") == 0 || strcmp(dk, "field_identifier") == 0 || |
463 | | - strcmp(dk, "operator_name") == 0 || strcmp(dk, "operator_cast") == 0 || |
464 | | - strcmp(dk, "destructor_name") == 0; |
465 | | -} |
466 | | - |
467 | | -// Resolve name from a C++ qualified_identifier/scoped_identifier. |
468 | | -static TSNode resolve_qualified_name(TSNode decl) { |
469 | | - static const char *name_kinds[] = {"operator_name", "operator_cast", "destructor_name", |
470 | | - "identifier", "field_identifier", NULL}; |
471 | | - for (const char **k = name_kinds; *k; k++) { |
472 | | - TSNode found = cbm_find_child_by_kind(decl, *k); |
473 | | - if (!ts_node_is_null(found)) { |
474 | | - return found; |
475 | | - } |
476 | | - } |
477 | | - TSNode null_node = {0}; |
478 | | - return null_node; |
479 | | -} |
480 | | - |
481 | 461 | // C++/CUDA: out-of-line method definitions name the function with a qualified |
482 | 462 | // declarator (`Foo::bar`, or `ns::Foo::bar`). Return the immediate enclosing |
483 | 463 | // class name (the scope segment directly left of the function name, e.g. "Foo"), |
@@ -528,30 +508,6 @@ static char *cpp_out_of_line_parent_class(CBMArena *a, TSNode node, const char * |
528 | 508 | return (text && text[0]) ? text : NULL; |
529 | 509 | } |
530 | 510 |
|
531 | | -// Resolve function name from C/C++/CUDA/GLSL declarator chain. |
532 | | -static TSNode resolve_c_declarator_name(TSNode node) { |
533 | | - TSNode decl = ts_node_child_by_field_name(node, TS_FIELD("declarator")); |
534 | | - for (int depth = 0; depth < DECLARATOR_DEPTH_LIMIT && !ts_node_is_null(decl); depth++) { |
535 | | - const char *dk = ts_node_type(decl); |
536 | | - if (is_c_terminal_name(dk)) { |
537 | | - return decl; |
538 | | - } |
539 | | - if (strcmp(dk, "qualified_identifier") == 0 || strcmp(dk, "scoped_identifier") == 0) { |
540 | | - return resolve_qualified_name(decl); |
541 | | - } |
542 | | - TSNode inner = ts_node_child_by_field_name(decl, TS_FIELD("declarator")); |
543 | | - if (ts_node_is_null(inner) && ts_node_named_child_count(decl) > 0) { |
544 | | - inner = ts_node_named_child(decl, 0); |
545 | | - } |
546 | | - if (ts_node_is_null(inner)) { |
547 | | - break; |
548 | | - } |
549 | | - decl = inner; |
550 | | - } |
551 | | - TSNode null_node = {0}; |
552 | | - return null_node; |
553 | | -} |
554 | | - |
555 | 511 | // R: resolve function_definition name from parent binary_operator lhs. |
556 | 512 | static TSNode resolve_r_func_name(TSNode node) { |
557 | 513 | TSNode parent = ts_node_parent(node); |
@@ -675,7 +631,7 @@ static TSNode resolve_func_name_c_family(TSNode *node_ptr, CBMLanguage lang, con |
675 | 631 | lang == CBM_LANG_GLSL || lang == CBM_LANG_HLSL || lang == CBM_LANG_ISPC || |
676 | 632 | lang == CBM_LANG_SLANG) && |
677 | 633 | strcmp(kind, "function_definition") == 0) { |
678 | | - return resolve_c_declarator_name(*node_ptr); |
| 634 | + return cbm_resolve_c_declarator_name_node(*node_ptr); |
679 | 635 | } |
680 | 636 | TSNode null_node = {0}; |
681 | 637 | return null_node; |
|
0 commit comments