FreeBSD/contrib/elftoolchain/libelftc/libelftc_dem_gnu2.c
/**
 * @brief Decode the input string by the GNU 2 style.
 *
 * @return New allocated demangled string or NULL if failed.
 */
@brief Decode the input string by the GNU 2 style.
@return New allocated demangled string or NULL if failed.
@brief Decode the input string by the GNU 2 style . @return New allocated demangled string or NULL if failed .
char *
cpp_demangle_gnu2(const char *org)
{
	struct demangle_data d;
	size_t arg_begin, arg_len;
	unsigned int try;
	char *rtn, *arg;
	if (org == NULL)
		return (NULL);
	if (init_demangle_data(&d) == false)
		return (NULL);
	try = 0;
	rtn = NULL;
	d.p = org;
	if (read_func_name(&d) == false)
		goto clean;
	switch (d.type) {
	case ENCODE_FUNC :
	case ENCODE_OP :
		break;
	case ENCODE_OP_CT :
		if (push_CTDT("::", 2, &d.vec) == false)
			goto clean;
                break;
	case ENCODE_OP_DT :
		if (push_CTDT("::~", 3, &d.vec) == false)
			goto clean;
		if (vector_str_push(&d.vec, "(void)", 6) == false)
			goto clean;
		goto flat;
	case ENCODE_OP_USER :
	case ENCODE_OP_TF :
	case ENCODE_OP_TI :
	case ENCODE_OP_VT :
		goto flat;
	}
	if (*d.p == 'F')
		++d.p;
	else if (*d.p == '\0') {
		if (d.class_name == true) {
			if (vector_str_push(&d.vec, "(void)", 6) == false)
				goto clean;
			goto flat;
		} else
			goto clean;
	}
	if (vector_str_push(&d.vec, "(", 1) == false)
		goto clean;
	for (;;) {
		if (*d.p == 'T') {
			const int rtn_subst = read_subst(&d);
			if (rtn_subst == -1)
				goto clean;
			else if (rtn_subst == 1)
				break;
			continue;
		}
		if (*d.p == 'N') {
			const int rtn_subst_iter = read_subst_iter(&d);
			if (rtn_subst_iter == -1)
				goto clean;
			else if(rtn_subst_iter == 1)
				break;
			continue;
		}
		arg_begin = d.vec.size;
		if (read_type(&d) == false)
			goto clean;
		if (d.ptr == true) {
			if (vector_str_push(&d.vec, "*", 1) == false)
				goto clean;
			d.ptr = false;
		}
		if (d.ref == true) {
			if (vector_str_push(&d.vec, "&", 1) == false)
				goto clean;
			d.ref = false;
		}
		if (d.cnst == true) {
			if (vector_str_push(&d.vec, " const", 6) == false)
				goto clean;
			d.cnst = false;
		}
		if (d.array == true) {
			if (vector_str_push(&d.vec, d.array_str.buf,
				d.array_str.size) == false)
				goto clean;
			dest_cstring(&d.array_str);
			d.array = false;
		}
		if (*d.p == '\0')
			break;
		if ((arg = vector_str_substr(&d.vec, arg_begin, d.vec.size - 1,
			    &arg_len)) == NULL)
			goto clean;
		if (vector_str_push(&d.arg, arg, arg_len) == false)
			goto clean;
		free(arg);
		if (vector_str_push(&d.vec, ", ", 2) == false)
			goto clean;
		if (++try > CPP_DEMANGLE_GNU2_TRY)
			goto clean;
	}
	if (vector_str_push(&d.vec, ")", 1) == false)
		goto clean;
flat:
	if (d.cnst_fn == true && vector_str_push(&d.vec, " const", 6) == false)
		goto clean;
	rtn = vector_str_get_flat(&d.vec, NULL);
clean:
	dest_demangle_data(&d);
	return (rtn);
}
char * cpp_demangle_gnu2 ( const char * org ) { struct demangle_data d ; size_t arg_begin , arg_len ; unsigned int try ; char * rtn , * arg ; if ( org == NULL ) return ( NULL ) ; if ( init_demangle_data ( & d ) == false ) return ( NULL ) ; try = 0 ; rtn = NULL ; d . p = org ; if ( read_func_name ( & d ) == false ) goto clean ; switch ( d . type ) { case ENCODE_FUNC : case ENCODE_OP : break ; case ENCODE_OP_CT : if ( push_CTDT ( " " , 2 , & d . vec ) == false ) goto clean ; break ; case ENCODE_OP_DT : if ( push_CTDT ( " " , 3 , & d . vec ) == false ) goto clean ; if ( vector_str_push ( & d . vec , " " , 6 ) == false ) goto clean ; goto flat ; case ENCODE_OP_USER : case ENCODE_OP_TF : case ENCODE_OP_TI : case ENCODE_OP_VT : goto flat ; } if ( * d . p == ' ' ) ++ d . p ; else if ( * d . p == ' \0 ' ) { if ( d . class_name == true ) { if ( vector_str_push ( & d . vec , " " , 6 ) == false ) goto clean ; goto flat ; } else goto clean ; } if ( vector_str_push ( & d . vec , " " , 1 ) == false ) goto clean ; for ( ; ; ) { if ( * d . p == ' ' ) { const int rtn_subst = read_subst ( & d ) ; if ( rtn_subst == -1 ) goto clean ; else if ( rtn_subst == 1 ) break ; continue ; } if ( * d . p == ' ' ) { const int rtn_subst_iter = read_subst_iter ( & d ) ; if ( rtn_subst_iter == -1 ) goto clean ; else if ( rtn_subst_iter == 1 ) break ; continue ; } arg_begin = d . vec . size ; if ( read_type ( & d ) == false ) goto clean ; if ( d . ptr == true ) { if ( vector_str_push ( & d . vec , " " , 1 ) == false ) goto clean ; d . ptr = false ; } if ( d . ref == true ) { if ( vector_str_push ( & d . vec , " " , 1 ) == false ) goto clean ; d . ref = false ; } if ( d . cnst == true ) { if ( vector_str_push ( & d . vec , " " , 6 ) == false ) goto clean ; d . cnst = false ; } if ( d . array == true ) { if ( vector_str_push ( & d . vec , d . array_str . buf , d . array_str . size ) == false ) goto clean ; dest_cstring ( & d . array_str ) ; d . array = false ; } if ( * d . p == ' \0 ' ) break ; if ( ( arg = vector_str_substr ( & d . vec , arg_begin , d . vec . size - 1 , & arg_len ) ) == NULL ) goto clean ; if ( vector_str_push ( & d . arg , arg , arg_len ) == false ) goto clean ; free ( arg ) ; if ( vector_str_push ( & d . vec , " " , 2 ) == false ) goto clean ; if ( ++ try > CPP_DEMANGLE_GNU2_TRY ) goto clean ; } if ( vector_str_push ( & d . vec , " " , 1 ) == false ) goto clean ; flat : if ( d . cnst_fn == true && vector_str_push ( & d . vec , " " , 6 ) == false ) goto clean ; rtn = vector_str_get_flat ( & d . vec , NULL ) ; clean : dest_demangle_data ( & d ) ; return ( rtn ) ; }
@brief Decode the input string by the GNU 2 style.
@brief Decode the input string by the GNU 2 style .
/* start argument types */ /* end argument types */