/*****************************************************
*				recognize switch statement			 *
*****************************************************/
void CompField::VisitSwitch(StmtSwitch *swStmt)
{
	nbASSERT(swStmt != NULL, "StmtSwitch cannot be NULL");


#ifdef DEBUG_COMPACT_FIELDS
	PrintNode(swStmt->Forest,"Debug_List_of_Switch_nodes.asm",0);
#endif
	if(checkingloop>0)
		ExtractFieldsFromExpr(swStmt->Forest,&m_symboltemp);	

	VisitTree(swStmt->Forest);				//Visit SWITCH Condition

	VisitCode(swStmt->Cases);				//Visit Cases

	StartCheck(NULL);

	if (swStmt->Default)					
		VisitCase(swStmt->Default, true);		//Visit Default

	StartCheck(NULL);
}
void CompField::VisitStatement(StmtBase *stmt)
{
	nbASSERT(stmt != NULL , "stmt cannot be NULL");

//Start STATEMENT CHECK:
//if this statement it's not GEN -> means that can't be a DEFFLD! -> we must "close" compattable-fixed-field-list!!!!
	if(stmt->Kind!=STMT_GEN)
		StartCheck(NULL);	
//End of STATEMENT CHECK

	switch(stmt->Kind)
	{
	case STMT_GEN:			//here we recognize FIELD DEFINITIONS -> DEFFLD
	{

		#ifdef DEBUG_COMPACT_FIELDS
		   PrintStmt(stmt,"Debug_Statement_Gen.txt");
		#endif
		VisitTree(stmt->Forest);	
	}break;
	case STMT_JUMP:
	case STMT_JUMP_FIELD:
	{
		VisitJump((StmtJump*)stmt);
	}break;
	case STMT_CASE:	  			//Gettin inside a Case! New "Context"
	{
		VisitCase((StmtCase*)stmt, false);
	}break;
	case STMT_SWITCH: 			//Gettin inside a SWITCH! New "Context"
	{
		VisitSwitch((StmtSwitch*)stmt);
	}break;
	case STMT_IF:  				//Gettin inside an IF! New "Context"
	{
		VisitIf((StmtIf*)stmt);
	}break;
	case STMT_LOOP:  			//only <loop type="times2repeat">
	{
		VisitLoop((StmtLoop*)stmt);
	}break;
	case STMT_WHILE:			//LOOP SIZE -> (CONVERTED) -> STATEMENT WHILE -> i'll convert loop in one variable FIELD (if can)
	{
	
		//if this is Loop-Size (converted in pdlparser to stmtWhile!) -> try compatting, otherwise not! only visit
		
		if(((StmtWhile*)stmt)->isLoopSize==true)	
		{
			
			checkingloop++; 	//Integer USED TO IDENTIFY if This LOOP is the first one or it's an Inner-Loop
			m_loopcomp=1;	

			if(checkingloop>1)	//fields used inside LOOP expression-> If InnerLoop ->need to check it - Otherwise not!
				UpdateMapField((StmtWhile*)stmt);	//ADD field-expr to Local-MAP of Used fields


			VisitWhileDo((StmtWhile*)stmt);		//Visit inside this WHILE 
			if(AllCompattable((StmtWhile*)stmt))//check if the validity of these fields end here or if at least one is also referentiated later
			{
			#ifdef DEBUG_COMPACT_FIELDS
				PrintFieldsMap(&m_DefUseLocal,"Debug_List_of_Fields_Used_insideLoop_Compattable.txt");
			#endif
				/****TRANSFORM LOOP IN A VARIABLE-FIELD****/
				TransformLoop((StmtWhile*)stmt);
			}

			CleanTempMap(&m_symboltemp);	//Clean Used Fields of this loop 
			CleanTempMap(&m_DefUseLocal);	//Clean Used Fields Defined inside this loop

			checkingloop--;
		}
		else
		{
				VisitWhileDo((StmtWhile*)stmt);		//Visit inside this WHILE 			
		}

		}break;
	case STMT_DO_WHILE:   	//Gettin inside a WHILE! New "Context"
	{
		VisitDoWhile((StmtWhile*)stmt);
	}break;
	case STMT_BLOCK:  	//Gettin inside a Block! New "Context"
	{
		VisitBlock((StmtBlock*)stmt);
	}break;
	case STMT_BREAK:			
	case STMT_CONTINUE:		//If Break or Continue (Inside Loops) -> Can't Compact this!! Don't know Total Size!! (Offset)
	{
		//TEMP!! THIS loop must be added to NeverLOOP LIST!!?
		//AddNeverCompattableLoop(actualoop,&m_symboltemp);
		m_loopcomp=0;
	}break;
	case STMT_LABEL:
	case STMT_FINFOST:			
	case STMT_COMMENT:			
	{	
		//Do nothing
	}break;
	default:
		nbASSERT(false, "COMPACT_STMT: CANNOT BE HERE!");
		break;
	}

}
Exemple #3
0
void Visitor::Visit(Element const& element)
{
    bool isElement = false;
    switch(element.Type())
    {
        // Constant Tokens
        case Types::NIL: VisitNil(); break;
        case Types::TRUE_: VisitTrue(); break; 
        case Types::FALSE_: VisitFalse(); break; 
        case Types::STRING:
        {
            String S = CastToString(element, isElement);
            VisitString(S);
        }
            break;
        case Types::SUPERSTRING:
        {
            SuperString S = CastToSuperString(element, isElement);
            VisitSuperString(S);
        }
            break;
        case Types::NUMBER:
        {
            Number N = CastToNumber(element, isElement);
            VisitNumber(N);
        }
            break;
        case Types::CONTAINER:
        {
            Container C = CastToContainer(element, isElement);
            VisitContainer(C);
        }
            break;
        case Types::BUILTIN:
        {
            Builtin B = CastToBuiltin(element, isElement);
            VisitBuiltin(B);
        }
            break;
        case Types::CALL:
        {
            Funcall F = CastToFuncall(element, isElement);
            VisitCall(F);
        }
            break;
        case Types::FUNCTION:
        {
            Function F = CastToFunction(element, isElement);
            VisitFunction(F);
        }
            break;
        case Types::IF:
        {
            If F = CastToIf(element, isElement);
            VisitIf(F);
        }
            break;
        case Types::SET:
        {
            Set F = CastToSet(element, isElement);
            VisitSet(F);
        }
            break;
        case Types::IMPERATIVE:
        {
            Imperative F = CastToImperative(element, isElement);
            VisitImperative(F);
        }
        case Types::CASE:
        {
            Case C = CastToCase(element, isElement);
            VisitCase(C);
        }
            break;
    };
}