cinap_lenrekadd hg and python4bb9e2215 years agoHistory
3292 lines · 89.5 KB · C
RawDownload
                return ast_for_assert_stmt(c, n);            default:                PyErr_Format(PyExc_SystemError,                             "unhandled small_stmt: TYPE=%d NCH=%d\n",                             TYPE(n), NCH(n));                return NULL;        }    }    else {        /* compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt	                | funcdef | classdef	*/	node *ch = CHILD(n, 0);	REQ(n, compound_stmt);	switch (TYPE(ch)) {            case if_stmt:                return ast_for_if_stmt(c, ch);            case while_stmt:                return ast_for_while_stmt(c, ch);            case for_stmt:                return ast_for_for_stmt(c, ch);            case try_stmt:                return ast_for_try_stmt(c, ch);            case with_stmt:                return ast_for_with_stmt(c, ch);            case funcdef:                return ast_for_funcdef(c, ch);            case classdef:                return ast_for_classdef(c, ch);            default:                PyErr_Format(PyExc_SystemError,                             "unhandled small_stmt: TYPE=%d NCH=%d\n",                             TYPE(n), NCH(n));                return NULL;	}    }} static PyObject *parsenumber(const char *s){	const char *end;	long x;	double dx;#ifndef WITHOUT_COMPLEX	Py_complex c;	int imflag;#endif 	errno = 0;	end = s + strlen(s) - 1;#ifndef WITHOUT_COMPLEX	imflag = *end == 'j' || *end == 'J';#endif	if (*end == 'l' || *end == 'L')		return PyLong_FromString((char *)s, (char **)0, 0);	if (s[0] == '0') {		x = (long) PyOS_strtoul((char *)s, (char **)&end, 0); 		if (x < 0 && errno == 0) {	 			return PyLong_FromString((char *)s,							 (char **)0,							 0);		}	}	else		x = PyOS_strtol((char *)s, (char **)&end, 0);	if (*end == '\0') {		if (errno != 0)			return PyLong_FromString((char *)s, (char **)0, 0);		return PyInt_FromLong(x);	}	/* XXX Huge floats may silently fail */#ifndef WITHOUT_COMPLEX	if (imflag) {		c.real = 0.;		PyFPE_START_PROTECT("atof", return 0)		c.imag = PyOS_ascii_atof(s);		PyFPE_END_PROTECT(c)		return PyComplex_FromCComplex(c);	}	else#endif	{		PyFPE_START_PROTECT("atof", return 0)		dx = PyOS_ascii_atof(s);		PyFPE_END_PROTECT(dx)		return PyFloat_FromDouble(dx);	}} static PyObject *decode_utf8(const char **sPtr, const char *end, char* encoding){#ifndef Py_USING_UNICODE	Py_FatalError("decode_utf8 should not be called in this build.");        return NULL;#else	PyObject *u, *v;	char *s, *t;	t = s = (char *)*sPtr;	/* while (s < end && *s != '\\') s++; */ /* inefficient for u".." */	while (s < end && (*s & 0x80)) s++;	*sPtr = s;	u = PyUnicode_DecodeUTF8(t, s - t, NULL);	if (u == NULL)		return NULL;	v = PyUnicode_AsEncodedString(u, encoding, NULL);	Py_DECREF(u);	return v;#endif} static PyObject *decode_unicode(const char *s, size_t len, int rawmode, const char *encoding){	PyObject *v, *u;	char *buf;	char *p;	const char *end;	if (encoding == NULL) {	     	buf = (char *)s;		u = NULL;	} else if (strcmp(encoding, "iso-8859-1") == 0) {	     	buf = (char *)s;		u = NULL;	} else {		/* "\XX" may become "\u005c\uHHLL" (12 bytes) */		u = PyString_FromStringAndSize((char *)NULL, len * 4);		if (u == NULL)			return NULL;		p = buf = PyString_AsString(u);		end = s + len;		while (s < end) {			if (*s == '\\') {				*p++ = *s++;				if (*s & 0x80) {					strcpy(p, "u005c");					p += 5;				}			}			if (*s & 0x80) { /* XXX inefficient */				PyObject *w;				char *r;				Py_ssize_t rn, i;				w = decode_utf8(&s, end, "utf-16-be");				if (w == NULL) {					Py_DECREF(u);					return NULL;				}				r = PyString_AsString(w);				rn = PyString_Size(w);				assert(rn % 2 == 0);				for (i = 0; i < rn; i += 2) {					sprintf(p, "\\u%02x%02x",						r[i + 0] & 0xFF,						r[i + 1] & 0xFF);					p += 6;				}				Py_DECREF(w);			} else {				*p++ = *s++;			}		}		len = p - buf;		s = buf;	}	if (rawmode)		v = PyUnicode_DecodeRawUnicodeEscape(s, len, NULL);	else		v = PyUnicode_DecodeUnicodeEscape(s, len, NULL);	Py_XDECREF(u);	return v;} /* s is a Python string literal, including the bracketing quote characters, * and r &/or u prefixes (if any), and embedded escape sequences (if any). * parsestr parses it, and returns the decoded Python string object. */static PyObject *parsestr(const char *s, const char *encoding){	size_t len;	int quote = Py_CHARMASK(*s);	int rawmode = 0;	int need_encoding;	int unicode = 0; 	if (isalpha(quote) || quote == '_') {		if (quote == 'u' || quote == 'U') {			quote = *++s;			unicode = 1;		}		if (quote == 'r' || quote == 'R') {			quote = *++s;			rawmode = 1;		}	}	if (quote != '\'' && quote != '\"') {		PyErr_BadInternalCall();		return NULL;	}	s++;	len = strlen(s);	if (len > INT_MAX) {		PyErr_SetString(PyExc_OverflowError, 				"string to parse is too long");		return NULL;	}	if (s[--len] != quote) {		PyErr_BadInternalCall();		return NULL;	}	if (len >= 4 && s[0] == quote && s[1] == quote) {		s += 2;		len -= 2;		if (s[--len] != quote || s[--len] != quote) {			PyErr_BadInternalCall();			return NULL;		}	}#ifdef Py_USING_UNICODE	if (unicode || Py_UnicodeFlag) {		return decode_unicode(s, len, rawmode, encoding);	}#endif	need_encoding = (encoding != NULL &&			 strcmp(encoding, "utf-8") != 0 &&			 strcmp(encoding, "iso-8859-1") != 0);	if (rawmode || strchr(s, '\\') == NULL) {		if (need_encoding) {#ifndef Py_USING_UNICODE			/* This should not happen - we never see any other			   encoding. */			Py_FatalError(                            "cannot deal with encodings in this build.");#else			PyObject *v, *u = PyUnicode_DecodeUTF8(s, len, NULL);			if (u == NULL)				return NULL;			v = PyUnicode_AsEncodedString(u, encoding, NULL);			Py_DECREF(u);			return v;#endif		} else {			return PyString_FromStringAndSize(s, len);		}	} 	return PyString_DecodeEscape(s, len, NULL, unicode,				     need_encoding ? encoding : NULL);} /* Build a Python string object out of a STRING atom.  This takes care of * compile-time literal catenation, calling parsestr() on each piece, and * pasting the intermediate results together. */static PyObject *parsestrplus(struct compiling *c, const node *n){	PyObject *v;	int i;	REQ(CHILD(n, 0), STRING);	if ((v = parsestr(STR(CHILD(n, 0)), c->c_encoding)) != NULL) {		/* String literal concatenation */		for (i = 1; i < NCH(n); i++) {			PyObject *s;			s = parsestr(STR(CHILD(n, i)), c->c_encoding);			if (s == NULL)				goto onError;			if (PyString_Check(v) && PyString_Check(s)) {				PyString_ConcatAndDel(&v, s);				if (v == NULL)				    goto onError;			}#ifdef Py_USING_UNICODE			else {				PyObject *temp = PyUnicode_Concat(v, s);				Py_DECREF(s);				Py_DECREF(v);				v = temp;				if (v == NULL)				    goto onError;			}#endif		}	}	return v;  onError:	Py_XDECREF(v);	return NULL;}

Lines 3001–3292 of 3292. Previous lines