static String genAccess(String tbl,String var,int bits){
  String access=null;
  int bitoffset=bits == 1 ? 5 : bits == 2 ? 4 : bits == 4 ? 3 : 0;
  for (int k=0; k < sizes.length; k++) {
    int offset=((k < sizes.length - 1) ? 0 : bitoffset);
    int shift=shifts[k] + offset;
    String shifted=(shift == 0) ? var : "(" + var + ">>"+ shift+ ")";
    int mask=(1 << (sizes[k] - offset)) - 1;
    String masked=(k == 0) ? shifted : "(" + shifted + "&0x"+ hex(mask)+ ")";
    String index=(k == 0) ? masked : (mask == 0) ? access : "(" + access + "|"+ masked+ ")";
    String indexNoParens=(index.charAt(0) != '(') ? index : index.substring(1,index.length() - 1);
    String tblname=(k == sizes.length - 1) ? tbl : tableName(k);
    String fetched=tblname + "[" + indexNoParens+ "]";
    String zeroextended=(zeroextend[k] == 0) ? fetched : "(" + fetched + "&0x"+ hex(zeroextend[k])+ ")";
    int adjustment=preshifted[k] ? 0 : sizes[k + 1] - ((k == sizes.length - 2) ? bitoffset : 0);
    String adjusted=(preshifted[k] || adjustment == 0) ? zeroextended : "(" + zeroextended + "<<"+ adjustment+ ")";
    String bitshift=(bits == 1) ? "(" + var + "&0x1F)" : (bits == 2) ? "((" + var + "&0xF)<<1)" : (bits == 4) ? "((" + var + "&7)<<2)" : null;
    String extracted=((k < sizes.length - 1) || (bits >= 8)) ? adjusted : "((" + adjusted + ">>"+ bitshift+ ")&"+ (bits == 4 ? "0xF" : "" + ((1 << bits) - 1))+ ")";
    access=extracted;
  }
  return access;
}

static String genAccess ( String tbl , String var , int bits ) { String access = null ; int bitoffset = bits == 1 ? 5 : bits == 2 ? 4 : bits == 4 ? 3 : 0 ; for ( int k = 0 ; k < sizes . length ; k ++ ) { int offset = ( ( k < sizes . length - 1 ) ? 0 : bitoffset ) ; int shift = shifts [ k ] + offset ; String shifted = ( shift == 0 ) ? var : "(" + var + ">>" + shift + ")" ; int mask = ( 1 << ( sizes [ k ] - offset ) ) - 1 ; String masked = ( k == 0 ) ? shifted : "(" + shifted + "&0x" + hex ( mask ) + ")" ; String index = ( k == 0 ) ? masked : ( mask == 0 ) ? access : "(" + access + "|" + masked + ")" ; String indexNoParens = ( index . charAt ( 0 ) != '(' ) ? index : index . substring ( 1 , index . length ( ) - 1 ) ; String tblname = ( k == sizes . length - 1 ) ? tbl : tableName ( k ) ; String fetched = tblname + "[" + indexNoParens + "]" ; String zeroextended = ( zeroextend [ k ] == 0 ) ? fetched : "(" + fetched + "&0x" + hex ( zeroextend [ k ] ) + ")" ; int adjustment = preshifted [ k ] ? 0 : sizes [ k + 1 ] - ( ( k == sizes . length - 2 ) ? bitoffset : 0 ) ; String adjusted = ( preshifted [ k ] || adjustment == 0 ) ? zeroextended : "(" + zeroextended + "<<" + adjustment + ")" ; String bitshift = ( bits == 1 ) ? "(" + var + "&0x1F)" : ( bits == 2 ) ? "((" + var + "&0xF)<<1)" : ( bits == 4 ) ? "((" + var + "&7)<<2)" : null ; String extracted = ( ( k < sizes . length - 1 ) || ( bits >= 8 ) ) ? adjusted : "((" + adjusted + ">>" + bitshift + ")&" + ( bits == 4 ? "0xF" : "" + ( ( 1 << bits ) - 1 ) ) + ")" ; access = extracted ; } return access ; }
the genaccess method generates source code for one table access expression . most of the complexity stems from handling various options as to table representation , such as whether it contains values so large that they are represented as negative values and whether the table values are preshifted . this method also avoids such " ugly " expressions as shifting by distance zero , masking when no masking is necessary , and so on . for clarity , it generates expressions that do not rely on operator precedence , but otherwise it avoids generating redundant parentheses . a generated expression might look like a [ y [ ( x [ ch > > 6 ] < < 6 ) | ( ch & 0x3f ) ] ] or a [ z [ y [ ( x [ ch > > 7 ] < < 4 ) | ( ( ch > > 3 ) & 0xf ) ] | ( ch & 0x7 ) ] ] , for example .
