Home | History | Annotate | Download | only in code
      1 /*
      2  * Copyright (C) 2009 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.dexgen.dex.code;
     18 
     19 import com.android.dexgen.rop.code.RegisterSpec;
     20 import com.android.dexgen.rop.code.RegisterSpecList;
     21 import com.android.dexgen.rop.code.SourcePosition;
     22 
     23 /**
     24  * Pseudo-instruction which is used to explicitly end the mapping of a
     25  * register to a named local variable. That is, an instance of this
     26  * class in an instruction stream indicates that starting with the
     27  * subsequent instruction, the indicated variable is no longer valid.
     28  */
     29 public final class LocalEnd extends ZeroSizeInsn {
     30     /**
     31      * {@code non-null;} register spec representing the local variable ended
     32      * by this instance. <b>Note:</b> Technically, only the register
     33      * number needs to be recorded here as the rest of the information
     34      * is implicit in the ambient local variable state, but other code
     35      * will check the other info for consistency.
     36      */
     37     private final RegisterSpec local;
     38 
     39     /**
     40      * Constructs an instance. The output address of this instance is initially
     41      * unknown ({@code -1}).
     42      *
     43      * @param position {@code non-null;} source position
     44      * @param local {@code non-null;} register spec representing the local
     45      * variable introduced by this instance
     46      */
     47     public LocalEnd(SourcePosition position, RegisterSpec local) {
     48         super(position);
     49 
     50         if (local == null) {
     51             throw new NullPointerException("local == null");
     52         }
     53 
     54         this.local = local;
     55     }
     56 
     57     /** {@inheritDoc} */
     58     @Override
     59     public DalvInsn withRegisterOffset(int delta) {
     60         return new LocalEnd(getPosition(), local.withOffset(delta));
     61     }
     62 
     63     /** {@inheritDoc} */
     64     @Override
     65     public DalvInsn withRegisters(RegisterSpecList registers) {
     66         return new LocalEnd(getPosition(), local);
     67     }
     68 
     69     /**
     70      * Gets the register spec representing the local variable ended
     71      * by this instance.
     72      *
     73      * @return {@code non-null;} the register spec
     74      */
     75     public RegisterSpec getLocal() {
     76         return local;
     77     }
     78 
     79     /** {@inheritDoc} */
     80     @Override
     81     protected String argString() {
     82         return local.toString();
     83     }
     84 
     85     /** {@inheritDoc} */
     86     @Override
     87     protected String listingString0(boolean noteIndices) {
     88         return "local-end " + LocalStart.localString(local);
     89     }
     90 }
     91