fix some lint warnings

pull/2099/head
alpharush 1 year ago
parent a6209dfe53
commit c21798021c
  1. 6
      slither/core/compilation_unit.py
  2. 3
      slither/slither.py
  3. 4
      slither/visitors/slithir/expression_to_slithir.py
  4. 5
      slither/vyper_parsing/ast/types.py
  5. 2
      slither/vyper_parsing/cfg/node.py
  6. 1
      slither/vyper_parsing/declarations/contract.py
  7. 1
      slither/vyper_parsing/declarations/event.py
  8. 457
      slither/vyper_parsing/declarations/function.py
  9. 2
      slither/vyper_parsing/declarations/struct.py
  10. 23
      slither/vyper_parsing/expressions/expression_parsing.py
  11. 17
      slither/vyper_parsing/expressions/find_variable.py
  12. 7
      slither/vyper_parsing/type_parsing.py
  13. 2
      slither/vyper_parsing/variables/event_variable.py
  14. 2
      slither/vyper_parsing/variables/state_variable.py
  15. 3
      slither/vyper_parsing/variables/structure_variable.py
  16. 2
      slither/vyper_parsing/vyper_compilation_unit.py
  17. 1
      tests/e2e/vyper_parsing/test_ast_parsing.py
  18. 27
      tests/unit/slithir/vyper/test_ir_generation.py

@ -38,10 +38,10 @@ class Language(Enum):
def from_str(label: str):
if label == "solc":
return Language.SOLIDITY
elif label == "vyper":
if label == "vyper":
return Language.VYPER
else:
raise ValueError(f"Unknown language: {label}")
raise ValueError(f"Unknown language: {label}")
# pylint: disable=too-many-instance-attributes,too-many-public-methods

@ -13,6 +13,7 @@ from slither.printers.abstract_printer import AbstractPrinter
from slither.solc_parsing.slither_compilation_unit_solc import SlitherCompilationUnitSolc
from slither.vyper_parsing.vyper_compilation_unit import VyperCompilationUnit
from slither.utils.output import Output
from slither.vyper_parsing.ast.ast import parse
logger = logging.getLogger("Slither")
logging.basicConfig()
@ -103,8 +104,6 @@ class Slither(SlitherCore): # pylint: disable=too-many-instance-attributes
if compilation_unit_slither.is_vyper:
vyper_parser = VyperCompilationUnit(compilation_unit_slither)
for path, ast in compilation_unit.asts.items():
from slither.vyper_parsing.ast.ast import parse
ast_nodes = parse(ast["ast"])
vyper_parser.parse_module(ast_nodes, path)
self._parsers.append(vyper_parser)

@ -171,7 +171,9 @@ class ExpressionToSlithIR(ExpressionVisitor):
def result(self) -> List[Operation]:
return self._result
def _post_assignement_operation(self, expression: AssignmentOperation) -> None:
def _post_assignement_operation(
self, expression: AssignmentOperation
) -> None: # pylint: disable=too-many-branches,too-many-statements
left = get(expression.expression_left)
right = get(expression.expression_right)
operation: Operation

@ -1,5 +1,5 @@
from __future__ import annotations
from typing import List, Optional, Dict, Union, ForwardRef
from typing import List, Optional, Union
from dataclasses import dataclass
@ -167,9 +167,6 @@ class Raise(ASTNode):
exc: ASTNode
from enum import Enum
@dataclass
class Expr(ASTNode):
value: ASTNode

@ -1,4 +1,4 @@
from typing import Union, Optional, Dict, TYPE_CHECKING
from typing import Optional, Dict
from slither.core.cfg.node import Node
from slither.core.cfg.node import NodeType

