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
b4c0f95c
Commit
b4c0f95c
authored
1 year ago
by
Frederik Hennig
Browse files
Options
Downloads
Patches
Plain Diff
add order-aware printing
parent
d91d00f2
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#58225
passed
1 year ago
Stage: pretest
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pystencilssfg/context.py
+16
-0
16 additions, 0 deletions
src/pystencilssfg/context.py
src/pystencilssfg/emission/printers.py
+1
-5
1 addition, 5 deletions
src/pystencilssfg/emission/printers.py
with
17 additions
and
5 deletions
src/pystencilssfg/context.py
+
16
−
0
View file @
b4c0f95c
...
...
@@ -36,6 +36,8 @@ class SfgContext:
self
.
_functions
:
dict
[
str
,
SfgFunction
]
=
dict
()
self
.
_classes
:
dict
[
str
,
SfgClass
]
=
dict
()
self
.
_declarations_ordered
:
list
[
str
|
SfgFunction
|
SfgClass
]
=
list
()
# Standard stuff
self
.
add_include
(
SfgHeaderInclude
(
"
cstdint
"
,
system_header
=
True
))
self
.
add_definition
(
"
#define RESTRICT __restrict__
"
)
...
...
@@ -109,6 +111,7 @@ class SfgContext:
def
add_definition
(
self
,
definition
:
str
):
self
.
_definitions
.
append
(
definition
)
self
.
_declarations_ordered
.
append
(
definition
)
def
set_namespace
(
self
,
namespace
:
str
):
if
self
.
_inner_namespace
is
not
None
:
...
...
@@ -151,6 +154,8 @@ class SfgContext:
raise
SfgException
(
f
"
Duplicate function:
{
func
.
name
}
"
)
self
.
_functions
[
func
.
name
]
=
func
self
.
_declarations_ordered
.
append
(
func
)
for
incl
in
CollectIncludes
().
visit
(
func
):
self
.
add_include
(
incl
)
...
...
@@ -169,6 +174,17 @@ class SfgContext:
raise
SfgException
(
f
"
Duplicate class:
{
cls
.
class_name
}
"
)
self
.
_classes
[
cls
.
class_name
]
=
cls
self
.
_declarations_ordered
.
append
(
cls
)
for
incl
in
CollectIncludes
().
visit
(
cls
):
self
.
add_include
(
incl
)
# ----------------------------------------------------------------------------------------------
# Declarations in order of addition
# ----------------------------------------------------------------------------------------------
def
declarations_ordered
(
self
)
->
Generator
[
str
|
SfgFunction
|
SfgClass
,
None
,
None
]:
"""
All declared definitions, classes and functions in the order they were added.
Awareness about order is necessary due to the C++ declare-before-use rules.
"""
yield
from
self
.
_declarations_ordered
This diff is collapsed.
Click to expand it.
src/pystencilssfg/emission/printers.py
+
1
−
5
View file @
b4c0f95c
...
...
@@ -93,11 +93,7 @@ class SfgHeaderPrinter(SfgGeneralPrinter):
code
+=
f
"
namespace
{
fq_namespace
}
{{
\n\n
"
parts
=
interleave
(
chain
(
ctx
.
definitions
(),
ctx
.
classes
(),
ctx
.
functions
()
),
ctx
.
declarations_ordered
(),
repeat
(
SfgEmptyLines
(
1
))
)
...
...
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