forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathast_to_asr.cpp
More file actions
57 lines (49 loc) · 1.54 KB
/
ast_to_asr.cpp
File metadata and controls
57 lines (49 loc) · 1.54 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
#include <fstream>
#include <iostream>
#include <map>
#include <memory>
#include <string>
#include <cmath>
#include <lpython/ast.h>
#include <libasr/asr.h>
#include <libasr/asr_utils.h>
#include <libasr/asr_verify.h>
#include <lpython/semantics/asr_implicit_cast_rules.h>
#include <lpython/semantics/ast_common_visitor.h>
#include <lpython/semantics/ast_to_asr.h>
#include <lpython/parser/parser_stype.h>
#include <libasr/string_utils.h>
#include <lpython/utils.h>
namespace LFortran {
Result<ASR::asr_t*> symbol_table_visitor(Allocator &al, AST::TranslationUnit_t &ast,
diag::Diagnostics &diagnostics,
SymbolTable *symbol_table);
Result<ASR::TranslationUnit_t*> body_visitor(Allocator &al,
AST::TranslationUnit_t &ast,
diag::Diagnostics &diagnostics,
ASR::asr_t *unit);
Result<ASR::TranslationUnit_t*> ast_to_asr(Allocator &al,
AST::TranslationUnit_t &ast, diag::Diagnostics &diagnostics,
SymbolTable *symbol_table, bool symtab_only)
{
ASR::asr_t *unit;
auto res = symbol_table_visitor(al, ast, diagnostics, symbol_table);
if (res.ok) {
unit = res.result;
} else {
return res.error;
}
ASR::TranslationUnit_t *tu = ASR::down_cast2<ASR::TranslationUnit_t>(unit);
LFORTRAN_ASSERT(asr_verify(*tu));
if (!symtab_only) {
auto res = body_visitor(al, ast, diagnostics, unit);
if (res.ok) {
tu = res.result;
} else {
return res.error;
}
LFORTRAN_ASSERT(asr_verify(*tu));
}
return tu;
}
} // namespace LFortran