Yul: minor modifs

- Rename YulObject to YulBlock
- Add some comments
pull/502/head
Josselin 4 years ago
parent e32089ba32
commit 945ff10aef
  1. 8
      slither/core/declarations/function.py
  2. 3
      slither/core/expressions/binary_operation.py
  3. 10
      slither/solc_parsing/declarations/function.py
  4. 7
      slither/solc_parsing/yul/parse_yul.py

@ -202,7 +202,13 @@ class Function(ChildContract, ChildInheritance, SourceMapping):
self._name = new_name self._name = new_name
@property @property
def scope(self): def scope(self) -> List[str]:
"""
Return a list of name representing the scope of the function
This is used to model nested functions declared in YUL
:return:
"""
return self._scope return self._scope
@scope.setter @scope.setter

@ -31,6 +31,9 @@ class BinaryOperationType(Enum):
ANDAND = 17 # && ANDAND = 17 # &&
OROR = 18 # || OROR = 18 # ||
# YUL specific operators
# TODO: investigate if we can remove these
# Find the types earlier on, and do the conversion
DIVISION_SIGNED = 19 DIVISION_SIGNED = 19
MODULO_SIGNED = 20 MODULO_SIGNED = 20
LESS_SIGNED = 21 LESS_SIGNED = 21

@ -18,7 +18,7 @@ from slither.solc_parsing.variables.local_variable_init_from_tuple import (
LocalVariableInitFromTupleSolc, LocalVariableInitFromTupleSolc,
) )
from slither.solc_parsing.variables.variable_declaration import MultipleVariablesDeclaration from slither.solc_parsing.variables.variable_declaration import MultipleVariablesDeclaration
from slither.solc_parsing.yul.parse_yul import YulObject from slither.solc_parsing.yul.parse_yul import YulBlock
from slither.utils.expression_manipulations import SplitTernaryExpression from slither.utils.expression_manipulations import SplitTernaryExpression
from slither.visitors.expression.export_values import ExportValues from slither.visitors.expression.export_values import ExportValues
from slither.visitors.expression.has_conditional import HasConditional from slither.visitors.expression.has_conditional import HasConditional
@ -81,7 +81,7 @@ class FunctionSolc:
self.returns_src = SourceMapping() self.returns_src = SourceMapping()
self._node_to_nodesolc: Dict[Node, NodeSolc] = dict() self._node_to_nodesolc: Dict[Node, NodeSolc] = dict()
self._node_to_yulobject: Dict[Node, YulObject] = dict() self._node_to_yulobject: Dict[Node, YulBlock] = dict()
self._local_variables_parser: List[ self._local_variables_parser: List[
Union[LocalVariableSolc, LocalVariableInitFromTupleSolc] Union[LocalVariableSolc, LocalVariableInitFromTupleSolc]
@ -319,9 +319,9 @@ class FunctionSolc:
self._node_to_nodesolc[node] = node_parser self._node_to_nodesolc[node] = node_parser
return node_parser return node_parser
def _new_yul_object(self, src: Union[str, Dict]) -> YulObject: def _new_yul_block(self, src: Union[str, Dict]) -> YulBlock:
node = self._function.new_node(NodeType.ASSEMBLY, src) node = self._function.new_node(NodeType.ASSEMBLY, src)
yul_object = YulObject(self._function.contract, node, [self._function.name, f"asm_{len(self._node_to_yulobject)}"], parent_func=self._function) yul_object = YulBlock(self._function.contract, node, [self._function.name, f"asm_{len(self._node_to_yulobject)}"], parent_func=self._function)
self._node_to_yulobject[node] = yul_object self._node_to_yulobject[node] = yul_object
return yul_object return yul_object
@ -821,7 +821,7 @@ class FunctionSolc:
# Added with solc 0.6 - the yul code is an AST # Added with solc 0.6 - the yul code is an AST
if 'AST' in statement: if 'AST' in statement:
self._function.contains_assembly = True self._function.contains_assembly = True
yul_object = self._new_yul_object(statement['src']) yul_object = self._new_yul_block(statement['src'])
entrypoint = yul_object.entrypoint entrypoint = yul_object.entrypoint
exitpoint = yul_object.convert(statement['AST']) exitpoint = yul_object.convert(statement['AST'])

@ -214,7 +214,12 @@ class YulFunction(YulScope):
return yul_node return yul_node
class YulObject(YulScope): class YulBlock(YulScope):
"""
A YulBlock represents a standalone yul component.
For example an inline assembly block
"""
__slots__ = ["_entrypoint", "_parent_func", "_nodes"] __slots__ = ["_entrypoint", "_parent_func", "_nodes"]
def __init__(self, contract: Contract, entrypoint: Node, id: List[str], **kwargs): def __init__(self, contract: Contract, entrypoint: Node, id: List[str], **kwargs):

Loading…
Cancel
Save