Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pugs
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
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
85569909
Commit
85569909
authored
Jul 9, 2019
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Use numbers instead of pointers to define node ids in dot file
parent
da9265a5
No related branches found
No related tags found
1 merge request
!37
Feature/language
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/language/ASTDotPrinter.cpp
+16
-5
16 additions, 5 deletions
src/language/ASTDotPrinter.cpp
src/language/ASTDotPrinter.hpp
+5
-0
5 additions, 0 deletions
src/language/ASTDotPrinter.hpp
with
21 additions
and
5 deletions
src/language/ASTDotPrinter.cpp
+
16
−
5
View file @
85569909
...
...
@@ -7,20 +7,21 @@ void
ASTDotPrinter
::
_print
(
std
::
ostream
&
os
,
const
ASTNode
&
node
)
const
{
if
(
node
.
is_root
())
{
os
<<
" x"
<<
&
node
<<
" [ label=
\"
root
\\
n"
<<
dataTypeName
(
node
.
m_data_type
)
<<
"
\"
]
\n
"
;
os
<<
" x"
<<
m_node_number_map
.
at
(
&
node
)
<<
" [ label=
\"
root
\\
n"
<<
dataTypeName
(
node
.
m_data_type
)
<<
"
\"
]
\n
"
;
}
else
{
if
(
node
.
has_content
())
{
os
<<
" x"
<<
&
node
<<
" [ label=
\"
"
<<
node
.
name
()
<<
"
\\
n"
os
<<
" x"
<<
m_node_number_map
.
at
(
&
node
)
<<
" [ label=
\"
"
<<
node
.
name
()
<<
"
\\
n"
<<
node
.
string_view
()
<<
"
\\
n"
<<
dataTypeName
(
node
.
m_data_type
)
<<
"
\"
]
\n
"
;
}
else
{
os
<<
" x"
<<
&
node
<<
" [ label=
\"
"
<<
node
.
name
()
<<
"
\\
n"
<<
dataTypeName
(
node
.
m_data_type
)
<<
"
\"
]
\n
"
;
os
<<
" x"
<<
m_node_number_map
.
at
(
&
node
)
<<
" [ label=
\"
"
<<
node
.
name
()
<<
"
\\
n"
<<
dataTypeName
(
node
.
m_data_type
)
<<
"
\"
]
\n
"
;
}
}
if
(
!
node
.
children
.
empty
())
{
os
<<
" x"
<<
&
node
<<
" -> { "
;
os
<<
" x"
<<
m_node_number_map
.
at
(
&
node
)
<<
" -> { "
;
for
(
auto
&
child
:
node
.
children
)
{
os
<<
"x"
<<
child
.
get
()
<<
((
child
==
node
.
children
.
back
())
?
" }
\n
"
:
", "
);
os
<<
"x"
<<
m_node_number_map
.
at
(
child
.
get
()
)
<<
((
child
==
node
.
children
.
back
())
?
" }
\n
"
:
", "
);
}
for
(
auto
&
child
:
node
.
children
)
{
this
->
_print
(
os
,
*
child
);
...
...
@@ -37,7 +38,17 @@ operator<<(std::ostream& os, const ASTDotPrinter& ast_printer)
return
os
;
}
void
ASTDotPrinter
::
_buildNodeNumberMap
(
const
ASTNode
&
node
)
{
m_node_number_map
[
&
node
]
=
m_node_number_map
.
size
();
for
(
auto
&
child
:
node
.
children
)
{
this
->
_buildNodeNumberMap
(
*
child
);
}
}
ASTDotPrinter
::
ASTDotPrinter
(
const
ASTNode
&
node
)
:
m_node
{
node
}
{
Assert
(
node
.
is_root
());
this
->
_buildNodeNumberMap
(
node
);
}
This diff is collapsed.
Click to expand it.
src/language/ASTDotPrinter.hpp
+
5
−
0
View file @
85569909
...
...
@@ -2,14 +2,19 @@
#define AST_DOT_PRINTER_HPP
#include
<ASTNode.hpp>
#include
<map>
class
ASTDotPrinter
{
private:
const
ASTNode
&
m_node
;
std
::
map
<
const
ASTNode
*
,
uint32_t
>
m_node_number_map
;
void
_print
(
std
::
ostream
&
os
,
const
ASTNode
&
node
)
const
;
void
_buildNodeNumberMap
(
const
ASTNode
&
node
);
public:
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
ASTDotPrinter
&
ast_printer
);
...
...
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