Exemplo n.º 1
0
/*
 * if_without_else
 * if_without_else T_ELSE stmnt
 */
void
if3(int els)
{

	if (els) {
		reached |= cstk->c_rchif;
	} else {
		reached = 1;
	}
	popctrl(T_IF);
}
Exemplo n.º 2
0
/*
 * while_expr stmnt
 * while_expr error
 */
void
while2(void)
{

	/*
	 * The end of the loop can be reached if it is no endless loop
	 * or there was a break statement which was reached.
	 */
	reached = !cstk->c_infinite || cstk->c_break;
	rchflg = 0;

	popctrl(T_WHILE);
}
Exemplo n.º 3
0
/*
 * switch_expr stmnt
 */
void
switch2(void)
{
	int	nenum = 0, nclab = 0;
	sym_t	*esym;
	clst_t	*cl;

	if (cstk->c_swtype == NULL)
		lerror("switch2() 1");

	/*
	 * If the switch expression was of type enumeration, count the case
	 * labels and the number of enumerators. If both counts are not
	 * equal print a warning.
	 */
	if (cstk->c_swtype->t_isenum) {
		nenum = nclab = 0;
		if (cstk->c_swtype->t_enum == NULL)
			lerror("switch2() 2");
		for (esym = cstk->c_swtype->t_enum->elem;
		     esym != NULL; esym = esym->s_nxt) {
			nenum++;
		}
		for (cl = cstk->c_clst; cl != NULL; cl = cl->cl_nxt)
			nclab++;
		if (hflag && eflag && nenum != nclab && !cstk->c_default) {
			/* enumeration value(s) not handled in switch */
			warning(206);
		}
	}

	if (cstk->c_break) {
		/*
		 * end of switch alway reached (c_break is only set if the
		 * break statement can be reached).
		 */
		reached = 1;
	} else if (!cstk->c_default &&
		   (!hflag || !cstk->c_swtype->t_isenum || nenum != nclab)) {
		/*
		 * there are possible values which are not handled in
		 * switch
		 */
		reached = 1;
	}	/*
		 * otherwise the end of the switch expression is reached
		 * if the end of the last statement inside it is reached.
		 */

	popctrl(T_SWITCH);
}
Exemplo n.º 4
0
/*
 * do stmnt do_while_expr
 * do error
 */
void
do2(tnode_t *tn)
{

	/*
	 * If there was a continue statement the expression controlling the
	 * loop is reached.
	 */
	if (cstk->c_cont)
		reached = 1;

	if (tn != NULL)
		tn = cconv(tn);
	if (tn != NULL)
		tn = promote(NOOP, 0, tn);
	if (tn != NULL && !issclt(tn->tn_type->t_tspec)) {
		/* controlling expressions must have scalar type */
		error(204);
		tn = NULL;
	}

	if (tn != NULL && tn->tn_op == CON) {
		if (isityp(tn->tn_type->t_tspec)) {
			cstk->c_infinite = tn->tn_val->v_quad != 0;
		} else {
			cstk->c_infinite = tn->tn_val->v_ldbl != 0.0;
		}
		if (!cstk->c_infinite && cstk->c_cont)
		    error(323);
	}

	expr(tn, 0, 1, 1);

	/*
	 * The end of the loop is only reached if it is no endless loop
	 * or there was a break statement which could be reached.
	 */
	reached = !cstk->c_infinite || cstk->c_break;
	rchflg = 0;

	popctrl(T_DO);
}
Exemplo n.º 5
0
/*
 * for_exprs stmnt
 * for_exprs error
 */
void
for2(void)
{
	pos_t	cpos, cspos;
	tnode_t	*tn3;

	if (cstk->c_cont)
		reached = 1;

	STRUCT_ASSIGN(cpos, curr_pos);
	STRUCT_ASSIGN(cspos, csrc_pos);

	/* Restore the tree memory for the reinitialisation expression */
	trestor(cstk->c_fexprm);
	tn3 = cstk->c_f3expr;
	STRUCT_ASSIGN(curr_pos, cstk->c_fpos);
	STRUCT_ASSIGN(csrc_pos, cstk->c_cfpos);

	/* simply "statement not reached" would be confusing */
	if (!reached && !rchflg) {
		/* end-of-loop code not reached */
		warning(223);
		reached = 1;
	}

	if (tn3 != NULL) {
		expr(tn3, 0, 0);
	} else {
		tfreeblk();
	}

	STRUCT_ASSIGN(curr_pos, cpos);
	STRUCT_ASSIGN(csrc_pos, cspos);

	/* An endless loop without break will never terminate */
	reached = cstk->c_break || !cstk->c_infinite;
	rchflg = 0;

	popctrl(T_FOR);
}