Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils-sfg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pycodegen
pystencils-sfg
Commits
8dd55ef2
Commit
8dd55ef2
authored
5 months ago
by
Frederik Hennig
Browse files
Options
Downloads
Patches
Plain Diff
Fix CppType factory: Fix cloning in `(de)constify`, enable immediate creation of `ref`s
parent
11f15805
No related branches found
No related tags found
1 merge request
!12
Improve versatility and robustness of `cpptype`, and document it in the user guide
Pipeline
#71501
failed
5 months ago
Stage: Code Quality
Stage: Tests
Stage: Documentation
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pystencilssfg/lang/types.py
+14
-3
14 additions, 3 deletions
src/pystencilssfg/lang/types.py
tests/lang/test_types.py
+22
-1
22 additions, 1 deletion
tests/lang/test_types.py
with
36 additions
and
4 deletions
src/pystencilssfg/lang/types.py
+
14
−
3
View file @
8dd55ef2
from
__future__
import
annotations
from
typing
import
Any
,
Iterable
from
typing
import
Any
,
Iterable
from
abc
import
ABC
from
abc
import
ABC
from
pystencils.types
import
PsType
,
PsPointerType
,
PsCustomType
from
pystencils.types
import
PsType
,
PsPointerType
,
PsCustomType
...
@@ -50,16 +51,26 @@ def cpptype(typestr: str, include: str | HeaderFile | Iterable[str | HeaderFile]
...
@@ -50,16 +51,26 @@ def cpptype(typestr: str, include: str | HeaderFile | Iterable[str | HeaderFile]
class
TypeClass
(
CppType
):
class
TypeClass
(
CppType
):
includes
=
frozenset
(
HeaderFile
.
parse
(
h
)
for
h
in
headers
)
includes
=
frozenset
(
HeaderFile
.
parse
(
h
)
for
h
in
headers
)
def
__init__
(
self
,
*
template_args
,
const
:
bool
=
False
,
**
template_kwargs
):
class
TypeClassFactory
(
TypeClass
):
def
__new__
(
# type: ignore
cls
,
*
template_args
,
const
:
bool
=
False
,
ref
:
bool
=
False
,
**
template_kwargs
,
)
->
PsType
:
template_args
=
tuple
(
_fixarg
(
arg
)
for
arg
in
template_args
)
template_args
=
tuple
(
_fixarg
(
arg
)
for
arg
in
template_args
)
template_kwargs
=
{
template_kwargs
=
{
key
:
_fixarg
(
value
)
for
key
,
value
in
template_kwargs
.
items
()
key
:
_fixarg
(
value
)
for
key
,
value
in
template_kwargs
.
items
()
}
}
name
=
typestr
.
format
(
*
template_args
,
**
template_kwargs
)
name
=
typestr
.
format
(
*
template_args
,
**
template_kwargs
)
super
().
__init__
(
name
,
const
)
obj
:
PsType
=
TypeClass
(
name
,
const
)
if
ref
:
obj
=
Ref
(
obj
)
return
obj
return
TypeClass
return
TypeClass
Factory
class
Ref
(
PsType
):
class
Ref
(
PsType
):
...
...
This diff is collapsed.
Click to expand it.
tests/lang/test_types.py
+
22
−
1
View file @
8dd55ef2
from
pystencilssfg.lang
import
cpptype
,
HeaderFile
from
pystencilssfg.lang
import
cpptype
,
HeaderFile
,
Ref
,
strip_ptr_ref
from
pystencils
import
create_type
from
pystencils
import
create_type
from
pystencils.types
import
constify
,
deconstify
def
test_cpptypes
():
def
test_cpptypes
():
...
@@ -12,3 +13,23 @@ def test_cpptypes():
...
@@ -12,3 +13,23 @@ def test_cpptypes():
==
vec_type
.
includes
==
vec_type
.
includes
==
{
HeaderFile
(
"
vector
"
,
system_header
=
True
)}
==
{
HeaderFile
(
"
vector
"
,
system_header
=
True
)}
)
)
assert
deconstify
(
constify
(
vec_type
))
==
vec_type
def
test_cpptype_const
():
tclass
=
cpptype
(
"
std::vector< {T} >
"
,
"
<vector>
"
)
vec_type
=
tclass
(
T
=
create_type
(
"
uint32
"
))
assert
constify
(
vec_type
)
==
tclass
(
T
=
create_type
(
"
uint32
"
),
const
=
True
)
vec_type
=
tclass
(
T
=
create_type
(
"
uint32
"
),
const
=
True
)
assert
deconstify
(
vec_type
)
==
tclass
(
T
=
create_type
(
"
uint32
"
),
const
=
False
)
def
test_cpptype_ref
():
tclass
=
cpptype
(
"
std::vector< {T} >
"
,
"
<vector>
"
)
vec_type
=
tclass
(
T
=
create_type
(
"
uint32
"
),
ref
=
True
)
assert
isinstance
(
vec_type
,
Ref
)
assert
strip_ptr_ref
(
vec_type
)
==
tclass
(
T
=
create_type
(
"
uint32
"
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment