Skip to content

Commit 6a45290

Browse files
committed
ASR: Remove goto support
1 parent 0577159 commit 6a45290

File tree

3 files changed

+2
-285
lines changed

3 files changed

+2
-285
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3792,8 +3792,6 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
37923792
vectorize = true;
37933793
} else if (name == "restriction") {
37943794
is_restriction = true;
3795-
} else if (name == "with_goto") {
3796-
// TODO: Use goto attribute in function?
37973795
} else if (name == "inline") {
37983796
is_inline = true;
37993797
} else if (name == "static") {
@@ -4336,8 +4334,6 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
43364334

43374335
public:
43384336
ASR::asr_t *asr;
4339-
std::map<std::string, std::tuple<int64_t, bool, Location>> goto_name2id;
4340-
int64_t gotoids;
43414337
std::vector<ASR::symbol_t*> do_loop_variables;
43424338
// Stores the name of imported functions and the modules they are imported from
43434339
std::map<std::string, std::string> imported_functions;
@@ -4347,13 +4343,12 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
43474343
bool main_module, std::map<int, ASR::symbol_t*> &ast_overload,
43484344
bool allow_implicit_casting_)
43494345
: CommonVisitor(al, lm, nullptr, diagnostics, main_module, ast_overload, "", {}, allow_implicit_casting_),
4350-
asr{unit}, gotoids{0}
4346+
asr{unit}
43514347
{}
43524348

43534349
// Transforms statements to a list of ASR statements
43544350
// In addition, it also inserts the following nodes if needed:
43554351
// * ImplicitDeallocate
4356-
// * GoToTarget
43574352
// The `body` Vec must already be reserved
43584353
void transform_stmts(Vec<ASR::stmt_t*> &body, size_t n_body, AST::stmt_t **m_body) {
43594354
tmp = nullptr;
@@ -4504,8 +4499,6 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
45044499
}
45054500

45064501
void visit_FunctionDef(const AST::FunctionDef_t &x) {
4507-
goto_name2id.clear();
4508-
gotoids = 0;
45094502
SymbolTable *old_scope = current_scope;
45104503
ASR::symbol_t *t = current_scope->get_symbol(x.m_name);
45114504
if (ASR::is_a<ASR::Function_t>(*t)) {
@@ -4526,13 +4519,6 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
45264519
}
45274520
current_scope = old_scope;
45284521
tmp = nullptr;
4529-
4530-
for( auto itr: goto_name2id ) {
4531-
if( !std::get<1>(itr.second) ) {
4532-
throw SemanticError("Label '" + itr.first + "' is not defined in '"
4533-
+ std::string(x.m_name) + "'", std::get<2>(itr.second));
4534-
}
4535-
}
45364522
}
45374523

45384524
void visit_Import(const AST::Import_t &x) {
@@ -5522,33 +5508,6 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
55225508
void visit_Attribute(const AST::Attribute_t &x) {
55235509
if (AST::is_a<AST::Name_t>(*x.m_value)) {
55245510
std::string value = AST::down_cast<AST::Name_t>(x.m_value)->m_id;
5525-
if( value == "label" ) {
5526-
std::string labelname = x.m_attr;
5527-
if( goto_name2id.find(labelname) == goto_name2id.end() ) {
5528-
goto_name2id[labelname] = std::make_tuple(gotoids, true, x.base.base.loc);
5529-
gotoids += 1;
5530-
} else if( !std::get<1>(goto_name2id[labelname]) ) {
5531-
goto_name2id[labelname] = std::make_tuple(
5532-
std::get<0>(goto_name2id[labelname]),
5533-
true,
5534-
std::get<2>(goto_name2id[labelname])
5535-
);
5536-
}
5537-
int id = std::get<0>(goto_name2id[labelname]);
5538-
tmp = ASR::make_GoToTarget_t(al, x.base.base.loc, id, x.m_attr);
5539-
return ;
5540-
}
5541-
5542-
if (value == "goto"){
5543-
std::string labelname = std::string(x.m_attr);
5544-
if( goto_name2id.find(labelname) == goto_name2id.end() ) {
5545-
goto_name2id[labelname] = std::make_tuple(gotoids, false, x.base.base.loc);
5546-
gotoids += 1;
5547-
}
5548-
int id = std::get<0>(goto_name2id[labelname]);
5549-
tmp = ASR::make_GoTo_t(al, x.base.base.loc, id, x.m_attr);
5550-
return ;
5551-
}
55525511

55535512
ASR::symbol_t *org_sym = current_scope->resolve_symbol(value);
55545513
if (!org_sym) {

src/runtime/lpython/goto.py

Lines changed: 0 additions & 241 deletions
This file was deleted.

src/runtime/lpython/lpython.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
import ctypes
44
import platform
55
from dataclasses import dataclass as py_dataclass, is_dataclass as py_is_dataclass
6-
from goto import with_goto
76

87
# TODO: this does not seem to restrict other imports
98
__slots__ = ["i8", "i16", "i32", "i64", "u8", "u16", "u32", "u64", "f32", "f64", "c32", "c64", "CPtr",
109
"overload", "ccall", "TypeVar", "pointer", "c_p_pointer", "Pointer",
11-
"p_c_pointer", "vectorize", "inline", "Union", "static", "with_goto",
10+
"p_c_pointer", "vectorize", "inline", "Union", "static",
1211
"packed", "Const", "sizeof", "ccallable", "ccallback", "Callable",
1312
"Allocatable"]
1413

0 commit comments

Comments
 (0)