void CSharpFlatCodeGen::COND_TRANSLATE() { out << " _widec = " << GET_KEY() << ";\n"; out << " _keys = " << vCS() << "<<1;\n" " _conds = " << CO() << "[" << vCS() << "];\n" // " _keys = " << ARR_OFF( CK(), "(" + vCS() + "<<1)" ) << ";\n" // " _conds = " << ARR_OFF( C(), CO() + "[" + vCS() + "]" ) << ";\n" "\n" " _slen = " << CSP() << "[" << vCS() << "];\n" " if (_slen > 0 && " << CK() << "[_keys] <=" << GET_WIDE_KEY() << " &&\n" " " << GET_WIDE_KEY() << " <= " << CK() << "[_keys+1])\n" " _cond = " << C() << "[_conds+" << GET_WIDE_KEY() << " - " << CK() << "[_keys]];\n" " else\n" " _cond = 0;" "\n"; /* XXX This version of the code doesn't work because Mono is weird. Works * fine in Microsoft's csc, even though the bug report filed claimed it * didn't. " _slen = " << CSP() << "[" << vCS() << "];\n" " _cond = _slen > 0 && " << CK() << "[_keys] <=" << GET_WIDE_KEY() << " &&\n" " " << GET_WIDE_KEY() << " <= " << CK() << "[_keys+1] ?\n" " " << C() << "[_conds+" << GET_WIDE_KEY() << " - " << CK() << "[_keys]] : 0;\n" "\n"; */ out << " switch ( _cond ) {\n"; for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) { GenCondSpace *condSpace = csi; out << " case " << condSpace->condSpaceId + 1 << ": {\n"; out << TABS(2) << "_widec = " << CAST(WIDE_ALPH_TYPE()) << "(" << KEY(condSpace->baseKey) << " + (" << GET_KEY() << " - " << KEY(keyOps->minKey) << "));\n"; for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) { out << TABS(2) << "if ( "; CONDITION( out, *csi ); Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize()); out << " ) _widec += " << condValOffset << ";\n"; } out << " }\n"; out << " break;\n"; } SWITCH_DEFAULT(); out << " }\n"; }
void CSharpTabCodeGen::COND_TRANSLATE() { out << " _widec = " << GET_KEY() << ";\n" " _klen = " << CL() << "[" << vCS() << "];\n" " _keys = " << CAST(keysType) << " ("<< CO() << "[" << vCS() << "]*2);\n" " if ( _klen > 0 ) {\n" " " << signedKeysType << " _lower = _keys;\n" " " << signedKeysType << " _mid;\n" " " << signedKeysType << " _upper = " << CAST(signedKeysType) << " (_keys + (_klen<<1) - 2);\n" " while (true) {\n" " if ( _upper < _lower )\n" " break;\n" "\n" " _mid = " << CAST(signedKeysType) << " (_lower + (((_upper-_lower) >> 1) & ~1));\n" " if ( " << GET_WIDE_KEY() << " < " << CK() << "[_mid] )\n" " _upper = " << CAST(signedKeysType) << " (_mid - 2);\n" " else if ( " << GET_WIDE_KEY() << " > " << CK() << "[_mid+1] )\n" " _lower = " << CAST(signedKeysType) << " (_mid + 2);\n" " else {\n" " switch ( " << C() << "[" << CO() << "[" << vCS() << "]" " + ((_mid - _keys)>>1)] ) {\n"; for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) { GenCondSpace *condSpace = csi; out << " case " << condSpace->condSpaceId << ": {\n"; out << TABS(2) << "_widec = " << CAST(WIDE_ALPH_TYPE()) << "(" << KEY(condSpace->baseKey) << " + (" << GET_KEY() << " - " << KEY(keyOps->minKey) << "));\n"; for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) { out << TABS(2) << "if ( "; CONDITION( out, *csi ); Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize()); out << " ) _widec += " << condValOffset << ";\n"; } out << " break;\n" " }\n"; } SWITCH_DEFAULT(); out << " }\n" " break;\n" " }\n" " }\n" " }\n" "\n"; }
void TabCodeGen::COND_TRANSLATE() { out << " _widec = " << GET_KEY() << ";\n" " _klen = " << CL() << "[" << vCS() << "];\n" " _keys = " << ARR_OFF( CK(), "(" + CO() + "[" + vCS() + "]*2)" ) << ";\n" " if ( _klen > 0 ) {\n" " " << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_lower = _keys;\n" " " << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_mid;\n" " " << PTR_CONST() << WIDE_ALPH_TYPE() << PTR_CONST_END() << POINTER() << "_upper = _keys + (_klen<<1) - 2;\n" " while (1) {\n" " if ( _upper < _lower )\n" " break;\n" "\n" " _mid = _lower + (((_upper-_lower) >> 1) & ~1);\n" " if ( " << GET_WIDE_KEY() << " < _mid[0] )\n" " _upper = _mid - 2;\n" " else if ( " << GET_WIDE_KEY() << " > _mid[1] )\n" " _lower = _mid + 2;\n" " else {\n" " switch ( " << C() << "[" << CO() << "[" << vCS() << "]" " + ((_mid - _keys)>>1)] ) {\n"; for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) { GenCondSpace *condSpace = csi; out << " case " << condSpace->condSpaceId << ": {\n"; out << TABS(2) << "_widec = " << CAST(WIDE_ALPH_TYPE()) << "(" << KEY(condSpace->baseKey) << " + (" << GET_KEY() << " - " << KEY(keyOps->minKey) << "));\n"; for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) { out << TABS(2) << "if ( "; CONDITION( out, *csi ); Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize()); out << " ) _widec += " << condValOffset << ";\n"; } out << " break;\n" " }\n"; } SWITCH_DEFAULT(); out << " }\n" " break;\n" " }\n" " }\n" " }\n" "\n"; }
void RbxGotoCodeGen::COND_TRANSLATE( GenStateCond *stateCond, int level ) { GenCondSpace *condSpace = stateCond->condSpace; out << TABS(level) << "_widec = " << KEY(condSpace->baseKey) << " + (" << GET_KEY() << " - " << KEY(keyOps->minKey) << ");\n"; for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) { out << TABS(level) << "if "; CONDITION( out, *csi ); Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize()); out << "\n _widec += " << condValOffset << ";\n end"; } }
void CSharpGotoCodeGen::COND_TRANSLATE( GenStateCond *stateCond, int level ) { GenCondSpace *condSpace = stateCond->condSpace; out << TABS(level) << L"_widec = " << CAST(WIDE_ALPH_TYPE()) << L"(" << KEY(condSpace->baseKey) << L" + (" << GET_KEY() << L" - " << KEY(keyOps->minKey) << L"));\n"; for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) { out << TABS(level) << L"if ( "; CONDITION( out, *csi ); Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize()); out << L" ) _widec += " << condValOffset << L";\n"; } }
void RubyTabCodeGen::COND_TRANSLATE() { out << " _widec = " << GET_KEY() << "\n" " _keys = " << CO() << "[" << vCS() << "]*2\n" " _klen = " << CL() << "[" << vCS() << "]\n" " if _klen > 0\n" " _lower = _keys\n" " _upper = _keys + (_klen<<1) - 2\n" " loop do\n" " break if _upper < _lower\n" " _mid = _lower + (((_upper-_lower) >> 1) & ~1)\n" " if " << GET_WIDE_KEY() << " < " << CK() << "[_mid]\n" " _upper = _mid - 2\n" " elsif " << GET_WIDE_KEY() << " > " << CK() << "[_mid+1]\n" " _lower = _mid + 2\n" " else\n" " case " << C() << "[" << CO() << "[" << vCS() << "]" " + ((_mid - _keys)>>1)]\n"; for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) { GenCondSpace *condSpace = csi; out << " when " << condSpace->condSpaceId << " then" ; out << " _widec = " << KEY(condSpace->baseKey) << "+ (" << GET_KEY() << " - " << KEY(keyOps->minKey) << ")\n"; for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) { Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize()); out << " _widec += " << condValOffset << " if ( "; CONDITION( out, *csi ); out << " )\n"; } } out << " end # case\n" " end\n" " end # loop\n" " end\n"; }
void FlatCodeGen::COND_TRANSLATE() { out << " _widec = " << GET_KEY() << ";\n"; out << " _keys = " << ARR_OFF( CK(), "(" + vCS() + "<<1)" ) << ";\n" " _conds = " << ARR_OFF( C(), CO() + "[" + vCS() + "]" ) << ";\n" "\n" " _slen = " << CSP() << "[" << vCS() << "];\n" " _cond = _slen > 0 && _keys[0] <=" << GET_WIDE_KEY() << " &&\n" " " << GET_WIDE_KEY() << " <= _keys[1] ?\n" " _conds[" << GET_WIDE_KEY() << " - _keys[0]] : 0;\n" "\n"; out << " switch ( _cond ) {\n"; for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) { GenCondSpace *condSpace = csi; out << " case " << condSpace->condSpaceId + 1 << ": {\n"; out << TABS(2) << "_widec = " << CAST(WIDE_ALPH_TYPE()) << "(" << KEY(condSpace->baseKey) << " + (" << GET_KEY() << " - " << KEY(keyOps->minKey) << "));\n"; for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) { out << TABS(2) << "if ( "; CONDITION( out, *csi ); Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize()); out << " ) _widec += " << condValOffset << ";\n"; } out << " }\n"; out << " break;\n"; } SWITCH_DEFAULT(); out << " }\n"; }
std::ostream &GraphvizDotGen::ONCHAR( Key lowKey, Key highKey ) { GenCondSpace *condSpace; if ( lowKey > keyOps->maxKey && (condSpace=findCondSpace(lowKey, highKey) ) ) { Key values = ( lowKey - condSpace->baseKey ) / keyOps->alphSize(); lowKey = keyOps->minKey + (lowKey - condSpace->baseKey - keyOps->alphSize() * values.getVal()); highKey = keyOps->minKey + (highKey - condSpace->baseKey - keyOps->alphSize() * values.getVal()); KEY( lowKey ); if ( lowKey != highKey ) { out << ".."; KEY( highKey ); } out << "("; for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) { bool set = values & (1 << csi.pos()); if ( !set ) out << "!"; out << (*csi)->nameOrLoc(); if ( !csi.last() ) out << ", "; } out << ")"; } else { /* Output the key. Possibly a range. */ KEY( lowKey ); if ( highKey != lowKey ) { out << ".."; KEY( highKey ); } } return out; }