def visitFunctionCallExpr(self, ctx: SolidityParser.FunctionCallExprContext): func = self.visit(ctx.func) args = self.handle_field(ctx.args) if isinstance(func, IdentifierExpr): if func.idf.name == 'reveal': if len(args) != 2: ReclassifyException( f'Invalid number of arguments for reveal: {args}') return ReclassifyExpr(args[0], args[1]) return FunctionCallExpr(func, args)
def test_builtin_code(self): f = BuiltinFunction('+') c = FunctionCallExpr(f, [NumberLiteralExpr(0), NumberLiteralExpr(0)]) self.assertEqual(c.code(), '0 + 0')
def visitIteExpr(self, ctx: SolidityParser.IteExprContext): f = BuiltinFunction('ite') cond = self.visit(ctx.cond) then_expr = self.visit(ctx.then_expr) else_expr = self.visit(ctx.else_expr) return FunctionCallExpr(f, [cond, then_expr, else_expr])
def _visitBinaryExpr(self, ctx): lhs = self.visit(ctx.lhs) rhs = self.visit(ctx.rhs) f = BuiltinFunction(ctx.op.text) return FunctionCallExpr(f, [lhs, rhs])
def visitNotExpr(self, ctx: SolidityParser.NotExprContext): f = BuiltinFunction('!') expr = self.visit(ctx.expr) return FunctionCallExpr(f, [expr])
def visitSignExpr(self, ctx: SolidityParser.SignExprContext): f = BuiltinFunction('sign' + ctx.op.getText()) expr = self.visit(ctx.expr) return FunctionCallExpr(f, expr)
def visitParenthesisExpr(self, ctx: SolidityParser.ParenthesisExprContext): f = BuiltinFunction('parenthesis') expr = self.visit(ctx.expr) return FunctionCallExpr(f, [expr])
def visitIndexExpr(self, ctx: SolidityParser.IndexExprContext): f = BuiltinFunction('index') arr = self.visit(ctx.arr) index = self.visit(ctx.index) return FunctionCallExpr(f, [arr, index])