Changeset 347:5a359869281c in finroc_core-java


Ignore:
Timestamp:
25.04.2021 07:48:28 (17 months ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Phase:
public
Message:

Adds separate type conversion rating for metadata operations - and optimizes the way they are handled

Location:
remote
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • remote/Definitions.java

    r333 r347  
    7373        IMPOSSIBLE, 
    7474        UNUSUAL_CONVERSION, 
     75        METADATA_OPERATION, 
    7576        TWO_EXPLICIT_CONVERSIONS, 
    7677        EXPLICIT_CONVERSION_TO_GENERIC_TYPE,   // value for single operations only to detect deprecated casts 
  • remote/RemoteConnectOptions.java

    r329 r347  
    291291        case EXPLICIT_CONVERSION_FROM_GENERIC_TYPE: 
    292292        case EXPLICIT_CONVERSION_TO_GENERIC_TYPE: 
     293        case METADATA_OPERATION: 
    293294            return 1; 
    294295        default: 
     
    311312        case EXPLICIT_CONVERSION_FROM_GENERIC_TYPE: 
    312313        case EXPLICIT_CONVERSION: 
     314        case METADATA_OPERATION: 
    313315            return "'" + operation1.toString(parameter1) + "'"; 
    314316        case EXPLICIT_CONVERSION_AND_IMPLICIT_CAST: 
  • remote/RemoteRuntime.java

    r346 r347  
    353353                if (IsSupportedMetadataCaptureType(type)) { 
    354354                    fromSourceType.add(new GetCastOperationEntry(captureMetadataOperation, type, false)); 
     355                    fromSourceType.get(fromSourceType.size() - 1).metadataOperation = true; 
    355356                } 
    356357            } 
     
    361362                if (appendMetadataSupported(sourceType, type)) { 
    362363                    fromSourceType.add(new GetCastOperationEntry(appendMetadataOperation, type, false)); 
     364                    fromSourceType.get(fromSourceType.size() - 1).metadataOperation = true; 
    363365                } 
    364366            } 
     
    403405            } 
    404406        } 
    405         if (captureMetadataOperation != null && IsSupportedMetadataCaptureType(destinationType)) { 
    406             for (int i = 0, n = remoteTypes.size(); i < n; i++) { 
    407                 RemoteType type = remoteTypes.get(i); 
    408                 fromDestinationType.add(new GetCastOperationEntry(captureMetadataOperation, type, false)); 
    409             } 
    410         } 
    411         if (appendMetadataOperation != null && destinationType.getTupleElementTypes() != null) { 
    412             RemoteType newType = remoteTypes.get(destinationType.getTupleElementTypes()[destinationType.getTupleElementTypes().length - 1]); 
    413             if (IsSupportedMetadataCaptureType(newType)) { 
    414                 for (int i = 0, n = remoteTypes.size(); i < n; i++) { 
    415                     RemoteType type = remoteTypes.get(i); 
    416                     if (appendMetadataSupported(type, destinationType)) { 
    417                         fromDestinationType.add(new GetCastOperationEntry(appendMetadataOperation, type, false)); 
    418                     } 
    419                 } 
    420             } 
    421         } 
    422407 
    423408 
     
    429414        for (GetCastOperationEntry entry : fromSourceType) { 
    430415            if (entry.intermediateType == destinationType) { 
    431                 result.add(new RemoteConnectOptions(entry.implicitCast ? Definitions.TypeConversionRating.IMPLICIT_CAST : Definitions.TypeConversionRating.EXPLICIT_CONVERSION, entry.operation)); 
     416                result.add(new RemoteConnectOptions(entry.metadataOperation ? Definitions.TypeConversionRating.METADATA_OPERATION : (entry.implicitCast ? Definitions.TypeConversionRating.IMPLICIT_CAST : Definitions.TypeConversionRating.EXPLICIT_CONVERSION), entry.operation)); 
    432417                if (entry.operation.getSupportedSourceTypes() == SupportedTypeFilter.GET_TUPLE_ELEMENT) { 
    433418                    result.get(result.size() - 1).parameter1 = new GenericObject(new CoreNumber(entry.tupleElementIndex), CoreNumber.TYPE, null); 
     
    445430            RemoteType fromSourceIntermediateType = fromSourceType.get(fromSourceIndex).intermediateType; 
    446431            RemoteType fromDestinationIntermediateType = fromDestinationType.get(fromDestinationIndex).intermediateType; 
    447             if (fromSourceIntermediateType.getHandle() < fromDestinationIntermediateType.getHandle()) { 
     432            if (fromSourceIntermediateType.getHandle() < fromDestinationIntermediateType.getHandle() || fromSourceType.get(fromSourceIndex).metadataOperation) { 
    448433                fromSourceIndex++; 
    449434            } else if (fromSourceIntermediateType.getHandle() > fromDestinationIntermediateType.getHandle()) { 
     
    476461                        fromDestinationIndexTemp++; 
    477462                    } 
    478                     fromSourceIndex++; 
     463                    do { 
     464                        fromSourceIndex++; 
     465                    } while (fromSourceIndex < fromSourceType.size() && fromSourceType.get(fromSourceIndex).metadataOperation); 
    479466                } 
    480467            } 
     
    526513        } 
    527514 
    528         // Remove nonsense metadata casts 
    529         for (int i = 0; i < result.size(); i++) { 
    530             RemoteConnectOptions operation = result.get(i); 
    531             if ((operation.operation1 == captureMetadataOperation || operation.operation1 == appendMetadataOperation) && (operation.operation2 == captureMetadataOperation || operation.operation2 == appendMetadataOperation)) { 
    532                 result.remove(i); 
    533                 i--; 
    534             } else if ((operation.operation1 == captureMetadataOperation || operation.operation2 == captureMetadataOperation) && operation.operation2 != null) { 
    535                 result.remove(i); 
    536                 i--; 
    537             } 
    538         } 
    539  
    540515        Collections.sort(result); 
    541516 
     
    725700            for (int i = 0; i < ratings.cachedConversionRatings.length; i++) { 
    726701                byte rating = ratings.cachedConversionRatings[i]; 
    727                 if (isSingleOperationRating(rating)) { 
     702                if (isSingleOperationRating(rating) && rating != Definitions.TypeConversionRating.METADATA_OPERATION.ordinal()) { 
    728703                    RemoteType intermediateType = remoteTypes.get(i); 
    729704                    boolean intermediateTypeBool = intermediateType.getName().equals("bool"); 
     
    11501125        final boolean implicitCast; 
    11511126        int tupleElementIndex; 
     1127        boolean metadataOperation; 
    11521128 
    11531129        public GetCastOperationEntry(RemoteTypeConversion operation, RemoteType intermediateType, boolean implicitCast) { 
     
    14591435        } 
    14601436 
     1437        RemoteTypeConversion captureMetadataOperation = getTypeConversionOperation("Capture Metadata"); 
     1438        if (captureMetadataOperation != null) { 
     1439            for (int i = 0, n = remoteTypes.size(); i < n; i++) { 
     1440                RemoteType candidateType = remoteTypes.get(i); 
     1441                if (IsSupportedMetadataCaptureType(candidateType) || appendMetadataSupported(type, candidateType)) { 
     1442                    updateConversionRating(ratings.cachedConversionRatings, candidateType.getHandle(), Definitions.TypeConversionRating.METADATA_OPERATION); 
     1443                } 
     1444            } 
     1445        } 
     1446 
    14611447 
    14621448        // Replace result if it has not changed 
     
    14741460     */ 
    14751461    private static boolean isSingleOperationRating(byte rating) { 
    1476         return rating == Definitions.TypeConversionRating.IMPLICIT_CAST.ordinal() || rating == Definitions.TypeConversionRating.EXPLICIT_CONVERSION.ordinal() || rating == Definitions.TypeConversionRating.EXPLICIT_CONVERSION_FROM_GENERIC_TYPE.ordinal() || rating == Definitions.TypeConversionRating.EXPLICIT_CONVERSION_TO_GENERIC_TYPE.ordinal(); 
     1462        return rating == Definitions.TypeConversionRating.IMPLICIT_CAST.ordinal() || rating == Definitions.TypeConversionRating.EXPLICIT_CONVERSION.ordinal() || rating == Definitions.TypeConversionRating.EXPLICIT_CONVERSION_FROM_GENERIC_TYPE.ordinal() || rating == Definitions.TypeConversionRating.EXPLICIT_CONVERSION_TO_GENERIC_TYPE.ordinal() || rating == Definitions.TypeConversionRating.METADATA_OPERATION.ordinal(); 
    14771463    } 
    14781464 
Note: See TracChangeset for help on using the changeset viewer.