< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/util/IntType.java

Print this page


   1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
  23 
  24 import com.sun.org.apache.bcel.internal.generic.BranchHandle;
  25 import com.sun.org.apache.bcel.internal.generic.BranchInstruction;
  26 import com.sun.org.apache.bcel.internal.generic.CHECKCAST;
  27 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
  28 import com.sun.org.apache.bcel.internal.generic.GOTO;
  29 import com.sun.org.apache.bcel.internal.generic.IFEQ;
  30 import com.sun.org.apache.bcel.internal.generic.IFGE;
  31 import com.sun.org.apache.bcel.internal.generic.IFGT;
  32 import com.sun.org.apache.bcel.internal.generic.IFLE;
  33 import com.sun.org.apache.bcel.internal.generic.IFLT;
  34 import com.sun.org.apache.bcel.internal.generic.IF_ICMPGE;
  35 import com.sun.org.apache.bcel.internal.generic.IF_ICMPGT;
  36 import com.sun.org.apache.bcel.internal.generic.IF_ICMPLE;
  37 import com.sun.org.apache.bcel.internal.generic.IF_ICMPLT;
  38 import com.sun.org.apache.bcel.internal.generic.ILOAD;
  39 import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
  40 import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
  41 import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
  42 import com.sun.org.apache.bcel.internal.generic.ISTORE;
  43 import com.sun.org.apache.bcel.internal.generic.Instruction;
  44 import com.sun.org.apache.bcel.internal.generic.InstructionConstants;
  45 import com.sun.org.apache.bcel.internal.generic.InstructionList;
  46 import com.sun.org.apache.bcel.internal.generic.NEW;
  47 import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants;
  48 import com.sun.org.apache.xalan.internal.xsltc.compiler.FlowList;
  49 
  50 /**
  51  * @author Jacek Ambroziak
  52  * @author Santiago Pericas-Geertsen
  53  */
  54 public final class IntType extends NumberType {
  55     protected IntType() {}
  56 
  57     public String toString() {
  58         return "int";
  59     }
  60 
  61     public boolean identicalTo(Type other) {
  62         return this == other;
  63     }
  64 


 230     public void translateBox(ClassGenerator classGen,
 231                              MethodGenerator methodGen) {
 232         translateTo(classGen, methodGen, Type.Reference);
 233     }
 234 
 235     /**
 236      * Translates an object of this type to its unboxed representation.
 237      */
 238     public void translateUnBox(ClassGenerator classGen,
 239                                MethodGenerator methodGen) {
 240         final ConstantPoolGen cpg = classGen.getConstantPool();
 241         final InstructionList il = methodGen.getInstructionList();
 242         il.append(new CHECKCAST(cpg.addClass(INTEGER_CLASS)));
 243         final int index = cpg.addMethodref(INTEGER_CLASS,
 244                                            INT_VALUE,
 245                                            INT_VALUE_SIG);
 246         il.append(new INVOKEVIRTUAL(index));
 247     }
 248 
 249     public Instruction ADD() {
 250         return InstructionConstants.IADD;
 251     }
 252 
 253     public Instruction SUB() {
 254         return InstructionConstants.ISUB;
 255     }
 256 
 257     public Instruction MUL() {
 258         return InstructionConstants.IMUL;
 259     }
 260 
 261     public Instruction DIV() {
 262         return InstructionConstants.IDIV;
 263     }
 264 
 265     public Instruction REM() {
 266         return InstructionConstants.IREM;
 267     }
 268 
 269     public Instruction NEG() {
 270         return InstructionConstants.INEG;
 271     }
 272 
 273     public Instruction LOAD(int slot) {
 274         return new ILOAD(slot);
 275     }
 276 
 277     public Instruction STORE(int slot) {
 278         return new ISTORE(slot);
 279     }
 280 
 281     public BranchInstruction GT(boolean tozero) {
 282         return tozero ? (BranchInstruction) new IFGT(null) :
 283             (BranchInstruction) new IF_ICMPGT(null);
 284     }
 285 
 286     public BranchInstruction GE(boolean tozero) {
 287         return tozero ? (BranchInstruction) new IFGE(null) :
 288             (BranchInstruction) new IF_ICMPGE(null);
 289     }
 290 
   1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.

   3  */
   4 /*
   5  * Licensed to the Apache Software Foundation (ASF) under one or more
   6  * contributor license agreements.  See the NOTICE file distributed with
   7  * this work for additional information regarding copyright ownership.
   8  * The ASF licenses this file to You under the Apache License, Version 2.0
   9  * (the "License"); you may not use this file except in compliance with
  10  * the License.  You may obtain a copy of the License at
  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 
  21 package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
  22 
  23 import com.sun.org.apache.bcel.internal.generic.BranchHandle;
  24 import com.sun.org.apache.bcel.internal.generic.BranchInstruction;
  25 import com.sun.org.apache.bcel.internal.generic.CHECKCAST;
  26 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
  27 import com.sun.org.apache.bcel.internal.generic.GOTO;
  28 import com.sun.org.apache.bcel.internal.generic.IFEQ;
  29 import com.sun.org.apache.bcel.internal.generic.IFGE;
  30 import com.sun.org.apache.bcel.internal.generic.IFGT;
  31 import com.sun.org.apache.bcel.internal.generic.IFLE;
  32 import com.sun.org.apache.bcel.internal.generic.IFLT;
  33 import com.sun.org.apache.bcel.internal.generic.IF_ICMPGE;
  34 import com.sun.org.apache.bcel.internal.generic.IF_ICMPGT;
  35 import com.sun.org.apache.bcel.internal.generic.IF_ICMPLE;
  36 import com.sun.org.apache.bcel.internal.generic.IF_ICMPLT;
  37 import com.sun.org.apache.bcel.internal.generic.ILOAD;
  38 import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
  39 import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
  40 import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
  41 import com.sun.org.apache.bcel.internal.generic.ISTORE;
  42 import com.sun.org.apache.bcel.internal.generic.Instruction;
  43 import com.sun.org.apache.bcel.internal.generic.InstructionConst;
  44 import com.sun.org.apache.bcel.internal.generic.InstructionList;
  45 import com.sun.org.apache.bcel.internal.generic.NEW;
  46 import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants;
  47 import com.sun.org.apache.xalan.internal.xsltc.compiler.FlowList;
  48 
  49 /**
  50  * @author Jacek Ambroziak
  51  * @author Santiago Pericas-Geertsen
  52  */
  53 public final class IntType extends NumberType {
  54     protected IntType() {}
  55 
  56     public String toString() {
  57         return "int";
  58     }
  59 
  60     public boolean identicalTo(Type other) {
  61         return this == other;
  62     }
  63 


 229     public void translateBox(ClassGenerator classGen,
 230                              MethodGenerator methodGen) {
 231         translateTo(classGen, methodGen, Type.Reference);
 232     }
 233 
 234     /**
 235      * Translates an object of this type to its unboxed representation.
 236      */
 237     public void translateUnBox(ClassGenerator classGen,
 238                                MethodGenerator methodGen) {
 239         final ConstantPoolGen cpg = classGen.getConstantPool();
 240         final InstructionList il = methodGen.getInstructionList();
 241         il.append(new CHECKCAST(cpg.addClass(INTEGER_CLASS)));
 242         final int index = cpg.addMethodref(INTEGER_CLASS,
 243                                            INT_VALUE,
 244                                            INT_VALUE_SIG);
 245         il.append(new INVOKEVIRTUAL(index));
 246     }
 247 
 248     public Instruction ADD() {
 249         return InstructionConst.IADD;
 250     }
 251 
 252     public Instruction SUB() {
 253         return InstructionConst.ISUB;
 254     }
 255 
 256     public Instruction MUL() {
 257         return InstructionConst.IMUL;
 258     }
 259 
 260     public Instruction DIV() {
 261         return InstructionConst.IDIV;
 262     }
 263 
 264     public Instruction REM() {
 265         return InstructionConst.IREM;
 266     }
 267 
 268     public Instruction NEG() {
 269         return InstructionConst.INEG;
 270     }
 271 
 272     public Instruction LOAD(int slot) {
 273         return new ILOAD(slot);
 274     }
 275 
 276     public Instruction STORE(int slot) {
 277         return new ISTORE(slot);
 278     }
 279 
 280     public BranchInstruction GT(boolean tozero) {
 281         return tozero ? (BranchInstruction) new IFGT(null) :
 282             (BranchInstruction) new IF_ICMPGT(null);
 283     }
 284 
 285     public BranchInstruction GE(boolean tozero) {
 286         return tozero ? (BranchInstruction) new IFGE(null) :
 287             (BranchInstruction) new IF_ICMPGE(null);
 288     }
 289 
< prev index next >