Changeset 340:016a7fdd87e9 in finroc_core-java


Ignore:
Timestamp:
05.04.2020 06:51:56 (11 months ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Phase:
public
Message:

Adapts to changes in rrlib_rtti_conversion

Location:
remote
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • remote/RemoteRuntime.java

    r339 r340  
    303303        for (int i = 0, n = remoteTypeConversions.size(); i < n; i++) { 
    304304            RemoteTypeConversion conversion = remoteTypeConversions.get(i); 
    305             if (isTypeSupported(sourceType, conversion.getSupportedSourceTypes(), conversion.getSupportedSourceType())) { 
    306                 addAllTypes(fromSourceType, conversion, conversion.getSupportedDestinationTypes(), conversion.getSupportedDestinationType()); 
     305            if (isTypeSupported(sourceType, conversion.getSupportedSourceTypes(), conversion.getSupportedSourceType(), conversion.sourceTypesApplyToUnderlyingTypes())) { 
     306                addAllTypes(fromSourceType, conversion, conversion.getSupportedDestinationTypes(), conversion.getSupportedDestinationType(), conversion.destinationTypesApplyToUnderlyingTypes()); 
    307307            } 
    308308        } 
     
    311311        RemoteTypeConversion arrayToListOperation = getTypeConversionOperation(RemoteTypeConversion.SupportedTypeFilter.ARRAY_TO_VECTOR); 
    312312        RemoteTypeConversion getTupleElementOperation = getTypeConversionOperation(RemoteTypeConversion.SupportedTypeFilter.GET_TUPLE_ELEMENT); 
    313         RemoteType underlyingInheritOperationsType = sourceType; 
    314         while ((underlyingInheritOperationsType.getTypeTraits() & DataTypeBase.INHERITS_UNDERLYING_TYPE_ELEMENT_ACCESS_OPERATIONS) != 0 && underlyingInheritOperationsType.getTypeClassification() != DataTypeBase.CLASSIFICATION_ARRAY && underlyingInheritOperationsType.getUnderlyingType() != 0) { 
    315             underlyingInheritOperationsType = remoteTypes.get(underlyingInheritOperationsType.getUnderlyingType()); 
    316         } 
    317         if (sourceType.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST || underlyingInheritOperationsType.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY) { 
    318             fromSourceType.add(new GetCastOperationEntry(getListElementOperation, remoteTypes.get(underlyingInheritOperationsType.getElementType()), false)); 
    319         } 
    320         if (sourceType.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY) { 
    321             for (int i = 0, n = remoteTypes.size(); i < n; i++) { 
    322                 RemoteType type = remoteTypes.get(i); 
    323                 if (type.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST && type.getElementType() == sourceType.getElementType()) { 
    324                     fromSourceType.add(new GetCastOperationEntry(arrayToListOperation, type, false)); 
    325                     break; 
    326                 } 
    327             } 
    328         } 
    329         if (sourceType.getTupleElementTypes() != null) { 
    330             for (int i = 0; i < sourceType.getTupleElementTypes().length; i++) { 
    331                 fromSourceType.add(new GetCastOperationEntry(getTupleElementOperation, remoteTypes.get(sourceType.getTupleElementTypes()[i]), false)); 
    332                 fromSourceType.get(fromSourceType.size() - 1).tupleElementIndex = i; 
    333             } 
     313        RemoteTypeConversion adjustLengthOperation = getTypeConversionOperation(RemoteTypeConversion.SupportedTypeFilter.ADJUST_LENGTH); 
     314        RemoteType checkType = sourceType; 
     315        while (checkType != null) { 
     316            if (checkType.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST || checkType.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY) { 
     317                fromSourceType.add(new GetCastOperationEntry(getListElementOperation, remoteTypes.get(checkType.getElementType()), false)); 
     318                for (int i = 0, n = remoteTypes.size(); i < n; i++) { 
     319                    RemoteType type = remoteTypes.get(i); 
     320                    RemoteType checkDestinationType = type; 
     321                    while (checkDestinationType != null) { 
     322                        if (checkDestinationType.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY && checkDestinationType.getElementType() == checkType.getElementType() && ((checkType == sourceType && checkDestinationType == type) || adjustLengthOperationEncouraged(sourceType, type))) { 
     323                            fromSourceType.add(new GetCastOperationEntry(adjustLengthOperation, type, false)); 
     324                            break; 
     325                        } 
     326                        checkDestinationType = getUnderlyingTypeOperationsAreInheritedFrom(checkDestinationType); 
     327                    } 
     328                } 
     329            } 
     330            if (checkType.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY) { 
     331                for (int i = 0, n = remoteTypes.size(); i < n; i++) { 
     332                    RemoteType type = remoteTypes.get(i); 
     333                    if (type.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST && type.getElementType() == checkType.getElementType()) { 
     334                        fromSourceType.add(new GetCastOperationEntry(arrayToListOperation, type, false)); 
     335                        break; 
     336                    } 
     337                } 
     338            } 
     339            if (checkType.getTupleElementTypes() != null) { 
     340                for (int i = 0; i < checkType.getTupleElementTypes().length; i++) { 
     341                    fromSourceType.add(new GetCastOperationEntry(getTupleElementOperation, remoteTypes.get(checkType.getTupleElementTypes()[i]), false)); 
     342                    fromSourceType.get(fromSourceType.size() - 1).tupleElementIndex = i; 
     343                } 
     344            } 
     345            checkType = getUnderlyingTypeOperationsAreInheritedFrom(checkType); 
    334346        } 
    335347 
     
    337349        for (int i = 0, n = remoteTypeConversions.size(); i < n; i++) { 
    338350            RemoteTypeConversion conversion = remoteTypeConversions.get(i); 
    339             if (isTypeSupported(destinationType, conversion.getSupportedDestinationTypes(), conversion.getSupportedDestinationType())) { 
    340                 addAllTypes(fromDestinationType, conversion, conversion.getSupportedSourceTypes(), conversion.getSupportedSourceType()); 
     351            if (isTypeSupported(destinationType, conversion.getSupportedDestinationTypes(), conversion.getSupportedDestinationType(), conversion.destinationTypesApplyToUnderlyingTypes())) { 
     352                addAllTypes(fromDestinationType, conversion, conversion.getSupportedSourceTypes(), conversion.getSupportedSourceType(), conversion.sourceTypesApplyToUnderlyingTypes()); 
    341353            } 
    342354        } 
     
    344356        for (int i = 0, n = remoteTypes.size(); i < n; i++) { 
    345357            RemoteType type = remoteTypes.get(i); 
    346             if (type.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST && type.getElementType() == destinationType.getHandle()) { 
    347                 fromDestinationType.add(new GetCastOperationEntry(getListElementOperation, type, false)); 
    348             } 
    349             if (destinationType.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST && type.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY && type.getElementType() == destinationType.getElementType()) { 
    350                 fromDestinationType.add(new GetCastOperationEntry(arrayToListOperation, type, false)); 
    351             } 
    352             if (type.getTupleElementTypes() != null) { 
    353                 short[] tupleElements = type.getTupleElementTypes(); 
    354                 for (int j = 0; j < type.getTupleElementTypes().length; j++) { 
    355                     if (tupleElements[j] == destinationType.getHandle()) { 
    356                         fromDestinationType.add(new GetCastOperationEntry(getTupleElementOperation, type, false)); 
    357                         fromDestinationType.get(fromDestinationType.size() - 1).tupleElementIndex = j; 
    358                     } 
    359                 } 
     358            checkType = type; 
     359            while (checkType != null) { 
     360                if ((checkType.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST || checkType.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY) && checkType.getElementType() == destinationType.getHandle()) { 
     361                    fromDestinationType.add(new GetCastOperationEntry(getListElementOperation, type, false)); 
     362                    RemoteType checkDestinationType = destinationType; 
     363                    while (checkDestinationType != null) { 
     364                        if (checkDestinationType.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY && checkDestinationType.getElementType() == checkType.getElementType() && ((checkType == type && checkDestinationType == destinationType) || adjustLengthOperationEncouraged(type, destinationType))) { 
     365                            fromDestinationType.add(new GetCastOperationEntry(adjustLengthOperation, type, false)); 
     366                            break; 
     367                        } 
     368                        checkDestinationType = getUnderlyingTypeOperationsAreInheritedFrom(checkDestinationType); 
     369                    } 
     370                } 
     371                if (destinationType.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST && checkType.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY && checkType.getElementType() == destinationType.getElementType()) { 
     372                    fromDestinationType.add(new GetCastOperationEntry(arrayToListOperation, type, false)); 
     373                } 
     374                if (checkType.getTupleElementTypes() != null) { 
     375                    short[] tupleElements = checkType.getTupleElementTypes(); 
     376                    for (int j = 0; j < checkType.getTupleElementTypes().length; j++) { 
     377                        if (tupleElements[j] == destinationType.getHandle()) { 
     378                            fromDestinationType.add(new GetCastOperationEntry(getTupleElementOperation, type, false)); 
     379                            fromDestinationType.get(fromDestinationType.size() - 1).tupleElementIndex = j; 
     380                        } 
     381                    } 
     382                } 
     383                checkType = getUnderlyingTypeOperationsAreInheritedFrom(checkType); 
    360384            } 
    361385        } 
     
    421445 
    422446        // Try for-each operations 
    423         boolean sourceIsListType = sourceType.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST; 
    424         boolean destinationIsListType = destinationType.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST; 
    425         boolean sourceIsArrayType = sourceType.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY; 
    426         boolean destinationIsArrayType = destinationType.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY; 
    427         if ((sourceIsListType && destinationIsListType) || (sourceIsArrayType && destinationIsListType) || (sourceIsArrayType && destinationIsArrayType && sourceType.getArraySize() == destinationType.getArraySize())) { 
    428             RemoteTypeConversion forEachOperation = getTypeConversionOperation(RemoteTypeConversion.SupportedTypeFilter.FOR_EACH); 
    429             RemoteType sourceElementType = remoteTypes.get(sourceType.getElementType()); 
    430             RemoteType destinationElementType = remoteTypes.get(destinationType.getElementType()); 
    431             for (RemoteConnectOptions operation : getConversionOptions(sourceElementType, destinationElementType, true)) { 
    432                 result.add(new RemoteConnectOptions(operation.conversionRating == Definitions.TypeConversionRating.IMPLICIT_CAST ? Definitions.TypeConversionRating.EXPLICIT_CONVERSION : Definitions.TypeConversionRating.TWO_EXPLICIT_CONVERSIONS, forEachOperation, sourceElementType, operation.operation1)); 
    433                 if (operation.operation1.getSupportedSourceTypes() == SupportedTypeFilter.GET_TUPLE_ELEMENT) { 
    434                     result.get(result.size() - 1).parameter2 = operation.parameter1; 
    435                 } 
    436             } 
     447        RemoteType checkSourceType = sourceType; 
     448        RemoteTypeConversion forEachOperation = getTypeConversionOperation(RemoteTypeConversion.SupportedTypeFilter.FOR_EACH); 
     449        while (checkSourceType != null) { 
     450            RemoteType checkDestinationType = destinationType; 
     451            while (checkDestinationType != null) { 
     452                boolean sourceIsListType = checkSourceType.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST; 
     453                boolean destinationIsListType = checkDestinationType.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST; 
     454                boolean sourceIsArrayType = checkSourceType.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY; 
     455                boolean destinationIsArrayType = checkDestinationType.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY; 
     456 
     457                if ((sourceIsListType || sourceIsArrayType) && (destinationIsListType || destinationIsArrayType)) { 
     458                    RemoteType sourceElementType = remoteTypes.get(checkSourceType.getElementType()); 
     459                    RemoteType destinationElementType = remoteTypes.get(checkDestinationType.getElementType()); 
     460                    if (sourceElementType != destinationElementType) { 
     461                        for (RemoteConnectOptions operation : getConversionOptions(sourceElementType, destinationElementType, true)) { 
     462                            result.add(new RemoteConnectOptions(operation.conversionRating == Definitions.TypeConversionRating.IMPLICIT_CAST ? Definitions.TypeConversionRating.EXPLICIT_CONVERSION : Definitions.TypeConversionRating.TWO_EXPLICIT_CONVERSIONS, forEachOperation, sourceElementType, operation.operation1)); 
     463                            if (operation.operation1.getSupportedSourceTypes() == SupportedTypeFilter.GET_TUPLE_ELEMENT) { 
     464                                result.get(result.size() - 1).parameter2 = operation.parameter1; 
     465                            } 
     466                        } 
     467                    } 
     468                } 
     469 
     470                checkDestinationType = getUnderlyingTypeOperationsAreInheritedFrom(checkDestinationType); 
     471            } 
     472            checkSourceType = getUnderlyingTypeOperationsAreInheritedFrom(checkSourceType); 
    437473        } 
    438474 
     
    447483        for (int i = 0; i < result.size(); i++) { 
    448484            RemoteConnectOptions operation = result.get(i); 
    449             if (operation.operation1 != null && operation.operation2 != null && operation.intermediateType.getName().equals("bool")) { 
     485            if (operation.conversionRating == TypeConversionRating.TWO_IMPLICIT_CASTS && operation.intermediateType.getName().equals("bool")) { 
    450486                result.remove(i); 
    451487                i--; 
     
    625661                byte rating = ratings.cachedConversionRatings[i]; 
    626662                if (isSingleOperationRating(rating)) { 
    627                     RemoteType.CachedConversionRatings intermediateRatings = getTypeSingleConversionRatings(remoteTypes.get(i)); 
     663                    RemoteType intermediateType = remoteTypes.get(i); 
     664                    boolean intermediateTypeBool = intermediateType.getName().equals("bool"); 
     665                    RemoteType.CachedConversionRatings intermediateRatings = getTypeSingleConversionRatings(intermediateType); 
    628666                    for (int j = 0; j < ratings.cachedConversionRatings.length; j++) { 
    629667                        byte rating2 = intermediateRatings.cachedConversionRatings[j]; 
     
    632670                            boolean deprecatedConversion = ((rating == Definitions.TypeConversionRating.EXPLICIT_CONVERSION_FROM_GENERIC_TYPE.ordinal()) && (rating2 == Definitions.TypeConversionRating.EXPLICIT_CONVERSION_TO_GENERIC_TYPE.ordinal())) || 
    633671                                                           ((rating2 == Definitions.TypeConversionRating.EXPLICIT_CONVERSION_FROM_GENERIC_TYPE.ordinal()) && (rating == Definitions.TypeConversionRating.EXPLICIT_CONVERSION_TO_GENERIC_TYPE.ordinal())); 
    634                             updateConversionRating(ratings.cachedConversionRatings, j, deprecatedConversion ? Definitions.TypeConversionRating.UNUSUAL_CONVERSION : (implicitCasts == 2 ? Definitions.TypeConversionRating.TWO_IMPLICIT_CASTS : (implicitCasts == 1 ? Definitions.TypeConversionRating.EXPLICIT_CONVERSION_AND_IMPLICIT_CAST : Definitions.TypeConversionRating.TWO_EXPLICIT_CONVERSIONS))); 
     672                            boolean filteredOperation = intermediateTypeBool && implicitCasts >= 2; 
     673                            if (!filteredOperation) { 
     674                                updateConversionRating(ratings.cachedConversionRatings, j, deprecatedConversion ? Definitions.TypeConversionRating.UNUSUAL_CONVERSION : (implicitCasts == 2 ? Definitions.TypeConversionRating.TWO_IMPLICIT_CASTS : (implicitCasts == 1 ? Definitions.TypeConversionRating.EXPLICIT_CONVERSION_AND_IMPLICIT_CAST : Definitions.TypeConversionRating.TWO_EXPLICIT_CONVERSIONS))); 
     675                            } 
    635676                        } 
    636677                    } 
     
    639680 
    640681            // For/each operation 
    641             if (type.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST || type.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY) { 
    642                 RemoteType elementType = remoteTypes.get(type.getElementType()); 
    643                 RemoteType.CachedConversionRatings intermediateRatings = getTypeSingleConversionRatings(elementType); 
    644                 for (int i = 0; i < ratings.cachedConversionRatings.length; i++) { 
    645                     RemoteType destinationType = remoteTypes.get(i); 
    646                     if (destinationType.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST || (destinationType.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY && type.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY && type.getArraySize() == destinationType.getArraySize())) { 
    647                         RemoteType destinationElementType = remoteTypes.get(destinationType.getElementType()); 
    648                         byte rating = intermediateRatings.cachedConversionRatings[destinationElementType.getHandle()]; 
    649                         if (isSingleOperationRating(rating)) { 
    650                             updateConversionRating(ratings.cachedConversionRatings, destinationType.getHandle(), rating == Definitions.TypeConversionRating.IMPLICIT_CAST.ordinal() ? Definitions.TypeConversionRating.EXPLICIT_CONVERSION : Definitions.TypeConversionRating.TWO_EXPLICIT_CONVERSIONS); 
     682            RemoteType checkSourceType = type; 
     683            while (checkSourceType != null) { 
     684                if (checkSourceType.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST || checkSourceType.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY) { 
     685                    RemoteType elementType = remoteTypes.get(checkSourceType.getElementType()); 
     686                    RemoteType.CachedConversionRatings intermediateRatings = getTypeSingleConversionRatings(elementType); 
     687                    for (int i = 0; i < ratings.cachedConversionRatings.length; i++) { 
     688                        RemoteType destinationType = remoteTypes.get(i); 
     689                        RemoteType checkDestinationType = destinationType; 
     690                        while (checkDestinationType != null) { 
     691                            if ((checkDestinationType.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST || checkDestinationType.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY) && checkDestinationType.getElementType() != checkSourceType.getElementType()) { 
     692                                byte rating = intermediateRatings.cachedConversionRatings[checkDestinationType.getElementType()]; 
     693                                if (isSingleOperationRating(rating)) { 
     694                                    updateConversionRating(ratings.cachedConversionRatings, destinationType.getHandle(), rating == Definitions.TypeConversionRating.IMPLICIT_CAST.ordinal() ? Definitions.TypeConversionRating.EXPLICIT_CONVERSION : Definitions.TypeConversionRating.TWO_EXPLICIT_CONVERSIONS); 
     695                                } 
     696                            } 
     697                            checkDestinationType = getUnderlyingTypeOperationsAreInheritedFrom(checkDestinationType); 
    651698                        } 
    652699                    } 
    653700                } 
     701                checkSourceType = getUnderlyingTypeOperationsAreInheritedFrom(checkSourceType); 
    654702            } 
    655703        } 
     
    10591107 
    10601108    /** 
     1109     * Obtains underlying type whose respectively flagged conversion operations are inherited 
     1110     * 
     1111     * @param type Type to obtain underlying type of 
     1112     * @return Underlying type whose respectively flagged conversion operations are inherited - or null if there is no such type 
     1113     */ 
     1114    private RemoteType getUnderlyingTypeOperationsAreInheritedFrom(RemoteType type) { 
     1115        return (type.getUnderlyingType() != 0 && (type.getTypeTraits() & (DataTypeBase.INHERITS_UNDERLYING_TYPE_ELEMENT_ACCESS_OPERATIONS | DataTypeBase.IS_CAST_TO_UNDERLYING_TYPE_IMPLICIT)) != 0) ? remoteTypes.get(type.getUnderlyingType()) : null; 
     1116    } 
     1117 
     1118    /** 
     1119     * \param underlyingType Candidate for underlying type 
     1120     * \param type Type to check 
     1121     * \return Whether type inherits operations from underlyingType 
     1122     */ 
     1123    public boolean inheritsOperationsFrom(RemoteType underlyingType, RemoteType type) { 
     1124        if (underlyingType == type) { 
     1125            return true; 
     1126        } 
     1127        RemoteType checkType = getUnderlyingTypeOperationsAreInheritedFrom(type); 
     1128        return checkType != null ? inheritsOperationsFrom(underlyingType, checkType) : false; 
     1129    } 
     1130 
     1131    /** 
     1132     * @param sourceType Source type 
     1133     * @param destinationType Destination type 
     1134     * @return Whether special change length conversion operation between the specified is encouraged 
     1135     */ 
     1136    private boolean adjustLengthOperationEncouraged(RemoteType sourceType, RemoteType destinationType) { 
     1137        if (sourceType.getSize() != destinationType.getSize()) { 
     1138            String sourceName = sourceType.getName(); 
     1139            String destinationName = destinationType.getName(); 
     1140            int minLength = Math.min(sourceName.length(), destinationName.length()); 
     1141            for (int i = 0; i < minLength; i++) { 
     1142                if (Character.isDigit(sourceName.charAt(i)) && Character.isDigit(destinationName.charAt(i))) { 
     1143                    return i > 0; 
     1144                } else if (sourceName.charAt(i) != destinationName.charAt(i)) { 
     1145                    return false; 
     1146                } 
     1147            } 
     1148        } 
     1149        return false; 
     1150    } 
     1151 
     1152    /** 
    10611153     * Helper function for getConversionOptions() 
    10621154     * 
     
    10641156     * @param filter Type filter to apply 
    10651157     * @param singleType Single type for type filter 'SINGLE' 
     1158     * @param filterAppliesToUnderlyingTypes Whether type filter applies to underlying types also 
    10661159     * @return Whether 'type' is supported by non-special function 
    10671160     */ 
    1068     private boolean isTypeSupported(RemoteType type, SupportedTypeFilter filter, RemoteType singleType) { 
    1069         return (type.getTypeClassification() != DataTypeBase.CLASSIFICATION_RPC_TYPE && type.getTypeClassification() != DataTypeBase.CLASSIFICATION_PORT_COMPOSITE_INTERFACE && type.getTypeClassification() != DataTypeBase.CLASSIFICATION_NULL_TYPE) && ( 
    1070                    (filter == SupportedTypeFilter.ALL) || 
    1071                    (filter == SupportedTypeFilter.BINARY_SERIALIZABLE && (type.getTypeTraits() & DataTypeBase.IS_BINARY_SERIALIZABLE) != 0) || 
    1072                    (filter == SupportedTypeFilter.SINGLE && singleType == type) || 
    1073                    (filter == SupportedTypeFilter.STRING_SERIALIZABLE && (type.getTypeTraits() & DataTypeBase.IS_STRING_SERIALIZABLE) != 0) || 
    1074                    (filter == SupportedTypeFilter.LISTS && (type.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST))); 
     1161    private boolean isTypeSupported(RemoteType type, SupportedTypeFilter filter, RemoteType singleType, boolean filterAppliesToUnderlyingTypes) { 
     1162        boolean result = (type.getTypeClassification() != DataTypeBase.CLASSIFICATION_RPC_TYPE && type.getTypeClassification() != DataTypeBase.CLASSIFICATION_PORT_COMPOSITE_INTERFACE && type.getTypeClassification() != DataTypeBase.CLASSIFICATION_NULL_TYPE) && ( 
     1163                             (filter == SupportedTypeFilter.ALL) || 
     1164                             (filter == SupportedTypeFilter.BINARY_SERIALIZABLE && (type.getTypeTraits() & DataTypeBase.IS_BINARY_SERIALIZABLE) != 0) || 
     1165                             (filter == SupportedTypeFilter.SINGLE && singleType == type) || 
     1166                             (filter == SupportedTypeFilter.STRING_SERIALIZABLE && (type.getTypeTraits() & DataTypeBase.IS_STRING_SERIALIZABLE) != 0) || 
     1167                             (filter == SupportedTypeFilter.LISTS && (type.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST))); 
     1168        if (filterAppliesToUnderlyingTypes && (!result)) { 
     1169            RemoteType underlyingType = getUnderlyingTypeOperationsAreInheritedFrom(type); 
     1170            result = underlyingType != null ? isTypeSupported(underlyingType, filter, singleType, filterAppliesToUnderlyingTypes) : false; 
     1171        } 
     1172        return result; 
    10751173    } 
    10761174 
     
    10811179     * @param operation Type conversion operation in question 
    10821180     * @param filter Type filter to apply 
     1181     * @param filterAppliesToUnderlyingTypes Whether type filter applies to underlying types also 
    10831182     * @param singleType Single type for type filter 'SINGLE' 
    10841183     */ 
    1085     private void addAllTypes(ArrayList<GetCastOperationEntry> result, RemoteTypeConversion operation, SupportedTypeFilter filter, RemoteType singleType) { 
     1184    private void addAllTypes(ArrayList<GetCastOperationEntry> result, RemoteTypeConversion operation, SupportedTypeFilter filter, RemoteType singleType, boolean filterAppliesToUnderlyingTypes) { 
    10861185        if (filter == SupportedTypeFilter.SINGLE) { 
    10871186            result.add(new GetCastOperationEntry(operation, singleType, false)); 
     1187            if (filterAppliesToUnderlyingTypes) { 
     1188                for (int i = 0, n = remoteTypes.size(); i < n; i++) { 
     1189                    RemoteType type = remoteTypes.get(i); 
     1190                    if (type != singleType && inheritsOperationsFrom(singleType, type)) { 
     1191                        result.add(new GetCastOperationEntry(operation, type, false)); 
     1192                    } 
     1193                } 
     1194            } 
    10881195        } else if (filter == SupportedTypeFilter.ALL || filter == SupportedTypeFilter.BINARY_SERIALIZABLE || filter == SupportedTypeFilter.STRING_SERIALIZABLE || filter == SupportedTypeFilter.LISTS) { 
    10891196            int requiredFlag = (filter == SupportedTypeFilter.ALL || filter == SupportedTypeFilter.LISTS) ? 0 : (filter == SupportedTypeFilter.BINARY_SERIALIZABLE ? DataTypeBase.IS_BINARY_SERIALIZABLE : DataTypeBase.IS_STRING_SERIALIZABLE); 
     
    10931200                if ((type.getTypeTraits() & requiredFlag) == requiredFlag && (requiredClassification == 0 || type.getTypeClassification() == requiredClassification)) { 
    10941201                    result.add(new GetCastOperationEntry(operation, type, false)); 
     1202                } else { 
     1203                    RemoteType underlying = getUnderlyingTypeOperationsAreInheritedFrom(type); 
     1204                    while (underlying != null) { 
     1205                        if ((underlying.getTypeTraits() & requiredFlag) == requiredFlag && (requiredClassification == 0 || underlying.getTypeClassification() == requiredClassification)) { 
     1206                            result.add(new GetCastOperationEntry(operation, type, false)); 
     1207                            break; 
     1208                        } 
     1209                        underlying = getUnderlyingTypeOperationsAreInheritedFrom(underlying); 
     1210                    } 
    10951211                } 
    10961212            } 
     
    11031219     * @param result Object to store result in 
    11041220     * @param operation Type conversion operation in question 
    1105      * @param filter Type filter to apply 
    1106      * @param singleType Single type for type filter 'SINGLE' 
    1107      * @param sourceFilter Whether this is the source filter 
    11081221     */ 
    11091222    private void addAllDestinationTypes(RemoteType.CachedConversionRatings result, RemoteTypeConversion operation) { 
     
    11121225            Definitions.TypeConversionRating rating = (operation.getSupportedSourceTypes() == SupportedTypeFilter.ALL || operation.getSupportedSourceTypes() == SupportedTypeFilter.BINARY_SERIALIZABLE || operation.getSupportedSourceTypes() == SupportedTypeFilter.STRING_SERIALIZABLE) ? Definitions.TypeConversionRating.EXPLICIT_CONVERSION_TO_GENERIC_TYPE : Definitions.TypeConversionRating.EXPLICIT_CONVERSION; 
    11131226            updateConversionRating(result.cachedConversionRatings, operation.getSupportedDestinationType().getHandle(), rating); 
     1227            if (operation.destinationTypesApplyToUnderlyingTypes()) { 
     1228                for (int i = 0; i < result.typeCount; i++) { 
     1229                    RemoteType type = remoteTypes.get(i); 
     1230                    if (type != operation.getSupportedDestinationType() && inheritsOperationsFrom(operation.getSupportedDestinationType(), type)) { 
     1231                        updateConversionRating(result.cachedConversionRatings, type.getHandle(), rating); 
     1232                    } 
     1233                } 
     1234            } 
    11141235        } else if (filter == SupportedTypeFilter.ALL || filter == SupportedTypeFilter.BINARY_SERIALIZABLE || filter == SupportedTypeFilter.STRING_SERIALIZABLE || filter == SupportedTypeFilter.LISTS) { 
    11151236            int requiredFlag = (filter == SupportedTypeFilter.ALL || filter == SupportedTypeFilter.LISTS) ? 0 : (filter == SupportedTypeFilter.BINARY_SERIALIZABLE ? DataTypeBase.IS_BINARY_SERIALIZABLE : DataTypeBase.IS_STRING_SERIALIZABLE); 
     
    11191240                if ((type.getTypeTraits() & requiredFlag) == requiredFlag && (requiredClassification == 0 || type.getTypeClassification() == requiredClassification) && type.getTypeClassification() != DataTypeBase.CLASSIFICATION_RPC_TYPE && type.getTypeClassification() != DataTypeBase.CLASSIFICATION_PORT_COMPOSITE_INTERFACE) { 
    11201241                    updateConversionRating(result.cachedConversionRatings, type.getHandle(), Definitions.TypeConversionRating.EXPLICIT_CONVERSION_FROM_GENERIC_TYPE); 
     1242                } else { 
     1243                    RemoteType underlying = getUnderlyingTypeOperationsAreInheritedFrom(type); 
     1244                    while (underlying != null) { 
     1245                        if ((underlying.getTypeTraits() & requiredFlag) == requiredFlag && (requiredClassification == 0 || underlying.getTypeClassification() == requiredClassification) && underlying.getTypeClassification() != DataTypeBase.CLASSIFICATION_RPC_TYPE && underlying.getTypeClassification() != DataTypeBase.CLASSIFICATION_PORT_COMPOSITE_INTERFACE) { 
     1246                            updateConversionRating(result.cachedConversionRatings, underlying.getHandle(), Definitions.TypeConversionRating.EXPLICIT_CONVERSION_FROM_GENERIC_TYPE); 
     1247                            break; 
     1248                        } 
     1249                        underlying = getUnderlyingTypeOperationsAreInheritedFrom(underlying); 
     1250                    } 
    11211251                } 
    11221252            } 
     
    12211351            for (int i = 0; i < ratings.typeConversionOperationCount; i++) { 
    12221352                RemoteTypeConversion conversion = remoteTypeConversions.get(i); 
    1223                 if (isTypeSupported(type, conversion.getSupportedSourceTypes(), conversion.getSupportedSourceType())) { 
     1353                if (isTypeSupported(type, conversion.getSupportedSourceTypes(), conversion.getSupportedSourceType(), conversion.sourceTypesApplyToUnderlyingTypes())) { 
    12241354                    addAllDestinationTypes(ratings, conversion); 
    12251355                } 
    12261356            } 
    12271357        } 
     1358 
    12281359        // Special operations 
    1229         // Get list elements operation 
    1230         if (type.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST || type.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY) { 
    1231             updateConversionRating(ratings.cachedConversionRatings, type.getElementType(), Definitions.TypeConversionRating.EXPLICIT_CONVERSION); 
    1232         } 
    1233         // Array to list operation 
    1234         if (type.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY) { 
    1235             for (int i = 0, n = remoteTypes.size(); i < n; i++) { 
    1236                 RemoteType listType = remoteTypes.get(i); 
    1237                 if (listType.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST && listType.getElementType() == type.getElementType()) { 
    1238                     updateConversionRating(ratings.cachedConversionRatings, listType.getHandle(), Definitions.TypeConversionRating.EXPLICIT_CONVERSION); 
    1239                     break; 
    1240                 } 
    1241             } 
    1242         } 
    1243         // Get tuple element operation 
    1244         if (type.getTupleElementTypes() != null) { 
    1245             for (int i = 0; i < type.getTupleElementTypes().length; i++) { 
    1246                 updateConversionRating(ratings.cachedConversionRatings, type.getTupleElementTypes()[i], Definitions.TypeConversionRating.EXPLICIT_CONVERSION); 
    1247             } 
     1360        RemoteType checkType = type; 
     1361        while (checkType != null) { 
     1362            // Get list elements operation 
     1363            if (checkType.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST || checkType.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY) { 
     1364                updateConversionRating(ratings.cachedConversionRatings, checkType.getElementType(), Definitions.TypeConversionRating.EXPLICIT_CONVERSION); 
     1365                for (int i = 0, n = remoteTypes.size(); i < n; i++) { 
     1366                    RemoteType destinationType = remoteTypes.get(i); 
     1367                    RemoteType checkDestinationType = destinationType; 
     1368                    while (checkDestinationType != null) { 
     1369                        if (checkDestinationType.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY && checkDestinationType.getElementType() == checkType.getElementType() && ((checkType == type && checkDestinationType == destinationType) || adjustLengthOperationEncouraged(type, destinationType))) { 
     1370                            updateConversionRating(ratings.cachedConversionRatings, destinationType.getHandle(), Definitions.TypeConversionRating.EXPLICIT_CONVERSION); 
     1371                            break; 
     1372                        } 
     1373                        checkDestinationType = getUnderlyingTypeOperationsAreInheritedFrom(checkDestinationType); 
     1374                    } 
     1375                } 
     1376            } 
     1377            // Array to list operation 
     1378            if (checkType.getTypeClassification() == DataTypeBase.CLASSIFICATION_ARRAY) { 
     1379                for (int i = 0, n = remoteTypes.size(); i < n; i++) { 
     1380                    RemoteType listType = remoteTypes.get(i); 
     1381                    if (listType.getTypeClassification() == DataTypeBase.CLASSIFICATION_LIST && listType.getElementType() == checkType.getElementType()) { 
     1382                        updateConversionRating(ratings.cachedConversionRatings, listType.getHandle(), Definitions.TypeConversionRating.EXPLICIT_CONVERSION); 
     1383                        break; 
     1384                    } 
     1385                } 
     1386            } 
     1387            // Get tuple element operation 
     1388            if (checkType.getTupleElementTypes() != null) { 
     1389                for (int i = 0; i < checkType.getTupleElementTypes().length; i++) { 
     1390                    updateConversionRating(ratings.cachedConversionRatings, checkType.getTupleElementTypes()[i], Definitions.TypeConversionRating.EXPLICIT_CONVERSION); 
     1391                } 
     1392            } 
     1393            checkType = getUnderlyingTypeOperationsAreInheritedFrom(checkType); 
    12481394        } 
    12491395 
  • remote/RemoteTypeConversion.java

    r294 r340  
    5252        GET_LIST_ELEMENT,    //!< Types supported by get list element 
    5353        ARRAY_TO_VECTOR,     //!< Types supported by array to vector operation 
    54         GET_TUPLE_ELEMENT    //!< Types supported by get tuple element operation 
     54        GET_TUPLE_ELEMENT,   //!< Types supported by get tuple element operation 
     55        ADJUST_LENGTH        //!< Types supported by adjust length operation 
    5556    } 
    5657 
    5758    public static final String STATIC_CAST_NAME = "static_cast", TO_EVENT_NAME = "ToEvent"; 
     59 
     60    /** 
     61     * @return Whether destination type filter applies to underlying types also (provided conversion to underlying type is implicit or cINHERITS_ELEMENT_ACCESS_CONVERSION_OPERATIONS is set in trait) 
     62     */ 
     63    public boolean destinationTypesApplyToUnderlyingTypes() { 
     64        return destinationTypesApplyToUnderlyingTypes; 
     65    } 
    5866 
    5967    /** 
     
    113121    } 
    114122 
     123    /** 
     124     * @return Whether source type filter applies to underlying types also (provided conversion to underlying type is implicit or cINHERITS_ELEMENT_ACCESS_CONVERSION_OPERATIONS is set in trait) 
     125     */ 
     126    public boolean sourceTypesApplyToUnderlyingTypes() { 
     127        return sourceTypesApplyToUnderlyingTypes; 
     128    } 
    115129 
    116130    @Override 
     
    137151        final int HAS_PARAMETER = 1; 
    138152        final int NOT_USUALLY_COMBINED_WITH = 2; 
     153        final int SOURCE_TYPES_APPLY_TO_UNDERLYING_TYPES = 4; 
     154        final int DESTINATION_TYPES_APPLY_TO_UNDERLYING_TYPES = 8; 
    139155        if ((flags & HAS_PARAMETER) == HAS_PARAMETER) { 
    140156            parameter = new ParameterDefinition(); 
     
    147163            notUsuallyCombinedWithHandle = stream.readShort(); 
    148164        } 
     165        sourceTypesApplyToUnderlyingTypes = (flags & SOURCE_TYPES_APPLY_TO_UNDERLYING_TYPES) != 0; 
     166        destinationTypesApplyToUnderlyingTypes = (flags & DESTINATION_TYPES_APPLY_TO_UNDERLYING_TYPES) != 0; 
    149167    } 
    150168 
     
    181199    private RemoteType supportedSourceType; 
    182200 
     201    /** Whether source type filter applies to underlying types also (provided conversion to underlying type is implicit or cINHERITS_ELEMENT_ACCESS_CONVERSION_OPERATIONS is set in trait) */ 
     202    private boolean sourceTypesApplyToUnderlyingTypes; 
     203 
    183204    /** Supported destination types: type filter */ 
    184205    private SupportedTypeFilter supportedDestinationTypes; 
     
    186207    /** In case 'supportedDestinationTypes' is SINGLE, contains uid of single supported destination type */ 
    187208    private RemoteType supportedDestinationType; 
     209 
     210    /** Whether destination type filter applies to underlying types also (provided conversion to underlying type is implicit or cINHERITS_ELEMENT_ACCESS_CONVERSION_OPERATIONS is set in trait) */ 
     211    private boolean destinationTypesApplyToUnderlyingTypes; 
    188212 
    189213    /** Parameter definition if conversion operation has a parameter (otherwise null) */ 
Note: See TracChangeset for help on using the changeset viewer.