author | joehw |
Sun, 13 Aug 2017 21:10:40 -0700 | |
changeset 46174 | 5611d2529b49 |
parent 44797 | 8b3b3b911b8a |
permissions | -rw-r--r-- |
6 | 1 |
/* |
2 |
* reserved comment block |
|
3 |
* DO NOT REMOVE OR ALTER! |
|
4 |
*/ |
|
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
5 |
/* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
6 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
7 |
* contributor license agreements. See the NOTICE file distributed with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
8 |
* this work for additional information regarding copyright ownership. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
9 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
10 |
* (the "License"); you may not use this file except in compliance with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
11 |
* the License. You may obtain a copy of the License at |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
12 |
* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
13 |
* http://www.apache.org/licenses/LICENSE-2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
14 |
* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
15 |
* Unless required by applicable law or agreed to in writing, software |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
16 |
* distributed under the License is distributed on an "AS IS" BASIS, |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
17 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
18 |
* See the License for the specific language governing permissions and |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
19 |
* limitations under the License. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
20 |
*/ |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
21 |
|
6 | 22 |
package com.sun.org.apache.bcel.internal.classfile; |
23 |
||
46174 | 24 |
import java.io.DataInput; |
25 |
import java.io.DataOutputStream; |
|
26 |
import java.io.IOException; |
|
6 | 27 |
|
28 |
/** |
|
29 |
* This class represents a (PC offset, line number) pair, i.e., a line number in |
|
30 |
* the source that corresponds to a relative address in the byte code. This |
|
31 |
* is used for debugging purposes. |
|
32 |
* |
|
46174 | 33 |
* @version $Id: LineNumber.java 1749603 2016-06-21 20:50:19Z ggregory $ |
6 | 34 |
* @see LineNumberTable |
35 |
*/ |
|
46174 | 36 |
public final class LineNumber implements Cloneable, Node { |
37 |
||
38 |
/** Program Counter (PC) corresponds to line */ |
|
39 |
private short start_pc; |
|
40 |
||
41 |
/** number in source file */ |
|
42 |
private short line_number; |
|
6 | 43 |
|
46174 | 44 |
/** |
45 |
* Initialize from another object. |
|
46 |
* |
|
47 |
* @param c the object to copy |
|
48 |
*/ |
|
49 |
public LineNumber(final LineNumber c) { |
|
50 |
this(c.getStartPC(), c.getLineNumber()); |
|
51 |
} |
|
6 | 52 |
|
53 |
||
46174 | 54 |
/** |
55 |
* Construct object from file stream. |
|
56 |
* |
|
57 |
* @param file Input stream |
|
58 |
* @throws IOEXception if an I/O Exception occurs in readUnsignedShort |
|
59 |
*/ |
|
60 |
LineNumber(final DataInput file) throws IOException { |
|
61 |
this(file.readUnsignedShort(), file.readUnsignedShort()); |
|
62 |
} |
|
63 |
||
6 | 64 |
|
46174 | 65 |
/** |
66 |
* @param start_pc Program Counter (PC) corresponds to |
|
67 |
* @param line_number line number in source file |
|
68 |
*/ |
|
69 |
public LineNumber(final int start_pc, final int line_number) { |
|
70 |
this.start_pc = (short) start_pc; |
|
71 |
this.line_number = (short)line_number; |
|
72 |
} |
|
73 |
||
74 |
||
75 |
/** |
|
76 |
* Called by objects that are traversing the nodes of the tree implicitely |
|
77 |
* defined by the contents of a Java class. I.e., the hierarchy of methods, |
|
78 |
* fields, attributes, etc. spawns a tree of objects. |
|
79 |
* |
|
80 |
* @param v Visitor object |
|
81 |
*/ |
|
82 |
@Override |
|
83 |
public void accept( final Visitor v ) { |
|
84 |
v.visitLineNumber(this); |
|
85 |
} |
|
86 |
||
6 | 87 |
|
46174 | 88 |
/** |
89 |
* Dump line number/pc pair to file stream in binary format. |
|
90 |
* |
|
91 |
* @param file Output file stream |
|
92 |
* @throws IOEXception if an I/O Exception occurs in writeShort |
|
93 |
*/ |
|
94 |
public final void dump( final DataOutputStream file ) throws IOException { |
|
95 |
file.writeShort(start_pc); |
|
96 |
file.writeShort(line_number); |
|
97 |
} |
|
98 |
||
6 | 99 |
|
46174 | 100 |
/** |
101 |
* @return Corresponding source line |
|
102 |
*/ |
|
103 |
public final int getLineNumber() { |
|
104 |
return 0xffff & line_number; |
|
105 |
} |
|
106 |
||
6 | 107 |
|
46174 | 108 |
/** |
109 |
* @return PC in code |
|
110 |
*/ |
|
111 |
public final int getStartPC() { |
|
112 |
return 0xffff & start_pc; |
|
113 |
} |
|
114 |
||
6 | 115 |
|
46174 | 116 |
/** |
117 |
* @param line_number the source line number |
|
118 |
*/ |
|
119 |
public final void setLineNumber( final int line_number ) { |
|
120 |
this.line_number = (short) line_number; |
|
121 |
} |
|
122 |
||
6 | 123 |
|
46174 | 124 |
/** |
125 |
* @param start_pc the pc for this line number |
|
126 |
*/ |
|
127 |
public final void setStartPC( final int start_pc ) { |
|
128 |
this.start_pc = (short) start_pc; |
|
129 |
} |
|
130 |
||
6 | 131 |
|
46174 | 132 |
/** |
133 |
* @return String representation |
|
134 |
*/ |
|
135 |
@Override |
|
136 |
public final String toString() { |
|
137 |
return "LineNumber(" + start_pc + ", " + line_number + ")"; |
|
138 |
} |
|
139 |
||
6 | 140 |
|
46174 | 141 |
/** |
142 |
* @return deep copy of this object |
|
143 |
*/ |
|
144 |
public LineNumber copy() { |
|
145 |
try { |
|
146 |
return (LineNumber) clone(); |
|
147 |
} catch (final CloneNotSupportedException e) { |
|
148 |
// TODO should this throw? |
|
149 |
} |
|
150 |
return null; |
|
151 |
} |
|
6 | 152 |
} |