コード例 #1
0
 def visitRaise(self, node):
     if node.type is None:
         return jast.Throw(jast.InvokeStatic("Py", "makeException", []))
     type = self.visit(node.type)
     inst = self.eval(node.inst, None)
     tback = self.eval(node.tback, None)
     return type.doraise(inst, tback)
コード例 #2
0
ファイル: Object.py プロジェクト: varialus/jython-legacy
 def doraise(self, code, exc_value=None, exc_traceback=None):
     args = [code]
     if exc_value is not None:
         args.append(exc_value.asAny())
     if exc_traceback is not None:
         args.append(exc_traceback.asAny())
     return jast.Throw(jast.InvokeStatic("Py", "makeException", args))
コード例 #3
0
def wrapThrows(stmt, throws, retType):
    if len(throws) == 0: return stmt
    catches = []
    throwableFound = 0
    for i in range(len(throws)):
        throw = throws[i]
        exctype = throw
        excname = jast.Identifier("exc%d" % i)
        body = jast.Block([jast.Throw(excname)])
        catches.append((exctype, excname, body))
        if throw == "java.lang.Throwable":
            throwableFound = 1

    if not throwableFound:
        body = jast.Block([
            jast.Invoke(jast.Identifier("inst"), "_jthrow",
                        [jast.Identifier("t")]),
            nullReturn(retType)
        ])
        catches.append(("java.lang.Throwable", jast.Identifier("t"), body))
    return jast.TryCatches(jast.Block([stmt]), catches)
コード例 #4
0
    def visitTryExcept(self, node):
        if node.orelse is not None:
            elseBool = self.frame.gettemp("boolean")

        jbody = jast.Block(self.suite(node.body))
        tests = []
        ifelse = None

        tname = jast.Identifier("x$%d" % self.nthrowables)
        self.nthrowables = self.nthrowables + 1

        exctmp = self.frame.gettemp("PyException")
        setexc = jast.Set(exctmp, jast.InvokeStatic("Py", "setException",
                                                    [tname, self.frame.frame]))

        for exchandler in node.handlers:
            if exchandler.type is None:
                ifelse = jast.Block(self.suite(exchandler.body))
                continue

            type = self.visit(exchandler.type)
            t = jast.InvokeStatic("Py", "matchException",
                                  [exctmp, type.asAny()])
            newbody = []

            if exchandler.name is not None:
                exceptionValue = self.factory.makePyObject(
                    jast.GetInstanceAttribute(exctmp, "value"))
                newbody.append(self.set(exchandler.name, exceptionValue))

            #print self.visit(ebody)
            newbody.append(self.suite(exchandler.body))
            #print newbody
            #print jast.Block(newbody)
            tests.append( (t, jast.Block(newbody)) )

        if ifelse is None:
            ifelse = jast.Throw(exctmp)

        if len(tests) == 0:
            catchBody = ifelse
        else:
            catchBody = jast.MultiIf(tests, ifelse)

        catchBody = [setexc, catchBody]
   
        if node.orelse is not None:
            catchBody = [jast.Set(elseBool, jast.False), catchBody]

        catchBody = jast.Block([catchBody])

        self.frame.freetemp(exctmp)

        ret = jast.TryCatch(jbody, "Throwable", tname, catchBody)

        if node.orelse is not None:
            ret = jast.Block([jast.Set(elseBool, jast.True), ret, 
                              jast.If(elseBool,
                                      jast.Block(self.suite(node.orelse)))])
            self.frame.freetemp(elseBool)

        return ret
コード例 #5
0
ファイル: SimpleCompiler.py プロジェクト: carvalhomb/tsmells
 def raise_stmt(self, exc_type=None, exc_value=None, exc_traceback=None):
     if exc_type is None:
         return jast.Throw(jast.InvokeStatic("Py", "makeException", []))
     return exc_type.doraise(exc_value, exc_traceback)