• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2013, Google LLC
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google LLC nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 package com.android.tools.smali.dexlib2.builder;
32 
33 import com.android.tools.smali.dexlib2.builder.debug.BuilderEndLocal;
34 import com.android.tools.smali.dexlib2.builder.debug.BuilderEpilogueBegin;
35 import com.android.tools.smali.dexlib2.builder.debug.BuilderLineNumber;
36 import com.android.tools.smali.dexlib2.builder.debug.BuilderPrologueEnd;
37 import com.android.tools.smali.dexlib2.builder.debug.BuilderRestartLocal;
38 import com.android.tools.smali.dexlib2.builder.debug.BuilderSetSourceFile;
39 import com.android.tools.smali.dexlib2.builder.debug.BuilderStartLocal;
40 import com.android.tools.smali.dexlib2.iface.instruction.Instruction;
41 import com.android.tools.smali.dexlib2.iface.reference.StringReference;
42 import com.android.tools.smali.dexlib2.iface.reference.TypeReference;
43 
44 import java.util.Set;
45 import javax.annotation.Nonnull;
46 import javax.annotation.Nullable;
47 
48 public class MethodLocation {
49     @Nullable BuilderInstruction instruction;
50     int codeAddress;
51     int index;
52 
53     private final LocatedItems<Label> labels;
54     private final LocatedItems<BuilderDebugItem> debugItems;
55 
MethodLocation(@ullable BuilderInstruction instruction, int codeAddress, int index)56     MethodLocation(@Nullable BuilderInstruction instruction, int codeAddress, int index) {
57         this.debugItems = new LocatedDebugItems();
58         this.labels = new LocatedLabels();
59         this.instruction = instruction;
60         this.codeAddress = codeAddress;
61         this.index = index;
62     }
63 
64     @Nullable
getInstruction()65     public Instruction getInstruction() {
66         return instruction;
67     }
68 
getCodeAddress()69     public int getCodeAddress() {
70         return codeAddress;
71     }
72 
getIndex()73     public int getIndex() {
74         return index;
75     }
76 
mergeInto(@onnull MethodLocation nextLocation)77     void mergeInto(@Nonnull MethodLocation nextLocation) {
78         labels.mergeItemsIntoNext(nextLocation, nextLocation.labels);
79         debugItems.mergeItemsIntoNext(nextLocation, nextLocation.debugItems);
80     }
81 
82     @Nonnull
getLabels()83     public Set<Label> getLabels() {
84         return labels.getModifiableItems(MethodLocation.this);
85     }
86 
87     @Nonnull
addNewLabel()88     public Label addNewLabel() {
89         Label newLabel = new Label();
90         getLabels().add(newLabel);
91         return newLabel;
92     }
93 
94     @Nonnull
getDebugItems()95     public Set<BuilderDebugItem> getDebugItems() {
96         return debugItems.getModifiableItems(MethodLocation.this);
97     }
98 
addLineNumber(int lineNumber)99     public void addLineNumber(int lineNumber) {
100         getDebugItems().add(new BuilderLineNumber(lineNumber));
101     }
102 
addStartLocal(int registerNumber, @Nullable StringReference name, @Nullable TypeReference type, @Nullable StringReference signature)103     public void addStartLocal(int registerNumber, @Nullable StringReference name, @Nullable TypeReference type,
104                               @Nullable StringReference signature) {
105         getDebugItems().add(new BuilderStartLocal(registerNumber, name, type, signature));
106     }
107 
addEndLocal(int registerNumber)108     public void addEndLocal(int registerNumber) {
109         getDebugItems().add(new BuilderEndLocal(registerNumber));
110     }
111 
addRestartLocal(int registerNumber)112     public void addRestartLocal(int registerNumber) {
113         getDebugItems().add(new BuilderRestartLocal(registerNumber));
114     }
115 
addPrologue()116     public void addPrologue() {
117         getDebugItems().add(new BuilderPrologueEnd());
118     }
119 
addEpilogue()120     public void addEpilogue() {
121         getDebugItems().add(new BuilderEpilogueBegin());
122     }
123 
addSetSourceFile(@ullable StringReference sourceFile)124     public void addSetSourceFile(@Nullable StringReference sourceFile) {
125         getDebugItems().add(new BuilderSetSourceFile(sourceFile));
126     }
127 }
128