void JavaTabCodeGen::writeExec()

in ragel/src/ragel/javacodegen.cpp [996:1169]


void JavaTabCodeGen::writeExec()
{
	out <<
		"	{\n"
		"	int _klen";

	if ( redFsm->anyRegCurStateRef() )
		out << ", _ps";

	out << 
		";\n"
		"	int _trans = 0;\n";

	if ( redFsm->anyConditions() )
		out << "	int _widec;\n";

	if ( redFsm->anyToStateActions() || redFsm->anyRegActions() || 
			redFsm->anyFromStateActions() )
	{
		out << 
			"	int _acts;\n"
			"	int _nacts;\n";
	}

	out <<
		"	int _keys;\n"
		"	int _goto_targ = 0;\n"
		"\n";
	
	out <<
		"	_goto: while (true) {\n"
		"	switch ( _goto_targ ) {\n"
		"	case 0:\n";

	if ( !noEnd ) {
		out << 
			"	if ( " << P() << " == " << PE() << " ) {\n"
			"		_goto_targ = " << _test_eof << ";\n"
			"		continue _goto;\n"
			"	}\n";
	}

	if ( redFsm->errState != 0 ) {
		out << 
			"	if ( " << vCS() << " == " << redFsm->errState->id << " ) {\n"
			"		_goto_targ = " << _out << ";\n"
			"		continue _goto;\n"
			"	}\n";
	}

	out << "case " << _resume << ":\n"; 

	if ( redFsm->anyFromStateActions() ) {
		out <<
			"	_acts = " << FSA() << "[" << vCS() << "]" << ";\n"
			"	_nacts = " << CAST("int") << " " << A() << "[_acts++];\n"
			"	while ( _nacts-- > 0 ) {\n"
			"		switch ( " << A() << "[_acts++] ) {\n";
			FROM_STATE_ACTION_SWITCH() <<
			"		}\n"
			"	}\n"
			"\n";
	}

	if ( redFsm->anyConditions() )
		COND_TRANSLATE();

	LOCATE_TRANS();

	if ( useIndicies )
		out << "	_trans = " << I() << "[_trans];\n";
	
	if ( redFsm->anyEofTrans() )
		out << "case " << _eof_trans << ":\n";

	if ( redFsm->anyRegCurStateRef() )
		out << "	_ps = " << vCS() << ";\n";

	out <<
		"	" << vCS() << " = " << TT() << "[_trans];\n"
		"\n";

	if ( redFsm->anyRegActions() ) {
		out <<
			"	if ( " << TA() << "[_trans] != 0 ) {\n"
			"		_acts = " <<  TA() << "[_trans]" << ";\n"
			"		_nacts = " << CAST("int") << " " <<  A() << "[_acts++];\n"
			"		while ( _nacts-- > 0 )\n	{\n"
			"			switch ( " << A() << "[_acts++] )\n"
			"			{\n";
			ACTION_SWITCH() <<
			"			}\n"
			"		}\n"
			"	}\n"
			"\n";
	}

	out << "case " << _again << ":\n";

	if ( redFsm->anyToStateActions() ) {
		out <<
			"	_acts = " << TSA() << "[" << vCS() << "]" << ";\n"
			"	_nacts = " << CAST("int") << " " << A() << "[_acts++];\n"
			"	while ( _nacts-- > 0 ) {\n"
			"		switch ( " << A() << "[_acts++] ) {\n";
			TO_STATE_ACTION_SWITCH() <<
			"		}\n"
			"	}\n"
			"\n";
	}

	if ( redFsm->errState != 0 ) {
		out << 
			"	if ( " << vCS() << " == " << redFsm->errState->id << " ) {\n"
			"		_goto_targ = " << _out << ";\n"
			"		continue _goto;\n"
			"	}\n";
	}

	if ( !noEnd ) {
		out << 
			"	if ( ++" << P() << " != " << PE() << " ) {\n"
			"		_goto_targ = " << _resume << ";\n"
			"		continue _goto;\n"
			"	}\n";
	}
	else {
		out << 
			"	" << P() << " += 1;\n"
			"	_goto_targ = " << _resume << ";\n"
			"	continue _goto;\n";
	}

	out << "case " << _test_eof << ":\n"; 

	if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
		out <<
			"	if ( " << P() << " == " << vEOF() << " )\n"
			"	{\n";

		if ( redFsm->anyEofTrans() ) {
			out <<
				"	if ( " << ET() << "[" << vCS() << "] > 0 ) {\n"
				"		_trans = " << ET() << "[" << vCS() << "] - 1;\n"
				"		_goto_targ = " << _eof_trans << ";\n"
				"		continue _goto;\n"
				"	}\n";
		}

		if ( redFsm->anyEofActions() ) {
			out <<
				"	int __acts = " << EA() << "[" << vCS() << "]" << ";\n"
				"	int __nacts = " << CAST("int") << " " << A() << "[__acts++];\n"
				"	while ( __nacts-- > 0 ) {\n"
				"		switch ( " << A() << "[__acts++] ) {\n";
				EOF_ACTION_SWITCH() <<
				"		}\n"
				"	}\n";
		}

		out <<
			"	}\n"
			"\n";
	}

	out << "case " << _out << ":\n"; 

	/* The switch and goto loop. */
	out << "	}\n";
	out << "	break; }\n";

	/* The execute block. */
	out << "	}\n";
}