Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add C support for a class containing only scalar data #1472

Merged
merged 94 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
b9db1a5
Printing Header c
sboof911 Jul 21, 2023
9b019a8
Adding the printing of the function of the class
sboof911 Jul 21, 2023
7d649d7
Add ConstructorCall
sboof911 Jul 21, 2023
055f90a
CHANGELOG
sboof911 Jul 21, 2023
e7322cf
Adding Tests
sboof911 Jul 21, 2023
36d6777
from an Assign(Variable, ConstructorCall) to a ConstructorCall
sboof911 Jul 24, 2023
3c75d18
Update semantic.py
sboof911 Jul 24, 2023
463a710
merge devel
sboof911 Jul 24, 2023
ba341d5
merge devel
sboof911 Jul 24, 2023
bf72c1c
from an Assign(Variable, ConstructorCall) to a ConstructorCall
sboof911 Jul 24, 2023
4c2f8e3
Update semantic.py
sboof911 Jul 24, 2023
8aa9377
ConstructorCall inherit from DottedFunctionCall
sboof911 Jul 24, 2023
9997703
fix inheritance
sboof911 Jul 24, 2023
f97c87e
fixing inheritance
sboof911 Jul 24, 2023
963ebd9
Assign to ConstructorCall
sboof911 Jul 25, 2023
224178a
deleting unnecessary code
sboof911 Jul 25, 2023
8d1f84a
deleting unnecessary code
sboof911 Jul 25, 2023
a3dc71f
deleting unnecessary code
sboof911 Jul 25, 2023
585bc3b
deleting unnecessary code
sboof911 Jul 25, 2023
0b087b6
optimizing the ConstructorCall
sboof911 Jul 25, 2023
62a45ab
deleting unnecessary code from _infer_type
sboof911 Jul 25, 2023
90a776f
some minor change
sboof911 Jul 25, 2023
3c20f6e
some minor change
sboof911 Jul 25, 2023
ef25891
cleaning code
sboof911 Jul 25, 2023
ec3274e
Update semantic
sboof911 Jul 26, 2023
920bba1
fixing errors in pycode.py
sboof911 Jul 26, 2023
6262381
fixing errors in pycode.py
sboof911 Jul 26, 2023
ed42d9d
fix fortran ContructorCall
sboof911 Jul 26, 2023
e0c5e6c
fix fortran ContructorCall
sboof911 Jul 26, 2023
121b961
merge
sboof911 Jul 26, 2023
1e5a077
CHANGELOG
sboof911 Jul 26, 2023
4cdc66b
merge
sboof911 Jul 26, 2023
a032321
Update CHANGELOG.md
sboof911 Jul 26, 2023
6e6f5cf
merge
sboof911 Jul 26, 2023
d25e721
edit FunctionCall
sboof911 Jul 26, 2023
e6aab9f
edit pycode
sboof911 Jul 26, 2023
6ed1047
fix docstrings
sboof911 Jul 26, 2023
e6d8492
fixing docstrings
sboof911 Jul 26, 2023
b4e1c67
fix docstrings cls_variable
sboof911 Jul 26, 2023
c8dc239
merge
sboof911 Jul 26, 2023
268e5d6
adding extended summary
sboof911 Jul 26, 2023
67ae2bf
CHANGELOG
sboof911 Jul 27, 2023
d132747
CHANGELOG
sboof911 Jul 27, 2023
3064d12
CustomDataType
sboof911 Jul 27, 2023
23efc36
end with a period
sboof911 Jul 27, 2023
b0c5114
delete _print_ConstructorCall() func
sboof911 Jul 27, 2023
0e71d48
fix summary
sboof911 Jul 27, 2023
d1b3856
deleting cls_variable parameter
sboof911 Jul 27, 2023
5a48945
removing unused code
sboof911 Jul 27, 2023
fd5135e
fixing some issues
sboof911 Jul 27, 2023
ec4cd26
Merge branch 'devel' into issue#1441
sboof911 Jul 27, 2023
4c17808
updating ccode from branch issue#1455
sboof911 Jul 27, 2023
a299dc2
fix codacy errors
sboof911 Jul 27, 2023
8fb1b3d
edit tests
sboof911 Jul 27, 2023
7bb9476
fix codacy
sboof911 Jul 27, 2023
b1aefbf
merge issue#1455
sboof911 Aug 1, 2023
2689b16
deleting trailing whitespace
sboof911 Aug 1, 2023
7a7b9d0
Add C support for a class containing only scalar data
sboof911 Aug 1, 2023
fac7fbb
deleting unwanted commit
sboof911 Aug 1, 2023
6c593d2
deleting unwanted tests
sboof911 Aug 1, 2023
451f778
Add C support for a class containing only scalar data
sboof911 Aug 1, 2023
fdffe6d
add protection
sboof911 Aug 2, 2023
44ead6f
merge
sboof911 Aug 2, 2023
ef0271a
CHANGELOG
sboof911 Aug 2, 2023
e9e45eb
Update classes_3.py
sboof911 Aug 2, 2023
c949714
fixing changelog
sboof911 Aug 3, 2023
18e06a4
edit test
sboof911 Aug 3, 2023
34017ce
edit test
sboof911 Aug 3, 2023
c3631e1
Rename classes_2.py to classes_2_C.py
sboof911 Aug 3, 2023
5b22666
Update test_pyccel.py
sboof911 Aug 3, 2023
b34c31a
format to fstring
sboof911 Aug 3, 2023
65c9f7a
update condition test_pyccel
sboof911 Aug 3, 2023
fd0c5c1
format to fstring
sboof911 Aug 3, 2023
d897f9f
fix conflicts
sboof911 Aug 3, 2023
973dc11
Merge branch 'issue#1441' into issue#1439
sboof911 Aug 3, 2023
eaff1ba
Rename classes_3.py to classes_3_C.py
sboof911 Aug 3, 2023
bab3ae5
delete unused import
sboof911 Aug 3, 2023
03f7363
fix
sboof911 Aug 3, 2023
93ca186
fixing test to not be arrays
sboof911 Aug 3, 2023
67b5a50
Delete classes_3_C.py
sboof911 Aug 3, 2023
9cd5cc4
Update ccode.py
sboof911 Aug 7, 2023
6ef9966
Merge branch 'devel' into issue#1439
sboof911 Sep 1, 2023
e40ebcb
CHANGELOG
sboof911 Sep 1, 2023
4f440b5
fix is_c_pointer
sboof911 Sep 1, 2023
d67d777
Merge branch 'devel' into issue#1439
yguclu Sep 4, 2023
9f941aa
add self._current_class
sboof911 Sep 4, 2023
aad91b8
fix visit lhs of a dottedvariable
sboof911 Sep 4, 2023
fe90aaa
add empty line
sboof911 Sep 4, 2023
1aa1651
reset test_pyccel
sboof911 Sep 4, 2023
2f3a91f
add tests
sboof911 Sep 4, 2023
28e9d98
change test
sboof911 Sep 4, 2023
b9b3535
fix self Functiondef argument
sboof911 Sep 4, 2023
cf931ae
CHANGELOG
sboof911 Sep 4, 2023
39ddc93
Update CHANGELOG.md
sboof911 Sep 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file.

