/*
 * C compiler
 * ==========
 *
 * Copyright 1989, 1990, 1991 Christoph van Wuellen.
 * Credits to Matthew Brandt.
 * All commercial rights reserved.
 *
 * This compiler may be redistributed as long there is no
 * commercial interest. The compiler must not be redistributed
 * without its full sources. This notice must stay intact.
 *
 * History:
 *
 * 1989   starting an 68000 C compiler, starting with material
 *        originally by M. Brandt
 * 1990   68000 C compiler further bug fixes
 *        started i386 port (December)
 * 1991   i386 port finished (January)
 *        further corrections in the front end and in the 68000
 *        code generator.
 *        The next port will be a SPARC port
 */

#include "chdr.h"
#ifdef EXTERNAL
#include "check.h"
#include "expr.h"
#include "cglbdec.h"
#include "proto.h"

#if defined(__STDC__) || defined(__cplusplus)
#define P_(s) s
#else
#define P_(s) ()
#endif

static	void	put_parms	P_(( BLOCK *));
static	void	put_typ		P_(( TYP *));

#undef P_

static void
put_parms P1( BLOCK *, block)
{
    lprintf("(");
    if (block != NIL_BLOCK) {
	 SYM * sp = block->symbols.head;
	if (sp != NIL_SYM) {
	    for(;;) {
		put_typ(sp->tp);
		sp = sp->next;
		if (sp == NIL_SYM)
		    break;
		lprintf (",");
	    }
	}
    }
    lprintf(")");
}

static void
put_typ P1( TYP *, tp)
{
    if (tp == NIL_TYP)
	return;
    if (is_const_qualified(tp))
	lprintf("const ");
    if (is_volatile_qualified(tp))
	lprintf("volatile ");
    switch (tp->type) {
      case bt_void:
	lprintf("void");
	break;
      case bt_schar:
	lprintf("signed char");
	break;
      case bt_uchar:
	lprintf("unsigned");
	/*FALLTHRU*/
      case bt_char:
      case bt_charu:
	lprintf("char");
	break;
      case bt_ushort:
	lprintf("unsigned");
	/*FALLTHRU*/
      case bt_short:
	lprintf("short");
	break;
      case bt_uint16:
      case bt_uint32:
	lprintf("unsigned");
	/*FALLTHRU*/
      case bt_int16:
      case bt_int32:
	lprintf("int");
	break;
      case bt_ulong:
	lprintf("unsigned");
	/*FALLTHRU*/
      case bt_long:
	lprintf("long");
	break;
      case bt_float:
	lprintf("float");
	break;
      case bt_longdouble:
	lprintf("long");
	/*FALLTHRU*/
      case bt_double:
	lprintf("double");
	break;
      case bt_pointer16:
      case bt_pointer32:
	if (is_array_type(tp)) {
	    put_typ(referenced_type(tp));
	    lprintf("[]");
	} else {
	    lprintf("*");
	    put_typ(referenced_type(tp));
	}
	break;
      case bt_union:
	lprintf("union");
	goto ucont;
      case bt_struct:
	lprintf("struct");
ucont:	if (tp->sname != 0)
	    lprintf(" %s", tp->sname);
	break;
      case bt_func:
	put_typ(returned_type(tp));
	put_parms(parameters(tp));
	break;
      case bt_bitfield:
      case bt_ubitfield:
	break;
      case bt_ellipsis:
	lprintf("...");
	break;
      default:
	FATAL((__FILE__, "put_typ","illegal type %d",tp->type));
    }
}


void
funclist P2( SYM *, sp,  SYM *, sp_parms)
{
    if (extern_option) {
	put_typ(returned_type(sp->tp));
	lprintf(" %s", sp->name);
	put_parms(parameters(sp_parms->tp));
	lprintf(";%s", newline);
    }
}
#endif /* EXTERNAL */
