Coverage for src / renaissance / integrations / clang / cpp_utils.py: 42%
12 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-09-09 14:04 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-09-09 14:04 +0000
1from renaissance.integrations.types import DeclarationExpression, Literal, Type
4def get_ancestor(node, kind: type[Type]):
5 parent = node.parent
6 if not parent:
7 return None
8 if isinstance(parent.ast_type(), kind):
9 return parent
10 return parent.get_ancestor(kind)
13def matches_kind(mine, other) -> bool:
14 return (
15 mine == other
16 or (isinstance(mine(), Literal) and isinstance(other(), DeclarationExpression))
17 or (isinstance(other(), Literal) and isinstance(mine(), DeclarationExpression))
18 )
21class CPPUtils:
22 # a set of cpp reserved keywords in reverse alphabetical order:
23 RESERVED_KEYWORDS = {
24 "while",
25 "wchar_t",
26 "void",
27 "volatile",
28 "virtual",
29 "unsigned",
30 "union",
31 "typename",
32 "typedef",
33 "try",
34 "true",
35 "throw",
36 "this",
37 "template",
38 "switch",
39 "struct",
40 "static_cast",
41 "static",
42 "sizeof",
43 "signed",
44 "short",
45 "return",
46 "reinterpret_cast",
47 "register",
48 "public",
49 "protected",
50 "private",
51 "operator",
52 "or_eq",
53 "or",
54 "not_eq",
55 "not",
56 "new",
57 "namespace",
58 "mutable",
59 "long",
60 "inline",
61 "int",
62 "if",
63 "goto",
64 "friend",
65 "for",
66 "float",
67 "false",
68 "extern",
69 "explicit",
70 "export",
71 "enum",
72 "else",
73 "double",
74 "do",
75 "delete",
76 "default",
77 "decltype",
78 "continue",
79 "const_cast",
80 "const",
81 "class",
82 "char16_t",
83 "char32_t",
84 "char",
85 "catch",
86 "case",
87 "break",
88 "bool",
89 "bitand",
90 "bitor",
91 "auto",
92 "asm",
93 "and_eq",
94 "and",
95 }