@ -1,4 +1,3 @@
import logging
from pathlib import Path
from typing import List, TYPE_CHECKING
from slither.vyper_parsing.ast.types import (

@ -1,7 +1,6 @@
"""
Event module
"""
from typing import TYPE_CHECKING, Dict
from slither.core.variables.event_variable import EventVariable
from slither.vyper_parsing.variables.event_variable import EventVariableVyper

@ -1,16 +1,13 @@
import logging
from typing import Dict, Optional, Union, List, TYPE_CHECKING, Tuple, Set
from typing import Dict, Union, List, TYPE_CHECKING, Tuple
from slither.core.cfg.node import NodeType, link_nodes, insert_node, Node
from slither.core.cfg.node import NodeType, link_nodes, Node
from slither.core.cfg.scope import Scope
from slither.core.declarations.contract import Contract
from slither.core.declarations.function import (
Function,
FunctionType,
)
from slither.core.declarations.function import ModifierStatements
from slither.core.declarations.modifier import Modifier
from slither.core.expressions import AssignmentOperation
from slither.core.source_mapping.source_mapping import Source
from slither.core.variables.local_variable import LocalVariable
from slither.vyper_parsing.cfg.node import NodeVyper
@ -41,6 +38,7 @@ class FunctionVyper:
self._functionNotParsed = function_data
self._decoratorNotParsed = None
self._local_variables_parser: List[LocalVariableVyper] = []
self._variables_renamed = []
self._contract_parser = contract_parser
self._node_to_NodeVyper: Dict[Node, NodeVyper] = {}
@ -226,277 +224,268 @@ class FunctionVyper:
self._function.entry_point = entry_node.underlying_node
scope = Scope(True, False, self.underlying_function)
curr_node = entry_node
for expr in cfg:
def parse_statement(
curr_node: NodeVyper,
expr: ASTNode,
continue_destination=None,
break_destination=None,
) -> NodeVyper:
if isinstance(expr, AnnAssign):
local_var = LocalVariable()
local_var.set_function(self._function)
local_var.set_offset(expr.src, self._function.compilation_unit)
local_var_parser = LocalVariableVyper(local_var, expr)
self._add_local_variable(local_var_parser)
new_node = self._new_node(NodeType.VARIABLE, expr.src, scope)
if expr.value is not None:
local_var.initialized = True
new_node.add_unparsed_expression(expr.value)
new_node.underlying_node.add_variable_declaration(local_var)
link_underlying_nodes(curr_node, new_node)
def parse_statement(
curr_node: NodeVyper,
expr: ASTNode,
continue_destination=None,
break_destination=None,
) -> NodeVyper:
if isinstance(expr, AnnAssign):
local_var = LocalVariable()
local_var.set_function(self._function)
local_var.set_offset(expr.src, self._function.compilation_unit)
local_var_parser = LocalVariableVyper(local_var, expr)
self._add_local_variable(local_var_parser)
new_node = self._new_node(NodeType.VARIABLE, expr.src, scope)
if expr.value is not None:
local_var.initialized = True
new_node.add_unparsed_expression(expr.value)
new_node.underlying_node.add_variable_declaration(local_var)
link_underlying_nodes(curr_node, new_node)
curr_node = new_node
curr_node = new_node
elif isinstance(expr, (AugAssign, Assign)):
new_node = self._new_node(NodeType.EXPRESSION, expr.src, scope)
new_node.add_unparsed_expression(expr)
link_underlying_nodes(curr_node, new_node)
elif isinstance(expr, (AugAssign, Assign)):
curr_node = new_node
elif isinstance(expr, Expr):
# TODO This is a workaround to handle Vyper putting payable/view in the function body...
if not isinstance(expr.value, Name):
new_node = self._new_node(NodeType.EXPRESSION, expr.src, scope)
new_node.add_unparsed_expression(expr)
new_node.add_unparsed_expression(expr.value)
link_underlying_nodes(curr_node, new_node)
curr_node = new_node
elif isinstance(expr, Expr):
# TODO This is a workaround to handle Vyper putting payable/view in the function body...
if not isinstance(expr.value, Name):
new_node = self._new_node(NodeType.EXPRESSION, expr.src, scope)
new_node.add_unparsed_expression(expr.value)
link_underlying_nodes(curr_node, new_node)
elif isinstance(expr, For):
curr_node = new_node
node_startLoop = self._new_node(NodeType.STARTLOOP, expr.src, scope)
node_endLoop = self._new_node(NodeType.ENDLOOP, expr.src, scope)
elif isinstance(expr, For):
link_underlying_nodes(curr_node, node_startLoop)
node_startLoop = self._new_node(NodeType.STARTLOOP, expr.src, scope)
node_endLoop = self._new_node(NodeType.ENDLOOP, expr.src, scope)
local_var = LocalVariable()
local_var.set_function(self._function)
local_var.set_offset(expr.src, self._function.compilation_unit)
link_underlying_nodes(curr_node, node_startLoop)
local_var = LocalVariable()
local_var.set_function(self._function)
local_var.set_offset(expr.src, self._function.compilation_unit)
counter_var = AnnAssign(
expr.target.src,
expr.target.node_id,
target=Name("-1:-1:-1", -1, "counter_var"),
annotation=Name("-1:-1:-1", -1, "uint256"),
value=Int("-1:-1:-1", -1, 0),
)
local_var_parser = LocalVariableVyper(local_var, counter_var)
self._add_local_variable(local_var_parser)
counter_node = self._new_node(NodeType.VARIABLE, expr.src, scope)
local_var.initialized = True
counter_node.add_unparsed_expression(counter_var.value)
counter_node.underlying_node.add_variable_declaration(local_var)
link_underlying_nodes(node_startLoop, counter_node)
node_condition = None
if isinstance(expr.iter, (Attribute, Name)):
# HACK
# The loop variable is not annotated so we infer its type by looking at the type of the iterator
if isinstance(expr.iter, Attribute): # state variable
iter_expr = expr.iter
loop_iterator = list(
filter(
lambda x: x._variable.name == iter_expr.attr,
self._contract_parser._variables_parser,
)
)[0]
else: # local variable
iter_expr = expr.iter
loop_iterator = list(
filter(
lambda x: x._variable.name == iter_expr.id,
self._local_variables_parser,
)
)[0]
# TODO use expr.src instead of -1:-1:1?
cond_expr = Compare(
"-1:-1:-1",
-1,
left=Name("-1:-1:-1", -1, "counter_var"),
op="<=",
right=Call(
"-1:-1:-1",
-1,
func=Name("-1:-1:-1", -1, "len"),
args=[iter_expr],
keywords=[],
keyword=None,
),
)
node_condition = self._new_node(NodeType.IFLOOP, expr.src, scope)
node_condition.add_unparsed_expression(cond_expr)
if loop_iterator._elem_to_parse.value.id == "DynArray":
loop_var_annotation = loop_iterator._elem_to_parse.slice.value.elements[
0
]
else:
loop_var_annotation = loop_iterator._elem_to_parse.value
value = Subscript(
"-1:-1:-1",
-1,
value=Name("-1:-1:-1", -1, loop_iterator._variable.name),
slice=Index("-1:-1:-1", -1, value=Name("-1:-1:-1", -1, "counter_var")),
)
loop_var = AnnAssign(
expr.target.src,
expr.target.node_id,
target=expr.target,
annotation=loop_var_annotation,
value=value,
)
elif isinstance(expr.iter, Call): # range
range_val = expr.iter.args[0]
cond_expr = Compare(
counter_var = AnnAssign(
expr.target.src,
expr.target.node_id,
target=Name("-1:-1:-1", -1, "counter_var"),
annotation=Name("-1:-1:-1", -1, "uint256"),
value=Int("-1:-1:-1", -1, 0),
)
local_var_parser = LocalVariableVyper(local_var, counter_var)
self._add_local_variable(local_var_parser)
counter_node = self._new_node(NodeType.VARIABLE, expr.src, scope)
local_var.initialized = True
counter_node.add_unparsed_expression(counter_var.value)
counter_node.underlying_node.add_variable_declaration(local_var)
link_underlying_nodes(node_startLoop, counter_node)
node_condition = None
if isinstance(expr.iter, (Attribute, Name)):
# HACK
# The loop variable is not annotated so we infer its type by looking at the type of the iterator
if isinstance(expr.iter, Attribute): # state variable
iter_expr = expr.iter
loop_iterator = list(
filter(
lambda x: x._variable.name == iter_expr.attr,
self._contract_parser._variables_parser,
)
)[0]
else: # local variable
iter_expr = expr.iter
loop_iterator = list(
filter(
lambda x: x._variable.name == iter_expr.id,
self._local_variables_parser,
)
)[0]
# TODO use expr.src instead of -1:-1:1?
cond_expr = Compare(
"-1:-1:-1",
-1,
left=Name("-1:-1:-1", -1, "counter_var"),
op="<=",
right=Call(
"-1:-1:-1",
-1,
left=Name("-1:-1:-1", -1, "counter_var"),
op="<=",
right=range_val,
)
node_condition = self._new_node(NodeType.IFLOOP, expr.src, scope)
node_condition.add_unparsed_expression(cond_expr)
loop_var = AnnAssign(
expr.target.src,
expr.target.node_id,
target=expr.target,
annotation=Name("-1:-1:-1", -1, "uint256"),
value=Name("-1:-1:-1", -1, "counter_var"),
)
func=Name("-1:-1:-1", -1, "len"),
args=[iter_expr],
keywords=[],
keyword=None,
),
)
node_condition = self._new_node(NodeType.IFLOOP, expr.src, scope)
node_condition.add_unparsed_expression(cond_expr)
if loop_iterator._elem_to_parse.value.id == "DynArray":
loop_var_annotation = loop_iterator._elem_to_parse.slice.value.elements[0]
else:
raise NotImplementedError
loop_var_annotation = loop_iterator._elem_to_parse.value
# After creating condition node, we link it declaration of the loop variable
link_underlying_nodes(counter_node, node_condition)
value = Subscript(
"-1:-1:-1",
-1,
value=Name("-1:-1:-1", -1, loop_iterator._variable.name),
slice=Index("-1:-1:-1", -1, value=Name("-1:-1:-1", -1, "counter_var")),
)
loop_var = AnnAssign(
expr.target.src,
expr.target.node_id,
target=expr.target,
annotation=loop_var_annotation,
value=value,
)
# Create an expression for the loop increment (counter_var += 1)
loop_increment = AugAssign(
elif isinstance(expr.iter, Call): # range
range_val = expr.iter.args[0]
cond_expr = Compare(
"-1:-1:-1",
-1,
target=Name("-1:-1:-1", -1, "counter_var"),
op="+=",
value=Int("-1:-1:-1", -1, 1),
left=Name("-1:-1:-1", -1, "counter_var"),
op="<=",
right=range_val,
)
node_condition = self._new_node(NodeType.IFLOOP, expr.src, scope)
node_condition.add_unparsed_expression(cond_expr)
loop_var = AnnAssign(
expr.target.src,
expr.target.node_id,
target=expr.target,
annotation=Name("-1:-1:-1", -1, "uint256"),
value=Name("-1:-1:-1", -1, "counter_var"),
)
node_increment = self._new_node(NodeType.EXPRESSION, expr.src, scope)
node_increment.add_unparsed_expression(loop_increment)
link_underlying_nodes(node_increment, node_condition)
prev_continue_destination = continue_destination
prev_break_destination = break_destination
continue_destination = node_increment
break_destination = node_endLoop
# We assign the index variable or range variable in the loop body on each iteration
expr.body.insert(0, loop_var)
body_node = None
new_node = node_condition
for stmt in expr.body:
body_node = parse_statement(
new_node, stmt, continue_destination, break_destination
)
new_node = body_node
# Reset to previous jump destinations for nested loops
continue_destination = prev_continue_destination
break_destination = prev_break_destination
if body_node is not None:
link_underlying_nodes(body_node, node_increment)
link_underlying_nodes(node_condition, node_endLoop)
curr_node = node_endLoop
elif isinstance(expr, Continue):
new_node = self._new_node(NodeType.CONTINUE, expr.src, scope)
link_underlying_nodes(curr_node, new_node)
link_underlying_nodes(new_node, continue_destination)
elif isinstance(expr, Break):
new_node = self._new_node(NodeType.BREAK, expr.src, scope)
link_underlying_nodes(curr_node, new_node)
link_underlying_nodes(new_node, break_destination)
else:
raise NotImplementedError
# After creating condition node, we link it declaration of the loop variable
link_underlying_nodes(counter_node, node_condition)
# Create an expression for the loop increment (counter_var += 1)
loop_increment = AugAssign(
"-1:-1:-1",
-1,
target=Name("-1:-1:-1", -1, "counter_var"),
op="+=",
value=Int("-1:-1:-1", -1, 1),
)
node_increment = self._new_node(NodeType.EXPRESSION, expr.src, scope)
node_increment.add_unparsed_expression(loop_increment)
link_underlying_nodes(node_increment, node_condition)
continue_destination = node_increment
break_destination = node_endLoop
# We assign the index variable or range variable in the loop body on each iteration
expr.body.insert(0, loop_var)
body_node = None
new_node = node_condition
for stmt in expr.body:
body_node = parse_statement(
new_node, stmt, continue_destination, break_destination
)
new_node = body_node
elif isinstance(expr, Return):
new_node = self._new_node(NodeType.RETURN, expr.src, scope)
if expr.value is not None:
new_node.add_unparsed_expression(expr.value)
if body_node is not None:
link_underlying_nodes(body_node, node_increment)
link_underlying_nodes(curr_node, new_node)
curr_node = new_node
link_underlying_nodes(node_condition, node_endLoop)
elif isinstance(expr, Assert):
new_node = self._new_node(NodeType.EXPRESSION, expr.src, scope)
new_node.add_unparsed_expression(expr)
curr_node = node_endLoop
link_underlying_nodes(curr_node, new_node)
curr_node = new_node
elif isinstance(expr, Continue):
new_node = self._new_node(NodeType.CONTINUE, expr.src, scope)
link_underlying_nodes(curr_node, new_node)
link_underlying_nodes(new_node, continue_destination)
elif isinstance(expr, Log):
new_node = self._new_node(NodeType.EXPRESSION, expr.src, scope)
elif isinstance(expr, Break):
new_node = self._new_node(NodeType.BREAK, expr.src, scope)
link_underlying_nodes(curr_node, new_node)
link_underlying_nodes(new_node, break_destination)
elif isinstance(expr, Return):
new_node = self._new_node(NodeType.RETURN, expr.src, scope)
if expr.value is not None:
new_node.add_unparsed_expression(expr.value)
link_underlying_nodes(curr_node, new_node)
curr_node = new_node
link_underlying_nodes(curr_node, new_node)
curr_node = new_node
elif isinstance(expr, If):
condition_node = self._new_node(NodeType.IF, expr.test.src, scope)
condition_node.add_unparsed_expression(expr.test)
elif isinstance(expr, Assert):
new_node = self._new_node(NodeType.EXPRESSION, expr.src, scope)
new_node.add_unparsed_expression(expr)
endIf_node = self._new_node(NodeType.ENDIF, expr.src, scope)
link_underlying_nodes(curr_node, new_node)
curr_node = new_node
true_node = None
new_node = condition_node
for stmt in expr.body:
true_node = parse_statement(
new_node, stmt, continue_destination, break_destination
)
new_node = true_node
elif isinstance(expr, Log):
new_node = self._new_node(NodeType.EXPRESSION, expr.src, scope)
new_node.add_unparsed_expression(expr.value)
link_underlying_nodes(true_node, endIf_node)
link_underlying_nodes(curr_node, new_node)
curr_node = new_node
false_node = None
new_node = condition_node
for stmt in expr.orelse:
false_node = parse_statement(
new_node, stmt, continue_destination, break_destination
)
new_node = false_node
elif isinstance(expr, If):
condition_node = self._new_node(NodeType.IF, expr.test.src, scope)
condition_node.add_unparsed_expression(expr.test)
if false_node is not None:
link_underlying_nodes(false_node, endIf_node)
endIf_node = self._new_node(NodeType.ENDIF, expr.src, scope)
else:
link_underlying_nodes(condition_node, endIf_node)
true_node = None
new_node = condition_node
for stmt in expr.body:
true_node = parse_statement(
new_node, stmt, continue_destination, break_destination
)
new_node = true_node
link_underlying_nodes(curr_node, condition_node)
curr_node = endIf_node
link_underlying_nodes(true_node, endIf_node)
elif isinstance(expr, Pass):
pass
elif isinstance(expr, Raise):
new_node = self._new_node(NodeType.EXPRESSION, expr.src, scope)
new_node.add_unparsed_expression(expr)
link_underlying_nodes(curr_node, new_node)
curr_node = new_node
false_node = None
new_node = condition_node
for stmt in expr.orelse:
false_node = parse_statement(
new_node, stmt, continue_destination, break_destination
)
new_node = false_node
if false_node is not None:
link_underlying_nodes(false_node, endIf_node)
else:
raise ParsingError(f"Statement not parsed {expr.__class__.__name__} {expr}")
link_underlying_nodes(condition_node, endIf_node)
link_underlying_nodes(curr_node, condition_node)
curr_node = endIf_node
return curr_node
elif isinstance(expr, Pass):
pass
elif isinstance(expr, Raise):
new_node = self._new_node(NodeType.EXPRESSION, expr.src, scope)
new_node.add_unparsed_expression(expr)
link_underlying_nodes(curr_node, new_node)
curr_node = new_node
else:
raise ParsingError(f"Statement not parsed {expr.__class__.__name__} {expr}")
return curr_node
curr_node = entry_node
for expr in cfg:
curr_node = parse_statement(curr_node, expr)
# endregion

@ -1,4 +1,4 @@
from typing import TYPE_CHECKING, Dict, List
from typing import List
from slither.core.declarations.structure import Structure
from slither.core.variables.structure_variable import StructureVariable

@ -1,8 +1,5 @@
import logging
import re
from typing import Union, Dict, TYPE_CHECKING, List, Any
import slither.core.expressions.type_conversion
from typing import Dict, TYPE_CHECKING
from collections import deque
from slither.core.declarations.solidity_variables import (
SOLIDITY_VARIABLES_COMPOSED,
SolidityVariableComposed,
@ -10,16 +7,11 @@ from slither.core.declarations.solidity_variables import (
from slither.core.declarations import SolidityFunction, Function
from slither.core.expressions import (
CallExpression,
ConditionalExpression,
ElementaryTypeNameExpression,
Identifier,
IndexAccess,
Literal,
MemberAccess,
NewArray,
NewContract,
NewElementaryType,
SuperCallExpression,
SelfIdentifier,
TupleExpression,
TypeConversion,
@ -43,12 +35,6 @@ from slither.core.declarations.contract import Contract
from slither.vyper_parsing.expressions.find_variable import find_variable
from slither.vyper_parsing.type_parsing import parse_type
from slither.all_exceptions import ParsingError
if TYPE_CHECKING:
from slither.core.expressions.expression import Expression
from collections import deque
from slither.vyper_parsing.ast.types import (
Int,
Call,
@ -72,8 +58,11 @@ from slither.vyper_parsing.ast.types import (
Raise,
)
if TYPE_CHECKING:
from slither.core.expressions.expression import Expression
def parse_expression(expression: Dict, caller_context) -> "Expression":
def parse_expression(expression: Dict, caller_context) -> "Expression": # pylint
if isinstance(expression, Int):
literal = Literal(str(expression.value), ElementaryType("uint256"))

@ -1,27 +1,17 @@
from typing import TYPE_CHECKING, Optional, Union, List, Tuple
from typing import TYPE_CHECKING, Optional, Union, Tuple
from slither.core.declarations import Event, Enum, Structure
from slither.core.declarations.contract import Contract
from slither.core.declarations.custom_error import CustomError
from slither.core.declarations.function import Function
from slither.core.declarations.function_contract import FunctionContract
from slither.core.declarations.function_top_level import FunctionTopLevel
from slither.core.declarations.solidity_import_placeholder import SolidityImportPlaceHolder
from slither.core.declarations.solidity_variables import (
SOLIDITY_FUNCTIONS,
SOLIDITY_VARIABLES,
SolidityFunction,
SolidityVariable,
)
from slither.core.scope.scope import FileScope
from slither.core.solidity_types import (
ArrayType,
FunctionType,
MappingType,
TypeAlias,
)
from slither.core.variables.variable import Variable
from slither.exceptions import SlitherError
from slither.solc_parsing.exceptions import VariableNotFound
if TYPE_CHECKING:
@ -109,8 +99,9 @@ def find_variable(
:rtype:
"""
from slither.vyper_parsing.declarations.contract import ContractVyper
from slither.vyper_parsing.declarations.function import FunctionVyper
from slither.vyper_parsing.declarations.function import (
FunctionVyper,
) # pylint: disable=import-outside-toplevel
if isinstance(caller_context, Contract):
current_scope = caller_context.file_scope

@ -12,7 +12,9 @@ from slither.core.solidity_types.user_defined_type import UserDefinedType
from slither.core.declarations.function_contract import FunctionContract
def parse_type(annotation: Union[Name, Subscript, Call, Tuple], caller_context):
def parse_type(
annotation: Union[Name, Subscript, Call, Tuple], caller_context
): # pylint disable=too-many-branches,too-many-return-statements,import-outside-toplevel
from slither.vyper_parsing.expressions.expression_parsing import parse_expression
if isinstance(caller_context, FunctionContract):
@ -33,8 +35,7 @@ def parse_type(annotation: Union[Name, Subscript, Call, Tuple], caller_context):
type_ = parse_type(annotation.slice.value.elements[0], caller_context)
length = parse_expression(annotation.slice.value.elements[1], caller_context)
return ArrayType(type_, length)
else:
assert annotation.value.id == "HashMap"
if annotation.value.id == "HashMap":
type_from = parse_type(annotation.slice.value.elements[0], caller_context)
type_to = parse_type(annotation.slice.value.elements[1], caller_context)

@ -1,5 +1,3 @@
from typing import Dict
from slither.core.variables.event_variable import EventVariable
from slither.vyper_parsing.type_parsing import parse_type
from slither.vyper_parsing.ast.types import AnnAssign, Call

@ -1,5 +1,3 @@
from typing import Dict
from slither.core.variables.state_variable import StateVariable
from slither.vyper_parsing.ast.types import VariableDecl
from slither.vyper_parsing.type_parsing import parse_type

@ -1,6 +1,3 @@
from typing import Dict
from slither.core.variables.structure_variable import StructureVariable
from slither.vyper_parsing.type_parsing import parse_type
from slither.vyper_parsing.ast.types import AnnAssign

@ -25,7 +25,7 @@ class VyperCompilationUnit:
sourceUnit = int(sourceUnit_candidates[0])
self._compilation_unit.source_units[sourceUnit] = filename
if os.path.isfile(filename) and not filename in self._compilation_unit.core.source_code:
if os.path.isfile(filename) and filename not in self._compilation_unit.core.source_code:
self._compilation_unit.core.add_source_code(filename)
scope = self._compilation_unit.get_scope(filename)

@ -1,4 +1,3 @@
from typing import Dict
from pathlib import Path
from slither import Slither

@ -1,38 +1,13 @@
# # pylint: disable=too-many-lines
import pathlib
from argparse import ArgumentTypeError
from collections import defaultdict
from inspect import getsourcefile
from typing import Union, List, Dict, Callable
import pytest
from slither import Slither
from slither.core.cfg.node import Node, NodeType
from slither.core.declarations import Function, Contract
from slither.core.solidity_types import ArrayType, ElementaryType
from slither.core.variables.local_variable import LocalVariable
from slither.core.variables.state_variable import StateVariable
from slither.core.solidity_types import ElementaryType
from slither.slithir.operations import (
OperationWithLValue,
Phi,
Assignment,
HighLevelCall,
Return,
Operation,
Binary,
BinaryType,
InternalCall,
Index,
InitArray,
)
from slither.slithir.utils.ssa import is_used_later
from slither.slithir.variables import (
Constant,
ReferenceVariable,
LocalIRVariable,
StateIRVariable,
TemporaryVariableSSA,
)

Loading…
Cancel
Save