< prev index next >

test/testlibrary/jittester/src/jdk/test/lib/jittester/factories/UnaryOperatorFactory.java

Print this page




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package jdk.test.lib.jittester.factories;
  25 
  26 import jdk.test.lib.jittester.IRNode;
  27 import jdk.test.lib.jittester.OperatorKind;
  28 import jdk.test.lib.jittester.ProductionFailedException;
  29 import jdk.test.lib.jittester.SymbolTable;
  30 import jdk.test.lib.jittester.Type;

  31 
  32 public abstract class UnaryOperatorFactory extends OperatorFactory {
  33     protected final OperatorKind opKind;
  34     protected final Type resultType;
  35     protected final Type ownerClass;
  36 
  37     protected UnaryOperatorFactory(OperatorKind opKind, long complexityLimit, int operatorLimit,
  38             Type ownerClass, Type resultType, boolean exceptionSafe, boolean noconsts) {
  39         super(opKind.priority, complexityLimit, operatorLimit, exceptionSafe, noconsts);
  40         this.opKind = opKind;
  41         this.resultType = resultType;
  42         this.ownerClass = ownerClass;
  43     }
  44 
  45     protected Type generateType() throws ProductionFailedException {
  46         return resultType;
  47     }
  48 
  49     protected abstract IRNode generateProduction(Type type) throws ProductionFailedException;
  50 
  51     protected abstract boolean isApplicable(Type resultType);
  52 
  53     @Override
  54     public IRNode produce() throws ProductionFailedException {
  55         if (!isApplicable(resultType)) {
  56             //avoid implicit use of resultType.toString()
  57             throw new ProductionFailedException("Type " + resultType.getName()
  58                     + " is not applicable by " + getClass().getName());
  59         }
  60         Type type;
  61         try {
  62             type = generateType();
  63         } catch (Exception ex) {
  64             throw new ProductionFailedException(ex.getMessage());
  65         }
  66         try {
  67             SymbolTable.push();
  68             IRNode result = generateProduction(type);
  69             SymbolTable.merge();
  70             return result;
  71         } catch (ProductionFailedException e) {
  72             SymbolTable.pop();
  73             throw e;
  74         }
  75     }
  76 }


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package jdk.test.lib.jittester.factories;
  25 

  26 import jdk.test.lib.jittester.OperatorKind;
  27 import jdk.test.lib.jittester.ProductionFailedException;
  28 import jdk.test.lib.jittester.SymbolTable;
  29 import jdk.test.lib.jittester.Type;
  30 import jdk.test.lib.jittester.UnaryOperator;
  31 
  32 public abstract class UnaryOperatorFactory extends OperatorFactory<UnaryOperator> {
  33     protected final OperatorKind opKind;
  34     protected final Type resultType;
  35     protected final Type ownerClass;
  36 
  37     protected UnaryOperatorFactory(OperatorKind opKind, long complexityLimit, int operatorLimit,
  38             Type ownerClass, Type resultType, boolean exceptionSafe, boolean noconsts) {
  39         super(opKind.priority, complexityLimit, operatorLimit, exceptionSafe, noconsts);
  40         this.opKind = opKind;
  41         this.resultType = resultType;
  42         this.ownerClass = ownerClass;
  43     }
  44 
  45     protected Type generateType() {
  46         return resultType;
  47     }
  48 
  49     protected abstract UnaryOperator generateProduction(Type type) throws ProductionFailedException;
  50 
  51     protected abstract boolean isApplicable(Type resultType);
  52 
  53     @Override
  54     public UnaryOperator produce() throws ProductionFailedException {
  55         if (!isApplicable(resultType)) {
  56             //avoid implicit use of resultType.toString()
  57             throw new ProductionFailedException("Type " + resultType.getName()
  58                     + " is not applicable by " + getClass().getName());
  59         }
  60         Type type;
  61         try {
  62             type = generateType();
  63         } catch (Exception ex) {
  64             throw new ProductionFailedException(ex.getMessage());
  65         }
  66         try {
  67             SymbolTable.push();
  68             UnaryOperator result = generateProduction(type);
  69             SymbolTable.merge();
  70             return result;
  71         } catch (ProductionFailedException e) {
  72             SymbolTable.pop();
  73             throw e;
  74         }
  75     }
  76 }
< prev index next >