From 6d8812204de3a5b97253901ebf119b7d316e3d8e Mon Sep 17 00:00:00 2001 From: Gemini CLI Date: Fri, 27 Mar 2026 09:39:51 +0000 Subject: [PATCH 1/2] Add constexpr support to functions and methods --- src/xyz/cppmodel.py | 22 +++++++++++++++++----- tests/test_cppmodel.py | 10 +++++++--- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/xyz/cppmodel.py b/src/xyz/cppmodel.py index 11f6728..d0c9135 100644 --- a/src/xyz/cppmodel.py +++ b/src/xyz/cppmodel.py @@ -76,20 +76,26 @@ def __init__(self, cursor): self.return_type: Type = Type(cursor.type.get_result()) self.arguments: List[FunctionArgument] = [] self.annotations: List[str] = _get_annotations(cursor) + self.is_constexpr: bool = "constexpr " in [t.spelling for t in cursor.get_tokens()] for t, n in zip(argument_types, arguments, strict=False): self.arguments.append(FunctionArgument(t, n)) - def __repr__(self) -> str: + def __str__(self) -> str: r = "{} {}({})".format( self.return_type.name, str(self.name), ", ".join([a.type.name for a in self.arguments]), ) + if self.is_constexpr: + r = "constexpr " + r if self.is_noexcept: r = r + " noexcept" return r + def __repr__(self) -> str: + return self.__str__() + class Function(_Function): def __init__(self, cursor, namespaces: list[str] | None = None): @@ -100,10 +106,13 @@ def __init__(self, cursor, namespaces: list[str] | None = None): if self.namespace: self.qualified_name = "::".join([self.namespace, self.name]) - def __repr__(self) -> str: - s = _Function.__repr__(self) + def __str__(self) -> str: + s = _Function.__str__(self) return "".format(s) + def __repr__(self) -> str: + return self.__str__() + def __eq__(self, f) -> bool: if self.name != f.name: return False @@ -125,8 +134,8 @@ def __init__(self, cursor): self.is_pure_virtual: bool = cursor.is_pure_virtual_method() self.is_public: bool = cursor.access_specifier == AccessSpecifier.PUBLIC - def __repr__(self) -> str: - s = _Function.__repr__(self) + def __str__(self) -> str: + s = _Function.__str__(self) if self.is_const: s = "{} const".format(s) if self.is_pure_virtual: @@ -135,6 +144,9 @@ def __repr__(self) -> str: s = "virtual {}".format(s) return "".format(s) + def __repr__(self) -> str: + return self.__str__() + class Class: def __init__(self, cursor: Cursor, namespaces: List[str]): diff --git a/tests/test_cppmodel.py b/tests/test_cppmodel.py index b5ca4da..625b12e 100644 --- a/tests/test_cppmodel.py +++ b/tests/test_cppmodel.py @@ -20,6 +20,7 @@ char c[8]; __attribute__((annotate("foo"))) int foo(int); + constexpr int constexpr_method() const; }; template @@ -29,6 +30,7 @@ class B { }; double bar(double); +constexpr int constexpr_func(); int main() {} """ @@ -49,9 +51,10 @@ def test_filename(model): def test_functions(model): - assert len(model.functions) == 2 + assert len(model.functions) == 3 assert str(model.functions[0]) == "" - assert str(model.functions[1]) == "" + assert str(model.functions[1]) == "" + assert str(model.functions[2]) == "" def test_classes(model): @@ -68,10 +71,11 @@ def test_class_members(model): assert str(model.classes[0].members[1]) == " b>" assert str(model.classes[0].members[2]) == " c>" - assert len(model.classes[0].methods) == 1 + assert len(model.classes[0].methods) == 2 assert str(model.classes[0].methods[0]) == "" assert len(model.classes[0].methods[0].annotations) == 1 assert model.classes[0].methods[0].annotations[0] == "foo" + assert str(model.classes[0].methods[1]) == "" def test_unmodelled_nodes(model): From c9feded06964f58a96a3b82ce586fe54e3e4b544 Mon Sep 17 00:00:00 2001 From: "Jonathan B. Coe" Date: Fri, 27 Mar 2026 09:52:25 +0000 Subject: [PATCH 2/2] Fix test failure --- src/xyz/cppmodel.py | 2 +- tests/test_cppmodel.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/xyz/cppmodel.py b/src/xyz/cppmodel.py index d0c9135..f10102f 100644 --- a/src/xyz/cppmodel.py +++ b/src/xyz/cppmodel.py @@ -76,7 +76,7 @@ def __init__(self, cursor): self.return_type: Type = Type(cursor.type.get_result()) self.arguments: List[FunctionArgument] = [] self.annotations: List[str] = _get_annotations(cursor) - self.is_constexpr: bool = "constexpr " in [t.spelling for t in cursor.get_tokens()] + self.is_constexpr: bool = "constexpr" in [t.spelling for t in cursor.get_tokens()] for t, n in zip(argument_types, arguments, strict=False): self.arguments.append(FunctionArgument(t, n)) diff --git a/tests/test_cppmodel.py b/tests/test_cppmodel.py index 625b12e..59b47aa 100644 --- a/tests/test_cppmodel.py +++ b/tests/test_cppmodel.py @@ -86,5 +86,5 @@ def test_unmodelled_nodes(model): ) assert ( str(model.unmodelled_nodes[1]) - == " >" + == " >" )