### Added

- #1472 : Add C printing support for a class containing scalar data.

### Fixed

- #1484 : Use scope for classes to avoid name clashes.
Expand Down
3 changes: 2 additions & 1 deletion pyccel/codegen/printing/ccode.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pyccel.ast.builtins import PythonList, PythonTuple

from pyccel.ast.core import Declare, For, CodeBlock
from pyccel.ast.core import FuncAddressDeclare, FunctionCall, FunctionCallArgument, FunctionDef
from pyccel.ast.core import FuncAddressDeclare, FunctionCall, FunctionCallArgument, ClassDef
from pyccel.ast.core import Allocate, Deallocate
from pyccel.ast.core import FunctionAddress, FunctionDefArgument
from pyccel.ast.core import Assign, Import, AugAssign, AliasAssign
Expand Down Expand Up @@ -736,6 +736,7 @@ def _print_ModuleHeader(self, expr):
funcs = ""
for classDef in expr.module.classes:
classes += f"struct {classDef.name} {{\n"
classes += ''.join(self._print(Declare(var.dtype,var)) for var in classDef.attributes)
for method in classDef.methods:
method.rename(classDef.name + ("__" + method.name if not method.name.startswith("__") else method.name))
funcs += f"{self.function_signature(method)};\n"
Expand Down
4 changes: 2 additions & 2 deletions pyccel/parser/semantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ def _assign_lhs_variable(self, lhs, d_var, rhs, new_expressions, is_augassign,ar
# the following is a small fix, since lhs must be already
# declared
if isinstance(lhs, DottedName):
lhs = var.clone(var.name, new_class = DottedVariable, lhs = lhs.name[0])
lhs = var.clone(var.name, new_class = DottedVariable, lhs = self._visit(lhs.name[0]))
else:
lhs = var
else:
Expand Down Expand Up @@ -3281,7 +3281,7 @@ def _visit_FunctionDef(self, expr):
dt = self.get_class_construct(cls_name)()
cls_base = self.scope.find(cls_name, 'classes')
cls_base.scope.insert_symbols(expr.scope.local_used_symbols.copy())
var = Variable(dt, 'self', cls_base=cls_base)
var = Variable(dt, 'self', cls_base=cls_base, is_argument=True)
self.scope.insert_variable(var)

if arguments:
Expand Down
24 changes: 24 additions & 0 deletions tests/pyccel/scripts/classes/classes_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# pylint: disable=missing-class-docstring, missing-function-docstring, missing-module-docstring
# coding: utf-8

#$ header class Point1(public)
#$ header method __init__(Point1, double)
#$ header class Point2(public)
#$ header method __init__(Point2, double)
#$ header method test_func(Point2)

class Point1:
def __init__(self, x):
self.x = x

class Point2:
def __init__(self, y):
self.y = y

def test_func(self):
p = Point1(self.y)
print(p.x)

if __name__ == '__main__':
j = Point2(2.2)
j.test_func()
5 changes: 3 additions & 2 deletions tests/pyccel/test_pyccel.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,9 +863,8 @@ def test_basic_header():

#------------------------------------------------------------------------------
@pytest.mark.parametrize( "test_file", ["scripts/classes/classes.py",
"scripts/classes/classes_1.py",
"scripts/classes/classes_5.py",
"scripts/classes/generic_methods.py",
"scripts/classes/classes_1.py",
] )
@pytest.mark.parametrize( 'language', (
pytest.param("python", marks = pytest.mark.python),
Expand All @@ -882,6 +881,8 @@ def test_classes_f_only( test_file , language):
#------------------------------------------------------------------------------
@pytest.mark.xdist_incompatible
@pytest.mark.parametrize( "test_file", ["scripts/classes/classes_2_C.py",
"scripts/classes/classes_5.py",
"scripts/classes/classes_3.py",
] )
@pytest.mark.parametrize( 'language', (
pytest.param("python", marks = pytest.mark.python),
Expand Down