|
|
@ -297,8 +297,9 @@ def parse_call(expression, caller_context): |
|
|
|
'IndexAccess', |
|
|
|
'IndexAccess', |
|
|
|
'MemberAccess'] |
|
|
|
'MemberAccess'] |
|
|
|
|
|
|
|
|
|
|
|
expression = parse_expression(expression_to_parse, caller_context) |
|
|
|
expression_parsed = parse_expression(expression_to_parse, caller_context) |
|
|
|
t = TypeConversion(expression, type_call) |
|
|
|
t = TypeConversion(expression_parsed, type_call) |
|
|
|
|
|
|
|
t.set_offset(expression['src'], caller_context.slither) |
|
|
|
return t |
|
|
|
return t |
|
|
|
|
|
|
|
|
|
|
|
if caller_context.is_compact_ast: |
|
|
|
if caller_context.is_compact_ast: |
|
|
@ -312,7 +313,9 @@ def parse_call(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::]] |
|
|
|
|
|
|
|
|
|
|
|
if isinstance(called, SuperCallExpression): |
|
|
|
if isinstance(called, SuperCallExpression): |
|
|
|
return SuperCallExpression(called, arguments, type_return) |
|
|
|
sp = SuperCallExpression(called, arguments, type_return) |
|
|
|
|
|
|
|
sp.set_offset(expression['src'], caller_context.slither) |
|
|
|
|
|
|
|
return sp |
|
|
|
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(expression['src'], caller_context.slither) |
|
|
|
return call_expression |
|
|
|
return call_expression |
|
|
@ -349,7 +352,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): |
|
|
|
""" |
|
|
|
""" |
|
|
@ -393,11 +398,12 @@ def parse_expression(expression, caller_context): |
|
|
|
operation_type = UnaryOperationType.get_type(attributes['operator'], attributes['prefix']) |
|
|
|
operation_type = UnaryOperationType.get_type(attributes['operator'], attributes['prefix']) |
|
|
|
|
|
|
|
|
|
|
|
if is_compact_ast: |
|
|
|
if is_compact_ast: |
|
|
|
expression = parse_expression(expression['subExpression'], caller_context) |
|
|
|
expression_parsed = parse_expression(expression['subExpression'], caller_context) |
|
|
|
else: |
|
|
|
else: |
|
|
|
assert len(expression['children']) == 1 |
|
|
|
assert len(expression['children']) == 1 |
|
|
|
expression = parse_expression(expression['children'][0], caller_context) |
|
|
|
expression_parsed = parse_expression(expression['children'][0], caller_context) |
|
|
|
unary_op = UnaryOperation(expression, operation_type) |
|
|
|
unary_op = UnaryOperation(expression_parsed, operation_type) |
|
|
|
|
|
|
|
unary_op.set_offset(expression['src'], caller_context.slither) |
|
|
|
return unary_op |
|
|
|
return unary_op |
|
|
|
|
|
|
|
|
|
|
|
elif name == 'BinaryOperation': |
|
|
|
elif name == 'BinaryOperation': |
|
|
@ -415,10 +421,11 @@ 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(expression['src'], caller_context.slither) |
|
|
|
return binary_op |
|
|
|
return binary_op |
|
|
|
|
|
|
|
|
|
|
|
elif name == 'FunctionCall': |
|
|
|
elif name == 'FunctionCall': |
|
|
|
return parse_call(expression, caller_context) |
|
|
|
return parse_call(expression, caller_context) |
|
|
|
|
|
|
|
|
|
|
|
elif name == 'TupleExpression': |
|
|
|
elif name == 'TupleExpression': |
|
|
|
""" |
|
|
|
""" |
|
|
@ -433,7 +440,7 @@ def parse_expression(expression, caller_context): |
|
|
|
Note: this is only possible with Solidity >= 0.4.12 |
|
|
|
Note: this is only possible with Solidity >= 0.4.12 |
|
|
|
""" |
|
|
|
""" |
|
|
|
if is_compact_ast: |
|
|
|
if is_compact_ast: |
|
|
|
expressions = [parse_expression(e, caller_context) if e else None for e in expression['components']] |
|
|
|
expressions = [parse_expression(e, caller_context) if e else None for e in expression['components']] |
|
|
|
else: |
|
|
|
else: |
|
|
|
if 'children' not in expression : |
|
|
|
if 'children' not in expression : |
|
|
|
attributes = expression['attributes'] |
|
|
|
attributes = expression['attributes'] |
|
|
@ -452,6 +459,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(expression['src'], caller_context.slither) |
|
|
|
return t |
|
|
|
return t |
|
|
|
|
|
|
|
|
|
|
|
elif name == 'Conditional': |
|
|
|
elif name == 'Conditional': |
|
|
@ -466,6 +474,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(expression['src'], caller_context.slither) |
|
|
|
return conditional |
|
|
|
return conditional |
|
|
|
|
|
|
|
|
|
|
|
elif name == 'Assignment': |
|
|
|
elif name == 'Assignment': |
|
|
@ -487,6 +496,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(expression['src'], caller_context.slither) |
|
|
|
return assignement |
|
|
|
return assignement |
|
|
|
|
|
|
|
|
|
|
|
elif name == 'Literal': |
|
|
|
elif name == 'Literal': |
|
|
@ -531,6 +541,7 @@ def parse_expression(expression, caller_context): |
|
|
|
else: |
|
|
|
else: |
|
|
|
type = ElementaryType('string') |
|
|
|
type = ElementaryType('string') |
|
|
|
literal = Literal(value, type) |
|
|
|
literal = Literal(value, type) |
|
|
|
|
|
|
|
literal.set_offset(expression['src'], caller_context.slither) |
|
|
|
return literal |
|
|
|
return literal |
|
|
|
|
|
|
|
|
|
|
|
elif name == 'Identifier': |
|
|
|
elif name == 'Identifier': |
|
|
@ -584,6 +595,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(expression['src'], caller_context.slither) |
|
|
|
return index |
|
|
|
return index |
|
|
|
|
|
|
|
|
|
|
|
elif name == 'MemberAccess': |
|
|
|
elif name == 'MemberAccess': |
|
|
@ -604,8 +616,11 @@ def parse_expression(expression, caller_context): |
|
|
|
raise VariableNotFound('Variable not found: {}'.format(super_name)) |
|
|
|
raise VariableNotFound('Variable not found: {}'.format(super_name)) |
|
|
|
return SuperIdentifier(var) |
|
|
|
return SuperIdentifier(var) |
|
|
|
member_access = MemberAccess(member_name, member_type, member_expression) |
|
|
|
member_access = MemberAccess(member_name, member_type, member_expression) |
|
|
|
|
|
|
|
member_access.set_offset(expression['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))) |
|
|
|
identifier = Identifier(SolidityVariableComposed(str(member_access))) |
|
|
|
|
|
|
|
identifier.set_offset(expression['src'], caller_context.slither) |
|
|
|
|
|
|
|
return identifier |
|
|
|
return member_access |
|
|
|
return member_access |
|
|
|
|
|
|
|
|
|
|
|
elif name == 'ElementaryTypeNameExpression': |
|
|
|
elif name == 'ElementaryTypeNameExpression': |
|
|
@ -647,6 +662,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(expression['src'], caller_context.slither) |
|
|
|
return array |
|
|
|
return array |
|
|
|
|
|
|
|
|
|
|
|
if type_name[caller_context.get_key()] == 'ElementaryTypeName': |
|
|
|
if type_name[caller_context.get_key()] == 'ElementaryTypeName': |
|
|
@ -655,6 +671,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(expression['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' |
|
|
@ -664,6 +681,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(expression['src'], caller_context.slither) |
|
|
|
return new |
|
|
|
return new |
|
|
|
|
|
|
|
|
|
|
|
elif name == 'ModifierInvocation': |
|
|
|
elif name == 'ModifierInvocation': |
|
|
|