Coverage Report - org.apache.commons.nabla.automatic.instructions.NarrowingTransformer
 
Classes in this File Line Coverage Branch Coverage Complexity
NarrowingTransformer
100%
8/8
N/A
1
NarrowingTransformer$1
N/A
N/A
1
NarrowingTransformer$LazyHolder
100%
2/2
N/A
1
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.commons.nabla.automatic.instructions;
 18  
 
 19  
 import org.apache.commons.nabla.automatic.analysis.InstructionsTransformer;
 20  
 import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
 21  
 import org.apache.commons.nabla.core.DifferentiationException;
 22  
 import org.objectweb.asm.Opcodes;
 23  
 import org.objectweb.asm.tree.AbstractInsnNode;
 24  
 import org.objectweb.asm.tree.InsnList;
 25  
 import org.objectweb.asm.tree.InsnNode;
 26  
 
 27  
 /** Differentiation transformer for narrowing a differential part on the stack
 28  
  * to a double.
 29  
  * <p>Some instructions (D2I, D2L, D2F, POP2) may handle differential pair
 30  
  * on the stack by simply popping the differential part out before being
 31  
  * applied.</p>
 32  
  */
 33  1
 public class NarrowingTransformer implements InstructionsTransformer {
 34  
 
 35  
     /** Holder for the singleton instance.*/
 36  1
     private static class LazyHolder  {
 37  
         /** The singleton instance. */
 38  1
         private static final InstructionsTransformer INSTANCE = new NarrowingTransformer();
 39  
     }
 40  
 
 41  
     /** Hidden constructor.
 42  
      */
 43  1
     private NarrowingTransformer() {
 44  1
     }
 45  
 
 46  
     /** Get the singleton instance.
 47  
      * <p>We use here the Initialization on Demand Holder idiom.</p>
 48  
      * @return the singleton instance
 49  
      */
 50  
     public static InstructionsTransformer getInstance() {
 51  1
         return LazyHolder.INSTANCE;
 52  
     }
 53  
 
 54  
     /** {@inheritDoc} */
 55  
     public InsnList getReplacement(final AbstractInsnNode insn,
 56  
                                    final MethodDifferentiator methodDifferentiator)
 57  
         throws DifferentiationException {
 58  1
         final InsnList list = new InsnList();
 59  1
         list.add(new InsnNode(Opcodes.POP2));
 60  1
         list.add(methodDifferentiator.clone(insn));
 61  1
         return list;
 62  
     }
 63  
 
 64  
 }