Home | History | Annotate | Download | only in code
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.dx.rop.code;
     18 
     19 import com.android.dx.rop.cst.Constant;
     20 import com.android.dx.rop.type.StdTypeList;
     21 import com.android.dx.rop.type.Type;
     22 import com.android.dx.rop.type.TypeList;
     23 
     24 /**
     25  * Instruction which contains an explicit reference to a constant
     26  * but which cannot throw an exception.
     27  */
     28 public final class PlainCstInsn
     29         extends CstInsn {
     30     /**
     31      * Constructs an instance.
     32      *
     33      * @param opcode {@code non-null;} the opcode
     34      * @param position {@code non-null;} source position
     35      * @param result {@code null-ok;} spec for the result, if any
     36      * @param sources {@code non-null;} specs for all the sources
     37      * @param cst {@code non-null;} the constant
     38      */
     39     public PlainCstInsn(Rop opcode, SourcePosition position,
     40                         RegisterSpec result, RegisterSpecList sources,
     41                         Constant cst) {
     42         super(opcode, position, result, sources, cst);
     43 
     44         if (opcode.getBranchingness() != Rop.BRANCH_NONE) {
     45             throw new IllegalArgumentException("bogus branchingness");
     46         }
     47     }
     48 
     49     /** {@inheritDoc} */
     50     @Override
     51     public TypeList getCatches() {
     52         return StdTypeList.EMPTY;
     53     }
     54 
     55     /** {@inheritDoc} */
     56     @Override
     57     public void accept(Visitor visitor) {
     58         visitor.visitPlainCstInsn(this);
     59     }
     60 
     61     /** {@inheritDoc} */
     62     @Override
     63     public Insn withAddedCatch(Type type) {
     64         throw new UnsupportedOperationException("unsupported");
     65     }
     66 
     67     /** {@inheritDoc} */
     68     @Override
     69     public Insn withRegisterOffset(int delta) {
     70         return new PlainCstInsn(getOpcode(), getPosition(),
     71                                 getResult().withOffset(delta),
     72                                 getSources().withOffset(delta),
     73                                 getConstant());
     74     }
     75 
     76     /** {@inheritDoc} */
     77     @Override
     78     public Insn withNewRegisters(RegisterSpec result,
     79             RegisterSpecList sources) {
     80 
     81         return new PlainCstInsn(getOpcode(), getPosition(),
     82                                 result,
     83                                 sources,
     84                                 getConstant());
     85 
     86     }
     87 }
     88