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 test_builtin_arity(self): f = BuiltinFunction('+') self.assertEqual(f.arity(), 2)
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])