forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpickle.cpp
More file actions
65 lines (55 loc) · 1.48 KB
/
pickle.cpp
File metadata and controls
65 lines (55 loc) · 1.48 KB
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
#include <string>
#include <lpython/pickle.h>
#include <lpython/bigint.h>
#include <lpython/python_ast.h>
#include <libasr/asr_utils.h>
#include <libasr/string_utils.h>
#include <libasr/location.h>
#include <libasr/pass/intrinsic_function_registry.h>
#include <libasr/pass/intrinsic_array_function_registry.h>
namespace LCompilers::LPython {
/********************** AST Pickle *******************/
class PickleVisitor : public AST::PickleBaseVisitor<PickleVisitor>
{
public:
std::string get_str() {
return s;
}
};
std::string pickle_python(AST::ast_t &ast, bool colors, bool indent) {
PickleVisitor v;
v.use_colors = colors;
v.indent = indent;
v.visit_ast(ast);
return v.get_str();
}
/********************** AST Pickle Tree *******************/
class ASTTreeVisitor : public AST::TreeBaseVisitor<ASTTreeVisitor>
{
public:
std::string get_str() {
return s;
}
};
std::string pickle_tree_python(AST::ast_t &ast, bool colors) {
ASTTreeVisitor v;
v.use_colors = colors;
v.visit_ast(ast);
return v.get_str();
}
/********************** AST Pickle Json *******************/
class ASTJsonVisitor :
public LPython::AST::JsonBaseVisitor<ASTJsonVisitor>
{
public:
using LPython::AST::JsonBaseVisitor<ASTJsonVisitor>::JsonBaseVisitor;
std::string get_str() {
return s;
}
};
std::string pickle_json(LPython::AST::ast_t &ast, LocationManager &lm) {
ASTJsonVisitor v(lm);
v.visit_ast(ast);
return v.get_str();
}
}