Exemple #1
0
    def visitIfStatement(self, ctx: SolidityParser.IfStatementContext):
        cond = self.visit(ctx.condition)
        then_branch = self.visit(ctx.then_branch)
        if not isinstance(then_branch, ast.Block):
            then_branch = ast.Block([then_branch], was_single_statement=True)

        if ctx.else_branch is not None:
            else_branch = self.visit(ctx.else_branch)
            if not isinstance(else_branch, ast.Block):
                else_branch = ast.Block([else_branch], was_single_statement=True)
        else:
            else_branch = None

        return ast.IfStatement(cond, then_branch, else_branch)
Exemple #2
0
 def visitForStatement(self, ctx: SolidityParser.ForStatementContext):
     init = None if ctx.init is None else self.visit(ctx.init)
     cond = self.visit(ctx.condition)
     update = None if ctx.update is None else self.visit(ctx.update)
     if isinstance(update, ast.Expression):
         update = ast.ExpressionStatement(update)
     body = self.visit(ctx.body)
     if not isinstance(body, ast.Block):
         body = ast.Block([body], was_single_statement=True)
     return ast.ForStatement(init, cond, update, body)
Exemple #3
0
 def visitDoWhileStatement(self, ctx: SolidityParser.DoWhileStatementContext):
     body = self.visit(ctx.body)
     cond = self.visit(ctx.condition)
     if not isinstance(body, ast.Block):
         body = ast.Block([body], was_single_statement=True)
     return ast.DoWhileStatement(body, cond)