/*
 * 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"
#include "expr.h"
#include "cglbdec.h"
#include "proto.h"

#ifdef FLOAT_SUPPORT
#ifndef FLOAT_BOOTSTRAP
/* floating point expression */
void
floatexpr P2(TYP *, tp, RVAL *, fp)
{
    EXPR   *ep = exprnc();
    if (ep == NIL_EXPR) {
	message(ERR_FPCON);
	FASSIGN(*fp, F_one);
	return;
    }

    ep = castop (ep, tp, implicit);
    ep = constantopt(ep);

    if (ep->nodetype == en_fcon) {
	FASSIGN(*fp, ep->v.f);
        return;
    }

    message (ERR_CONSTFLOAT);
    FASSIGN(*fp, F_one);
}
#endif /* FLOAT_BOOTSTRAP */
#endif /* FLOAT_SUPPORT */

/* integer arithmetic expression */
IVAL
arithexpr P1(TYP *, tp)
{
    EXPR   *ep = exprnc();
    if (ep == NIL_EXPR) {
	message(ERR_INTEXPR);
	getsym();
	return 0L;
    }

    ep = castop (ep, tp, implicit);
    ep = constantopt(ep);

    if (ep->nodetype == en_icon)
        return ep->v.i;

    message (ERR_CONSTINT);
    getsym();
    return 0L;
}

IVAL
intexpr P0(void)
{
    EXPR   *ep = exprnc();
    if (ep == NIL_EXPR) {
	message(ERR_INTEXPR);
	/*
	 * any return value is wrong, but 1 is 
	 * less likely than 0 to cause spurious
	 * errors later in the compilation.
	 */
	return 1L;
    }
    ep = constantopt(ep);

    if (ep->nodetype != en_icon) {
	message(ERR_CONSTINT);
	/*
	 * any return value is wrong, but 1 is 
	 * less likely than 0 to cause spurious
	 * errors later in the compilation.
	 */
	return 1L;
    }
    return ep->v.i;
}
