@@ -28,129 +28,6 @@ std::string pickle_python(AST::ast_t &ast, bool colors, bool indent) {
28
28
return v.get_str ();
29
29
}
30
30
31
- /* ********************* ASR Pickle *******************/
32
- class ASRPickleVisitor :
33
- public ASR::PickleBaseVisitor<ASRPickleVisitor>
34
- {
35
- public:
36
- bool show_intrinsic_modules;
37
-
38
- std::string get_str () {
39
- return s;
40
- }
41
- void visit_symbol (const ASR::symbol_t &x) {
42
- s.append (ASRUtils::symbol_parent_symtab (&x)->get_counter ());
43
- s.append (" " );
44
- if (use_colors) {
45
- s.append (color (fg::yellow));
46
- }
47
- s.append (ASRUtils::symbol_name (&x));
48
- if (use_colors) {
49
- s.append (color (fg::reset));
50
- }
51
- }
52
- void visit_IntegerConstant (const ASR::IntegerConstant_t &x) {
53
- s.append (" (" );
54
- if (use_colors) {
55
- s.append (color (style::bold));
56
- s.append (color (fg::magenta));
57
- }
58
- s.append (" IntegerConstant" );
59
- if (use_colors) {
60
- s.append (color (fg::reset));
61
- s.append (color (style::reset));
62
- }
63
- s.append (" " );
64
- if (use_colors) {
65
- s.append (color (fg::cyan));
66
- }
67
- s.append (std::to_string (x.m_n ));
68
- if (use_colors) {
69
- s.append (color (fg::reset));
70
- }
71
- s.append (" " );
72
- this ->visit_ttype (*x.m_type );
73
- s.append (" )" );
74
- }
75
- void visit_Module (const ASR::Module_t &x) {
76
- // hide intrinsic modules and numpy module by default
77
- if (!show_intrinsic_modules &&
78
- (x.m_intrinsic || startswith (x.m_name , " numpy" ))) {
79
- s.append (" (" );
80
- if (use_colors) {
81
- s.append (color (style::bold));
82
- s.append (color (fg::magenta));
83
- }
84
- s.append (x.m_intrinsic ? " IntrinsicModule" : " Module" );
85
- if (use_colors) {
86
- s.append (color (fg::reset));
87
- s.append (color (style::reset));
88
- }
89
- s.append (" " );
90
- s.append (x.m_name );
91
- s.append (" )" );
92
- } else {
93
- ASR::PickleBaseVisitor<ASRPickleVisitor>::visit_Module (x);
94
- };
95
- }
96
-
97
- std::string convert_intrinsic_id (int x) {
98
- std::string s;
99
- if (use_colors) {
100
- s.append (color (style::bold));
101
- s.append (color (fg::green));
102
- }
103
- s.append (ASRUtils::get_intrinsic_name (x));
104
- if (use_colors) {
105
- s.append (color (fg::reset));
106
- s.append (color (style::reset));
107
- }
108
- return s;
109
- }
110
-
111
- std::string convert_impure_intrinsic_id (int x) {
112
- std::string s;
113
- if (use_colors) {
114
- s.append (color (style::bold));
115
- s.append (color (fg::green));
116
- }
117
- s.append (ASRUtils::get_impure_intrinsic_name (x));
118
- if (use_colors) {
119
- s.append (color (fg::reset));
120
- s.append (color (style::reset));
121
- }
122
- return s;
123
- }
124
-
125
- std::string convert_array_intrinsic_id (int x) {
126
- std::string s;
127
- if (use_colors) {
128
- s.append (color (style::bold));
129
- s.append (color (fg::green));
130
- }
131
- s.append (ASRUtils::get_array_intrinsic_name (x));
132
- if (use_colors) {
133
- s.append (color (fg::reset));
134
- s.append (color (style::reset));
135
- }
136
- return s;
137
- }
138
- };
139
-
140
- std::string pickle (ASR::asr_t &asr, bool colors, bool indent,
141
- bool show_intrinsic_modules) {
142
- ASRPickleVisitor v;
143
- v.use_colors = colors;
144
- v.indent = indent;
145
- v.show_intrinsic_modules = show_intrinsic_modules;
146
- v.visit_asr (asr);
147
- return v.get_str ();
148
- }
149
-
150
- std::string pickle (ASR::TranslationUnit_t &asr, bool colors, bool indent, bool show_intrinsic_modules) {
151
- return pickle ((ASR::asr_t &)asr, colors, indent, show_intrinsic_modules);
152
- }
153
-
154
31
/* ********************* AST Pickle Tree *******************/
155
32
class ASTTreeVisitor : public AST ::TreeBaseVisitor<ASTTreeVisitor>
156
33
{
@@ -167,31 +44,6 @@ std::string pickle_tree_python(AST::ast_t &ast, bool colors) {
167
44
return v.get_str ();
168
45
}
169
46
170
- /* ********************* ASR Pickle Tree *******************/
171
- class ASRTreeVisitor :
172
- public ASR::TreeBaseVisitor<ASRTreeVisitor>
173
- {
174
- public:
175
- bool show_intrinsic_modules;
176
-
177
- std::string get_str () {
178
- return s;
179
- }
180
-
181
- };
182
-
183
- std::string pickle_tree (ASR::asr_t &asr, bool colors, bool show_intrinsic_modules) {
184
- ASRTreeVisitor v;
185
- v.use_colors = colors;
186
- v.show_intrinsic_modules = show_intrinsic_modules;
187
- v.visit_asr (asr);
188
- return v.get_str ();
189
- }
190
-
191
- std::string pickle_tree (ASR::TranslationUnit_t &asr, bool colors, bool show_intrinsic_modules) {
192
- return pickle_tree ((ASR::asr_t &)asr, colors, show_intrinsic_modules);
193
- }
194
-
195
47
/* ********************* AST Pickle Json *******************/
196
48
class ASTJsonVisitor :
197
49
public LPython::AST::JsonBaseVisitor<ASTJsonVisitor>
@@ -210,88 +62,4 @@ std::string pickle_json(LPython::AST::ast_t &ast, LocationManager &lm) {
210
62
return v.get_str ();
211
63
}
212
64
213
- /* ********************* ASR Pickle Json *******************/
214
- class ASRJsonVisitor :
215
- public ASR::JsonBaseVisitor<ASRJsonVisitor>
216
- {
217
- public:
218
- bool show_intrinsic_modules;
219
-
220
- using ASR::JsonBaseVisitor<ASRJsonVisitor>::JsonBaseVisitor;
221
-
222
- std::string get_str () {
223
- return s;
224
- }
225
-
226
- void visit_symbol (const ASR::symbol_t &x) {
227
- s.append (" \" " );
228
- s.append (ASRUtils::symbol_name (&x));
229
- s.append (" (SymbolTable" );
230
- s.append (ASRUtils::symbol_parent_symtab (&x)->get_counter ());
231
- s.append (" )\" " );
232
- }
233
-
234
- void visit_Module (const ASR::Module_t &x) {
235
- // hide intrinsic modules and numpy module by default
236
- if (!show_intrinsic_modules &&
237
- (x.m_intrinsic || startswith (x.m_name , " numpy" ))) {
238
- s.append (" {" );
239
- inc_indent (); s.append (" \n " + indtd);
240
- s.append (" \" node\" : \" Module\" " );
241
- s.append (" ,\n " + indtd);
242
- s.append (" \" fields\" : {" );
243
- inc_indent (); s.append (" \n " + indtd);
244
- s.append (" \" name\" : " );
245
- s.append (" \" " + std::string (x.m_name ) + " \" " );
246
- s.append (" ,\n " + indtd);
247
- s.append (" \" dependencies\" : " );
248
- s.append (" [" );
249
- if (x.n_dependencies > 0 ) {
250
- inc_indent (); s.append (" \n " + indtd);
251
- for (size_t i=0 ; i<x.n_dependencies ; i++) {
252
- s.append (" \" " + std::string (x.m_dependencies [i]) + " \" " );
253
- if (i < x.n_dependencies -1 ) {
254
- s.append (" ,\n " + indtd);
255
- };
256
- }
257
- dec_indent (); s.append (" \n " + indtd);
258
- }
259
- s.append (" ]" );
260
- s.append (" ,\n " + indtd);
261
- s.append (" \" loaded_from_mod\" : " );
262
- if (x.m_loaded_from_mod ) {
263
- s.append (" true" );
264
- } else {
265
- s.append (" false" );
266
- }
267
- s.append (" ,\n " + indtd);
268
- s.append (" \" intrinsic\" : " );
269
- if (x.m_intrinsic ) {
270
- s.append (" true" );
271
- } else {
272
- s.append (" false" );
273
- }
274
- dec_indent (); s.append (" \n " + indtd);
275
- s.append (" }" );
276
- s.append (" ,\n " + indtd);
277
- append_location (s, x.base .base .loc .first , x.base .base .loc .last );
278
- dec_indent (); s.append (" \n " + indtd);
279
- s.append (" }" );
280
- } else {
281
- ASR::JsonBaseVisitor<ASRJsonVisitor>::visit_Module (x);
282
- }
283
- }
284
- };
285
-
286
- std::string pickle_json (ASR::asr_t &asr, LocationManager &lm, bool show_intrinsic_modules) {
287
- ASRJsonVisitor v (lm);
288
- v.show_intrinsic_modules = show_intrinsic_modules;
289
- v.visit_asr (asr);
290
- return v.get_str ();
291
- }
292
-
293
- std::string pickle_json (ASR::TranslationUnit_t &asr, LocationManager &lm, bool show_intrinsic_modules) {
294
- return pickle_json ((ASR::asr_t &)asr, lm, show_intrinsic_modules);
295
- }
296
-
297
65
}
0 commit comments