FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
lpython/src/lpython/ast_serialization.cpp at Smit-create-patch-1 · kinshukdua/lpython · GitHub
kinshukdua
/
lpython
Public
forked from
lcompilers/lpython
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
lpython
/
src
/
lpython
/
ast_serialization.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
83 lines (71 loc) · 1.83 KB
Breadcrumbs
lpython
/
src
/
lpython
/
ast_serialization.cpp
Copy path
File metadata and controls
83 lines (71 loc) · 1.83 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#
include
<
string
>
#
include
<
libasr/config.h
>
#
include
<
lpython/ast_serialization.h
>
#
include
<
lpython/parser/parser.h
>
#
include
<
lpython/parser/parser.tab.hh
>
#
include
<
libasr/asr_utils.h
>
#
include
<
libasr/asr_verify.h
>
#
include
<
libasr/bwriter.h
>
#
include
<
libasr/string_utils.h
>
using
LFortran::ASRUtils::symbol_parent_symtab;
using
LFortran::ASRUtils::symbol_name;
namespace
LFortran
{
class
ASTSerializationVisitor
:
#
ifdef
WITH_LFORTRAN_BINARY_MODFILES
public BinaryWriter,
#
else
public TextWriter,
#
endif
public
AST
::SerializationBaseVisitor<ASTSerializationVisitor>
{
public:
void
write_bool
(
bool
b) {
if
(b) {
write_int8
(
1
);
}
else
{
write_int8
(
0
);
}
}
};
std::string
serialize
(
const
AST
::
ast_t
&ast) {
ASTSerializationVisitor v;
v.
write_int8
(ast.
type
);
v.
visit_ast
(ast);
return
v.
get_str
();
}
std::string
serialize
(
const
AST
::TranslationUnit_t &unit) {
return
serialize
((
AST
::
ast_t
&)(unit));
}
class
ASTDeserializationVisitor
:
#
ifdef
WITH_LFORTRAN_BINARY_MODFILES
public BinaryReader,
#
else
public TextReader,
#
endif
public
AST
::DeserializationBaseVisitor<ASTDeserializationVisitor>
{
public:
ASTDeserializationVisitor
(Allocator &al,
const
std::string &s) :
#
ifdef
WITH_LFORTRAN_BINARY_MODFILES
BinaryReader
(s),
#
else
TextReader
(s),
#
endif
DeserializationBaseVisitor
(al,
true
) {}
bool
read_bool
() {
uint8_t
b =
read_int8
();
return
(b ==
1
);
}
char
*
read_cstring
() {
std::string s =
read_string
();
LFortran::Str cs;
cs.
from_str_view
(s);
char
* p = cs.
c_str
(al);
return
p;
}
};
AST
::
ast_t
*
deserialize_ast
(Allocator &al,
const
std::string &s) {
ASTDeserializationVisitor
v
(al, s);
return
v.
deserialize_node
();
}
}
//
namespace LFortran
Back
|
FazBrowse Home
|
New Git URL