Skip to content

Commit 66dd29e

Browse files
committed
tmp
1 parent 30f052b commit 66dd29e

File tree

9 files changed

+221
-152
lines changed

9 files changed

+221
-152
lines changed

examples/expr2.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from a import i
2+
13
def main0():
24
x: i32
3-
x = (2+3)*5
5+
x = i
6+
x = 2.14
47
print(x)
58

69
main0()

src/bin/lpython.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ int emit_asr(const std::string &infile,
164164

165165
diagnostics.diagnostics.clear();
166166
LFortran::Result<LFortran::ASR::TranslationUnit_t*>
167-
r = LFortran::LPython::python_ast_to_asr(al, *ast, diagnostics, compiler_options, true, infile);
167+
r = LFortran::LPython::python_ast_to_asr(al, *ast, lm, diagnostics, compiler_options, true, infile, input);
168168
std::cerr << diagnostics.render(input, lm, compiler_options);
169169
if (!r.ok) {
170170
LFORTRAN_ASSERT(diagnostics.has_error())
@@ -206,7 +206,7 @@ int emit_cpp(const std::string &infile,
206206

207207
diagnostics.diagnostics.clear();
208208
LFortran::Result<LFortran::ASR::TranslationUnit_t*>
209-
r1 = LFortran::LPython::python_ast_to_asr(al, *ast, diagnostics, compiler_options, true, infile);
209+
r1 = LFortran::LPython::python_ast_to_asr(al, *ast, lm, diagnostics, compiler_options, true, infile, input);
210210
std::cerr << diagnostics.render(input, lm, compiler_options);
211211
if (!r1.ok) {
212212
LFORTRAN_ASSERT(diagnostics.has_error())
@@ -246,7 +246,7 @@ int emit_c(const std::string &infile,
246246

247247
diagnostics.diagnostics.clear();
248248
LFortran::Result<LFortran::ASR::TranslationUnit_t*>
249-
r1 = LFortran::LPython::python_ast_to_asr(al, *ast, diagnostics, compiler_options, true, infile);
249+
r1 = LFortran::LPython::python_ast_to_asr(al, *ast, lm, diagnostics, compiler_options, true, infile, input);
250250
std::cerr << diagnostics.render(input, lm, compiler_options);
251251
if (!r1.ok) {
252252
LFORTRAN_ASSERT(diagnostics.has_error())
@@ -286,7 +286,7 @@ int emit_wat(const std::string &infile,
286286

287287
diagnostics.diagnostics.clear();
288288
LFortran::Result<LFortran::ASR::TranslationUnit_t*>
289-
r1 = LFortran::LPython::python_ast_to_asr(al, *ast, diagnostics, compiler_options, true, infile);
289+
r1 = LFortran::LPython::python_ast_to_asr(al, *ast, lm, diagnostics, compiler_options, true, infile, input);
290290
std::cerr << diagnostics.render(input, lm, compiler_options);
291291
if (!r1.ok) {
292292
LFORTRAN_ASSERT(diagnostics.has_error())
@@ -329,7 +329,7 @@ int get_symbols (const std::string &infile,
329329
if (r1.ok) {
330330
LFortran::LPython::AST::ast_t* ast = r1.result;
331331
LFortran::Result<LFortran::ASR::TranslationUnit_t*>
332-
x = LFortran::LPython::python_ast_to_asr(al, *ast, diagnostics, compiler_options, true, infile);
332+
x = LFortran::LPython::python_ast_to_asr(al, *ast, lm, diagnostics, compiler_options, true, infile, input);
333333
if (!x.ok) {
334334
std::cout << "{}\n";
335335
return 0;
@@ -421,7 +421,7 @@ int get_errors (const std::string &infile,
421421
if (r1.ok) {
422422
LFortran::LPython::AST::ast_t* ast = r1.result;
423423
LFortran::Result<LFortran::ASR::TranslationUnit_t*>
424-
r = LFortran::LPython::python_ast_to_asr(al, *ast, diagnostics, compiler_options, true, infile);
424+
r = LFortran::LPython::python_ast_to_asr(al, *ast, lm, diagnostics, compiler_options, true, infile, input);
425425
}
426426
std::vector<LFortran::LPython::error_highlight> diag_lists;
427427
LFortran::LPython::error_highlight h;
@@ -532,7 +532,7 @@ int emit_llvm(const std::string &infile,
532532
LFortran::LPython::AST::ast_t* ast = r.result;
533533
diagnostics.diagnostics.clear();
534534
LFortran::Result<LFortran::ASR::TranslationUnit_t*>
535-
r1 = LFortran::LPython::python_ast_to_asr(al, *ast, diagnostics, compiler_options, true, infile);
535+
r1 = LFortran::LPython::python_ast_to_asr(al, *ast, lm, diagnostics, compiler_options, true, infile, input);
536536
std::cerr << diagnostics.render(input, lm, compiler_options);
537537
if (!r1.ok) {
538538
LFORTRAN_ASSERT(diagnostics.has_error())
@@ -572,6 +572,7 @@ int compile_python_to_object_file(
572572
auto file_reading_end = std::chrono::high_resolution_clock::now();
573573
times.push_back(std::make_pair("File reading", std::chrono::duration<double, std::milli>(file_reading_end - file_reading_start).count()));
574574
lm.init_simple(input);
575+
std::cout << "lpython.cpp: " << lm.files[0].in_filename << std::endl;
575576
auto parsing_start = std::chrono::high_resolution_clock::now();
576577
LFortran::Result<LFortran::LPython::AST::ast_t*> r = parse_python_file(
577578
al, runtime_library_dir, infile, diagnostics, compiler_options.new_parser);
@@ -588,11 +589,12 @@ int compile_python_to_object_file(
588589
diagnostics.diagnostics.clear();
589590
auto ast_to_asr_start = std::chrono::high_resolution_clock::now();
590591
LFortran::Result<LFortran::ASR::TranslationUnit_t*>
591-
r1 = LFortran::LPython::python_ast_to_asr(al, *ast, diagnostics, compiler_options,
592-
!(arg_c && compiler_options.disable_main), infile);
592+
r1 = LFortran::LPython::python_ast_to_asr(al, *ast, lm, diagnostics, compiler_options,
593+
!(arg_c && compiler_options.disable_main), infile, input);
593594

594595
auto ast_to_asr_end = std::chrono::high_resolution_clock::now();
595596
times.push_back(std::make_pair("AST to ASR", std::chrono::duration<double, std::milli>(ast_to_asr_end - ast_to_asr_start).count()));
597+
std::cout << "input: \n" << input << std::endl;
596598
std::cerr << diagnostics.render(input, lm, compiler_options);
597599
if (!r1.ok) {
598600
LFORTRAN_ASSERT(diagnostics.has_error())
@@ -672,7 +674,7 @@ int compile_to_binary_wasm(
672674
diagnostics.diagnostics.clear();
673675
auto ast_to_asr_start = std::chrono::high_resolution_clock::now();
674676
LFortran::Result<LFortran::ASR::TranslationUnit_t*>
675-
r1 = LFortran::LPython::python_ast_to_asr(al, *ast, diagnostics, compiler_options, true, infile);
677+
r1 = LFortran::LPython::python_ast_to_asr(al, *ast, lm, diagnostics, compiler_options, true, infile, input);
676678
auto ast_to_asr_end = std::chrono::high_resolution_clock::now();
677679
times.push_back(std::make_pair("AST to ASR", std::chrono::duration<double, std::milli>(ast_to_asr_end - ast_to_asr_start).count()));
678680
std::cerr << diagnostics.render(input, lm, compiler_options);
@@ -737,7 +739,7 @@ int compile_to_binary_x86(
737739
diagnostics.diagnostics.clear();
738740
auto ast_to_asr_start = std::chrono::high_resolution_clock::now();
739741
LFortran::Result<LFortran::ASR::TranslationUnit_t*>
740-
r1 = LFortran::LPython::python_ast_to_asr(al, *ast, diagnostics, compiler_options, true, infile);
742+
r1 = LFortran::LPython::python_ast_to_asr(al, *ast, lm, diagnostics, compiler_options, true, infile, input);
741743
auto ast_to_asr_end = std::chrono::high_resolution_clock::now();
742744
times.push_back(std::make_pair("AST to ASR", std::chrono::duration<double, std::milli>(ast_to_asr_end - ast_to_asr_start).count()));
743745
std::cerr << diagnostics.render(input, lm, compiler_options);
@@ -802,7 +804,7 @@ int compile_to_binary_wasm_to_x86(
802804
diagnostics.diagnostics.clear();
803805
auto ast_to_asr_start = std::chrono::high_resolution_clock::now();
804806
LFortran::Result<LFortran::ASR::TranslationUnit_t*>
805-
r1 = LFortran::LPython::python_ast_to_asr(al, *ast, diagnostics, compiler_options, true, infile);
807+
r1 = LFortran::LPython::python_ast_to_asr(al, *ast, lm, diagnostics, compiler_options, true, infile, input);
806808
auto ast_to_asr_end = std::chrono::high_resolution_clock::now();
807809
times.push_back(std::make_pair("AST to ASR", std::chrono::duration<double, std::milli>(ast_to_asr_end - ast_to_asr_start).count()));
808810
std::cerr << diagnostics.render(input, lm, compiler_options);
@@ -1067,7 +1069,7 @@ EMSCRIPTEN_KEEPALIVE char* emit_asr_from_source(char *input) {
10671069
if (ast.ok) {
10681070
auto casted_ast = (LFortran::LPython::AST::ast_t*)ast.result;
10691071
LFortran::Result<LFortran::ASR::TranslationUnit_t*>
1070-
asr = LFortran::LPython::python_ast_to_asr(al, *casted_ast, diagnostics, compiler_options, true, "input");
1072+
asr = LFortran::LPython::python_ast_to_asr(al, *casted_ast, diagnostics, compiler_options, true, "input", input);
10711073
out = diagnostics.render(input, lm, compiler_options);
10721074
if (asr.ok) {
10731075
out += LFortran::pickle(*asr.result, compiler_options.use_colors, compiler_options.indent,
@@ -1085,7 +1087,7 @@ EMSCRIPTEN_KEEPALIVE char* emit_wat_from_source(char *input) {
10851087
if (ast.ok) {
10861088
auto casted_ast = (LFortran::LPython::AST::ast_t*)ast.result;
10871089
LFortran::Result<LFortran::ASR::TranslationUnit_t*>
1088-
asr = LFortran::LPython::python_ast_to_asr(al, *casted_ast, diagnostics, compiler_options, true, "input");
1090+
asr = LFortran::LPython::python_ast_to_asr(al, *casted_ast, diagnostics, compiler_options, true, "input", input);
10891091
out = diagnostics.render(input, lm, compiler_options);
10901092
if (asr.ok) {
10911093
LFortran::Result<LFortran::Vec<uint8_t>>
@@ -1112,7 +1114,7 @@ EMSCRIPTEN_KEEPALIVE char* emit_cpp_from_source(char *input) {
11121114
if (ast.ok) {
11131115
auto casted_ast = (LFortran::LPython::AST::ast_t*)ast.result;
11141116
LFortran::Result<LFortran::ASR::TranslationUnit_t*>
1115-
asr = LFortran::LPython::python_ast_to_asr(al, *casted_ast, diagnostics, compiler_options, true, "input");
1117+
asr = LFortran::LPython::python_ast_to_asr(al, *casted_ast, diagnostics, compiler_options, true, "input", input);
11161118
out = diagnostics.render(input, lm, compiler_options);
11171119
if (asr.ok) {
11181120
auto res = LFortran::asr_to_cpp(al, *asr.result, diagnostics,
@@ -1150,7 +1152,7 @@ EMSCRIPTEN_KEEPALIVE char* emit_wasm_from_source(char *input) {
11501152
if (ast.ok) {
11511153
auto casted_ast = (LFortran::LPython::AST::ast_t*)ast.result;
11521154
LFortran::Result<LFortran::ASR::TranslationUnit_t*>
1153-
asr = LFortran::LPython::python_ast_to_asr(al, *casted_ast, diagnostics, compiler_options, true, "input");
1155+
asr = LFortran::LPython::python_ast_to_asr(al, *casted_ast, diagnostics, compiler_options, true, "input", input);
11541156
out = diagnostics.render(input, lm, compiler_options);
11551157
if (asr.ok) {
11561158
LFortran::Result<LFortran::Vec<uint8_t>>

src/libasr/codegen/asr_to_llvm.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
381381
void debug_get_line_column(const uint32_t &loc_first,
382382
uint32_t &line, uint32_t &column) {
383383
LocationManager lm;
384-
lm.in_filename = infile;
385-
lm.init_simple(LFortran::read_file(infile));
386-
lm.pos_to_linecol(lm.output_to_input_pos(loc_first, false), line, column);
384+
lm.lm.in_filename = infile;
385+
lm.lm.init_simple(LFortran::read_file(infile));
386+
lm.lm.pos_to_linecol(lm.lm.output_to_input_pos(loc_first, false), line, column);
387387
}
388388

389389
template <typename T>

src/libasr/diagnostics.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ std::string get_line(std::string str, int n)
110110

111111
void populate_span(diag::Span &s, const LocationManager &lm,
112112
const std::string &input) {
113-
lm.pos_to_linecol(lm.output_to_input_pos(s.loc.first, false),
114-
s.first_line, s.first_column);
115-
lm.pos_to_linecol(lm.output_to_input_pos(s.loc.last, true),
116-
s.last_line, s.last_column);
117-
s.filename = lm.in_filename;
113+
lm.pos_to_linecol(s.loc.first,
114+
s.first_line, s.first_column, s.filename);
115+
lm.pos_to_linecol(s.loc.last,
116+
s.last_line, s.last_column, s.filename);
117+
// s.filename = lm.in_filename;
118118
for (uint32_t i = s.first_line; i <= s.last_line; i++) {
119119
s.source_code.push_back(get_line(input, i));
120120
}
@@ -178,7 +178,7 @@ std::string render_diagnostic_human(const Diagnostic &d, bool use_colors) {
178178
std::string type_color = "";
179179
switch (d.level) {
180180
case (Level::Error):
181-
primary_color = red_bold;
181+
primary_color = red_bold;
182182
type_color = primary_color;
183183
switch (d.stage) {
184184
case (Stage::CPreprocessor):
@@ -205,17 +205,17 @@ std::string render_diagnostic_human(const Diagnostic &d, bool use_colors) {
205205
}
206206
break;
207207
case (Level::Warning):
208-
primary_color = yellow_bold;
208+
primary_color = yellow_bold;
209209
type_color = primary_color;
210210
message_type = "warning";
211211
break;
212212
case (Level::Note):
213-
primary_color = bold;
213+
primary_color = bold;
214214
type_color = primary_color;
215215
message_type = "note";
216216
break;
217217
case (Level::Help):
218-
primary_color = bold;
218+
primary_color = bold;
219219
type_color = primary_color;
220220
message_type = "help";
221221
break;

0 commit comments

Comments
 (0)