self.emit("obj2ast_%s(PyObject* obj, %s* out, PyArena* arena)" % (name, ctype), 0)
self.emit("{", 0)
self.emit("PyObject* tmp = NULL;", 1)
+ # Prevent compiler warnings about unused variable.
+ self.emit("tmp = tmp;", 1)
self.emit("int isinstance;", 1)
self.emit("", 0)
- def sumTrailer(self, name):
+ def sumTrailer(self, name, add_label=False):
self.emit("", 0)
- self.emit("tmp = PyObject_Repr(obj);", 1)
# there's really nothing more we can do if this fails ...
- self.emit("if (tmp == NULL) goto failed;", 1)
- error = "expected some sort of %s, but got %%.400s" % name
- format = "PyErr_Format(PyExc_TypeError, \"%s\", PyBytes_AS_STRING(tmp));"
+ error = "expected some sort of %s, but got %%R" % name
+ format = "PyErr_Format(PyExc_TypeError, \"%s\", obj);"
self.emit(format % error, 1, reflow=False)
- self.emit("failed:", 0)
- self.emit("Py_XDECREF(tmp);", 1)
+ if add_label:
+ self.emit("failed:", 1)
self.emit("return 1;", 1)
self.emit("}", 0)
self.emit("", 0)
self.emit("if (*out == NULL) goto failed;", 2)
self.emit("return 0;", 2)
self.emit("}", 1)
- self.sumTrailer(name)
+ self.sumTrailer(name, True)
def visitAttributeDeclaration(self, a, name, sum=sum):
ctype = get_c_type(a.type)
obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
{
PyObject* tmp = NULL;
+ tmp = tmp;
int isinstance;
return 0;
}
- tmp = PyObject_Repr(obj);
- if (tmp == NULL) goto failed;
- PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %.400s", PyBytes_AS_STRING(tmp));
-failed:
- Py_XDECREF(tmp);
+ PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
+ failed:
return 1;
}
obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
{
PyObject* tmp = NULL;
+ tmp = tmp;
int isinstance;
int lineno;
return 0;
}
- tmp = PyObject_Repr(obj);
- if (tmp == NULL) goto failed;
- PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %.400s", PyBytes_AS_STRING(tmp));
-failed:
- Py_XDECREF(tmp);
+ PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
+ failed:
return 1;
}
obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
{
PyObject* tmp = NULL;
+ tmp = tmp;
int isinstance;
int lineno;
return 0;
}
- tmp = PyObject_Repr(obj);
- if (tmp == NULL) goto failed;
- PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %.400s", PyBytes_AS_STRING(tmp));
-failed:
- Py_XDECREF(tmp);
+ PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
+ failed:
return 1;
}
obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
{
PyObject* tmp = NULL;
+ tmp = tmp;
int isinstance;
isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type);
return 0;
}
- tmp = PyObject_Repr(obj);
- if (tmp == NULL) goto failed;
- PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %.400s", PyBytes_AS_STRING(tmp));
-failed:
- Py_XDECREF(tmp);
+ PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
return 1;
}
obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
{
PyObject* tmp = NULL;
+ tmp = tmp;
int isinstance;
return 0;
}
- tmp = PyObject_Repr(obj);
- if (tmp == NULL) goto failed;
- PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %.400s", PyBytes_AS_STRING(tmp));
-failed:
- Py_XDECREF(tmp);
+ PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj);
+ failed:
return 1;
}
obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
{
PyObject* tmp = NULL;
+ tmp = tmp;
int isinstance;
isinstance = PyObject_IsInstance(obj, (PyObject *)And_type);
return 0;
}
- tmp = PyObject_Repr(obj);
- if (tmp == NULL) goto failed;
- PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %.400s", PyBytes_AS_STRING(tmp));
-failed:
- Py_XDECREF(tmp);
+ PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
return 1;
}
obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
{
PyObject* tmp = NULL;
+ tmp = tmp;
int isinstance;
isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type);
return 0;
}
- tmp = PyObject_Repr(obj);
- if (tmp == NULL) goto failed;
- PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %.400s", PyBytes_AS_STRING(tmp));
-failed:
- Py_XDECREF(tmp);
+ PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
return 1;
}
obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
{
PyObject* tmp = NULL;
+ tmp = tmp;
int isinstance;
isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type);
return 0;
}
- tmp = PyObject_Repr(obj);
- if (tmp == NULL) goto failed;
- PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %.400s", PyBytes_AS_STRING(tmp));
-failed:
- Py_XDECREF(tmp);
+ PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
return 1;
}
obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
{
PyObject* tmp = NULL;
+ tmp = tmp;
int isinstance;
isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type);
return 0;
}
- tmp = PyObject_Repr(obj);
- if (tmp == NULL) goto failed;
- PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %.400s", PyBytes_AS_STRING(tmp));
-failed:
- Py_XDECREF(tmp);
+ PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
return 1;
}
obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
{
PyObject* tmp = NULL;
+ tmp = tmp;
int isinstance;
int lineno;
return 0;
}
- tmp = PyObject_Repr(obj);
- if (tmp == NULL) goto failed;
- PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %.400s", PyBytes_AS_STRING(tmp));
-failed:
- Py_XDECREF(tmp);
+ PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
+ failed:
return 1;
}