Skip to content

Commit

Permalink
Remove dead code (#1625)
Browse files Browse the repository at this point in the history
Drastically simplify handling of `CodeBlock` nodes in `SemanticParser._visit_Assign` by removing dead code, which has been superseded by `SemanticParser._additional_exprs`. Fixes #1390. Fixes #1594.
  • Loading branch information
EmilyBourne committed Nov 21, 2023
1 parent 4e566c1 commit 40a8143
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ All notable changes to this project will be documented in this file.
- \[INTERNALS\] #1593 : Rename `PyccelAstNode.fst` to the `PyccelAstNode.ast`.
- \[INTERNALS\] #1593 : Use a setter instead of a method to update `PyccelAstNode.ast`.
- \[INTERNALS\] #1593 : Rename `BasicParser._current_fst_node` to the `BasicParser._current_ast_node`.
- \[INTERNALS\] #1390 : Remove dead code handling a `CodeBlock` in an assignment.

### Deprecated

Expand Down
27 changes: 2 additions & 25 deletions pyccel/parser/semantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2909,31 +2909,8 @@ def _visit_Assign(self, expr):
i.set_current_ast(python_ast)
return rhs

elif isinstance(rhs, CodeBlock):
if len(rhs.body)>1 and isinstance(rhs.body[1], FunctionalFor):
return rhs

# case of complex stmt
# that needs to be splitted
# into a list of stmts
stmts = rhs.body
stmt = stmts[-1]
lhs = expr.lhs
if isinstance(lhs, PyccelSymbol):
name = lhs
if self.check_for_variable(name) is None:
d_var = self._infer_type(stmt)
dtype = d_var.pop('datatype')
lhs = Variable(dtype, name , **d_var, is_temp = lhs.is_temp)
self.scope.insert_variable(lhs)

if isinstance(expr, Assign):
stmt = Assign(lhs, stmt)
elif isinstance(expr, AugAssign):
stmt = AugAssign(lhs, expr.op, stmt)
stmt.set_current_ast(python_ast)
stmts[-1] = stmt
return CodeBlock(stmts)
elif isinstance(rhs, CodeBlock) and len(rhs.body)>1 and isinstance(rhs.body[1], FunctionalFor):
return rhs

elif isinstance(rhs, FunctionCall):
func = rhs.funcdef
Expand Down

0 comments on commit 40a8143

Please sign in to comment.