Exemple #1
0
Error * PopError()
{
	if(ErrorStack&&(ErrorStack->itemcount))
		return LL_pop(ErrorStack);
	else
		return 0;
}
Exemple #2
0
void PopErrorHandler()
{
	if(ErrorHandlerStack&&(ErrorHandlerStack->itemcount))
		LL_pop(ErrorHandlerStack);

	return;
}
Exemple #3
0
void DeleteErrorStack(void * par)
{
	if(ErrorStack)
	{
		while(ErrorStack->itemcount)
			DeleteError((Error *)LL_pop(ErrorStack));
		LL_delete(ErrorStack);
		ErrorStack=0;
	}

	return;
}
Exemple #4
0
void PreOrder(BTNode *node)
{
    LinkedList list = LL_init();
    while (node != NULL || !LL_isEmpty(list)) {
        if (node != NULL) {
            H_DEBUG_MSG("%s", node->data);
            LL_push(list, node);
            node = node->left;
        } else {
            node = ((BTNode *)LL_pop(list))->right;
        }
    }
}
Exemple #5
0
Tr_exp Tr_forExp(Tr_exp var, Tr_exp low, Tr_exp high, Tr_exp body){
debug("Tr_forExp");

	T_stm st;
	T_exp v = unEx(var);
	Temp_label t = Temp_newlabel();
	Temp_label f = LL_peek();//Get done label from the list, which should have been prepared before this function is called.
	Temp_label start = Temp_newlabel();

	T_stm cond = T_Cjump(T_le, v, unEx(high), t, f);

	/*
		T_Move   var <- low
		T_Label  start
		T_CJump	 var <= high, t, f
		T_Label(t)
		body
		T_Move   var + 1
		T_Jump	 start
		T_Label(f)
	*/
	st = T_Seq(T_Move(v, unEx(low)),
			T_Seq(T_Label(start),
				T_Seq(cond,
					T_Seq(T_Label(t),
						T_Seq(unNx(body),
							T_Seq(T_Move(v, T_Binop(T_plus, v, T_Const(1))),
								T_Seq(
									T_Jump(
										T_Name(start), 
										Temp_LabelList(start, NULL)
									),
									T_Label(f)
								)
							)
						)
					)
				)
			)
		);

	//Pop the label as it's no longer used
	LL_pop();

	return Tr_Nx(st);
}
Exemple #6
0
Tr_exp Tr_whileExp(Tr_exp cond, Tr_exp body){
debug("Tr_whileExp");

	T_stm st;
	struct Cx cx_cond = unCx(cond);

	Temp_label t = Temp_newlabel();
	Temp_label f = LL_peek();//Get done label from the list, which should have been prepared before this function is called.
	Temp_label start = Temp_newlabel();

	doPatch(cx_cond.trues, t);
	doPatch(cx_cond.falses, f);

	/*
		T_Label  start
		cx_cond.stm (true->t, false->f)
		T_Label(t)
		body
		T_Jump	 start
		T_Label(f)
	*/
	st = T_Seq(T_Label(start),
			T_Seq(cx_cond.stm,
				T_Seq(T_Label(t),
					T_Seq(unNx(body),
						T_Seq(
							T_Jump(
								T_Name(start), 
								Temp_LabelList(start, NULL)
							),
							T_Label(f)
						)
					)
				)
			)
		);
	
	//Pop the label as it's no longer used
	LL_pop();

	return Tr_Nx(st);
}
Exemple #7
0
void PostOrder(BTNode *node)
{
    LinkedList list = LL_init();
    BTNode *tmp;
    while (node != NULL || !LL_isEmpty(list)) {
        if (node != NULL) {
            LL_push(list, node);
            node = node->left;
        } else {
            tmp = (BTNode *)LL_pop(list);
            if (tmp->first == 0) { // first time
                tmp->first = 1;
                LL_push(list, tmp);
                node = tmp->right;
            } else {
                H_DEBUG_MSG("%s", tmp->data);
                node = NULL;
            }
        }
    }
}
void LL_free(LL *list) {
    while(!LL_isEmpty(list)) {
        LL_pop(list);
    }
    free(list);
}