Coverage for src/renaissance/integrations/clang/cpp_utils.py: 62%
8 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-15 10:34 +0000
« 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
7"""AI: Helper predicates and constants for working with C/C++ AST node kinds."""
10def matches_node_kind(mine, other) -> bool:
11 """AI: Return True if two nodes share the same semantic kind or parser kind."""
12 if mine.semantic_kind.value != "node" and other.semantic_kind.value != "node":
13 return mine.semantic_kind is other.semantic_kind
14 return mine.parser_kind == other.parser_kind
17def is_clang_kind(node, *parser_kinds: str) -> bool:
18 """AI: Return True if node's parser_kind matches one of the given kind strings."""
19 return node.parser_kind in parser_kinds
22class CPPUtils:
23 """AI: Constants and helpers for working with C++ reserved keywords and type names."""
25 # a set of cpp reserved keywords in reverse alphabetical order:
26 RESERVED_KEYWORDS = {
27 "while",
28 "wchar_t",
29 "void",
30 "volatile",
31 "virtual",
32 "unsigned",
33 "union",
34 "typename",
35 "typedef",
36 "try",
37 "true",
38 "throw",
39 "this",
40 "template",
41 "switch",
42 "struct",
43 "static_cast",
44 "static",
45 "sizeof",
46 "signed",
47 "short",
48 "return",
49 "reinterpret_cast",
50 "register",
51 "public",
52 "protected",
53 "private",
54 "operator",
55 "or_eq",
56 "or",
57 "not_eq",
58 "not",
59 "new",
60 "namespace",
61 "mutable",
62 "long",
63 "inline",
64 "int",
65 "if",
66 "goto",
67 "friend",
68 "for",
69 "float",
70 "false",
71 "extern",
72 "explicit",
73 "export",
74 "enum",
75 "else",
76 "double",
77 "do",
78 "delete",
79 "default",
80 "decltype",
81 "continue",
82 "const_cast",
83 "const",
84 "class",
85 "char16_t",
86 "char32_t",
87 "char",
88 "catch",
89 "case",
90 "break",
91 "bool",
92 "bitand",
93 "bitor",
94 "auto",
95 "asm",
96 "and_eq",
97 "and",
98 }