All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jruby.truffle.stdlib.digest.DigestLayoutImpl Maven / Gradle / Ivy

The newest version!
package org.jruby.truffle.stdlib.digest;

import java.util.EnumSet;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.dsl.GeneratedBy;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.object.DynamicObjectFactory;
import com.oracle.truffle.api.object.HiddenKey;
import com.oracle.truffle.api.object.LocationModifier;
import com.oracle.truffle.api.object.ObjectType;
import com.oracle.truffle.api.object.Property;
import com.oracle.truffle.api.object.Shape;
import org.jruby.truffle.stdlib.digest.DigestLayout;
import org.jruby.truffle.core.basicobject.BasicObjectLayoutImpl;

@GeneratedBy(org.jruby.truffle.stdlib.digest.DigestLayout.class)
public class DigestLayoutImpl extends BasicObjectLayoutImpl implements DigestLayout {
    
    public static final DigestLayout INSTANCE = new DigestLayoutImpl();
    
    public static class DigestType extends BasicObjectLayoutImpl.BasicObjectType {
        
        public DigestType(
                com.oracle.truffle.api.object.DynamicObject logicalClass,
                com.oracle.truffle.api.object.DynamicObject metaClass) {
            super(
                logicalClass,
                metaClass);
        }
        
        @Override
        public DigestType setLogicalClass(com.oracle.truffle.api.object.DynamicObject logicalClass) {
            return new DigestType(
                logicalClass,
                metaClass);
        }
        
        @Override
        public DigestType setMetaClass(com.oracle.truffle.api.object.DynamicObject metaClass) {
            return new DigestType(
                logicalClass,
                metaClass);
        }
        
    }
    
    protected static final Shape.Allocator DIGEST_ALLOCATOR = LAYOUT.createAllocator();
    
    protected static final HiddenKey ALGORITHM_IDENTIFIER = new HiddenKey("algorithm");
    protected static final Property ALGORITHM_PROPERTY = Property.create(ALGORITHM_IDENTIFIER, DIGEST_ALLOCATOR.locationForType(org.jruby.truffle.stdlib.digest.DigestAlgorithm.class, EnumSet.of(LocationModifier.NonNull, LocationModifier.Final)), 0);
    
    protected static final HiddenKey DIGEST_IDENTIFIER = new HiddenKey("digest");
    protected static final Property DIGEST_PROPERTY = Property.create(DIGEST_IDENTIFIER, DIGEST_ALLOCATOR.locationForType(java.security.MessageDigest.class, EnumSet.of(LocationModifier.NonNull, LocationModifier.Final)), 0);
    
    protected DigestLayoutImpl() {
    }
    
    @Override
    public DynamicObjectFactory createDigestShape(
            com.oracle.truffle.api.object.DynamicObject logicalClass,
            com.oracle.truffle.api.object.DynamicObject metaClass) {
        return LAYOUT.createShape(new DigestType(
                logicalClass,
                metaClass))
            .addProperty(ALGORITHM_PROPERTY)
            .addProperty(DIGEST_PROPERTY)
            .createFactory();
    }
    
    @Override
    public DynamicObject createDigest(
            DynamicObjectFactory factory,
            org.jruby.truffle.stdlib.digest.DigestAlgorithm algorithm,
            java.security.MessageDigest digest) {
        assert factory != null;
        CompilerAsserts.partialEvaluationConstant(factory);
        assert createsDigest(factory);
        assert factory.getShape().hasProperty(ALGORITHM_IDENTIFIER);
        assert factory.getShape().hasProperty(DIGEST_IDENTIFIER);
        assert algorithm != null;
        assert digest != null;
        return factory.newInstance(
            algorithm,
            digest);
    }
    
    private static boolean isDigest(DynamicObject object) {
        return isDigest(object.getShape().getObjectType());
    }
    
    private static boolean isDigest(ObjectType objectType) {
        return objectType instanceof DigestType;
    }
    
    private static boolean createsDigest(DynamicObjectFactory factory) {
        return isDigest(factory.getShape().getObjectType());
    }
    
    @Override
    public org.jruby.truffle.stdlib.digest.DigestAlgorithm getAlgorithm(DynamicObject object) {
        assert isDigest(object);
        assert object.getShape().hasProperty(ALGORITHM_IDENTIFIER);
        
        return (org.jruby.truffle.stdlib.digest.DigestAlgorithm) ALGORITHM_PROPERTY.get(object, isDigest(object));
    }
    
    @Override
    public java.security.MessageDigest getDigest(DynamicObject object) {
        assert isDigest(object);
        assert object.getShape().hasProperty(DIGEST_IDENTIFIER);
        
        return (java.security.MessageDigest) DIGEST_PROPERTY.get(object, isDigest(object));
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy