示例#1
0
static void print_type_eng(type *ref)
{
	if(!ref)
		return;

	print_type_eng(ref->ref);

	switch(ref->type){
		case type_auto:
			ICE("__auto_type");

		case type_cast:
			if(ref->bits.cast.is_signed_cast)
				fprintf(cc1_out, "%s ", ref->bits.cast.signed_true ? "signed" : "unsigned");
			else
				fprintf(cc1_out, "%s", type_qual_to_str(ref->bits.cast.qual, 1));
			break;

		case type_ptr:
			fprintf(cc1_out, "pointer to ");
			break;

		case type_block:
			fprintf(cc1_out, "block returning ");
			break;

		case type_func:
		{
#ifdef ENGLISH_PRINT_ARGLIST
			funcargs *fargs = ref->bits.func.args;
			decl **iter;
#endif

			fputs("function", cc1_out);

#ifdef ENGLISH_PRINT_ARGLIST
			fputc('(', cc1_out);
			if(fargs->arglist){

				for(iter = fargs->arglist; iter && *iter; iter++){
					print_decl(*iter, PDECL_NONE);
					if(iter[1])
						fputs(", ", cc1_out);
				}

				if(fargs->variadic)
					fputs("variadic", cc1_out);

			}else{
				fprintf(cc1_out, "taking %s arguments", fargs->args_void ? "no" : "unspecified");
			}
			fputc(')', cc1_out);
#endif
			fputs(" returning ", cc1_out);

			break;
		}

		case type_array:
			fputs("array[", cc1_out);
			if(ref->bits.array.size)
				print_expr_val(ref->bits.array.size);
			fputs("] of ", cc1_out);
			break;

		case type_btype:
			fprintf(cc1_out, "%s", btype_to_str(ref->bits.type));
			break;

		case type_tdef:
		case type_attr:
			ICE("TODO");
		case type_where:
			break;
	}
}
示例#2
0
文件: type.c 项目: 8l/ucc-c-compiler
static
type *type_add_type_str(type *r,
		char **bufp, int *sz,
		enum type_str_opts const opts)
{
	/* go down to the first type or typedef, print it and then its descriptions */
	type *ty;

	**bufp = '\0';
	for(ty = r;
			ty && ty->type != type_btype;
			ty = ty->ref)
	{
		if((opts & TY_STR_NO_TDEF) == 0 && ty->type == type_tdef)
			break;
	}

	if(!ty)
		return NULL;

	if(ty->type == type_tdef){
		char buf[BTYPE_STATIC_BUFSIZ];
		decl *d = ty->bits.tdef.decl;
		type *of;

		if(d){
			BUF_ADD("%s", d->spel);
			of = d->ref;

		}else{
			expr *const e = ty->bits.tdef.type_of;
			int const is_type = !e->expr;

			BUF_ADD("typeof(%s%s)",
					/* e is always expr_sizeof() */
					is_type ? "" : "expr: ",
					is_type ? type_to_str_r_spel_opts(buf, e->tree_type, NULL, TY_STR_NOOPT)
						: e->expr->f_str());

			/* don't show aka for typeof types - it's there already */
			of = is_type ? NULL : e->tree_type;
		}

		if((opts & TY_STR_AKA) && of){
			/* descend to the type if it's next */
			type *t_ref = type_is_primitive(of, type_unknown);
			const btype *t = t_ref ? t_ref->bits.type : NULL;

			BUF_ADD(" (aka '%s')",
					t ? btype_to_str(t)
					: type_to_str_r_spel_opts(buf, type_skip_tdefs(of), NULL, TY_STR_NOOPT));
		}

		return ty;

	}else{
		BUF_ADD("%s", btype_to_str(ty->bits.type));
	}

	return NULL;
}