@ -228,7 +228,7 @@ def filter_name(value):
###################################################################################
###################################################################################
def parse_call ( expression , caller_context ) :
def parse_call ( expression , caller_context ) :
src = expression [ ' src ' ]
if caller_context . is_compact_ast :
if caller_context . is_compact_ast :
attributes = expression
attributes = expression
type_conversion = expression [ ' kind ' ] == ' typeConversion '
type_conversion = expression [ ' kind ' ] == ' typeConversion '
@ -261,6 +261,7 @@ def parse_call(expression, caller_context):
expression = parse_expression ( expression_to_parse , caller_context )
expression = parse_expression ( expression_to_parse , caller_context )
t = TypeConversion ( expression , type_call )
t = TypeConversion ( expression , type_call )
t . set_offset ( src , caller_context . slither )
return t
return t
if caller_context . is_compact_ast :
if caller_context . is_compact_ast :
@ -276,7 +277,7 @@ def parse_call(expression, caller_context):
if isinstance ( called , SuperCallExpression ) :
if isinstance ( called , SuperCallExpression ) :
return SuperCallExpression ( called , arguments , type_return )
return SuperCallExpression ( called , arguments , type_return )
call_expression = CallExpression ( called , arguments , type_return )
call_expression = CallExpression ( called , arguments , type_return )
call_expression . set_offset ( expression [ ' src' ] , caller_context . slither )
call_expression . set_offset ( src , caller_context . slither )
return call_expression
return call_expression
def parse_super_name ( expression , is_compact_ast ) :
def parse_super_name ( expression , is_compact_ast ) :
@ -311,7 +312,9 @@ def _parse_elementary_type_name_expression(expression, is_compact_ast, caller_co
value = expression [ ' attributes ' ] [ ' value ' ]
value = expression [ ' attributes ' ] [ ' value ' ]
t = parse_type ( UnknownType ( value ) , caller_context )
t = parse_type ( UnknownType ( value ) , caller_context )
return ElementaryTypeNameExpression ( t )
e = ElementaryTypeNameExpression ( t )
e . set_offset ( expression [ ' src ' ] , caller_context . slither )
return e
def parse_expression ( expression , caller_context ) :
def parse_expression ( expression , caller_context ) :
"""
"""
@ -345,6 +348,7 @@ def parse_expression(expression, caller_context):
# The AST naming does not follow the spec
# The AST naming does not follow the spec
name = expression [ caller_context . get_key ( ) ]
name = expression [ caller_context . get_key ( ) ]
is_compact_ast = caller_context . is_compact_ast
is_compact_ast = caller_context . is_compact_ast
src = expression [ ' src ' ]
if name == ' UnaryOperation ' :
if name == ' UnaryOperation ' :
if is_compact_ast :
if is_compact_ast :
@ -360,6 +364,7 @@ def parse_expression(expression, caller_context):
assert len ( expression [ ' children ' ] ) == 1
assert len ( expression [ ' children ' ] ) == 1
expression = parse_expression ( expression [ ' children ' ] [ 0 ] , caller_context )
expression = parse_expression ( expression [ ' children ' ] [ 0 ] , caller_context )
unary_op = UnaryOperation ( expression , operation_type )
unary_op = UnaryOperation ( expression , operation_type )
unary_op . set_offset ( src , caller_context . slither )
return unary_op
return unary_op
elif name == ' BinaryOperation ' :
elif name == ' BinaryOperation ' :
@ -377,6 +382,7 @@ def parse_expression(expression, caller_context):
left_expression = parse_expression ( expression [ ' children ' ] [ 0 ] , caller_context )
left_expression = parse_expression ( expression [ ' children ' ] [ 0 ] , caller_context )
right_expression = parse_expression ( expression [ ' children ' ] [ 1 ] , caller_context )
right_expression = parse_expression ( expression [ ' children ' ] [ 1 ] , caller_context )
binary_op = BinaryOperation ( left_expression , right_expression , operation_type )
binary_op = BinaryOperation ( left_expression , right_expression , operation_type )
binary_op . set_offset ( src , caller_context . slither )
return binary_op
return binary_op
elif name == ' FunctionCall ' :
elif name == ' FunctionCall ' :
@ -414,6 +420,7 @@ def parse_expression(expression, caller_context):
if elems [ idx ] == ' ' :
if elems [ idx ] == ' ' :
expressions . insert ( idx , None )
expressions . insert ( idx , None )
t = TupleExpression ( expressions )
t = TupleExpression ( expressions )
t . set_offset ( src , caller_context . slither )
return t
return t
elif name == ' Conditional ' :
elif name == ' Conditional ' :
@ -428,6 +435,7 @@ def parse_expression(expression, caller_context):
then_expression = parse_expression ( children [ 1 ] , caller_context )
then_expression = parse_expression ( children [ 1 ] , caller_context )
else_expression = parse_expression ( children [ 2 ] , caller_context )
else_expression = parse_expression ( children [ 2 ] , caller_context )
conditional = ConditionalExpression ( if_expression , then_expression , else_expression )
conditional = ConditionalExpression ( if_expression , then_expression , else_expression )
conditional . set_offset ( src , caller_context . slither )
return conditional
return conditional
elif name == ' Assignment ' :
elif name == ' Assignment ' :
@ -449,6 +457,7 @@ def parse_expression(expression, caller_context):
operation_return_type = attributes [ ' type ' ]
operation_return_type = attributes [ ' type ' ]
assignement = AssignmentOperation ( left_expression , right_expression , operation_type , operation_return_type )
assignement = AssignmentOperation ( left_expression , right_expression , operation_type , operation_return_type )
assignement . set_offset ( src , caller_context . slither )
return assignement
return assignement
@ -498,6 +507,7 @@ def parse_expression(expression, caller_context):
else :
else :
type = ElementaryType ( ' string ' )
type = ElementaryType ( ' string ' )
literal = Literal ( value , type , subdenomination )
literal = Literal ( value , type , subdenomination )
literal . set_offset ( src , caller_context . slither )
return literal
return literal
elif name == ' Identifier ' :
elif name == ' Identifier ' :
@ -528,7 +538,7 @@ def parse_expression(expression, caller_context):
var = find_variable ( value , caller_context , referenced_declaration )
var = find_variable ( value , caller_context , referenced_declaration )
identifier = Identifier ( var )
identifier = Identifier ( var )
identifier . set_offset ( expression [ ' src' ] , caller_context . slither )
identifier . set_offset ( src , caller_context . slither )
return identifier
return identifier
elif name == ' IndexAccess ' :
elif name == ' IndexAccess ' :
@ -551,6 +561,7 @@ def parse_expression(expression, caller_context):
left_expression = parse_expression ( left , caller_context )
left_expression = parse_expression ( left , caller_context )
right_expression = parse_expression ( right , caller_context )
right_expression = parse_expression ( right , caller_context )
index = IndexAccess ( left_expression , right_expression , index_type )
index = IndexAccess ( left_expression , right_expression , index_type )
index . set_offset ( src , caller_context . slither )
return index
return index
elif name == ' MemberAccess ' :
elif name == ' MemberAccess ' :
@ -569,10 +580,15 @@ def parse_expression(expression, caller_context):
var = find_variable ( super_name , caller_context , is_super = True )
var = find_variable ( super_name , caller_context , is_super = True )
if var is None :
if var is None :
raise VariableNotFound ( ' Variable not found: {} ' . format ( super_name ) )
raise VariableNotFound ( ' Variable not found: {} ' . format ( super_name ) )
return SuperIdentifier ( var )
sup = SuperIdentifier ( var )
sup . set_offset ( src , caller_context . slither )
return sup
member_access = MemberAccess ( member_name , member_type , member_expression )
member_access = MemberAccess ( member_name , member_type , member_expression )
member_access . set_offset ( src , caller_context . slither )
if str ( member_access ) in SOLIDITY_VARIABLES_COMPOSED :
if str ( member_access ) in SOLIDITY_VARIABLES_COMPOSED :
return Identifier ( SolidityVariableComposed ( str ( member_access ) ) )
idx = Identifier ( SolidityVariableComposed ( str ( member_access ) ) )
idx . set_offset ( src , caller_context . slither )
return idx
return member_access
return member_access
elif name == ' ElementaryTypeNameExpression ' :
elif name == ' ElementaryTypeNameExpression ' :
@ -614,6 +630,7 @@ def parse_expression(expression, caller_context):
else :
else :
raise ParsingError ( ' Incorrect type array {} ' . format ( type_name ) )
raise ParsingError ( ' Incorrect type array {} ' . format ( type_name ) )
array = NewArray ( depth , array_type )
array = NewArray ( depth , array_type )
array . set_offset ( src , caller_context . slither )
return array
return array
if type_name [ caller_context . get_key ( ) ] == ' ElementaryTypeName ' :
if type_name [ caller_context . get_key ( ) ] == ' ElementaryTypeName ' :
@ -622,6 +639,7 @@ def parse_expression(expression, caller_context):
else :
else :
elem_type = ElementaryType ( type_name [ ' attributes ' ] [ ' name ' ] )
elem_type = ElementaryType ( type_name [ ' attributes ' ] [ ' name ' ] )
new_elem = NewElementaryType ( elem_type )
new_elem = NewElementaryType ( elem_type )
new_elem . set_offset ( src , caller_context . slither )
return new_elem
return new_elem
assert type_name [ caller_context . get_key ( ) ] == ' UserDefinedTypeName '
assert type_name [ caller_context . get_key ( ) ] == ' UserDefinedTypeName '
@ -631,6 +649,7 @@ def parse_expression(expression, caller_context):
else :
else :
contract_name = type_name [ ' attributes ' ] [ ' name ' ]
contract_name = type_name [ ' attributes ' ] [ ' name ' ]
new = NewContract ( contract_name )
new = NewContract ( contract_name )
new . set_offset ( src , caller_context . slither )
return new
return new
elif name == ' ModifierInvocation ' :
elif name == ' ModifierInvocation ' :
@ -646,7 +665,7 @@ def parse_expression(expression, caller_context):
arguments = [ parse_expression ( a , caller_context ) for a in children [ 1 : : ] ]
arguments = [ parse_expression ( a , caller_context ) for a in children [ 1 : : ] ]
call = CallExpression ( called , arguments , ' Modifier ' )
call = CallExpression ( called , arguments , ' Modifier ' )
call . set_offset ( expression [ ' src' ] , caller_context . slither )
call . set_offset ( src , caller_context . slither )
return call
return call
raise ParsingError ( ' Expression not parsed %s ' % name )
raise ParsingError ( ' Expression not parsed %s ' % name )