static int print_pointer_type(compile_t* c, printbuf_t* buf, ast_t* type) { ast_t* typeargs = ast_childidx(type, 2); ast_t* elem = ast_child(typeargs); if(is_pointer(elem) || is_maybe(elem)) return print_pointer_type(c, buf, elem) + 1; print_base_type(c, buf, elem); return 1; }
static void print_type_name(compile_t* c, printbuf_t* buf, ast_t* type) { if(is_pointer(type) || is_maybe(type)) { int depth = print_pointer_type(c, buf, type); for(int i = 0; i < depth; i++) printbuf(buf, "*"); } else { print_base_type(c, buf, type); } }
void print_type(const type_t *type) { if (type == NULL) { fputs("nil type", out); return; } switch (type->kind) { case TYPE_INVALID: fputs("invalid", out); return; case TYPE_TYPEOF: { const typeof_type_t *typeof_type = (const typeof_type_t*) type; fputs("typeof(", out); print_expression(typeof_type->expression); fputs(")", out); return; } case TYPE_ERROR: fputs("error", out); return; case TYPE_VOID: fputs("void", out); return; case TYPE_ATOMIC: print_atomic_type(&type->atomic); return; case TYPE_COMPOUND_UNION: case TYPE_COMPOUND_STRUCT: print_compound_type(&type->compound); return; case TYPE_FUNCTION: print_function_type(&type->function); return; case TYPE_POINTER: print_pointer_type(&type->pointer); return; case TYPE_ARRAY: print_array_type(&type->array); return; case TYPE_REFERENCE: print_type_reference(&type->reference); return; case TYPE_REFERENCE_TYPE_VARIABLE: print_type_reference_variable(&type->reference); return; case TYPE_BIND_TYPEVARIABLES: print_bind_type_variables(&type->bind_typevariables); return; } fputs("unknown", out); }