Skip to content

Commit

Permalink
add three-way comparison operator
Browse files Browse the repository at this point in the history
  • Loading branch information
SzopuCpp committed May 5, 2024
1 parent a2fae7f commit 12ca4fa
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/devana/syntax_abstraction/classinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def check_operator(name: str) -> bool:
"operator<=",
"operator<",
"operator>",
"operator<=>",
"operator+",
"operator-",
"operator*",
Expand Down
16 changes: 16 additions & 0 deletions tests/code_generation/unit/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@ def test_function_body_with_brace(self):
result = self.printer.print(source)
self.assertEqual(result, "float foo()\n{\n return 6.7;\n}\n")

def test_print_three_way_comparison_operator(self):
source = FunctionInfo()
source.name = "operator<=>"
source.return_type = BasicType.BOOL
arg1 = FunctionInfo.Argument()
arg1.type = TypeExpression()
arg1.type.details = BasicType.INT
arg1.name = "a"
arg2 = FunctionInfo.Argument()
arg2.type = TypeExpression()
arg2.type.details = BasicType.INT
arg2.name = "b"
source.arguments = [arg1, arg2]
result = self.printer.print(source)
self.assertEqual(result, "bool operator<=>(int a, int b);\n")


class TestFunctionTemplate(unittest.TestCase):

Expand Down
1 change: 1 addition & 0 deletions tests/parsing/unit/source_files/core_class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class ClassOperators
bool operator<=(double a);
bool operator<(double a);
bool operator>(double a);
bool operator<=>(double a);
bool operator+(double a);
bool operator-(double a);
bool operator*(double a);
Expand Down
8 changes: 6 additions & 2 deletions tests/parsing/unit/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import os
import clang.cindex
import clang

from devana.configuration import LanguageStandard
from tests.helpers import find_by_name
from devana.syntax_abstraction.typeexpression import BasicType, TypeModification
from devana.syntax_abstraction.classinfo import *
Expand All @@ -13,7 +15,9 @@ class TestClassBasic(unittest.TestCase):

def setUp(self):
index = clang.cindex.Index.create()
self.cursor = index.parse(os.path.dirname(__file__) + r"/source_files/core_class.hpp").cursor
config: Configuration = Configuration()
config.parsing.language_version = LanguageStandard.CPP_20
self.cursor = index.parse(os.path.dirname(__file__) + r"/source_files/core_class.hpp", args=config.parsing.parsing_options()).cursor

def test_struct_simple_def(self):
node = find_by_name(self.cursor, "SimpleStructTest")
Expand Down Expand Up @@ -183,7 +187,7 @@ def test_class_sections(self):
def test_class_operators(self):
node = find_by_name(self.cursor, "ClassOperators")
result = ClassInfo.from_cursor(node)
self.assertEqual(len(result.content), 46)
self.assertEqual(len(result.content), 47)
for op in result.content:
self.assertTrue(op.type.is_operator, f"{op}")

Expand Down

0 comments on commit 12ca4fa

Please sign in to comment.