Coverage for src/renaissance/integrations/clang/predicates.py: 100%

21 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-15 10:34 +0000

1# Copyright (C) 2024-2026 TNO 

2# 

3# Licensed under the terms specified in the LICENSE file in the root directory 

4# of this repository, also available at: 

5# https://github.com/TNO/Renaissance.Py/blob/main/LICENSE 

6 

7"""AI: Predicate helpers for identifying specific Clang AST node kinds.""" 

8 

9from renaissance.syntax_tree.node_protocol import NodeProtocol 

10 

11TYPE_REFERENCE_KINDS = frozenset({"TypeRef", "TYPE_REF", "type_identifier"}) 

12DECLARATION_REFERENCE_KINDS = frozenset({"DeclRefExpr", "DECL_REF_EXPR"}) 

13COMPOUND_STATEMENT_KINDS = frozenset({"CompoundStmt", "COMPOUND_STMT"}) 

14MACRO_DEFINITION_KINDS = frozenset({"MacroDefinition", "MACRO_DEFINITION"}) 

15METHOD_KINDS = frozenset({"CXXMethodDecl", "CXX_METHOD"}) 

16CONSTRUCTOR_KINDS = frozenset({"CXXConstructorDecl", "CXX_CONSTRUCTOR"}) 

17 

18 

19def is_clang_kind(node: NodeProtocol, *parser_kinds: str) -> bool: 

20 """AI: Return True if node's parser_kind matches one of the given kind strings.""" 

21 return node.parser_kind in parser_kinds 

22 

23 

24def is_clang_type_reference(node: NodeProtocol) -> bool: 

25 """AI: Return True if node is a Clang type-reference node.""" 

26 return node.parser_kind in TYPE_REFERENCE_KINDS 

27 

28 

29def is_clang_declaration_reference(node: NodeProtocol) -> bool: 

30 """AI: Return True if node is a Clang declaration-reference node.""" 

31 return node.parser_kind in DECLARATION_REFERENCE_KINDS 

32 

33 

34def is_clang_compound_statement(node: NodeProtocol) -> bool: 

35 """AI: Return True if node is a Clang compound statement (block).""" 

36 return node.parser_kind in COMPOUND_STATEMENT_KINDS 

37 

38 

39def is_clang_macro_definition(node: NodeProtocol) -> bool: 

40 """AI: Return True if node is a Clang macro definition.""" 

41 return node.parser_kind in MACRO_DEFINITION_KINDS 

42 

43 

44def is_clang_method(node: NodeProtocol) -> bool: 

45 """AI: Return True if node is a Clang C++ method declaration.""" 

46 return node.parser_kind in METHOD_KINDS 

47 

48 

49def is_clang_constructor(node: NodeProtocol) -> bool: 

50 """AI: Return True if node is a Clang C++ constructor declaration.""" 

51 return node.parser_kind in CONSTRUCTOR_KINDS