Skip to content

Commit

Permalink
fix: keep information from AST about a TupleExpression being an inlin…
Browse files Browse the repository at this point in the history
…e array and generate SlithIR accordingly
  • Loading branch information
gfeng-certik committed Jan 29, 2023
1 parent 86dfd12 commit 9a2b815
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions slither/core/expressions/tuple_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@


class TupleExpression(Expression):
def __init__(self, expressions: List[Expression]) -> None:
def __init__(self, expressions: List[Expression], is_inline_array: bool = False) -> None:
assert all(isinstance(x, Expression) for x in expressions if x)
super().__init__()
self._expressions = expressions
self._is_inline_array = is_inline_array

@property
def expressions(self) -> List[Expression]:
return self._expressions

@property
def is_inline_array(self) -> bool:
return self._is_inline_array

def __str__(self) -> str:
expressions_str = [str(e) for e in self.expressions]
return "(" + ",".join(expressions_str) + ")"
l_bracket, r_bracket = ("[","]") if self._is_inline_array else ("(",")")
return l_bracket + ",".join(expressions_str) + r_bracket
2 changes: 1 addition & 1 deletion slither/solc_parsing/expressions/expression_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def parse_expression(expression: Dict, caller_context: CallerContextExpression)
for idx, _ in enumerate(elems):
if elems[idx] == "":
expressions.insert(idx, None)
t = TupleExpression(expressions)
t = TupleExpression(expressions, is_inline_array=expression.get("isInlineArray", False))
t.set_offset(src, caller_context.compilation_unit)
return t

Expand Down
8 changes: 7 additions & 1 deletion slither/visitors/slithir/expression_to_slithir.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,13 @@ def _post_new_elementary_type(self, expression):

def _post_tuple_expression(self, expression):
expressions = [get(e) if e else None for e in expression.expressions]
if len(expressions) == 1:
if expression.is_inline_array:
temp_var = TemporaryVariable(self._node)
init_arr = InitArray(expressions, temp_var)
self._result.append(init_arr)
# Use the new temporary variable in place of the array.
val = temp_var
elif len(expressions) == 1:
val = expressions[0]
else:
val = expressions
Expand Down

0 comments on commit 9a2b815

Please sign in to comment.