protected EnumTypedef findMatchingEnum ( EnumTypedef varenum ) throws DapException { List < EnumTypedef > candidates = new ArrayList <> ( ) ; for ( Map . Entry < DapNode , CDMNode > entry : this . nodemap . getCDMMap ( ) . entrySet ( ) ) { CDMNode cdmnode = entry . getValue ( ) ; if ( cdmnode . getSort ( ) != CDMSort . ENUMERATION ) continue ; // Compare the enumeration (note names will differ) EnumTypedef target = ( EnumTypedef ) cdmnode ; /* Ideally, we should test the types of the enums, but, unfortunately, the var enum is always enum4. if(target.getBaseType() != varenum.getBaseType()) continue; */ Map < Integer , String > targetmap = target . getMap ( ) ; Map < Integer , String > varmap = varenum . getMap ( ) ; if ( targetmap . size ( ) != varmap . size ( ) ) continue ; boolean match = true ; // until otherwise shown for ( Map . Entry < Integer , String > tpair : targetmap . entrySet ( ) ) { String tname = tpair . getValue ( ) ; int value = ( int ) tpair . getKey ( ) ; boolean found = false ; for ( Map . Entry < Integer , String > vpair : varmap . entrySet ( ) ) { if ( tname . equals ( vpair . getValue ( ) ) && value == ( int ) vpair . getKey ( ) ) { found = true ; break ; } } if ( ! found ) { match = false ; break ; } } if ( ! match ) continue ; // Save it unless it is shadowed by a closer enum boolean shadowed = false ; for ( EnumTypedef etd : candidates ) { if ( shadows ( etd . getGroup ( ) , target . getGroup ( ) ) ) { shadowed = true ; break ; } } if ( ! shadowed ) candidates . add ( target ) ; } switch ( candidates . size ( ) ) { case 0 : throw new DapException ( "CDMDSP: No matching enum type decl: " + varenum . getShortName ( ) ) ; case 1 : break ; default : throw new DapException ( "CDMDSP: Multiple matching enum type decls: " + varenum . getShortName ( ) ) ; } return candidates . get ( 0 ) ; }
Unfortunately the CDM Iosp does not actually use the declared enums . Rather for every enum type d variable a new enum decl is defined . So we need to find the original enum decl that matches the variable s enum .