Lexical lifetimes of named C++ locals/parameters, not corpus callees.
(body, source: bytes)
| 5674 | |
| 5675 | |
| 5676 | def _cpp_local_binding_ranges(body, source: bytes) -> dict[str, list[tuple[int, int, str, str, str, bool]]]: |
| 5677 | """Lexical lifetimes of named C++ locals/parameters, not corpus callees.""" |
| 5678 | ranges: dict[str, list[tuple[int, int, str, str, bool]]] = {} |
| 5679 | scopes = {"compound_statement", "for_statement", "for_range_loop", "if_statement", |
| 5680 | "switch_statement", "catch_clause", "function_definition", "lambda_expression"} |
| 5681 | stack = [body] |
| 5682 | function = body.parent |
| 5683 | if function is not None and function.type == "function_definition": |
| 5684 | declarator = function.child_by_field_name("declarator") |
| 5685 | if declarator is not None: |
| 5686 | stack.append(declarator) |
| 5687 | while stack: |
| 5688 | node = stack.pop() |
| 5689 | if node.type in {"class_specifier", "struct_specifier", "function_definition"}: |
| 5690 | continue |
| 5691 | if node.type in {"declaration", "parameter_declaration", "optional_parameter_declaration", |
| 5692 | "lambda_capture_initializer"}: |
| 5693 | scope = node.parent |
| 5694 | while scope is not None and scope.type not in scopes: |
| 5695 | scope = scope.parent |
| 5696 | if scope is not None: |
| 5697 | declarators = node.children_by_field_name( |
| 5698 | "left" if node.type == "lambda_capture_initializer" else "declarator") |
| 5699 | for declarator in declarators: |
| 5700 | name = _cpp_declarator_name(declarator, source) |
| 5701 | if name: |
| 5702 | type_node = node.child_by_field_name("type") |
| 5703 | dependent = type_node is not None and ( |
| 5704 | type_node.type == "dependent_type" or _cpp_type_is_dependent(type_node, source) |
| 5705 | ) |
| 5706 | ranges.setdefault(name, []).append(( |
| 5707 | declarator.start_byte, scope.end_byte, |
| 5708 | _cpp_declared_receiver_type(node, declarator, source), |
| 5709 | _cpp_lookup_scope(node, source), |
| 5710 | _cpp_qualified_name(node, "", source).rstrip(":"), |
| 5711 | dependent, |
| 5712 | )) |
| 5713 | stack.extend(node.named_children) |
| 5714 | return ranges |
| 5715 | |
| 5716 | |
| 5717 | def _cpp_local_var_types(body_node, source: bytes, table: dict[str, str]) -> None: |
no test coverage detected