Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert(isinstance(expr, AbstractExpression))
if (isinstance(expr, Value)):
return expr.typ
elif (isinstance(expr, constructs.Variable)):
return expr.typ
elif (isinstance(expr, constructs.Reference)):
return expr.objectRef.typ
elif (isinstance(expr, AbstractBinaryOpNode)):
left_type = getType(expr.left)
right_type = getType(expr.right)
return result_type(left_type, right_type)
elif (isinstance(expr, AbstractUnaryOpNode)):
return getType(expr.child)
elif (isinstance(expr, constructs.Cast)):
return expr.typ
elif (isinstance(expr, constructs.Select)):
true_type = getType(expr.trueExpression)
false_type = getType(expr.falseExpression)
assert true_type == false_type
return true_type
elif (isinstance(expr, InbuiltFunction)):
return expr.getType()
raise TypeError(type(expr))
return simplify_expr(new_expr)
elif (isinstance(expr, AbstractUnaryOpNode)):
child = substitute_vars(expr.child, var_to_expr_map)
op = expr.op
new_expr = AbstractUnaryOpNode(child, op)
return simplify_expr(new_expr)
elif (isinstance(expr, constructs.Cast)):
typ = expr.typ
return \
constructs.Cast(typ,
substitute_vars(expr.expression, var_to_expr_map))
elif (isinstance(expr, constructs.Select)):
new_cond = substitute_vars(expr.condition, var_to_expr_map)
new_true = substitute_vars(expr.trueExpression, var_to_expr_map)
new_false = substitute_vars(expr.falseExpression, var_to_expr_map)
return constructs.Select(new_cond, new_true, new_false)
elif (isinstance(expr, InbuiltFunction)):
expr = expr.clone()
expr.substitute_vars(var_to_expr_map)
return expr
raise TypeError(type(expr))