@ -256,7 +256,7 @@ class FunctionSolc(Function):
condition = ifStatement [ ' condition ' ]
condition = ifStatement [ ' condition ' ]
# Note: check if the expression could be directly
# Note: check if the expression could be directly
# parsed here
# parsed here
condition_node = self . _new_node ( NodeType . IF , ifStatement [ ' src ' ] )
condition_node = self . _new_node ( NodeType . IF , condition [ ' src ' ] )
condition_node . add_unparsed_expression ( condition )
condition_node . add_unparsed_expression ( condition )
link_nodes ( node , condition_node )
link_nodes ( node , condition_node )
trueStatement = self . _parse_statement ( ifStatement [ ' trueBody ' ] , condition_node )
trueStatement = self . _parse_statement ( ifStatement [ ' trueBody ' ] , condition_node )
@ -267,7 +267,7 @@ class FunctionSolc(Function):
condition = children [ 0 ]
condition = children [ 0 ]
# Note: check if the expression could be directly
# Note: check if the expression could be directly
# parsed here
# parsed here
condition_node = self . _new_node ( NodeType . IF , ifStatement [ ' src ' ] )
condition_node = self . _new_node ( NodeType . IF , condition [ ' src ' ] )
condition_node . add_unparsed_expression ( condition )
condition_node . add_unparsed_expression ( condition )
link_nodes ( node , condition_node )
link_nodes ( node , condition_node )
trueStatement = self . _parse_statement ( children [ 1 ] , condition_node )
trueStatement = self . _parse_statement ( children [ 1 ] , condition_node )
@ -287,14 +287,15 @@ class FunctionSolc(Function):
# WhileStatement = 'while' '(' Expression ')' Statement
# WhileStatement = 'while' '(' Expression ')' Statement
node_startWhile = self . _new_node ( NodeType . STARTLOOP , whileStatement [ ' src ' ] )
node_startWhile = self . _new_node ( NodeType . STARTLOOP , whileStatement [ ' src ' ] )
node_condition = self . _new_node ( NodeType . IFLOOP , whileStatement [ ' src ' ] )
if self . is_compact_ast :
if self . is_compact_ast :
node_condition = self . _new_node ( NodeType . IFLOOP , whileStatement [ ' condition ' ] [ ' src ' ] )
node_condition . add_unparsed_expression ( whileStatement [ ' condition ' ] )
node_condition . add_unparsed_expression ( whileStatement [ ' condition ' ] )
statement = self . _parse_statement ( whileStatement [ ' body ' ] , node_condition )
statement = self . _parse_statement ( whileStatement [ ' body ' ] , node_condition )
else :
else :
children = whileStatement [ self . get_children ( ' children ' ) ]
children = whileStatement [ self . get_children ( ' children ' ) ]
expression = children [ 0 ]
expression = children [ 0 ]
node_condition = self . _new_node ( NodeType . IFLOOP , expression [ ' src ' ] )
node_condition . add_unparsed_expression ( expression )
node_condition . add_unparsed_expression ( expression )
statement = self . _parse_statement ( children [ 1 ] , node_condition )
statement = self . _parse_statement ( children [ 1 ] , node_condition )
@ -323,7 +324,7 @@ class FunctionSolc(Function):
link_nodes ( node , node_startLoop )
link_nodes ( node , node_startLoop )
if condition :
if condition :
node_condition = self . _new_node ( NodeType . IFLOOP , statement [ ' src ' ] )
node_condition = self . _new_node ( NodeType . IFLOOP , condition [ ' src ' ] )
node_condition . add_unparsed_expression ( condition )
node_condition . add_unparsed_expression ( condition )
link_nodes ( node_startLoop , node_condition )
link_nodes ( node_startLoop , node_condition )
link_nodes ( node_condition , node_endLoop )
link_nodes ( node_condition , node_endLoop )
@ -417,9 +418,9 @@ class FunctionSolc(Function):
if candidate [ self . get_key ( ) ] not in [ ' VariableDefinitionStatement ' ,
if candidate [ self . get_key ( ) ] not in [ ' VariableDefinitionStatement ' ,
' VariableDeclarationStatement ' ,
' VariableDeclarationStatement ' ,
' ExpressionStatement ' ] :
' ExpressionStatement ' ] :
node_condition = self . _new_node ( NodeType . IFLOOP , statement [ ' src ' ] )
#expression = parse_expression(candidate, self)
expression = candidate
expression = candidate
node_condition = self . _new_node ( NodeType . IFLOOP , expression [ ' src ' ] )
#expression = parse_expression(candidate, self)
node_condition . add_unparsed_expression ( expression )
node_condition . add_unparsed_expression ( expression )
link_nodes ( node_startLoop , node_condition )
link_nodes ( node_startLoop , node_condition )
link_nodes ( node_condition , node_endLoop )
link_nodes ( node_condition , node_endLoop )
@ -448,15 +449,16 @@ class FunctionSolc(Function):
def _parse_dowhile ( self , doWhilestatement , node ) :
def _parse_dowhile ( self , doWhilestatement , node ) :
node_startDoWhile = self . _new_node ( NodeType . STARTLOOP , doWhilestatement [ ' src ' ] )
node_startDoWhile = self . _new_node ( NodeType . STARTLOOP , doWhilestatement [ ' src ' ] )
node_condition = self . _new_node ( NodeType . IFLOOP , doWhilestatement [ ' src ' ] )
if self . is_compact_ast :
if self . is_compact_ast :
node_condition = self . _new_node ( NodeType . IFLOOP , doWhilestatement [ ' condition ' ] [ ' src ' ] )
node_condition . add_unparsed_expression ( doWhilestatement [ ' condition ' ] )
node_condition . add_unparsed_expression ( doWhilestatement [ ' condition ' ] )
statement = self . _parse_statement ( doWhilestatement [ ' body ' ] , node_condition )
statement = self . _parse_statement ( doWhilestatement [ ' body ' ] , node_condition )
else :
else :
children = doWhilestatement [ self . get_children ( ' children ' ) ]
children = doWhilestatement [ self . get_children ( ' children ' ) ]
# same order in the AST as while
# same order in the AST as while
expression = children [ 0 ]
expression = children [ 0 ]
node_condition = self . _new_node ( NodeType . IFLOOP , expression [ ' src ' ] )
node_condition . add_unparsed_expression ( expression )
node_condition . add_unparsed_expression ( expression )
statement = self . _parse_statement ( children [ 1 ] , node_condition )
statement = self . _parse_statement ( children [ 1 ] , node_condition )
@ -964,7 +966,8 @@ class FunctionSolc(Function):
if has_cond . result ( ) :
if has_cond . result ( ) :
st = SplitTernaryExpression ( node . expression )
st = SplitTernaryExpression ( node . expression )
condition = st . condition
condition = st . condition
assert condition
if not condition :
raise ParsingError ( f ' Incorrect ternary conversion { node . expression } { node . source_mapping_str } ' )
true_expr = st . true_expression
true_expr = st . true_expression
false_expr = st . false_expression
false_expr = st . false_expression
self . split_ternary_node ( node , condition , true_expr , false_expr )
self . split_ternary_node ( node , condition , true_expr , false_expr )